/******************************************************************************/
/****              Generated by IBExpert 1/28/2017 7:22:10 PM              ****/
/******************************************************************************/

/******************************************************************************/
/****     Following SET SQL DIALECT is just for the Database Comparer      ****/
/******************************************************************************/
SET SQL DIALECT 3;



/******************************************************************************/
/****                                Tables                                ****/
/******************************************************************************/


CREATE GENERATOR GEN_USER_DEVICES_ID;

CREATE TABLE USER_DEVICES (
    ID          INTEGER NOT NULL,
    USER_ID     INTEGER NOT NULL,
    DEVICE_ID   VARCHAR(255) NOT NULL,
    PLATFORM    VARCHAR(255),
    CREATED_AT  TIMESTAMP NOT NULL,
    UPDATED_AT  TIMESTAMP NOT NULL,
    DELETED_AT  TIMESTAMP
);




/******************************************************************************/
/****                             Primary keys                             ****/
/******************************************************************************/

ALTER TABLE USER_DEVICES ADD CONSTRAINT PK_USER_DEVICES PRIMARY KEY (ID);


/******************************************************************************/
/****                             Foreign keys                             ****/
/******************************************************************************/

ALTER TABLE USER_DEVICES ADD CONSTRAINT FK_USER_DEVICES_1 FOREIGN KEY (USER_ID) REFERENCES TBLKOMITENTI (SIFRA_KOMITENTA) ON DELETE CASCADE;


/******************************************************************************/
/****                               Triggers                               ****/
/******************************************************************************/



SET TERM ^ ;



/******************************************************************************/
/****                         Triggers for tables                          ****/
/******************************************************************************/



/* Trigger: USER_DEVICES_BI */
CREATE OR ALTER TRIGGER USER_DEVICES_BI FOR USER_DEVICES
ACTIVE BEFORE INSERT POSITION 0
as
begin
  if (new.id is null) then
    new.id = gen_id(gen_user_devices_id,1);
end
^

SET TERM ; ^



/******************************************************************************/
/****                              Privileges                              ****/
/******************************************************************************/
