From 7f959ce8694a539156c8f5bc39743beda2474ff9 Mon Sep 17 00:00:00 2001 From: Paulo Gustavo Veiga Date: Sat, 17 Feb 2024 13:48:11 -0800 Subject: [PATCH] Add postgress suppot --- .../src/main/resources/data-postgresql.sql | 91 ++----------------- .../src/main/resources/schema-postgresql.sql | 85 +++++++++++++++++ 2 files changed, 95 insertions(+), 81 deletions(-) create mode 100644 wise-api/src/main/resources/schema-postgresql.sql diff --git a/wise-api/src/main/resources/data-postgresql.sql b/wise-api/src/main/resources/data-postgresql.sql index d169ff67..c3bf7e8b 100644 --- a/wise-api/src/main/resources/data-postgresql.sql +++ b/wise-api/src/main/resources/data-postgresql.sql @@ -1,86 +1,15 @@ -CREATE TABLE COLLABORATOR ( - id SERIAL NOT NULL PRIMARY KEY, - email VARCHAR(255) NOT NULL UNIQUE, - creation_date DATE -); -CREATE TABLE "USER" ( - authentication_type TEXT NOT NULL, - authenticator_uri VARCHAR(255), - collaborator_id INTEGER NOT NULL PRIMARY KEY, - firstname VARCHAR(255) NOT NULL, - lastname VARCHAR(255) NOT NULL, - password VARCHAR(255) NOT NULL, - activation_code BIGINT NOT NULL, - activation_date DATE, - allow_send_email TEXT NOT NULL DEFAULT 0, - locale VARCHAR(5), - google_sync BOOLEAN, - sync_code VARCHAR(255), - google_token VARCHAR(255), - FOREIGN KEY (collaborator_id) REFERENCES COLLABORATOR (id) ON DELETE CASCADE ON UPDATE NO ACTION -); +INSERT INTO COLLABORATOR (id, email, creation_date) VALUES (1, 'test@wisemapping.org', CURRENT_DATE) +ON CONFLICT DO NOTHING; -CREATE TABLE "LABEL" ( - id INTEGER NOT NULL PRIMARY KEY, - title VARCHAR(255), - creator_id INTEGER NOT NULL, - parent_label_id INTEGER, - color VARCHAR(7) NOT NULL, - FOREIGN KEY (creator_id) REFERENCES "USER" (collaborator_id) -); +INSERT INTO ACCOUNT (collaborator_id, firstname, lastname, password, activation_code, activation_date, allow_send_email,authentication_type) + VALUES (1, 'Test', 'User', 'ENC:a94a8fe5ccb19ba61c4c0873d391e987982fbbd3', 1237, CURRENT_DATE, 1,'D') +ON CONFLICT DO NOTHING; -CREATE TABLE MINDMAP ( - id SERIAL NOT NULL PRIMARY KEY, - title VARCHAR(255) NOT NULL, - description VARCHAR(255), - xml BYTEA NOT NULL, - public BOOL NOT NULL DEFAULT FALSE, - creation_date TIMESTAMP, - edition_date TIMESTAMP, - creator_id INTEGER NOT NULL, - last_editor_id INTEGER NOT NULL --, ---FOREIGN KEY(creator_id) REFERENCES "USER"(collaborator_id) ON DELETE CASCADE ON UPDATE NO ACTION -); +INSERT INTO COLLABORATOR (id, email, creation_date) VALUES (2, 'admin@wisemapping.org', CURRENT_DATE) +ON CONFLICT DO NOTHING; -CREATE TABLE R_LABEL_MINDMAP ( - mindmap_id INTEGER NOT NULL, - label_id INTEGER NOT NULL, - PRIMARY KEY (mindmap_id, label_id), - FOREIGN KEY (mindmap_id) REFERENCES MINDMAP (id), - FOREIGN KEY (label_id) REFERENCES "LABEL" (id) ON DELETE CASCADE ON UPDATE NO ACTION -); +INSERT INTO ACCOUNT (collaborator_id, firstname, lastname, password, activation_code, activation_date, allow_send_email,authentication_type) + VALUES (2, 'Admin', 'User', 'ENC:a94a8fe5ccb19ba61c4c0873d391e987982fbbd3', 1237, CURRENT_DATE, 1,'D') +ON CONFLICT DO NOTHING; -CREATE TABLE MINDMAP_HISTORY -(id SERIAL NOT NULL PRIMARY KEY, - xml BYTEA NOT NULL, - mindmap_id INTEGER NOT NULL, - creation_date TIMESTAMP, - editor_id INTEGER NOT NULL, - FOREIGN KEY (mindmap_id) REFERENCES MINDMAP (id) ON DELETE CASCADE ON UPDATE NO ACTION -); - - -CREATE TABLE COLLABORATION_PROPERTIES ( - id SERIAL NOT NULL PRIMARY KEY, - starred BOOL NOT NULL DEFAULT FALSE, - mindmap_properties VARCHAR(512) -); - -CREATE TABLE COLLABORATION ( - id SERIAL NOT NULL PRIMARY KEY, - collaborator_id INTEGER NOT NULL, - properties_id INTEGER NOT NULL, - mindmap_id INTEGER NOT NULL, - role_id INTEGER NOT NULL, - FOREIGN KEY (collaborator_id) REFERENCES COLLABORATOR (id), - FOREIGN KEY (mindmap_id) REFERENCES MINDMAP (id) ON DELETE CASCADE ON UPDATE NO ACTION, - FOREIGN KEY (properties_id) REFERENCES COLLABORATION_PROPERTIES (id) ON DELETE CASCADE ON UPDATE NO ACTION -); - -CREATE TABLE ACCESS_AUDITORY ( - id SERIAL NOT NULL PRIMARY KEY, - login_date DATE, - user_id INTEGER NOT NULL, - FOREIGN KEY (user_id) REFERENCES "USER" (collaborator_id) ON DELETE CASCADE ON UPDATE NO ACTION -); \ No newline at end of file diff --git a/wise-api/src/main/resources/schema-postgresql.sql b/wise-api/src/main/resources/schema-postgresql.sql new file mode 100644 index 00000000..2da60758 --- /dev/null +++ b/wise-api/src/main/resources/schema-postgresql.sql @@ -0,0 +1,85 @@ +create TABLE IF NOT EXISTS COLLABORATOR ( + id SERIAL NOT NULL PRIMARY KEY, + email VARCHAR(255) NOT NULL UNIQUE, + creation_date DATE +); + +create TABLE IF NOT EXISTS ACCOUNT ( + authentication_type TEXT NOT NULL, + authenticator_uri VARCHAR(255), + collaborator_id INTEGER NOT NULL PRIMARY KEY, + firstname VARCHAR(255) NOT NULL, + lastname VARCHAR(255) NOT NULL, + password VARCHAR(255) NOT NULL, + activation_code BIGINT NOT NULL, + activation_date DATE, + allow_send_email TEXT NOT NULL DEFAULT 0, + locale VARCHAR(5), + google_sync BOOLEAN, + sync_code VARCHAR(255), + google_token VARCHAR(255), + FOREIGN KEY (collaborator_id) REFERENCES COLLABORATOR (id) ON delete CASCADE ON update NO ACTION +); + +create TABLE IF NOT EXISTS MINDMAP_LABEL ( + id INTEGER NOT NULL PRIMARY KEY, + title VARCHAR(255), + creator_id INTEGER NOT NULL, + parent_label_id INTEGER, + color VARCHAR(7) NOT NULL, + FOREIGN KEY (creator_id) REFERENCES ACCOUNT (collaborator_id) +); + +create TABLE IF NOT EXISTS MINDMAP ( + id SERIAL NOT NULL PRIMARY KEY, + title VARCHAR(255) NOT NULL, + description VARCHAR(255), + xml BYTEA NOT NULL, + public BOOL NOT NULL DEFAULT FALSE, + creation_date TIMESTAMP, + edition_date TIMESTAMP, + creator_id INTEGER NOT NULL, + last_editor_id INTEGER NOT NULL --, +--FOREIGN KEY(creator_id) REFERENCES "USER"(collaborator_id) ON DELETE CASCADE ON UPDATE NO ACTION +); + +create TABLE IF NOT EXISTS R_LABEL_MINDMAP ( + mindmap_id INTEGER NOT NULL, + label_id INTEGER NOT NULL, + PRIMARY KEY (mindmap_id, label_id), + FOREIGN KEY (mindmap_id) REFERENCES MINDMAP (id), + FOREIGN KEY (label_id) REFERENCES MINDMAP_LABEL (id) ON delete CASCADE ON update NO ACTION +); + +create TABLE IF NOT EXISTS MINDMAP_HISTORY +(id SERIAL NOT NULL PRIMARY KEY, + xml BYTEA NOT NULL, + mindmap_id INTEGER NOT NULL, + creation_date TIMESTAMP, + editor_id INTEGER NOT NULL, + FOREIGN KEY (mindmap_id) REFERENCES MINDMAP (id) ON delete CASCADE ON update NO ACTION +); + +create TABLE IF NOT EXISTS COLLABORATION_PROPERTIES ( + id SERIAL NOT NULL PRIMARY KEY, + starred BOOL NOT NULL DEFAULT FALSE, + mindmap_properties VARCHAR(512) +); + +create TABLE IF NOT EXISTS COLLABORATION ( + id SERIAL NOT NULL PRIMARY KEY, + collaborator_id INTEGER NOT NULL, + properties_id INTEGER NOT NULL, + mindmap_id INTEGER NOT NULL, + role_id INTEGER NOT NULL, + FOREIGN KEY (collaborator_id) REFERENCES COLLABORATOR (id), + FOREIGN KEY (mindmap_id) REFERENCES MINDMAP (id) ON delete CASCADE ON update NO ACTION, + FOREIGN KEY (properties_id) REFERENCES COLLABORATION_PROPERTIES (id) ON delete CASCADE ON update NO ACTION +); + +create TABLE IF NOT EXISTS ACCESS_AUDITORY ( + id SERIAL NOT NULL PRIMARY KEY, + login_date DATE, + user_id INTEGER NOT NULL, + FOREIGN KEY (user_id) REFERENCES ACCOUNT (collaborator_id) ON delete CASCADE ON update NO ACTION +); \ No newline at end of file