From d799545179173ac768b8446568cd06698c7eeb63 Mon Sep 17 00:00:00 2001 From: Happy2C0de <46957159+Happy2C0de@users.noreply.github.com> Date: Sat, 4 Nov 2023 21:44:03 +0100 Subject: [PATCH 1/3] Database schema update (postgres) --- ...accountwallet_walletoperationhistories.sql | 32 +++--- ...untdids_accountkeys_accountcredentials.sql | 103 ++++++++++++++++++ .../db/postgres/V5__create_table_issuers.sql | 34 ++++++ ...V6__insert_default_issuer_for_accounts.sql | 10 ++ 4 files changed, 163 insertions(+), 16 deletions(-) create mode 100644 src/main/resources/db/postgres/V4__create_tables_keys_dids_credentials_accountdids_accountkeys_accountcredentials.sql create mode 100644 src/main/resources/db/postgres/V5__create_table_issuers.sql create mode 100644 src/main/resources/db/postgres/V6__insert_default_issuer_for_accounts.sql diff --git a/src/main/resources/db/postgres/V1__create_tables_account_email_wallet_accountwallet_walletoperationhistories.sql b/src/main/resources/db/postgres/V1__create_tables_account_email_wallet_accountwallet_walletoperationhistories.sql index 17b36bd..67d5f1e 100644 --- a/src/main/resources/db/postgres/V1__create_tables_account_email_wallet_accountwallet_walletoperationhistories.sql +++ b/src/main/resources/db/postgres/V1__create_tables_account_email_wallet_accountwallet_walletoperationhistories.sql @@ -3,9 +3,9 @@ -- ---------------------------------- CREATE TABLE IF NOT EXISTS "emails" ( - id uuid NOT NULL, - email text COLLATE pg_catalog."default" NOT NULL, - password text COLLATE pg_catalog."default" NOT NULL, + "id" uuid NOT NULL, + "email" text COLLATE pg_catalog."default" NOT NULL, + "password" text COLLATE pg_catalog."default" NOT NULL, CONSTRAINT "emails_pkey" PRIMARY KEY (id), CONSTRAINT email UNIQUE (email) ); @@ -14,9 +14,9 @@ CREATE TABLE IF NOT EXISTS "emails" -- ---------------------------------- CREATE TABLE IF NOT EXISTS "wallets" ( - id uuid NOT NULL, - address text COLLATE pg_catalog."default" NOT NULL, - ecosystem text COLLATE pg_catalog."default" NOT NULL, + "id" uuid NOT NULL, + "address" text COLLATE pg_catalog."default" NOT NULL, + "ecosystem" text COLLATE pg_catalog."default" NOT NULL, CONSTRAINT wallets_pkey PRIMARY KEY (id), CONSTRAINT address UNIQUE (address) ); @@ -25,9 +25,9 @@ CREATE TABLE IF NOT EXISTS "wallets" -- ---------------------------------- CREATE TABLE IF NOT EXISTS "accounts" ( - id uuid NOT NULL, - email uuid NULL, - wallet uuid NULL, + "id" uuid NOT NULL, + "email" uuid NULL, + "wallet" uuid NULL, CONSTRAINT accounts_pkey PRIMARY KEY (id), CONSTRAINT accounts_email_wallet_unique UNIQUE (email, wallet) INCLUDE(email, wallet), @@ -45,9 +45,9 @@ CREATE TABLE IF NOT EXISTS "accounts" -- ---------------------------------- CREATE TABLE IF NOT EXISTS "account_wallets" ( - id uuid NOT NULL, - account uuid NOT NULL, - wallet uuid NOT NULL, + "id" uuid NOT NULL, + "account" uuid NOT NULL, + "wallet" uuid NOT NULL, CONSTRAINT account_wallets_pkey PRIMARY KEY (id), CONSTRAINT account_wallets_account_fk FOREIGN KEY (account) REFERENCES "accounts" (id) MATCH SIMPLE @@ -63,11 +63,11 @@ CREATE TABLE IF NOT EXISTS "account_wallets" -- ---------------------------------- CREATE TABLE IF NOT EXISTS "wallet_operation_histories" ( - id uuid NOT NULL, - account uuid NOT NULL, + "id" uuid NOT NULL, + "account" uuid NOT NULL, "timestamp" text COLLATE pg_catalog."default" NOT NULL, - operation text COLLATE pg_catalog."default" NOT NULL, - data text COLLATE pg_catalog."default" NOT NULL, + "operation" text COLLATE pg_catalog."default" NOT NULL, + "data" text COLLATE pg_catalog."default" NOT NULL, CONSTRAINT wallet_operation_histories_pkey PRIMARY KEY (id), CONSTRAINT wallet_operation_histories_account_fk FOREIGN KEY (account) REFERENCES "accounts" (id) MATCH SIMPLE diff --git a/src/main/resources/db/postgres/V4__create_tables_keys_dids_credentials_accountdids_accountkeys_accountcredentials.sql b/src/main/resources/db/postgres/V4__create_tables_keys_dids_credentials_accountdids_accountkeys_accountcredentials.sql new file mode 100644 index 0000000..6fc0ff4 --- /dev/null +++ b/src/main/resources/db/postgres/V4__create_tables_keys_dids_credentials_accountdids_accountkeys_accountcredentials.sql @@ -0,0 +1,103 @@ +-- ---------------------------------- +-- Keys table +-- ---------------------------------- +CREATE TABLE IF NOT EXISTS "keys" +( + "id" uuid NOT NULL, + "kid" text COLLATE pg_catalog."default" NOT NULL, + "document" text COLLATE pg_catalog."default" NOT NULL, + CONSTRAINT "keys_pkey" PRIMARY KEY (id) +); +-- ---------------------------------- +-- Dids table +-- ---------------------------------- +CREATE TABLE IF NOT EXISTS "dids" +( + "id" uuid NOT NULL, + "did" text COLLATE pg_catalog."default" NOT NULL, + "document" text COLLATE pg_catalog."default" NOT NULL, + "key" uuid NOT NULL, + CONSTRAINT "dids_pkey" PRIMARY KEY (id), + CONSTRAINT did_key_fk FOREIGN KEY (key) + REFERENCES public.keys (id) MATCH SIMPLE + ON UPDATE CASCADE + ON DELETE CASCADE +); +-- ---------------------------------- +-- Credentials table +-- ---------------------------------- +CREATE TABLE IF NOT EXISTS "credentials" +( + "id" uuid NOT NULL, + "cid" text COLLATE pg_catalog."default" NOT NULL, + "document" text COLLATE pg_catalog."default" NOT NULL, + CONSTRAINT "credentials_pkey" PRIMARY KEY (id) +); +-- ---------------------------------- +-- AccountKeys table +-- ---------------------------------- +CREATE TABLE IF NOT EXISTS "account_keys" +( + "id" uuid NOT NULL, + "account" uuid NOT NULL, + "key" uuid NOT NULL, + CONSTRAINT "account_keys_pkey" PRIMARY KEY (id), + CONSTRAINT account_keys_account_fk FOREIGN KEY (account) + REFERENCES public.accounts (id) MATCH SIMPLE + ON UPDATE CASCADE + ON DELETE CASCADE, + CONSTRAINT account_keys_key_fk FOREIGN KEY (key) + REFERENCES public.keys (id) MATCH SIMPLE + ON UPDATE CASCADE + ON DELETE CASCADE +); +-- ---------------------------------- +-- AccountDids table +-- ---------------------------------- +CREATE TABLE IF NOT EXISTS "account_dids" +( + "id" uuid NOT NULL, + "account" uuid NOT NULL, + "did" uuid NOT NULL, + "alias" text COLLATE pg_catalog."default" NOT NULL, + "default" BOOLEAN NOT NULL DEFAULT FALSE, + CONSTRAINT "account_dids_pkey" PRIMARY KEY (id), + CONSTRAINT account_dids_account_fk FOREIGN KEY (account) + REFERENCES public.accounts (id) MATCH SIMPLE + ON UPDATE CASCADE + ON DELETE CASCADE, + CONSTRAINT account_dids_did_fk FOREIGN KEY (did) + REFERENCES public.dids (id) MATCH SIMPLE + ON UPDATE CASCADE + ON DELETE CASCADE +); +-- ---------------------------------- +-- AccountCredentials table +-- ---------------------------------- +CREATE TABLE IF NOT EXISTS "account_credentials" +( + "id" uuid NOT NULL, + "account" uuid NOT NULL, + "credential" uuid NOT NULL, + CONSTRAINT "account_credentials_pkey" PRIMARY KEY (id), + CONSTRAINT account_credentials_account_fk FOREIGN KEY (account) + REFERENCES public.accounts (id) MATCH SIMPLE + ON UPDATE CASCADE + ON DELETE CASCADE, + CONSTRAINT account_credentials_credential_fk FOREIGN KEY (credential) + REFERENCES public.credentials (id) MATCH SIMPLE + ON UPDATE CASCADE + ON DELETE CASCADE +); +-- ---------------------------------- +-- Keys index +-- ---------------------------------- +CREATE UNIQUE INDEX keys_kid ON keys(kid); +-- ---------------------------------- +-- Dids index +-- ---------------------------------- +CREATE UNIQUE INDEX dids_did ON dids(did); +-- ---------------------------------- +-- Credentials index +-- ---------------------------------- +CREATE UNIQUE INDEX credentials_cid ON credentials(cid); \ No newline at end of file diff --git a/src/main/resources/db/postgres/V5__create_table_issuers.sql b/src/main/resources/db/postgres/V5__create_table_issuers.sql new file mode 100644 index 0000000..b25c4d4 --- /dev/null +++ b/src/main/resources/db/postgres/V5__create_table_issuers.sql @@ -0,0 +1,34 @@ +-- ---------------------------------- +-- Issuers table +-- ---------------------------------- +CREATE TABLE IF NOT EXISTS "issuers" +( + "id" uuid NOT NULL, + "name" text COLLATE pg_catalog."default" NOT NULL, + "description" text COLLATE pg_catalog."default" NOT NULL, + "ui" text COLLATE pg_catalog."default" NOT NULL, + "configuration" text COLLATE pg_catalog."default" NOT NULL, + CONSTRAINT "issuers_pkey" PRIMARY KEY (id) +); +-- ---------------------------------- +-- AccountIssuers table +-- ---------------------------------- +CREATE TABLE IF NOT EXISTS "account_issuers" +( + "id" uuid NOT NULL, + "account" uuid NOT NULL, + "issuer" uuid NOT NULL, + CONSTRAINT "account_issuers_pkey" PRIMARY KEY (id), + CONSTRAINT account_issuers_account_fk FOREIGN KEY (account) + REFERENCES public.accounts (id) MATCH SIMPLE + ON UPDATE CASCADE + ON DELETE CASCADE, + CONSTRAINT account_issuers_issuer_fk FOREIGN KEY (issuer) + REFERENCES public.issuers (id) MATCH SIMPLE + ON UPDATE CASCADE + ON DELETE CASCADE +); +-- ---------------------------------- +-- AccountIssuers unique index +-- ---------------------------------- +CREATE UNIQUE INDEX account_issuers_account_issuer ON account_issuers(account, issuer); \ No newline at end of file diff --git a/src/main/resources/db/postgres/V6__insert_default_issuer_for_accounts.sql b/src/main/resources/db/postgres/V6__insert_default_issuer_for_accounts.sql new file mode 100644 index 0000000..c340136 --- /dev/null +++ b/src/main/resources/db/postgres/V6__insert_default_issuer_for_accounts.sql @@ -0,0 +1,10 @@ +-- ---------------------------------- +-- Insert issuers table +-- ---------------------------------- +INSERT INTO public."issuers" ("id", "name", "description", "ui", "configuration") +VALUES ('6B638061-E4C6-4636-B4E4-F4BE2FCA582C'::UUID, 'walt.id', 'walt.id issuer portal', 'https://portal.walt.id/credentials?ids=', 'https://issuer.portal.walt.id/.well-known/openid-credential-issuer'); +-- ---------------------------------- +-- Insert account-issuers table +-- ---------------------------------- +INSERT INTO public."account_issuers" ("id", "account", "issuer") +VALUES ('3FAD4023-9E97-4DD0-8B42-9471517757EF'::UUID, 'C59A7223-BF89-A04A-97B2-7C4F121F83B1', '6B638061-E4C6-4636-B4E4-F4BE2FCA582C'); \ No newline at end of file From dc50857f63f0876dacade6c36419db1b151f3b46 Mon Sep 17 00:00:00 2001 From: mikeplotean Date: Fri, 24 Nov 2023 23:42:41 +0200 Subject: [PATCH 2/3] Add docker-compose options for Postgres DB # Conflicts: # docker-compose/docker-compose.yaml --- docker-compose/docker-compose.yaml | 4 ++++ docker-compose/wallet-backend/config/db.conf | 1 + .../wallet-backend/config/db.postgres.conf | 13 +++++++++++++ 3 files changed, 18 insertions(+) create mode 100644 docker-compose/wallet-backend/config/db.postgres.conf diff --git a/docker-compose/docker-compose.yaml b/docker-compose/docker-compose.yaml index ae02e4b..4d0232d 100644 --- a/docker-compose/docker-compose.yaml +++ b/docker-compose/docker-compose.yaml @@ -1,4 +1,8 @@ services: + # postgresdb: # Uncomment to connect a Postgres DB + # image: postgres + # environment: + # POSTGRES_PASSWORD: secret wallet-backend: image: waltid/wallet-backend:latest volumes: diff --git a/docker-compose/wallet-backend/config/db.conf b/docker-compose/wallet-backend/config/db.conf index 1ab9596..f491984 100644 --- a/docker-compose/wallet-backend/config/db.conf +++ b/docker-compose/wallet-backend/config/db.conf @@ -1 +1,2 @@ +# database = "db.postgres" database = "db.sqlite" \ No newline at end of file diff --git a/docker-compose/wallet-backend/config/db.postgres.conf b/docker-compose/wallet-backend/config/db.postgres.conf new file mode 100644 index 0000000..7295a95 --- /dev/null +++ b/docker-compose/wallet-backend/config/db.postgres.conf @@ -0,0 +1,13 @@ +hikariDataSource { + jdbcUrl = "jdbc:postgresql://postgresdb:5432/postgres" + driverClassName = "org.postgresql.Driver" + username = "postgres" + password = "secret" + transactionIsolation = "TRANSACTION_SERIALIZABLE" + maximumPoolSize = 5 + autoCommit = false + dataSource { + journalMode = WAL + fullColumnNames = false + } +} \ No newline at end of file From c78532241b820bca7b47d94fd076b3b99b88f1aa Mon Sep 17 00:00:00 2001 From: mikeplotean Date: Sat, 25 Nov 2023 00:19:58 +0200 Subject: [PATCH 3/3] chore: minor consistency related updates --- ...accountwallet_walletoperationhistories.sql | 72 ++++++++-------- ...untdids_accountkeys_accountcredentials.sql | 84 +++++++++---------- .../db/postgres/V5__create_table_issuers.sql | 30 +++---- 3 files changed, 93 insertions(+), 93 deletions(-) diff --git a/src/main/resources/db/postgres/V1__create_tables_account_email_wallet_accountwallet_walletoperationhistories.sql b/src/main/resources/db/postgres/V1__create_tables_account_email_wallet_accountwallet_walletoperationhistories.sql index 67d5f1e..0e0818d 100644 --- a/src/main/resources/db/postgres/V1__create_tables_account_email_wallet_accountwallet_walletoperationhistories.sql +++ b/src/main/resources/db/postgres/V1__create_tables_account_email_wallet_accountwallet_walletoperationhistories.sql @@ -3,40 +3,40 @@ -- ---------------------------------- CREATE TABLE IF NOT EXISTS "emails" ( - "id" uuid NOT NULL, - "email" text COLLATE pg_catalog."default" NOT NULL, - "password" text COLLATE pg_catalog."default" NOT NULL, - CONSTRAINT "emails_pkey" PRIMARY KEY (id), - CONSTRAINT email UNIQUE (email) + "id" UUID NOT NULL, + "email" TEXT COLLATE pg_catalog."default" NOT NULL, + "password" TEXT COLLATE pg_catalog."default" NOT NULL, + CONSTRAINT "emails_pkey" PRIMARY KEY ("id"), + CONSTRAINT "email" UNIQUE ("email") ); -- ---------------------------------- -- Wallets table -- ---------------------------------- CREATE TABLE IF NOT EXISTS "wallets" ( - "id" uuid NOT NULL, - "address" text COLLATE pg_catalog."default" NOT NULL, - "ecosystem" text COLLATE pg_catalog."default" NOT NULL, - CONSTRAINT wallets_pkey PRIMARY KEY (id), - CONSTRAINT address UNIQUE (address) + "id" UUID NOT NULL, + "address" TEXT COLLATE pg_catalog."default" NOT NULL, + "ecosystem" TEXT COLLATE pg_catalog."default" NOT NULL, + CONSTRAINT "wallets_pkey" PRIMARY KEY ("id"), + CONSTRAINT "address" UNIQUE ("address") ); -- ---------------------------------- -- Accounts table -- ---------------------------------- CREATE TABLE IF NOT EXISTS "accounts" ( - "id" uuid NOT NULL, - "email" uuid NULL, - "wallet" uuid NULL, - CONSTRAINT accounts_pkey PRIMARY KEY (id), - CONSTRAINT accounts_email_wallet_unique UNIQUE (email, wallet) - INCLUDE(email, wallet), - CONSTRAINT account_email_fk FOREIGN KEY (email) - REFERENCES public.emails (id) MATCH SIMPLE + "id" UUID NOT NULL, + "email" UUID NULL, + "wallet" UUID NULL, + CONSTRAINT "accounts_pkey" PRIMARY KEY ("id"), + CONSTRAINT "accounts_email_wallet_unique" UNIQUE ("email", "wallet") + INCLUDE("email", "wallet"), + CONSTRAINT "account_email_fk" FOREIGN KEY ("email") + REFERENCES "emails" ("id") MATCH SIMPLE ON UPDATE CASCADE ON DELETE CASCADE, - CONSTRAINT account_wallet_fk FOREIGN KEY (wallet) - REFERENCES public.wallets (id) MATCH SIMPLE + CONSTRAINT "account_wallet_fk" FOREIGN KEY ("wallet") + REFERENCES "wallets" ("id") MATCH SIMPLE ON UPDATE CASCADE ON DELETE CASCADE ); @@ -45,16 +45,16 @@ CREATE TABLE IF NOT EXISTS "accounts" -- ---------------------------------- CREATE TABLE IF NOT EXISTS "account_wallets" ( - "id" uuid NOT NULL, - "account" uuid NOT NULL, - "wallet" uuid NOT NULL, - CONSTRAINT account_wallets_pkey PRIMARY KEY (id), - CONSTRAINT account_wallets_account_fk FOREIGN KEY (account) - REFERENCES "accounts" (id) MATCH SIMPLE + "id" UUID NOT NULL, + "account" UUID NOT NULL, + "wallet" UUID NOT NULL, + CONSTRAINT "account_wallets_pkey" PRIMARY KEY ("id"), + CONSTRAINT "account_wallets_account_fk" FOREIGN KEY ("account") + REFERENCES "accounts" ("id") MATCH SIMPLE ON UPDATE CASCADE ON DELETE CASCADE, - CONSTRAINT account_wallets_wallet_fk FOREIGN KEY (wallet) - REFERENCES "wallets" (id) MATCH SIMPLE + CONSTRAINT "account_wallets_wallet_fk" FOREIGN KEY ("wallet") + REFERENCES "wallets" ("id") MATCH SIMPLE ON UPDATE CASCADE ON DELETE CASCADE ); @@ -63,14 +63,14 @@ CREATE TABLE IF NOT EXISTS "account_wallets" -- ---------------------------------- CREATE TABLE IF NOT EXISTS "wallet_operation_histories" ( - "id" uuid NOT NULL, - "account" uuid NOT NULL, - "timestamp" text COLLATE pg_catalog."default" NOT NULL, - "operation" text COLLATE pg_catalog."default" NOT NULL, - "data" text COLLATE pg_catalog."default" NOT NULL, - CONSTRAINT wallet_operation_histories_pkey PRIMARY KEY (id), - CONSTRAINT wallet_operation_histories_account_fk FOREIGN KEY (account) - REFERENCES "accounts" (id) MATCH SIMPLE + "id" UUID NOT NULL, + "account" UUID NOT NULL, + "timestamp" TEXT COLLATE pg_catalog."default" NOT NULL, + "operation" TEXT COLLATE pg_catalog."default" NOT NULL, + "data" TEXT COLLATE pg_catalog."default" NOT NULL, + CONSTRAINT "wallet_operation_histories_pkey" PRIMARY KEY ("id"), + CONSTRAINT "wallet_operation_histories_account_fk" FOREIGN KEY ("account") + REFERENCES "accounts" ("id") MATCH SIMPLE ON UPDATE CASCADE ON DELETE CASCADE ); \ No newline at end of file diff --git a/src/main/resources/db/postgres/V4__create_tables_keys_dids_credentials_accountdids_accountkeys_accountcredentials.sql b/src/main/resources/db/postgres/V4__create_tables_keys_dids_credentials_accountdids_accountkeys_accountcredentials.sql index 6fc0ff4..bffb2ec 100644 --- a/src/main/resources/db/postgres/V4__create_tables_keys_dids_credentials_accountdids_accountkeys_accountcredentials.sql +++ b/src/main/resources/db/postgres/V4__create_tables_keys_dids_credentials_accountdids_accountkeys_accountcredentials.sql @@ -3,23 +3,23 @@ -- ---------------------------------- CREATE TABLE IF NOT EXISTS "keys" ( - "id" uuid NOT NULL, - "kid" text COLLATE pg_catalog."default" NOT NULL, - "document" text COLLATE pg_catalog."default" NOT NULL, - CONSTRAINT "keys_pkey" PRIMARY KEY (id) + "id" UUID NOT NULL, + "kid" TEXT COLLATE pg_catalog."default" NOT NULL, + "document" TEXT COLLATE pg_catalog."default" NOT NULL, + CONSTRAINT "keys_pkey" PRIMARY KEY ("id") ); -- ---------------------------------- -- Dids table -- ---------------------------------- CREATE TABLE IF NOT EXISTS "dids" ( - "id" uuid NOT NULL, - "did" text COLLATE pg_catalog."default" NOT NULL, - "document" text COLLATE pg_catalog."default" NOT NULL, - "key" uuid NOT NULL, - CONSTRAINT "dids_pkey" PRIMARY KEY (id), - CONSTRAINT did_key_fk FOREIGN KEY (key) - REFERENCES public.keys (id) MATCH SIMPLE + "id" UUID NOT NULL, + "did" TEXT COLLATE pg_catalog."default" NOT NULL, + "document" TEXT COLLATE pg_catalog."default" NOT NULL, + "key" UUID NOT NULL, + CONSTRAINT "dids_pkey" PRIMARY KEY ("id"), + CONSTRAINT "did_key_fk" FOREIGN KEY ("key") + REFERENCES "keys" ("id") MATCH SIMPLE ON UPDATE CASCADE ON DELETE CASCADE ); @@ -28,26 +28,26 @@ CREATE TABLE IF NOT EXISTS "dids" -- ---------------------------------- CREATE TABLE IF NOT EXISTS "credentials" ( - "id" uuid NOT NULL, - "cid" text COLLATE pg_catalog."default" NOT NULL, - "document" text COLLATE pg_catalog."default" NOT NULL, - CONSTRAINT "credentials_pkey" PRIMARY KEY (id) + "id" UUID NOT NULL, + "cid" TEXT COLLATE pg_catalog."default" NOT NULL, + "document" TEXT COLLATE pg_catalog."default" NOT NULL, + CONSTRAINT "credentials_pkey" PRIMARY KEY ("id") ); -- ---------------------------------- -- AccountKeys table -- ---------------------------------- CREATE TABLE IF NOT EXISTS "account_keys" ( - "id" uuid NOT NULL, - "account" uuid NOT NULL, - "key" uuid NOT NULL, - CONSTRAINT "account_keys_pkey" PRIMARY KEY (id), - CONSTRAINT account_keys_account_fk FOREIGN KEY (account) - REFERENCES public.accounts (id) MATCH SIMPLE + "id" UUID NOT NULL, + "account" UUID NOT NULL, + "key" UUID NOT NULL, + CONSTRAINT "account_keys_pkey" PRIMARY KEY ("id"), + CONSTRAINT "account_keys_account_fk" FOREIGN KEY ("account") + REFERENCES "accounts" ("id") MATCH SIMPLE ON UPDATE CASCADE ON DELETE CASCADE, - CONSTRAINT account_keys_key_fk FOREIGN KEY (key) - REFERENCES public.keys (id) MATCH SIMPLE + CONSTRAINT "account_keys_key_fk" FOREIGN KEY (key) + REFERENCES "keys" ("id") MATCH SIMPLE ON UPDATE CASCADE ON DELETE CASCADE ); @@ -56,18 +56,18 @@ CREATE TABLE IF NOT EXISTS "account_keys" -- ---------------------------------- CREATE TABLE IF NOT EXISTS "account_dids" ( - "id" uuid NOT NULL, - "account" uuid NOT NULL, - "did" uuid NOT NULL, - "alias" text COLLATE pg_catalog."default" NOT NULL, + "id" UUID NOT NULL, + "account" UUID NOT NULL, + "did" UUID NOT NULL, + "alias" TEXT COLLATE pg_catalog."default" NOT NULL, "default" BOOLEAN NOT NULL DEFAULT FALSE, - CONSTRAINT "account_dids_pkey" PRIMARY KEY (id), - CONSTRAINT account_dids_account_fk FOREIGN KEY (account) - REFERENCES public.accounts (id) MATCH SIMPLE + CONSTRAINT "account_dids_pkey" PRIMARY KEY ("id"), + CONSTRAINT "account_dids_account_fk" FOREIGN KEY ("account") + REFERENCES "accounts" ("id") MATCH SIMPLE ON UPDATE CASCADE ON DELETE CASCADE, - CONSTRAINT account_dids_did_fk FOREIGN KEY (did) - REFERENCES public.dids (id) MATCH SIMPLE + CONSTRAINT "account_dids_did_fk" FOREIGN KEY ("did") + REFERENCES "dids" ("id") MATCH SIMPLE ON UPDATE CASCADE ON DELETE CASCADE ); @@ -76,28 +76,28 @@ CREATE TABLE IF NOT EXISTS "account_dids" -- ---------------------------------- CREATE TABLE IF NOT EXISTS "account_credentials" ( - "id" uuid NOT NULL, - "account" uuid NOT NULL, - "credential" uuid NOT NULL, + "id" UUID NOT NULL, + "account" UUID NOT NULL, + "credential" UUID NOT NULL, CONSTRAINT "account_credentials_pkey" PRIMARY KEY (id), - CONSTRAINT account_credentials_account_fk FOREIGN KEY (account) - REFERENCES public.accounts (id) MATCH SIMPLE + CONSTRAINT "account_credentials_account_fk" FOREIGN KEY ("account") + REFERENCES "accounts" ("id") MATCH SIMPLE ON UPDATE CASCADE ON DELETE CASCADE, - CONSTRAINT account_credentials_credential_fk FOREIGN KEY (credential) - REFERENCES public.credentials (id) MATCH SIMPLE + CONSTRAINT "account_credentials_credential_fk" FOREIGN KEY ("credential") + REFERENCES "credentials" ("id") MATCH SIMPLE ON UPDATE CASCADE ON DELETE CASCADE ); -- ---------------------------------- -- Keys index -- ---------------------------------- -CREATE UNIQUE INDEX keys_kid ON keys(kid); +CREATE UNIQUE INDEX "keys_kid" ON "keys"("kid"); -- ---------------------------------- -- Dids index -- ---------------------------------- -CREATE UNIQUE INDEX dids_did ON dids(did); +CREATE UNIQUE INDEX "dids_did" ON "dids"("did"); -- ---------------------------------- -- Credentials index -- ---------------------------------- -CREATE UNIQUE INDEX credentials_cid ON credentials(cid); \ No newline at end of file +CREATE UNIQUE INDEX "credentials_cid" ON "credentials"("cid"); \ No newline at end of file diff --git a/src/main/resources/db/postgres/V5__create_table_issuers.sql b/src/main/resources/db/postgres/V5__create_table_issuers.sql index b25c4d4..1cc38eb 100644 --- a/src/main/resources/db/postgres/V5__create_table_issuers.sql +++ b/src/main/resources/db/postgres/V5__create_table_issuers.sql @@ -3,32 +3,32 @@ -- ---------------------------------- CREATE TABLE IF NOT EXISTS "issuers" ( - "id" uuid NOT NULL, - "name" text COLLATE pg_catalog."default" NOT NULL, - "description" text COLLATE pg_catalog."default" NOT NULL, - "ui" text COLLATE pg_catalog."default" NOT NULL, - "configuration" text COLLATE pg_catalog."default" NOT NULL, - CONSTRAINT "issuers_pkey" PRIMARY KEY (id) + "id" UUID NOT NULL, + "name" TEXT COLLATE pg_catalog."default" NOT NULL, + "description" TEXT COLLATE pg_catalog."default" NOT NULL, + "ui" TEXT COLLATE pg_catalog."default" NOT NULL, + "configuration" TEXT COLLATE pg_catalog."default" NOT NULL, + CONSTRAINT "issuers_pkey" PRIMARY KEY ("id") ); -- ---------------------------------- -- AccountIssuers table -- ---------------------------------- CREATE TABLE IF NOT EXISTS "account_issuers" ( - "id" uuid NOT NULL, - "account" uuid NOT NULL, - "issuer" uuid NOT NULL, - CONSTRAINT "account_issuers_pkey" PRIMARY KEY (id), - CONSTRAINT account_issuers_account_fk FOREIGN KEY (account) - REFERENCES public.accounts (id) MATCH SIMPLE + "id" UUID NOT NULL, + "account" UUID NOT NULL, + "issuer" UUID NOT NULL, + CONSTRAINT "account_issuers_pkey" PRIMARY KEY ("id"), + CONSTRAINT "account_issuers_account_fk" FOREIGN KEY ("account") + REFERENCES "accounts" ("id") MATCH SIMPLE ON UPDATE CASCADE ON DELETE CASCADE, - CONSTRAINT account_issuers_issuer_fk FOREIGN KEY (issuer) - REFERENCES public.issuers (id) MATCH SIMPLE + CONSTRAINT "account_issuers_issuer_fk" FOREIGN KEY (issuer) + REFERENCES "issuers" ("id") MATCH SIMPLE ON UPDATE CASCADE ON DELETE CASCADE ); -- ---------------------------------- -- AccountIssuers unique index -- ---------------------------------- -CREATE UNIQUE INDEX account_issuers_account_issuer ON account_issuers(account, issuer); \ No newline at end of file +CREATE UNIQUE INDEX "account_issuers_account_issuer" ON "account_issuers"("account", "issuer"); \ No newline at end of file