From 9bb29e08a9799650ba22f33ac5877dc883fdc316 Mon Sep 17 00:00:00 2001 From: Kyle Spearrin Date: Mon, 12 Jul 2021 09:58:36 -0400 Subject: [PATCH] delete old postgres work that was never used --- src/Sql/PostgreSQL/Functions/user_create.sql | 105 ------------------ .../Functions/user_delete_by_id.sql | 71 ------------ .../Functions/user_read_by_email.sql | 20 ---- .../PostgreSQL/Functions/user_read_by_id.sql | 20 ---- src/Sql/PostgreSQL/Functions/user_search.sql | 30 ----- src/Sql/PostgreSQL/Functions/user_update.sql | 75 ------------- .../PostgreSQL/Functions/user_update_keys.sql | 27 ----- .../user_update_renewal_reminder_date.sql | 20 ---- src/Sql/PostgreSQL/Role/create_role.sql | 2 - src/Sql/PostgreSQL/Schema/bitwarden.sql | 3 - src/Sql/PostgreSQL/Tables/cipher.sql | 29 ----- src/Sql/PostgreSQL/Tables/collection.sql | 19 ---- .../PostgreSQL/Tables/collection_cipher.sql | 15 --- .../PostgreSQL/Tables/collection_group.sql | 11 -- src/Sql/PostgreSQL/Tables/collection_user.sql | 11 -- src/Sql/PostgreSQL/Tables/device.sql | 25 ----- src/Sql/PostgreSQL/Tables/event.sql | 22 ---- src/Sql/PostgreSQL/Tables/folder.sql | 18 --- src/Sql/PostgreSQL/Tables/grant.sql | 22 ---- src/Sql/PostgreSQL/Tables/group.sql | 14 --- src/Sql/PostgreSQL/Tables/group_user.sql | 17 --- src/Sql/PostgreSQL/Tables/installation.sql | 12 -- src/Sql/PostgreSQL/Tables/organization.sql | 44 -------- .../PostgreSQL/Tables/organization_user.sql | 28 ----- src/Sql/PostgreSQL/Tables/transaction.sql | 29 ----- src/Sql/PostgreSQL/Tables/u2f.sql | 22 ---- src/Sql/PostgreSQL/Tables/user.sql | 43 ------- src/Sql/PostgreSQL/Views/cipher_view.sql | 6 - src/Sql/PostgreSQL/Views/collection_view.sql | 6 - src/Sql/PostgreSQL/Views/device_view.sql | 6 - src/Sql/PostgreSQL/Views/event_view.sql | 6 - src/Sql/PostgreSQL/Views/folder_view.sql | 6 - src/Sql/PostgreSQL/Views/grant_view.sql | 6 - src/Sql/PostgreSQL/Views/group_view.sql | 6 - .../PostgreSQL/Views/installation_view.sql | 6 - ...ization_user_organization_details_view.sql | 25 ----- .../organization_user_user_details_view.sql | 18 --- .../Views/organization_user_view.sql | 6 - .../PostgreSQL/Views/organization_view.sql | 6 - src/Sql/PostgreSQL/Views/transaction_view.sql | 6 - src/Sql/PostgreSQL/Views/u2f_view.sql | 6 - src/Sql/PostgreSQL/Views/user_view.sql | 6 - 42 files changed, 875 deletions(-) delete mode 100644 src/Sql/PostgreSQL/Functions/user_create.sql delete mode 100644 src/Sql/PostgreSQL/Functions/user_delete_by_id.sql delete mode 100644 src/Sql/PostgreSQL/Functions/user_read_by_email.sql delete mode 100644 src/Sql/PostgreSQL/Functions/user_read_by_id.sql delete mode 100644 src/Sql/PostgreSQL/Functions/user_search.sql delete mode 100644 src/Sql/PostgreSQL/Functions/user_update.sql delete mode 100644 src/Sql/PostgreSQL/Functions/user_update_keys.sql delete mode 100644 src/Sql/PostgreSQL/Functions/user_update_renewal_reminder_date.sql delete mode 100644 src/Sql/PostgreSQL/Role/create_role.sql delete mode 100644 src/Sql/PostgreSQL/Schema/bitwarden.sql delete mode 100644 src/Sql/PostgreSQL/Tables/cipher.sql delete mode 100644 src/Sql/PostgreSQL/Tables/collection.sql delete mode 100644 src/Sql/PostgreSQL/Tables/collection_cipher.sql delete mode 100644 src/Sql/PostgreSQL/Tables/collection_group.sql delete mode 100644 src/Sql/PostgreSQL/Tables/collection_user.sql delete mode 100644 src/Sql/PostgreSQL/Tables/device.sql delete mode 100644 src/Sql/PostgreSQL/Tables/event.sql delete mode 100644 src/Sql/PostgreSQL/Tables/folder.sql delete mode 100644 src/Sql/PostgreSQL/Tables/grant.sql delete mode 100644 src/Sql/PostgreSQL/Tables/group.sql delete mode 100644 src/Sql/PostgreSQL/Tables/group_user.sql delete mode 100644 src/Sql/PostgreSQL/Tables/installation.sql delete mode 100644 src/Sql/PostgreSQL/Tables/organization.sql delete mode 100644 src/Sql/PostgreSQL/Tables/organization_user.sql delete mode 100644 src/Sql/PostgreSQL/Tables/transaction.sql delete mode 100644 src/Sql/PostgreSQL/Tables/u2f.sql delete mode 100644 src/Sql/PostgreSQL/Tables/user.sql delete mode 100644 src/Sql/PostgreSQL/Views/cipher_view.sql delete mode 100644 src/Sql/PostgreSQL/Views/collection_view.sql delete mode 100644 src/Sql/PostgreSQL/Views/device_view.sql delete mode 100644 src/Sql/PostgreSQL/Views/event_view.sql delete mode 100644 src/Sql/PostgreSQL/Views/folder_view.sql delete mode 100644 src/Sql/PostgreSQL/Views/grant_view.sql delete mode 100644 src/Sql/PostgreSQL/Views/group_view.sql delete mode 100644 src/Sql/PostgreSQL/Views/installation_view.sql delete mode 100644 src/Sql/PostgreSQL/Views/organization_user_organization_details_view.sql delete mode 100644 src/Sql/PostgreSQL/Views/organization_user_user_details_view.sql delete mode 100644 src/Sql/PostgreSQL/Views/organization_user_view.sql delete mode 100644 src/Sql/PostgreSQL/Views/organization_view.sql delete mode 100644 src/Sql/PostgreSQL/Views/transaction_view.sql delete mode 100644 src/Sql/PostgreSQL/Views/u2f_view.sql delete mode 100644 src/Sql/PostgreSQL/Views/user_view.sql diff --git a/src/Sql/PostgreSQL/Functions/user_create.sql b/src/Sql/PostgreSQL/Functions/user_create.sql deleted file mode 100644 index 3314427b4d..0000000000 --- a/src/Sql/PostgreSQL/Functions/user_create.sql +++ /dev/null @@ -1,105 +0,0 @@ -DROP FUNCTION IF EXISTS user_create(UUID,VARCHAR,VARCHAR,BOOLEAN,VARCHAR,VARCHAR,VARCHAR,VARCHAR,TEXT,VARCHAR,TEXT,TEXT,TIMESTAMPTZ,TEXT,TEXT,TEXT,BOOLEAN,TIMESTAMPTZ,TIMESTAMPTZ,BIGINT,SMALLINT,SMALLINT,VARCHAR,VARCHAR,VARCHAR,SMALLINT,INT,TIMESTAMPTZ,TIMESTAMPTZ); - -CREATE OR REPLACE FUNCTION user_create -( - _id UUID, - _name VARCHAR, - _email VARCHAR, - _email_verified BOOLEAN, - _master_password VARCHAR, - _master_password_hint VARCHAR, - _culture VARCHAR, - _security_stamp VARCHAR, - _two_factor_providers TEXT, - _two_factor_recovery_code VARCHAR, - _equivalent_domains TEXT, - _excluded_global_equivalent_domains TEXT, - _account_revision_date TIMESTAMPTZ, - _key TEXT, - _public_key TEXT, - _private_key TEXT, - _premium BOOLEAN, - _premium_expiration_date TIMESTAMPTZ, - _renewal_reminder_date TIMESTAMPTZ, - _storage BIGINT, - _max_storage_gb SMALLINT, - _gateway SMALLINT, - _gateway_customer_id VARCHAR, - _gateway_subscription_id VARCHAR, - _license_key VARCHAR, - _kdf SMALLINT, - _kdf_iterations INT, - _creation_date TIMESTAMPTZ, - _revision_date TIMESTAMPTZ -) -RETURNS VOID -LANGUAGE 'plpgsql' -AS -$$ -BEGIN - INSERT INTO "user" - ( - id, - name, - email, - email_verified, - master_password, - master_password_hint, - culture, - security_stamp, - two_factor_providers, - two_factor_recovery_code, - equivalent_domains, - excluded_global_equivalent_domains, - account_revision_date, - key, - public_key, - private_key, - premium, - premium_expiration_date, - renewal_reminder_date, - storage, - max_storage_gb, - gateway, - gateway_customer_id, - gateway_subscription_id, - license_key, - kdf, - kdf_iterations, - creation_date, - revision_date - ) - VALUES - ( - _id, - _name, - _email, - _email_verified, - _master_password, - _master_password_hint, - _culture, - _security_stamp, - _two_factor_providers, - _two_factor_recovery_code, - _equivalent_domains, - _excluded_global_equivalent_domains, - _account_revision_date, - _key, - _public_key, - _private_key, - _premium, - _premium_expiration_date, - _renewal_reminder_date, - _storage, - _max_storage_gb, - _gateway, - _gateway_customer_id, - _gateway_subscription_id, - _license_key, - _kdf, - _kdf_iterations, - _creation_date, - _revision_date - ); -END -$$ diff --git a/src/Sql/PostgreSQL/Functions/user_delete_by_id.sql b/src/Sql/PostgreSQL/Functions/user_delete_by_id.sql deleted file mode 100644 index 0321eabfbf..0000000000 --- a/src/Sql/PostgreSQL/Functions/user_delete_by_id.sql +++ /dev/null @@ -1,71 +0,0 @@ -DROP FUNCTION IF EXISTS user_delete_by_id (UUID); - -CREATE OR REPLACE FUNCTION user_delete_by_id -( - _id UUID -) -RETURNS VOID -LANGUAGE 'plpgsql' -AS -$BODY$ -BEGIN - -- functions dont support commit/rollback transactions, only v11+ procedures can do this - DELETE FROM - cipher - WHERE - user_id = _id; - - -- Delete folders - DELETE FROM - folder - WHERE - user_id = _id; - - -- Delete devices - DELETE FROM - device - WHERE - user_id = _id; - - -- Delete collection users - DELETE FROM - collection_user CU - USING - organization_user OU - WHERE - OU.id = CU.organization_user_id - AND - OU.user_id = _id; - - -- Delete group users - DELETE FROM - group_user GU - USING - organization_user OU - WHERE - OU.id = GU.organization_user_id - AND - OU.user_id = _id; - - -- Delete organization users - DELETE - FROM - organization_user - WHERE - user_id = _id; - - -- Delete U2F logins - DELETE - FROM - u2f - WHERE - user_id = _id; - - -- Finally, delete the user - DELETE - FROM - "user" - WHERE - id = _id; -END -$BODY$ diff --git a/src/Sql/PostgreSQL/Functions/user_read_by_email.sql b/src/Sql/PostgreSQL/Functions/user_read_by_email.sql deleted file mode 100644 index fcadb529e5..0000000000 --- a/src/Sql/PostgreSQL/Functions/user_read_by_email.sql +++ /dev/null @@ -1,20 +0,0 @@ -DROP FUNCTION IF EXISTS user_read_by_email (VARCHAR); - -CREATE OR REPLACE FUNCTION user_read_by_email -( - _email VARCHAR -) -RETURNS SETOF user_view -LANGUAGE 'plpgsql' -AS -$BODY$ -BEGIN - RETURN QUERY - SELECT - * - FROM - user_view - WHERE - email = _email; -END -$BODY$ diff --git a/src/Sql/PostgreSQL/Functions/user_read_by_id.sql b/src/Sql/PostgreSQL/Functions/user_read_by_id.sql deleted file mode 100644 index a4780dab68..0000000000 --- a/src/Sql/PostgreSQL/Functions/user_read_by_id.sql +++ /dev/null @@ -1,20 +0,0 @@ -DROP FUNCTION IF EXISTS user_read_by_id; - -CREATE OR REPLACE FUNCTION user_read_by_id -( - _id uuid -) -RETURNS SETOF user_view -LANGUAGE 'plpgsql' -AS -$BODY$ -BEGIN - RETURN QUERY - SELECT - * - FROM - user_view - WHERE - id = _id; -END -$BODY$; diff --git a/src/Sql/PostgreSQL/Functions/user_search.sql b/src/Sql/PostgreSQL/Functions/user_search.sql deleted file mode 100644 index 605695576a..0000000000 --- a/src/Sql/PostgreSQL/Functions/user_search.sql +++ /dev/null @@ -1,30 +0,0 @@ -DROP FUNCTION IF EXISTS user_search (VARCHAR,INT,INT); - -CREATE OR REPLACE FUNCTION user_search -( - _email VARCHAR, - _skip INT DEFAULT 0, - _take INT DEFAULT 25 -) -RETURNS SETOF user_view -LANGUAGE 'plpgsql' -AS -$BODY$ -DECLARE - email_like_search VARCHAR(261) = _email || '%'; - -BEGIN - RETURN QUERY - SELECT - * - FROM - user_view - WHERE - email IS NULL - OR - email LIKE email_like_search - ORDER BY email ASC - OFFSET _skip ROWS - FETCH NEXT _take ROWS only; -end -$BODY$ diff --git a/src/Sql/PostgreSQL/Functions/user_update.sql b/src/Sql/PostgreSQL/Functions/user_update.sql deleted file mode 100644 index 7cf44b90ed..0000000000 --- a/src/Sql/PostgreSQL/Functions/user_update.sql +++ /dev/null @@ -1,75 +0,0 @@ -DROP FUNCTION IF EXISTS user_update(UUID,VARCHAR,VARCHAR,BOOLEAN,VARCHAR,VARCHAR,VARCHAR,VARCHAR,TEXT,VARCHAR,TEXT,TEXT,TIMESTAMPTZ,TEXT,TEXT,TEXT,BOOLEAN,TIMESTAMPTZ,TIMESTAMPTZ,BIGINT,SMALLINT,SMALLINT,VARCHAR,VARCHAR,VARCHAR,SMALLINT,INT,TIMESTAMPTZ,TIMESTAMPTZ) - -CREATE OR REPLACE FUNCTION user_update -( - _id UUID, - _name VARCHAR, - _email VARCHAR, - _email_verified BOOLEAN, - _master_password VARCHAR, - _master_password_hint VARCHAR, - _culture VARCHAR, - _security_stamp VARCHAR, - _two_factor_providers TEXT, - _two_factor_recovery_code VARCHAR, - _equivalent_domains TEXT, - _excluded_global_equivalent_domains TEXT, - _account_revision_date TIMESTAMPTZ, - _key TEXT, - _public_key TEXT, - _private_key TEXT , - _premium BOOLEAN, - _premium_expiration_date TIMESTAMPTZ, - _renewal_reminder_date TIMESTAMPTZ, - _storage BIGINT, - _max_storage_gb SMALLINT, - _gateway SMALLINT, - _gateway_customer_id VARCHAR, - _gateway_subscription_id VARCHAR, - _license_key VARCHAR, - _kdf SMALLINT, - _kdf_iterations INT, - _creation_date TIMESTAMPTZ, - _revision_date TIMESTAMPTZ -) -RETURNS VOID -LANGUAGE plpgsql -AS -$$ -begin - - UPDATE - "user" - SET name = _name, - email = _email, - email_verified = _email_verified, - master_password = _master_password, - master_password_hint = _master_password_hint, - culture = _culture, - security_stamp = _security_stamp, - two_factor_providers = _two_factor_providers, - two_factor_recovery_code = _two_factor_recovery_code, - equivalent_domains = _equivalent_domains, - excluded_global_equivalent_domains = _excluded_global_equivalent_domains, - account_revision_date = _account_revision_date, - key = _key, - public_key = _public_key, - private_key = _private_key, - premium = _premium, - premium_expiration_date = _premium_expiration_date, - renewal_reminder_date = _renewal_reminder_date, - storage = _storage, - max_storage_gb = _max_storage_gb, - gateway = _gateway, - gateway_customer_id = _gateway_customer_id, - gateway_subscription_id = _gateway_subscription_id, - license_key = _license_key, - kdf = _kdf, - kdf_iterations = _kdf_iterations, - creation_date = _creation_date, - revision_date = _revision_date - WHERE - id = _id - ; -end; -$$ diff --git a/src/Sql/PostgreSQL/Functions/user_update_keys.sql b/src/Sql/PostgreSQL/Functions/user_update_keys.sql deleted file mode 100644 index 90c7a25168..0000000000 --- a/src/Sql/PostgreSQL/Functions/user_update_keys.sql +++ /dev/null @@ -1,27 +0,0 @@ -DROP FUNCTION IF EXISTS user_update_keys (UUID,VARCHAR,TEXT,TEXT,TIMESTAMPTZ); - -CREATE OR REPLACE FUNCTION user_update_keys -( - _id UUID, - _security_stamp VARCHAR, - _key TEXT, - _private_key TEXT, - _revision_date TIMESTAMPTZ -) -RETURNS VOID -LANGUAGE 'plpgsql' -AS -$BODY$ -BEGIN - UPDATE - "user" - SET - security_stamp = _security_stamp, - key = _key, - private_key = _private_key, - revision_date = _revision_date, - account_revision_date = _revision_date - WHERE - id = _id; -END -$BODY$ diff --git a/src/Sql/PostgreSQL/Functions/user_update_renewal_reminder_date.sql b/src/Sql/PostgreSQL/Functions/user_update_renewal_reminder_date.sql deleted file mode 100644 index 2dc43f5813..0000000000 --- a/src/Sql/PostgreSQL/Functions/user_update_renewal_reminder_date.sql +++ /dev/null @@ -1,20 +0,0 @@ -DROP FUNCTION IF EXISTS user_update_renewal_reminder_date (UUID,TIMESTAMPTZ); - -CREATE OR REPLACE FUNCTION user_update_renewal_reminder_date -( - _id UUID, - _renewal_reminder_date TIMESTAMPTZ -) -RETURNS VOID -LANGUAGE 'plpgsql' -AS -$BODY$ -BEGIN - UPDATE - "user" - SET - renewal_reminder_date = _renewal_reminder_date - WHERE - id = _id; -end -$BODY$ diff --git a/src/Sql/PostgreSQL/Role/create_role.sql b/src/Sql/PostgreSQL/Role/create_role.sql deleted file mode 100644 index 01709f3f77..0000000000 --- a/src/Sql/PostgreSQL/Role/create_role.sql +++ /dev/null @@ -1,2 +0,0 @@ --- Example command to create the standard bitwarden user role in an existing postgreSQL instance --- CREATE ROLE bitwarden NOSUPERUSER NOCREATEDB NOCREATEROLE NOINHERIT LOGIN PASSWORD 'bitwarden'; diff --git a/src/Sql/PostgreSQL/Schema/bitwarden.sql b/src/Sql/PostgreSQL/Schema/bitwarden.sql deleted file mode 100644 index 25b50cfe38..0000000000 --- a/src/Sql/PostgreSQL/Schema/bitwarden.sql +++ /dev/null @@ -1,3 +0,0 @@ -DROP SCHEMA if exists bitwarden cascade; -CREATE SCHEMA bitwarden AUTHORIZATION bitwarden; -ALTER ROLE bitwarden SET search_path TO bitwarden; diff --git a/src/Sql/PostgreSQL/Tables/cipher.sql b/src/Sql/PostgreSQL/Tables/cipher.sql deleted file mode 100644 index f81c97eac7..0000000000 --- a/src/Sql/PostgreSQL/Tables/cipher.sql +++ /dev/null @@ -1,29 +0,0 @@ -DROP TABLE IF EXISTS cipher; - -CREATE TABLE IF NOT EXISTS cipher ( - id UUID NOT NULL, - user_id UUID NULL, - organization_id UUID NULL, - type SMALLINT NOT NULL, - data TEXT NOT NULL, - favorites TEXT NULL, - folders TEXT NULL, - attachments TEXT NULL, - creation_date TIMESTAMPTZ NOT NULL, - revision_date TIMESTAMPTZ NOT NULL, - CONSTRAINT pk_cipher PRIMARY KEY (id), - CONSTRAINT fk_cipher_organization FOREIGN KEY (organization_id) REFERENCES Organization (id), - CONSTRAINT fk_cipher_user FOREIGN KEY (user_id) REFERENCES "user" (id) -); - - - -CREATE INDEX ix_cipher_user_id_organization_id_include_all - ON cipher(user_id ASC, organization_id ASC) - INCLUDE (type, data, favorites, folders, attachments, creation_date, revision_date); - - - -CREATE INDEX ix_cipher_organization_id - ON cipher(organization_id ASC); - diff --git a/src/Sql/PostgreSQL/Tables/collection.sql b/src/Sql/PostgreSQL/Tables/collection.sql deleted file mode 100644 index c6384fc362..0000000000 --- a/src/Sql/PostgreSQL/Tables/collection.sql +++ /dev/null @@ -1,19 +0,0 @@ -DROP TABLE IF EXISTS collection; - -CREATE TABLE IF NOT EXISTS collection ( - id UUID NOT NULL, - organization_id UUID NOT NULL, - name TEXT NOT NULL, - external_id VARCHAR (300) NULL, - creation_date TIMESTAMPTZ NOT NULL, - revision_date TIMESTAMPTZ NOT NULL, - CONSTRAINT pk_collection PRIMARY KEY (id), - CONSTRAINT fk_collection_organization FOREIGN KEY (organization_id) REFERENCES organization (id) ON DELETE CASCADE -); - - -CREATE INDEX ix_collection_organization_id_include_all - ON collection(organization_id ASC) - INCLUDE(creation_date, name, revision_date); - - diff --git a/src/Sql/PostgreSQL/Tables/collection_cipher.sql b/src/Sql/PostgreSQL/Tables/collection_cipher.sql deleted file mode 100644 index d40773ef6f..0000000000 --- a/src/Sql/PostgreSQL/Tables/collection_cipher.sql +++ /dev/null @@ -1,15 +0,0 @@ -DROP TABLE IF EXISTS collection_cipher; - -CREATE TABLE IF NOT EXISTS collection_cipher ( - collection_id UUID NOT NULL, - cipher_id UUID NOT NULL, - CONSTRAINT pk_collection_cipher PRIMARY KEY (collection_id, cipher_id), - CONSTRAINT fk_collection_cipher_cipher FOREIGN KEY (cipher_id) REFERENCES cipher (id) ON DELETE CASCADE, - CONSTRAINT fk_collection_cipher_collection FOREIGN KEY (collection_id) REFERENCES collection (id) ON DELETE CASCADE -); - - - -CREATE INDEX ix_collection_cipher_cipher_id - ON collection_cipher(cipher_id ASC); - diff --git a/src/Sql/PostgreSQL/Tables/collection_group.sql b/src/Sql/PostgreSQL/Tables/collection_group.sql deleted file mode 100644 index 782cbaa248..0000000000 --- a/src/Sql/PostgreSQL/Tables/collection_group.sql +++ /dev/null @@ -1,11 +0,0 @@ -DROP TABLE IF EXISTS collection_group; - -CREATE TABLE IF NOT EXISTS collection_group ( - collection_id UUID NOT NULL, - group_id UUID NOT NULL, - read_only BIT NOT NULL, - CONSTRAINT pk_collection_group PRIMARY KEY (collection_id, group_id), - CONSTRAINT fk_collection_group_collection FOREIGN KEY (collection_id) REFERENCES collection (id), - CONSTRAINT fk_collection_group_group FOREIGN KEY (group_id) REFERENCES "group" (id) ON DELETE CASCADE -); - diff --git a/src/Sql/PostgreSQL/Tables/collection_user.sql b/src/Sql/PostgreSQL/Tables/collection_user.sql deleted file mode 100644 index f31f803c44..0000000000 --- a/src/Sql/PostgreSQL/Tables/collection_user.sql +++ /dev/null @@ -1,11 +0,0 @@ -DROP TABLE IF EXISTS collection_user; - -CREATE TABLE IF NOT EXISTS collection_user ( - collection_id UUID NOT NULL, - organization_user_id UUID NOT NULL, - read_only BIT NOT NULL, - CONSTRAINT pk_collection_user PRIMARY KEY (collection_id, organization_user_id), - CONSTRAINT fk_collection_user_collection FOREIGN KEY (collection_id) REFERENCES collection (id) ON DELETE CASCADE, - CONSTRAINT fk_collection_user_organization_user FOREIGN KEY (organization_user_id) REFERENCES organization_user (id) -); - diff --git a/src/Sql/PostgreSQL/Tables/device.sql b/src/Sql/PostgreSQL/Tables/device.sql deleted file mode 100644 index 09a6721211..0000000000 --- a/src/Sql/PostgreSQL/Tables/device.sql +++ /dev/null @@ -1,25 +0,0 @@ -DROP TABLE IF EXISTS device; - -CREATE TABLE IF NOT EXISTS device ( - id UUID NOT NULL, - user_id UUID NOT NULL, - name VARCHAR (50) NOT NULL, - type SMALLINT NOT NULL, - identifier VARCHAR (50) NOT NULL, - push_token VARCHAR (255) NULL, - creation_date TIMESTAMPTZ NOT NULL, - revision_date TIMESTAMPTZ NOT NULL, - CONSTRAINT pk_device PRIMARY KEY (id), - CONSTRAINT fk_device_user FOREIGN KEY (user_id) REFERENCES "user" (id) -); - - - -CREATE UNIQUE INDEX ux_device_user_id_identifier - ON device(user_id ASC, identifier ASC); - - - -CREATE INDEX ix_device_identifier - ON device(identifier ASC); - diff --git a/src/Sql/PostgreSQL/Tables/event.sql b/src/Sql/PostgreSQL/Tables/event.sql deleted file mode 100644 index d497efa135..0000000000 --- a/src/Sql/PostgreSQL/Tables/event.sql +++ /dev/null @@ -1,22 +0,0 @@ -DROP TABLE IF EXISTS event; - -CREATE TABLE IF NOT EXISTS event ( - id UUID NOT NULL, - type INT NOT NULL, - user_id UUID NULL, - organization_id UUID NULL, - cipher_id UUID NULL, - collection_id UUID NULL, - group_id UUID NULL, - organization_user_id UUID NULL, - acting_user_id UUID NULL, - device_type SMALLINT NULL, - ip_address VARCHAR(50) NULL, - date TIMESTAMPTZ NOT NULL, - CONSTRAINT pk_event PRIMARY KEY (id) -); - - -CREATE INDEX ix_event_date_organization_id_user_id - ON event(date DESC, organization_id ASC, acting_user_id ASC, cipher_id ASC); - diff --git a/src/Sql/PostgreSQL/Tables/folder.sql b/src/Sql/PostgreSQL/Tables/folder.sql deleted file mode 100644 index ba4b846c66..0000000000 --- a/src/Sql/PostgreSQL/Tables/folder.sql +++ /dev/null @@ -1,18 +0,0 @@ -DROP TABLE IF EXISTS folder; - -CREATE TABLE IF NOT EXISTS folder ( - id UUID NOT NULL, - user_id UUID NOT NULL, - name TEXT NULL, - creation_date TIMESTAMPTZ NOT NULL, - revision_date TIMESTAMPTZ NOT NULL, - CONSTRAINT pk_folder PRIMARY KEY (id), - CONSTRAINT fk_folder_user FOREIGN KEY (user_id) REFERENCES "user" (id) -); - - - -CREATE INDEX ix_folder_user_id_include_all - ON folder(user_id ASC) - INCLUDE (name, creation_date, revision_date); - diff --git a/src/Sql/PostgreSQL/Tables/grant.sql b/src/Sql/PostgreSQL/Tables/grant.sql deleted file mode 100644 index 6a6ab36619..0000000000 --- a/src/Sql/PostgreSQL/Tables/grant.sql +++ /dev/null @@ -1,22 +0,0 @@ -DROP TABLE IF EXISTS "grant"; - -CREATE TABLE IF NOT EXISTS "grant" ( - key VARCHAR (200) NOT NULL, - type VARCHAR (50) NULL, - subject_id VARCHAR (50) NULL, - client_id VARCHAR (50) NOT NULL, - creation_date TIMESTAMPTZ NOT NULL, - expiration_date TIMESTAMPTZ NULL, - data TEXT NOT NULL, - CONSTRAINT pk_grant PRIMARY KEY (key) -); - - - -CREATE INDEX ix_grant_subject_id_client_id_type - ON "grant"(subject_id ASC, client_id ASC, type ASC); - - -CREATE INDEX ix_grant_expiration_date - ON "grant"(expiration_date ASC); - diff --git a/src/Sql/PostgreSQL/Tables/group.sql b/src/Sql/PostgreSQL/Tables/group.sql deleted file mode 100644 index 8935f56263..0000000000 --- a/src/Sql/PostgreSQL/Tables/group.sql +++ /dev/null @@ -1,14 +0,0 @@ -DROP TABLE IF EXISTS "group"; - -CREATE TABLE IF NOT EXISTS "group" ( - id UUID NOT NULL, - organization_id UUID NOT NULL, - name VARCHAR (100) NOT NULL, - access_all BIT NOT NULL, - external_id VARCHAR (300) NULL, - creation_date TIMESTAMPTZ NOT NULL, - revision_date TIMESTAMPTZ NOT NULL, - CONSTRAINT pk_group PRIMARY KEY (id), - CONSTRAINT fk_group_organization FOREIGN KEY (organization_id) REFERENCES organization (id) ON DELETE CASCADE -); - diff --git a/src/Sql/PostgreSQL/Tables/group_user.sql b/src/Sql/PostgreSQL/Tables/group_user.sql deleted file mode 100644 index 573cb5073e..0000000000 --- a/src/Sql/PostgreSQL/Tables/group_user.sql +++ /dev/null @@ -1,17 +0,0 @@ -DROP TABLE IF EXISTS group_user; - -CREATE TABLE IF NOT EXISTS group_user ( - group_id UUID NOT NULL, - organization_user_id UUID NOT NULL, - CONSTRAINT Pk_group_user PRIMARY KEY (group_id, organization_user_id), - CONSTRAINT Fk_group_user_group FOREIGN KEY (group_id) REFERENCES "group" (id) ON DELETE CASCADE, - CONSTRAINT Fk_group_user_organization_user FOREIGN KEY (organization_user_id) REFERENCES organization_user (id) -); - - - -CREATE INDEX ix_group_user_organization_user_id - ON group_user(organization_user_id ASC); - - - diff --git a/src/Sql/PostgreSQL/Tables/installation.sql b/src/Sql/PostgreSQL/Tables/installation.sql deleted file mode 100644 index dfa5430070..0000000000 --- a/src/Sql/PostgreSQL/Tables/installation.sql +++ /dev/null @@ -1,12 +0,0 @@ -DROP TABLE IF EXISTS installation; - - -CREATE TABLE IF NOT EXISTS installation ( - id UUID NOT NULL, - email VARCHAR (256) NOT NULL, - key VARCHAR (150) NOT NULL, - enabled BIT NOT NULL, - creation_date TIMESTAMPTZ NOT NULL, - CONSTRAINT pk_installation PRIMARY KEY (id) -); - diff --git a/src/Sql/PostgreSQL/Tables/organization.sql b/src/Sql/PostgreSQL/Tables/organization.sql deleted file mode 100644 index 328be5f6d2..0000000000 --- a/src/Sql/PostgreSQL/Tables/organization.sql +++ /dev/null @@ -1,44 +0,0 @@ -DROP TABLE IF EXISTS organization; - -CREATE TABLE IF NOT EXISTS organization ( - id UUID NOT NULL, - name VARCHAR (50) NOT NULL, - business_name VARCHAR (50) NULL, - business_address_1 VARCHAR (50) NULL, - business_address_2 VARCHAR (50) NULL, - business_address_3 VARCHAR (50) NULL, - business_country VARCHAR (2) NULL, - business_tax_number VARCHAR (30) NULL, - billing_email VARCHAR (256) NOT NULL, - plan VARCHAR (50) NOT NULL, - plan_type SMALLINT NOT NULL, - seats SMALLINT NULL, - max_collections SMALLINT NULL, - use_groups BIT NOT NULL, - use_directory BIT NOT NULL, - use_events BIT NOT NULL, - use_totp BIT NOT NULL, - use_2fa BIT NOT NULL, - use_api BIT NOT NULL, - self_host BIT NOT NULL, - users_get_premium BIT NOT NULL, - storage BIGINT NULL, - max_storage_gb SMALLINT NULL, - gateway SMALLINT NULL, - gateway_customer_id VARCHAR (50) NULL, - gateway_subscription_id VARCHAR (50) NULL, - enabled BIT NOT NULL, - license_key VARCHAR (100) NULL, - api_key VARCHAR (30) NOT NULL, - two_factor_providers TEXT NULL, - expiration_date TIMESTAMPTZ NULL, - creation_date TIMESTAMPTZ NOT NULL, - revision_date TIMESTAMPTZ NOT NULL, - CONSTRAINT pk_organization PRIMARY KEY (id) -); - - -CREATE INDEX ix_organization_enabled - ON organization(id ASC, enabled ASC) - INCLUDE (use_totp); - diff --git a/src/Sql/PostgreSQL/Tables/organization_user.sql b/src/Sql/PostgreSQL/Tables/organization_user.sql deleted file mode 100644 index 8c19fb790c..0000000000 --- a/src/Sql/PostgreSQL/Tables/organization_user.sql +++ /dev/null @@ -1,28 +0,0 @@ -DROP TABLE IF EXISTS organization_user; - -CREATE TABLE IF NOT EXISTS organization_user ( - id UUID NOT NULL, - organization_id UUID NOT NULL, - user_id UUID NULL, - email VARCHAR (256) NULL, - key TEXT NULL, - status SMALLINT NOT NULL, - type SMALLINT NOT NULL, - access_all BIT NOT NULL, - external_id VARCHAR (300) NULL, - creation_date TIMESTAMPTZ NOT NULL, - revision_date TIMESTAMPTZ NOT NULL, - CONSTRAINT pk_organization_user PRIMARY KEY (id), - CONSTRAINT fk_organization_user_organization FOREIGN KEY (organization_id) REFERENCES organization (id) ON DELETE CASCADE, - CONSTRAINT fk_organization_user_user FOREIGN KEY (user_id) REFERENCES "user" (id) -); - - -CREATE INDEX ix_organization_user_user_id_organization_id_status - ON organization_user(user_id ASC, organization_id ASC, Status ASC) - INCLUDE (access_all); - - -CREATE INDEX ix_organization_user_organization_id - ON organization_user(organization_id aSC); - diff --git a/src/Sql/PostgreSQL/Tables/transaction.sql b/src/Sql/PostgreSQL/Tables/transaction.sql deleted file mode 100644 index 094554ccba..0000000000 --- a/src/Sql/PostgreSQL/Tables/transaction.sql +++ /dev/null @@ -1,29 +0,0 @@ -DROP TABLE IF EXISTS "transaction"; - -CREATE TABLE IF NOT EXISTS "transaction" ( - id UUID NOT NULL, - user_id UUID NULL, - organization_id UUID NULL, - type SMALLINT NOT NULL, - amount NUMERIC (19,4) NOT NULL, - refunded BIT NULL, - refunded_amount NUMERIC (19,4) NULL, - details VARCHAR(100) NULL, - payment_method_type SMALLINT NULL, - gateway SMALLINT NULL, - gateway_id VARCHAR(50) NULL, - creation_date TIMESTAMPTZ NOT NULL, - CONSTRAINT pk_transaction PRIMARY KEY (id), - CONSTRAINT fk_transaction_user FOREIGN KEY (user_id) REFERENCES "user" (id) ON DELETE CASCADE, - CONSTRAINT fk_transaction_organization FOREIGN KEY (organization_id) REFERENCES organization (id) ON DELETE CASCADE -); - - -CREATE UNIQUE INDEX ix_transaction_gateway_gatewayid - ON "transaction"(gateway ASC, gateway_id ASC) - WHERE gateway IS NOT NULL AND gateway_id IS NOT NULL; - - -CREATE INDEX ix_transaction_user_id_organization_id_creation_date - ON "transaction"(user_id ASC, Organization_id ASC, Creation_date ASC); - diff --git a/src/Sql/PostgreSQL/Tables/u2f.sql b/src/Sql/PostgreSQL/Tables/u2f.sql deleted file mode 100644 index 19166ba82f..0000000000 --- a/src/Sql/PostgreSQL/Tables/u2f.sql +++ /dev/null @@ -1,22 +0,0 @@ -DROP TABLE IF EXISTS u2f CASCADE; - -CREATE TABLE IF NOT EXISTS u2f ( - id SERIAL NOT NULL, - user_id UUID NOT NULL, - key_handle VARCHAR (200) NULL, - challenge VARCHAR (200) NOT NULL, - app_id VARCHAR (50) NOT NULL, - version VARCHAR (20) NOT NULL, - creation_date TIMESTAMPTZ NOT NULL, - CONSTRAINT pk_u2f PRIMARY KEY (id), - CONSTRAINT fk_u2f_user FOREIGN KEY (user_id) REFERENCES "user" (id) -); - - -CREATE INDEX ix_u2f_creation_date - ON u2f(creation_date ASC); - - -CREATE INDEX ix_u2f_user_id - ON u2f(user_id ASC); - diff --git a/src/Sql/PostgreSQL/Tables/user.sql b/src/Sql/PostgreSQL/Tables/user.sql deleted file mode 100644 index 8318db8fad..0000000000 --- a/src/Sql/PostgreSQL/Tables/user.sql +++ /dev/null @@ -1,43 +0,0 @@ -DROP TABLE IF EXISTS "user" CASCADE; - -CREATE TABLE "user" ( - id UUID NOT NULL, - name VARCHAR (50) NULL, - email VARCHAR (256) NOT NULL, - email_verified BOOLEAN NOT NULL, - master_password VARCHAR (300) NOT NULL, - master_password_hint VARCHAR (50) NULL, - culture VARCHAR (10) NOT NULL, - security_stamp VARCHAR (50) NOT NULL, - two_factor_providers TEXT NULL, - two_factor_recovery_code VARCHAR (32) NULL, - equivalent_domains TEXT NULL, - excluded_global_equivalent_domains TEXT NULL, - account_revision_date TIMESTAMPTZ NOT NULL, - key TEXT NULL, - public_key TEXT NULL, - private_key TEXT NULL, - premium BOOLEAN NOT NULL, - premium_expiration_date TIMESTAMPTZ NULL, - renewal_reminder_date TIMESTAMPTZ NULL, - storage BIGINT NULL, - max_storage_gb SMALLINT NULL, - gateway SMALLINT NULL, - gateway_customer_id VARCHAR (50) NULL, - gateway_subscription_id VARCHAR (50) NULL, - license_key VARCHAR (100) NULL, - kdf SMALLINT NOT NULL, - kdf_iterations INT NOT NULL, - creation_date TIMESTAMPTZ NOT NULL, - revision_date TIMESTAMPTZ NOT NULL, - CONSTRAINT pk_user PRIMARY KEY (id) -); - - -CREATE UNIQUE INDEX ix_user_email - ON "user"(email ASC); - - -CREATE INDEX ix_user_premium_premium_expiration_date_renewal_reminder_date - ON "user"(premium ASC, premium_expiration_date ASC, renewal_reminder_date ASC); - diff --git a/src/Sql/PostgreSQL/Views/cipher_view.sql b/src/Sql/PostgreSQL/Views/cipher_view.sql deleted file mode 100644 index 8ab20c7d88..0000000000 --- a/src/Sql/PostgreSQL/Views/cipher_view.sql +++ /dev/null @@ -1,6 +0,0 @@ -CREATE OR REPLACE VIEW cipher_view -AS -SELECT - * -FROM - cipher; \ No newline at end of file diff --git a/src/Sql/PostgreSQL/Views/collection_view.sql b/src/Sql/PostgreSQL/Views/collection_view.sql deleted file mode 100644 index 89ea0ce5aa..0000000000 --- a/src/Sql/PostgreSQL/Views/collection_view.sql +++ /dev/null @@ -1,6 +0,0 @@ -CREATE OR REPLACE VIEW collection_view -AS -SELECT - * -FROM - collection; \ No newline at end of file diff --git a/src/Sql/PostgreSQL/Views/device_view.sql b/src/Sql/PostgreSQL/Views/device_view.sql deleted file mode 100644 index f2ed62e4c2..0000000000 --- a/src/Sql/PostgreSQL/Views/device_view.sql +++ /dev/null @@ -1,6 +0,0 @@ -CREATE OR REPLACE VIEW device_view -AS -SELECT - * -FROM - device; \ No newline at end of file diff --git a/src/Sql/PostgreSQL/Views/event_view.sql b/src/Sql/PostgreSQL/Views/event_view.sql deleted file mode 100644 index fe507f4042..0000000000 --- a/src/Sql/PostgreSQL/Views/event_view.sql +++ /dev/null @@ -1,6 +0,0 @@ -CREATE OR REPLACE VIEW event_view -AS -SELECT - * -FROM - event; \ No newline at end of file diff --git a/src/Sql/PostgreSQL/Views/folder_view.sql b/src/Sql/PostgreSQL/Views/folder_view.sql deleted file mode 100644 index 45fa5c61d4..0000000000 --- a/src/Sql/PostgreSQL/Views/folder_view.sql +++ /dev/null @@ -1,6 +0,0 @@ -CREATE OR REPLACE VIEW folder_view -AS -SELECT - * -FROM - folder; \ No newline at end of file diff --git a/src/Sql/PostgreSQL/Views/grant_view.sql b/src/Sql/PostgreSQL/Views/grant_view.sql deleted file mode 100644 index 5f01479441..0000000000 --- a/src/Sql/PostgreSQL/Views/grant_view.sql +++ /dev/null @@ -1,6 +0,0 @@ -CREATE OR REPLACE VIEW grant_view -AS -SELECT - * -FROM - "grant"; \ No newline at end of file diff --git a/src/Sql/PostgreSQL/Views/group_view.sql b/src/Sql/PostgreSQL/Views/group_view.sql deleted file mode 100644 index 000a6d00d3..0000000000 --- a/src/Sql/PostgreSQL/Views/group_view.sql +++ /dev/null @@ -1,6 +0,0 @@ -CREATE OR REPLACE VIEW group_view -AS -SELECT - * -FROM - "group"; \ No newline at end of file diff --git a/src/Sql/PostgreSQL/Views/installation_view.sql b/src/Sql/PostgreSQL/Views/installation_view.sql deleted file mode 100644 index c20b032cd3..0000000000 --- a/src/Sql/PostgreSQL/Views/installation_view.sql +++ /dev/null @@ -1,6 +0,0 @@ -CREATE OR REPLACE VIEW installation_view -AS -SELECT - * -FROM - installation; \ No newline at end of file diff --git a/src/Sql/PostgreSQL/Views/organization_user_organization_details_view.sql b/src/Sql/PostgreSQL/Views/organization_user_organization_details_view.sql deleted file mode 100644 index f5de1ce36b..0000000000 --- a/src/Sql/PostgreSQL/Views/organization_user_organization_details_view.sql +++ /dev/null @@ -1,25 +0,0 @@ -CREATE OR REPLACE VIEW organization_user_organization_details_view -AS -SELECT - ou.user_id, - ou.organization_id, - o.name, - o.enabled, - o.use_groups, - o.use_directory, - o.use_events, - o.use_totp, - o.use_2fa, - o.use_api, - o.self_host, - o.users_get_premium, - o.seats, - o.max_collections, - o.max_storage_gb, - ou.key, - ou.status, - ou.type -FROM - organization_user ou -INNER JOIN - organization o ON o.id = ou.organization_id; \ No newline at end of file diff --git a/src/Sql/PostgreSQL/Views/organization_user_user_details_view.sql b/src/Sql/PostgreSQL/Views/organization_user_user_details_view.sql deleted file mode 100644 index f436c65bd0..0000000000 --- a/src/Sql/PostgreSQL/Views/organization_user_user_details_view.sql +++ /dev/null @@ -1,18 +0,0 @@ -CREATE OR REPLACE VIEW organization_user_user_details_view -AS -SELECT - ou.id, - ou.user_id, - ou.organization_id, - u.name, - coalesce(u.email, ou.email) email, - u.two_factor_providers, - u.premium, - ou.status, - ou.type, - ou.access_all, - ou.external_id -FROM - organization_user ou -LEFT JOIN - "user" u ON U.id = ou.user_id; \ No newline at end of file diff --git a/src/Sql/PostgreSQL/Views/organization_user_view.sql b/src/Sql/PostgreSQL/Views/organization_user_view.sql deleted file mode 100644 index 0238c84981..0000000000 --- a/src/Sql/PostgreSQL/Views/organization_user_view.sql +++ /dev/null @@ -1,6 +0,0 @@ -CREATE OR REPLACE VIEW organization_user_view -AS -SELECT - * -FROM - organization_user; \ No newline at end of file diff --git a/src/Sql/PostgreSQL/Views/organization_view.sql b/src/Sql/PostgreSQL/Views/organization_view.sql deleted file mode 100644 index 005e7f39a2..0000000000 --- a/src/Sql/PostgreSQL/Views/organization_view.sql +++ /dev/null @@ -1,6 +0,0 @@ -CREATE OR REPLACE VIEW organization_view -AS -SELECT - * -FROM - organization; \ No newline at end of file diff --git a/src/Sql/PostgreSQL/Views/transaction_view.sql b/src/Sql/PostgreSQL/Views/transaction_view.sql deleted file mode 100644 index 9eb4b01d1d..0000000000 --- a/src/Sql/PostgreSQL/Views/transaction_view.sql +++ /dev/null @@ -1,6 +0,0 @@ -CREATE OR REPLACE VIEW transaction_view -AS -SELECT - * -FROM - transaction; \ No newline at end of file diff --git a/src/Sql/PostgreSQL/Views/u2f_view.sql b/src/Sql/PostgreSQL/Views/u2f_view.sql deleted file mode 100644 index 756a40d2c1..0000000000 --- a/src/Sql/PostgreSQL/Views/u2f_view.sql +++ /dev/null @@ -1,6 +0,0 @@ -CREATE VIEW u2f_view -AS -SELECT - * -FROM - u2f; \ No newline at end of file diff --git a/src/Sql/PostgreSQL/Views/user_view.sql b/src/Sql/PostgreSQL/Views/user_view.sql deleted file mode 100644 index c91ea0a91a..0000000000 --- a/src/Sql/PostgreSQL/Views/user_view.sql +++ /dev/null @@ -1,6 +0,0 @@ -CREATE VIEW user_view -AS -SELECT - * -FROM - "user";