CREATE TABLE UM_TENANT(
    UM_ID DECIMAL(31,0) NOT NULL,
    UM_DOMAIN_NAME VARCHAR(255) NOT NULL,
    UM_EMAIL VARCHAR(255),
    UM_ACTIVE SMALLINT DEFAULT 0,
    UM_CREATED_DATE TIMESTAMP NOT NULL,
    UM_USER_CONFIG BLOB(2G) NOT LOGGED,
    PRIMARY KEY(UM_ID),
    UNIQUE(UM_DOMAIN_NAME)
)/

CREATE UNIQUE INDEX INDEX_UM_TENANT_UM_DOMAIN_NAME
                    ON UM_TENANT (UM_DOMAIN_NAME)/

CREATE SEQUENCE UM_TENANT_SEQUENCE AS DECIMAL(27,0)
    INCREMENT BY 1
    START WITH 1
    NO CACHE/

CREATE TRIGGER UM_TENANT_TRIGGER NO CASCADE BEFORE INSERT ON UM_TENANT
REFERENCING NEW AS NEW FOR EACH ROW MODE DB2SQL 

BEGIN ATOMIC
    
    SET (NEW.UM_ID)
       = (NEXTVAL FOR UM_TENANT_SEQUENCE);

END/

CREATE TABLE UM_DOMAIN(
            UM_DOMAIN_ID DECIMAL(31,0) NOT NULL,
            UM_DOMAIN_NAME VARCHAR(255) NOT NULL,
            UM_TENANT_ID INTEGER DEFAULT 0 NOT NULL,
            PRIMARY KEY (UM_DOMAIN_ID, UM_TENANT_ID),
            UNIQUE(UM_DOMAIN_NAME,UM_TENANT_ID)
)/

CREATE SEQUENCE UM_DOMAIN_SEQUENCE AS DECIMAL(27,0)
    INCREMENT BY 1
    START WITH 1
    NO CACHE/

CREATE TRIGGER UM_DOMAIN_TRIGGER NO CASCADE BEFORE INSERT ON UM_DOMAIN
REFERENCING NEW AS NEW FOR EACH ROW MODE DB2SQL 

BEGIN ATOMIC
    
    SET (NEW.UM_DOMAIN_ID)
       = (NEXTVAL FOR UM_DOMAIN_SEQUENCE);

END/


CREATE TABLE UM_USER(
    UM_ID DECIMAL(31,0) NOT NULL,
    UM_USER_NAME VARCHAR(255) NOT NULL,
    UM_USER_PASSWORD VARCHAR(255) NOT NULL,
    UM_SALT_VALUE VARCHAR(31),
    UM_REQUIRE_CHANGE SMALLINT DEFAULT 0,
    UM_CHANGED_TIME TIMESTAMP NOT NULL,
    UM_TENANT_ID DECIMAL(31,0) DEFAULT 0 NOT NULL,
    PRIMARY KEY(UM_ID,UM_TENANT_ID),
    UNIQUE(UM_USER_NAME,UM_TENANT_ID)
)/

CREATE SEQUENCE UM_USER_SEQUENCE AS DECIMAL(27,0)
    INCREMENT BY 1
    START WITH 1
    NO CACHE/

CREATE TRIGGER UM_USER_TRIGGER NO CASCADE BEFORE INSERT ON UM_USER
REFERENCING NEW AS NEW FOR EACH ROW MODE DB2SQL 

BEGIN ATOMIC
    
    SET (NEW.UM_ID)
       = (NEXTVAL FOR UM_USER_SEQUENCE);

END/

CREATE TABLE UM_SYSTEM_USER ( 
             UM_ID DECIMAL(31,0) NOT NULL, 
             UM_USER_NAME VARCHAR(255) NOT NULL, 
             UM_USER_PASSWORD VARCHAR(255) NOT NULL,
             UM_SALT_VALUE VARCHAR(31),
             UM_REQUIRE_CHANGE SMALLINT DEFAULT 0,
             UM_CHANGED_TIME TIMESTAMP NOT NULL,
             UM_TENANT_ID DECIMAL(31,0) DEFAULT 0 NOT NULL, 
             PRIMARY KEY (UM_ID, UM_TENANT_ID), 
             UNIQUE(UM_USER_NAME, UM_TENANT_ID)
)/

CREATE SEQUENCE UM_SYSTEM_USER_SEQUENCE AS DECIMAL(27,0)
    INCREMENT BY 1
    START WITH 1
    NO CACHE/

CREATE TRIGGER UM_SYSTEM_USER_TRIGGER NO CASCADE BEFORE INSERT ON UM_SYSTEM_USER
REFERENCING NEW AS NEW FOR EACH ROW MODE DB2SQL 

BEGIN ATOMIC
    
    SET (NEW.UM_ID)
       = (NEXTVAL FOR UM_SYSTEM_USER_SEQUENCE);

END/

CREATE TABLE UM_USER_ATTRIBUTE(
    UM_ID DECIMAL(31,0) NOT NULL,
    UM_ATTR_NAME VARCHAR(255) NOT NULL,
    UM_ATTR_VALUE VARCHAR(255),
    UM_PROFILE_ID VARCHAR(255),
    UM_USER_ID DECIMAL(31,0),
    UM_TENANT_ID DECIMAL(31,0) DEFAULT 0 NOT NULL,
    FOREIGN KEY(UM_USER_ID,UM_TENANT_ID) REFERENCES UM_USER(UM_ID,UM_TENANT_ID) ON DELETE CASCADE ,
    PRIMARY KEY(UM_ID,UM_TENANT_ID)
)/

CREATE INDEX UM_USER_ID_INDEX ON UM_USER_ATTRIBUTE(UM_USER_ID)/

CREATE SEQUENCE UM_USER_ATTRIBUTE_SEQUENCE AS DECIMAL(27,0)
    INCREMENT BY 1
    START WITH 1
    NO CACHE/


CREATE TRIGGER UM_USER_ATTRIBUTE1 NO CASCADE BEFORE INSERT ON UM_USER_ATTRIBUTE
REFERENCING NEW AS NEW FOR EACH ROW MODE DB2SQL 

BEGIN ATOMIC
    
    SET (NEW.UM_ID)
       = (NEXTVAL FOR UM_USER_ATTRIBUTE_SEQUENCE);

END/


CREATE TABLE UM_ROLE(
    UM_ID DECIMAL(31,0) NOT NULL,
    UM_ROLE_NAME VARCHAR(255) NOT NULL,
    UM_TENANT_ID DECIMAL(31,0) DEFAULT 0 NOT NULL,
    UM_SHARED_ROLE SMALLINT DEFAULT 0,
    PRIMARY KEY(UM_ID,UM_TENANT_ID),
    UNIQUE(UM_ROLE_NAME,UM_TENANT_ID)
)/

CREATE SEQUENCE UM_ROLE_SEQUENCE AS DECIMAL(27,0)
    INCREMENT BY 1
    START WITH 1
    NO CACHE/

CREATE TRIGGER UM_ROLE_TRIGGER NO CASCADE BEFORE INSERT ON UM_ROLE
REFERENCING NEW AS NEW FOR EACH ROW MODE DB2SQL 

BEGIN ATOMIC
    
    SET (NEW.UM_ID)
       = (NEXTVAL FOR UM_ROLE_SEQUENCE);

END/

CREATE TABLE UM_MODULE(
	UM_ID INTEGER  NOT NULL,
	UM_MODULE_NAME VARCHAR(100) NOT NULL,
	PRIMARY KEY(UM_ID),
	UNIQUE(UM_MODULE_NAME)
)/


CREATE SEQUENCE UM_MODULE_SEQUENCE AS DECIMAL(27,0)
    INCREMENT BY 1
    START WITH 1
    NO CACHE/

CREATE TRIGGER UM_MODULE_TRIGGER NO CASCADE BEFORE INSERT ON UM_MODULE
REFERENCING NEW AS NEW FOR EACH ROW MODE DB2SQL 

BEGIN ATOMIC
    
    SET (NEW.UM_ID)
       = (NEXTVAL FOR UM_MODULE_SEQUENCE);

END/


CREATE TABLE UM_MODULE_ACTIONS(
	UM_ACTION VARCHAR(255) NOT NULL,
	UM_MODULE_ID INTEGER NOT NULL,
	PRIMARY KEY(UM_ACTION, UM_MODULE_ID),
	FOREIGN KEY (UM_MODULE_ID) REFERENCES UM_MODULE(UM_ID) ON DELETE CASCADE
)/

CREATE TABLE UM_PERMISSION(
    UM_ID DECIMAL(31,0) NOT NULL,
    UM_RESOURCE_ID VARCHAR(255) NOT NULL,
    UM_ACTION VARCHAR(255) NOT NULL,
    UM_TENANT_ID DECIMAL(31,0) DEFAULT 0 NOT NULL,
    UM_MODULE_ID INTEGER DEFAULT 0,
    UNIQUE(UM_RESOURCE_ID,UM_ACTION, UM_TENANT_ID),
    PRIMARY KEY(UM_ID,UM_TENANT_ID)
)/

CREATE SEQUENCE UM_PERMISSION_SEQUENCE AS DECIMAL(27,0)
    INCREMENT BY 1
    START WITH 1
    NO CACHE/


CREATE TRIGGER UM_PERMISSION_TRI1 NO CASCADE BEFORE INSERT ON UM_PERMISSION
REFERENCING NEW AS NEW FOR EACH ROW MODE DB2SQL 

BEGIN ATOMIC
    
    SET (NEW.UM_ID)
       = (NEXTVAL FOR UM_PERMISSION_SEQUENCE);

END/

CREATE INDEX INDEX_UM_PERMISSION_UM_RESOURCE_ID_UM_ACTION
    ON UM_PERMISSION (UM_RESOURCE_ID, UM_ACTION, UM_TENANT_ID)/

CREATE TABLE UM_ROLE_PERMISSION(
    UM_ID DECIMAL(31,0) NOT NULL,
    UM_PERMISSION_ID DECIMAL(31,0) NOT NULL,
    UM_ROLE_NAME VARCHAR(255) NOT NULL,
    UM_IS_ALLOWED SMALLINT NOT NULL,
    UM_TENANT_ID DECIMAL(31,0) DEFAULT 0 NOT NULL,
    UM_DOMAIN_ID DECIMAL(31,0) NOT NULL, 
    UNIQUE(UM_PERMISSION_ID,UM_ROLE_NAME,UM_TENANT_ID,UM_DOMAIN_ID),
    FOREIGN KEY(UM_PERMISSION_ID,UM_TENANT_ID) REFERENCES UM_PERMISSION(UM_ID,UM_TENANT_ID) ON DELETE CASCADE ,
    FOREIGN KEY (UM_DOMAIN_ID, UM_TENANT_ID) REFERENCES UM_DOMAIN(UM_DOMAIN_ID, UM_TENANT_ID) ON DELETE CASCADE, 
    PRIMARY KEY(UM_ID,UM_TENANT_ID)
)/

CREATE SEQUENCE UM_ROLE_PERMISSION_SEQUENCE AS DECIMAL(27,0)
    INCREMENT BY 1
    START WITH 1
    NO CACHE/


CREATE TRIGGER UM_ROLE_PERMISSIO1 NO CASCADE BEFORE INSERT ON UM_ROLE_PERMISSION
REFERENCING NEW AS NEW FOR EACH ROW MODE DB2SQL 

BEGIN ATOMIC
    
    SET (NEW.UM_ID)
       = (NEXTVAL FOR UM_ROLE_PERMISSION_SEQUENCE);

END/


CREATE TABLE UM_USER_PERMISSION(
    UM_ID DECIMAL(31,0) NOT NULL,
    UM_PERMISSION_ID DECIMAL(31,0) NOT NULL,
    UM_USER_NAME VARCHAR(255) NOT NULL,
    UM_IS_ALLOWED SMALLINT NOT NULL,
    UM_TENANT_ID DECIMAL(31,0) DEFAULT 0 NOT NULL,
    UNIQUE(UM_PERMISSION_ID,UM_USER_NAME,UM_TENANT_ID),
    FOREIGN KEY(UM_PERMISSION_ID,UM_TENANT_ID) REFERENCES UM_PERMISSION(UM_ID,UM_TENANT_ID) ON DELETE CASCADE,
    PRIMARY KEY(UM_ID,UM_TENANT_ID)
)/

CREATE SEQUENCE UM_USER_PERMISSION_SEQUENCE AS DECIMAL(27,0)
    INCREMENT BY 1
    START WITH 1
    NO CACHE/


CREATE TRIGGER UM_USER_PERMISSIO1 NO CASCADE BEFORE INSERT ON UM_USER_PERMISSION
REFERENCING NEW AS NEW FOR EACH ROW MODE DB2SQL 

BEGIN ATOMIC
    
    SET (NEW.UM_ID)
       = (NEXTVAL FOR UM_USER_PERMISSION_SEQUENCE);

END/


CREATE TABLE UM_USER_ROLE(
    UM_ID DECIMAL(31,0) NOT NULL,
    UM_ROLE_ID DECIMAL(31,0) NOT NULL,
    UM_USER_ID DECIMAL(31,0) NOT NULL,
    UM_TENANT_ID DECIMAL(31,0) DEFAULT 0 NOT NULL,
    UNIQUE(UM_USER_ID,UM_ROLE_ID,UM_TENANT_ID),
    FOREIGN KEY(UM_ROLE_ID,UM_TENANT_ID) REFERENCES UM_ROLE(UM_ID,UM_TENANT_ID),
    FOREIGN KEY(UM_USER_ID,UM_TENANT_ID) REFERENCES UM_USER(UM_ID,UM_TENANT_ID),
    PRIMARY KEY(UM_ID,UM_TENANT_ID)
)/

CREATE SEQUENCE UM_USER_ROLE_SEQUENCE AS DECIMAL(27,0)
    INCREMENT BY 1
    START WITH 1
    NO CACHE/


CREATE TRIGGER UM_USER_ROLE_TRIG1 NO CASCADE BEFORE INSERT ON UM_USER_ROLE
REFERENCING NEW AS NEW FOR EACH ROW MODE DB2SQL 

BEGIN ATOMIC
    
    SET (NEW.UM_ID)
       = (NEXTVAL FOR UM_USER_ROLE_SEQUENCE);

END/

CREATE TABLE UM_ACCOUNT_MAPPING(
	UM_ID INTEGER NOT NULL,
	UM_USER_NAME VARCHAR(255) NOT NULL,
	UM_TENANT_ID INTEGER NOT NULL,
	UM_USER_STORE_DOMAIN VARCHAR(100) NOT NULL,
	UM_ACC_LINK_ID INTEGER NOT NULL,
	UNIQUE(UM_USER_NAME, UM_TENANT_ID, UM_USER_STORE_DOMAIN, UM_ACC_LINK_ID),
	FOREIGN KEY (UM_TENANT_ID) REFERENCES UM_TENANT(UM_ID) ON DELETE CASCADE,
	PRIMARY KEY (UM_ID)
)/

CREATE SEQUENCE UM_ACCOUNT_MAPPING_SEQUENCE AS DECIMAL(27,0)
    INCREMENT BY 1
    START WITH 1
    NO CACHE/


CREATE TRIGGER UM_ACCOUNT_MAPPING_TRIG1 NO CASCADE BEFORE INSERT ON UM_ACCOUNT_MAPPING
REFERENCING NEW AS NEW FOR EACH ROW MODE DB2SQL 

BEGIN ATOMIC
    
    SET (NEW.UM_ID)
       = (NEXTVAL FOR UM_ACCOUNT_MAPPING_SEQUENCE);

END/

CREATE TABLE UM_SHARED_USER_ROLE(
    UM_ROLE_ID DECIMAL(31,0) NOT NULL,
    UM_USER_ID DECIMAL(31,0) NOT NULL,
    UM_USER_TENANT_ID DECIMAL(31,0) NOT NULL,
    UM_ROLE_TENANT_ID DECIMAL(31,0) NOT NULL,
    UNIQUE(UM_USER_ID,UM_ROLE_ID,UM_USER_TENANT_ID, UM_ROLE_TENANT_ID),
    FOREIGN KEY(UM_ROLE_ID,UM_ROLE_TENANT_ID) REFERENCES UM_ROLE(UM_ID,UM_TENANT_ID) ON DELETE CASCADE ,
    FOREIGN KEY(UM_USER_ID,UM_USER_TENANT_ID) REFERENCES UM_USER(UM_ID,UM_TENANT_ID) ON DELETE CASCADE 
)/

CREATE TABLE UM_DIALECT(
    UM_ID DECIMAL(31,0) NOT NULL,
    UM_DIALECT_URI VARCHAR(255) NOT NULL,
    UM_TENANT_ID DECIMAL(31,0) DEFAULT 0 NOT NULL,
    UNIQUE(UM_DIALECT_URI,UM_TENANT_ID),
    PRIMARY KEY(UM_ID,UM_TENANT_ID)
)/

CREATE SEQUENCE UM_DIALECT_SEQUENCE AS DECIMAL(27,0)
    INCREMENT BY 1
    START WITH 1
    NO CACHE/

CREATE TRIGGER UM_DIALECT_TRIGGER NO CASCADE BEFORE INSERT ON UM_DIALECT
REFERENCING NEW AS NEW FOR EACH ROW MODE DB2SQL 

BEGIN ATOMIC
    
    SET (NEW.UM_ID)
       = (NEXTVAL FOR UM_DIALECT_SEQUENCE);

END/


CREATE TABLE UM_CLAIM(
    UM_ID DECIMAL(31,0) NOT NULL,
    UM_DIALECT_ID DECIMAL(31,0) NOT NULL,
    UM_CLAIM_URI VARCHAR(255) NOT NULL,
    UM_DISPLAY_TAG VARCHAR(255),
    UM_DESCRIPTION VARCHAR(255),
    UM_MAPPED_ATTRIBUTE_DOMAIN VARCHAR(255),
    UM_MAPPED_ATTRIBUTE VARCHAR(255),
    UM_REG_EX VARCHAR(255),
    UM_SUPPORTED SMALLINT,
    UM_REQUIRED SMALLINT,
    UM_DISPLAY_ORDER DECIMAL(31,0),
    UM_CHECKED_ATTRIBUTE SMALLINT,
    UM_READ_ONLY SMALLINT,
    UM_TENANT_ID DECIMAL(31,0) DEFAULT 0 NOT NULL,
    UNIQUE(UM_DIALECT_ID,UM_CLAIM_URI,UM_TENANT_ID),
    FOREIGN KEY(UM_DIALECT_ID,UM_TENANT_ID) REFERENCES UM_DIALECT(UM_ID,UM_TENANT_ID),
    PRIMARY KEY(UM_ID,UM_TENANT_ID)
)/

CREATE SEQUENCE UM_CLAIM_SEQUENCE AS DECIMAL(27,0)
    INCREMENT BY 1
    START WITH 1
    NO CACHE/

CREATE TRIGGER UM_CLAIM_TRIGGER NO CASCADE BEFORE INSERT ON UM_CLAIM
REFERENCING NEW AS NEW FOR EACH ROW MODE DB2SQL 

BEGIN ATOMIC
    
    SET (NEW.UM_ID)
       = (NEXTVAL FOR UM_CLAIM_SEQUENCE);

END/


CREATE TABLE UM_PROFILE_CONFIG(
    UM_ID DECIMAL(31,0) NOT NULL,
    UM_DIALECT_ID DECIMAL(31,0),
    UM_PROFILE_NAME VARCHAR(255),
    UM_TENANT_ID DECIMAL(31,0) DEFAULT 0 NOT NULL,
    FOREIGN KEY(UM_DIALECT_ID,UM_TENANT_ID) REFERENCES UM_DIALECT(UM_ID,UM_TENANT_ID),
    PRIMARY KEY(UM_ID,UM_TENANT_ID)
)/

CREATE SEQUENCE UM_PROFILE_CONFIG_SEQUENCE AS DECIMAL(27,0)
    INCREMENT BY 1
    START WITH 1
    NO CACHE/


CREATE TRIGGER UM_PROFILE_CONFIG1 NO CASCADE BEFORE INSERT ON UM_PROFILE_CONFIG
REFERENCING NEW AS NEW FOR EACH ROW MODE DB2SQL 

BEGIN ATOMIC
    
    SET (NEW.UM_ID)
       = (NEXTVAL FOR UM_PROFILE_CONFIG_SEQUENCE);

END/


CREATE TABLE UM_CLAIM_BEHAVIOR(
    UM_ID DECIMAL(31,0) NOT NULL,
    UM_PROFILE_ID DECIMAL(31,0),
    UM_CLAIM_ID DECIMAL(31,0),
    UM_BEHAVIOUR SMALLINT,
    UM_TENANT_ID DECIMAL(31,0) DEFAULT 0 NOT NULL,
    FOREIGN KEY(UM_PROFILE_ID,UM_TENANT_ID) REFERENCES UM_PROFILE_CONFIG(UM_ID,UM_TENANT_ID),
    FOREIGN KEY(UM_CLAIM_ID,UM_TENANT_ID) REFERENCES UM_CLAIM(UM_ID,UM_TENANT_ID),
    PRIMARY KEY(UM_ID,UM_TENANT_ID)
)/

CREATE SEQUENCE UM_CLAIM_BEHAVIOR_SEQUENCE AS DECIMAL(27,0)
    INCREMENT BY 1
    START WITH 1
    NO CACHE/


CREATE TRIGGER UM_CLAIM_BEHAVIOR1 NO CASCADE BEFORE INSERT ON UM_CLAIM_BEHAVIOR
REFERENCING NEW AS NEW FOR EACH ROW MODE DB2SQL 

BEGIN ATOMIC
    
    SET (NEW.UM_ID)
       = (NEXTVAL FOR UM_CLAIM_BEHAVIOR_SEQUENCE);

END/


CREATE TABLE UM_HYBRID_ROLE(
    UM_ID DECIMAL(31,0) NOT NULL,
    UM_ROLE_NAME VARCHAR(255) NOT NULL,
    UM_TENANT_ID DECIMAL(31,0) DEFAULT 0 NOT NULL,
    PRIMARY KEY(UM_ID,UM_TENANT_ID),
    UNIQUE(UM_ROLE_NAME,UM_TENANT_ID)
)/

CREATE INDEX UM_ROLE_NAME_IND ON UM_HYBRID_ROLE(UM_ROLE_NAME)/

CREATE SEQUENCE UM_HYBRID_ROLE_SEQUENCE AS DECIMAL(27,0)
    INCREMENT BY 1
    START WITH 1
    NO CACHE/


CREATE TRIGGER UM_HYBRID_ROLE_TR1 NO CASCADE BEFORE INSERT ON UM_HYBRID_ROLE
REFERENCING NEW AS NEW FOR EACH ROW MODE DB2SQL 

BEGIN ATOMIC
    
    SET (NEW.UM_ID)
       = (NEXTVAL FOR UM_HYBRID_ROLE_SEQUENCE);

END/


CREATE TABLE UM_HYBRID_USER_ROLE(
    UM_ID DECIMAL(31,0) NOT NULL,
    UM_USER_NAME VARCHAR(255) NOT NULL,
    UM_ROLE_ID DECIMAL(31,0) NOT NULL,
    UM_TENANT_ID DECIMAL(31,0) DEFAULT 0 NOT NULL,
    UM_DOMAIN_ID DECIMAL(31,0) DEFAULT 0 NOT NULL,
    UNIQUE(UM_USER_NAME,UM_ROLE_ID,UM_TENANT_ID),
    FOREIGN KEY(UM_ROLE_ID,UM_TENANT_ID) REFERENCES UM_HYBRID_ROLE(UM_ID,UM_TENANT_ID) ON DELETE CASCADE,
    PRIMARY KEY(UM_ID,UM_TENANT_ID)
)/

CREATE SEQUENCE UM_HYBRID_USER_ROLE_SEQUENCE AS DECIMAL(27,0)
    INCREMENT BY 1
    START WITH 1
    NO CACHE/


CREATE TRIGGER UM_HYBRID_USER_RO1 NO CASCADE BEFORE INSERT ON UM_HYBRID_USER_ROLE
REFERENCING NEW AS NEW FOR EACH ROW MODE DB2SQL 

BEGIN ATOMIC
    
    SET (NEW.UM_ID)
       = (NEXTVAL FOR UM_HYBRID_USER_ROLE_SEQUENCE);

END/

CREATE TABLE UM_SYSTEM_ROLE(
            UM_ID DECIMAL(31,0) NOT NULL,
            UM_ROLE_NAME VARCHAR(255) NOT NULL,
            UM_TENANT_ID INTEGER DEFAULT 0 NOT NULL,
            PRIMARY KEY (UM_ID, UM_TENANT_ID),
            UNIQUE(UM_ROLE_NAME,UM_TENANT_ID)
)/

CREATE SEQUENCE UM_SYSTEM_ROLE_SEQUENCE AS DECIMAL(27,0)
    INCREMENT BY 1
    START WITH 1
    NO CACHE/


CREATE TRIGGER UM_SYSTEM_ROLE_TRIGGER NO CASCADE BEFORE INSERT ON UM_SYSTEM_ROLE
REFERENCING NEW AS NEW FOR EACH ROW MODE DB2SQL 

BEGIN ATOMIC
    
    SET (NEW.UM_ID)
       = (NEXTVAL FOR UM_SYSTEM_ROLE_SEQUENCE);

END/

CREATE TABLE UM_SYSTEM_USER_ROLE(
            UM_ID DECIMAL(31,0) NOT NULL,
            UM_USER_NAME VARCHAR(255) NOT NULL,
            UM_ROLE_ID INTEGER NOT NULL,
            UM_TENANT_ID INTEGER DEFAULT 0 NOT NULL,
            UNIQUE (UM_USER_NAME, UM_ROLE_ID, UM_TENANT_ID),
            FOREIGN KEY (UM_ROLE_ID, UM_TENANT_ID) REFERENCES UM_SYSTEM_ROLE(UM_ID, UM_TENANT_ID),
            PRIMARY KEY (UM_ID, UM_TENANT_ID)
)/

CREATE SEQUENCE UM_SYSTEM_USER_ROLE_SEQUENCE AS DECIMAL(27,0)
    INCREMENT BY 1
    START WITH 1
    NO CACHE/


CREATE TRIGGER UM_SYSTEM_USER_ROLE_TRIGGER NO CASCADE BEFORE INSERT ON UM_SYSTEM_USER_ROLE
REFERENCING NEW AS NEW FOR EACH ROW MODE DB2SQL 

BEGIN ATOMIC
    
    SET (NEW.UM_ID)
       = (NEXTVAL FOR UM_SYSTEM_USER_ROLE_SEQUENCE);

END/


CREATE TABLE UM_HYBRID_REMEMBER_ME (
            UM_ID DECIMAL(31,0) NOT NULL,
			UM_USER_NAME VARCHAR(255) NOT NULL,
			UM_COOKIE_VALUE VARCHAR(1024),
			UM_CREATED_TIME TIMESTAMP,
            UM_TENANT_ID INTEGER DEFAULT 0 NOT NULL,
			PRIMARY KEY (UM_ID, UM_TENANT_ID)
)/

CREATE SEQUENCE UM_HYBRID_REMEMBER_ME_SEQUENCE AS DECIMAL(27,0)
    INCREMENT BY 1
    START WITH 1
    NO CACHE/


CREATE TRIGGER UMHYBRID_REMEMB_ME NO CASCADE BEFORE INSERT ON UM_HYBRID_REMEMBER_ME
REFERENCING NEW AS NEW FOR EACH ROW MODE DB2SQL 

BEGIN ATOMIC
    
    SET (NEW.UM_ID)
       = (NEXTVAL FOR UM_HYBRID_REMEMBER_ME_SEQUENCE);

END/

