-- H2 2.1.214; 
SET DB_CLOSE_DELAY -1;         
;              
CREATE USER IF NOT EXISTS "SA" SALT 'da4612686a72cd38' HASH '04ebb7206a62e58d294b05b619bcb6a9a280b7e6a0c54215159f2894e2cd74b0' ADMIN;          
CREATE CACHED TABLE "PUBLIC"."AUTHORITIES"(
    "ID" BIGINT GENERATED BY DEFAULT AS IDENTITY(START WITH 1 RESTART WITH 33) NOT NULL,
    "AUTHORITY" CHARACTER VARYING(255),
    "USER_ID" BIGINT
);           
ALTER TABLE "PUBLIC"."AUTHORITIES" ADD CONSTRAINT "PUBLIC"."CONSTRAINT_A" PRIMARY KEY("ID");   
-- 3 +/- SELECT COUNT(*) FROM PUBLIC.AUTHORITIES;              
INSERT INTO "PUBLIC"."AUTHORITIES"("ID", "AUTHORITY", "USER_ID") VALUES(1, 'ROLE_ADMIN', 1);   
INSERT INTO "PUBLIC"."AUTHORITIES"("ID", "AUTHORITY", "USER_ID") VALUES(2, 'STIRLING-PDF-BACKEND-API-USER', 2);
INSERT INTO "PUBLIC"."AUTHORITIES"("ID", "AUTHORITY", "USER_ID") VALUES(4, 'ROLE_USER', 4);    
CREATE CACHED TABLE "PUBLIC"."PERSISTENT_LOGINS"(
    "SERIES" CHARACTER VARYING(255) NOT NULL,
    "LAST_USED" TIMESTAMP(6) NOT NULL,
    "TOKEN" CHARACTER VARYING(64) NOT NULL,
    "USERNAME" CHARACTER VARYING(64) NOT NULL
);            
ALTER TABLE "PUBLIC"."PERSISTENT_LOGINS" ADD CONSTRAINT "PUBLIC"."CONSTRAINT_A3" PRIMARY KEY("SERIES");        
-- 0 +/- SELECT COUNT(*) FROM PUBLIC.PERSISTENT_LOGINS;        
CREATE CACHED TABLE "PUBLIC"."SESSIONS"(
    "SESSION_ID" CHARACTER VARYING(255) NOT NULL,
    "EXPIRED" BOOLEAN NOT NULL,
    "LAST_REQUEST" TIMESTAMP(6),
    "PRINCIPAL_NAME" CHARACTER LARGE OBJECT
);     
ALTER TABLE "PUBLIC"."SESSIONS" ADD CONSTRAINT "PUBLIC"."CONSTRAINT_8" PRIMARY KEY("SESSION_ID");              
-- 2 +/- SELECT COUNT(*) FROM PUBLIC.SESSIONS; 
INSERT INTO "PUBLIC"."SESSIONS"("SESSION_ID", "EXPIRED", "LAST_REQUEST", "PRINCIPAL_NAME") VALUES('node01hkmp3phofwa92c2yyzvmyqxp3', TRUE, TIMESTAMP '2024-10-10 12:00:54.038', 'Carina');     
INSERT INTO "PUBLIC"."SESSIONS"("SESSION_ID", "EXPIRED", "LAST_REQUEST", "PRINCIPAL_NAME") VALUES('node07dya3qspggrfssbg9yexwcn65', TRUE, TIMESTAMP '2024-10-10 12:02:36.685', 'Carina');      
CREATE CACHED TABLE "PUBLIC"."USER_SETTINGS"(
    "USER_ID" BIGINT NOT NULL,
    "SETTING_VALUE" CHARACTER LARGE OBJECT,
    "SETTING_KEY" CHARACTER VARYING(255) NOT NULL
);  
ALTER TABLE "PUBLIC"."USER_SETTINGS" ADD CONSTRAINT "PUBLIC"."CONSTRAINT_9" PRIMARY KEY("USER_ID", "SETTING_KEY");             
-- 0 +/- SELECT COUNT(*) FROM PUBLIC.USER_SETTINGS;            
CREATE CACHED TABLE "PUBLIC"."USERS"(
    "USER_ID" BIGINT GENERATED BY DEFAULT AS IDENTITY(START WITH 1 RESTART WITH 33) NOT NULL,
    "API_KEY" CHARACTER VARYING(255),
    "AUTHENTICATIONTYPE" CHARACTER VARYING(255),
    "ENABLED" BOOLEAN,
    "IS_FIRST_LOGIN" BOOLEAN,
    "PASSWORD" CHARACTER VARYING(255),
    "ROLE_NAME" CHARACTER VARYING(255),
    "USERNAME" CHARACTER VARYING(255)
);        
ALTER TABLE "PUBLIC"."USERS" ADD CONSTRAINT "PUBLIC"."CONSTRAINT_4" PRIMARY KEY("USER_ID");    
-- 3 +/- SELECT COUNT(*) FROM PUBLIC.USERS;    
INSERT INTO "PUBLIC"."USERS"("USER_ID", "API_KEY", "AUTHENTICATIONTYPE", "ENABLED", "IS_FIRST_LOGIN", "PASSWORD", "ROLE_NAME", "USERNAME") VALUES(1, NULL, 'web', TRUE, FALSE, '$2a$10$MAHiiv7hASj3Jcoy7736VO2SG6MwI9Ez7bAB9n6tA2h2A.HqgClh.', NULL, 'andre'); 
INSERT INTO "PUBLIC"."USERS"("USER_ID", "API_KEY", "AUTHENTICATIONTYPE", "ENABLED", "IS_FIRST_LOGIN", "PASSWORD", "ROLE_NAME", "USERNAME") VALUES(2, 'b12eb09a-4fd1-496f-9c0e-12c80f1d94ad', 'web', TRUE, FALSE, '$2a$10$muwG4M6gUcmygmMmhsquTOE/QzqO1wlCzpyke2MKE9zXzIgTePbEW', NULL, 'STIRLING-PDF-BACKEND-API-USER');       
INSERT INTO "PUBLIC"."USERS"("USER_ID", "API_KEY", "AUTHENTICATIONTYPE", "ENABLED", "IS_FIRST_LOGIN", "PASSWORD", "ROLE_NAME", "USERNAME") VALUES(4, NULL, 'web', TRUE, FALSE, '$2a$10$xqUP2IL2FCAJQkaObm7cV.1rs1E8EZR1ezUL589yjmSj2WRVRXiB2', NULL, 'Carina');
ALTER TABLE "PUBLIC"."USERS" ADD CONSTRAINT "PUBLIC"."UKR43AF9AP4EDM43MMTQ01ODDJ6" UNIQUE("USERNAME");         
ALTER TABLE "PUBLIC"."AUTHORITIES" ADD CONSTRAINT "PUBLIC"."FKK91UPMBUEYIM93V469WJ7B2QH" FOREIGN KEY("USER_ID") REFERENCES "PUBLIC"."USERS"("USER_ID") NOCHECK;
ALTER TABLE "PUBLIC"."USER_SETTINGS" ADD CONSTRAINT "PUBLIC"."FK8V82NJ88RMAI0NYCK19F873DW" FOREIGN KEY("USER_ID") REFERENCES "PUBLIC"."USERS"("USER_ID") NOCHECK;              
