Skip to content
This repository has been archived by the owner on Jan 9, 2024. It is now read-only.

chore: pr66 #74

Merged
merged 3 commits into from
Nov 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docker-compose/docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
1 change: 1 addition & 0 deletions docker-compose/wallet-backend/config/db.conf
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
# database = "db.postgres"
database = "db.sqlite"
13 changes: 13 additions & 0 deletions docker-compose/wallet-backend/config/db.postgres.conf
Original file line number Diff line number Diff line change
@@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
);
Expand All @@ -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
);
Expand All @@ -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
);
Original file line number Diff line number Diff line change
@@ -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 "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 "accounts" ("id") MATCH SIMPLE
ON UPDATE CASCADE
ON DELETE CASCADE,
CONSTRAINT "account_keys_key_fk" FOREIGN KEY (key)
REFERENCES "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 "accounts" ("id") MATCH SIMPLE
ON UPDATE CASCADE
ON DELETE CASCADE,
CONSTRAINT "account_dids_did_fk" FOREIGN KEY ("did")
REFERENCES "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 "accounts" ("id") MATCH SIMPLE
ON UPDATE CASCADE
ON DELETE CASCADE,
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");
-- ----------------------------------
-- Dids index
-- ----------------------------------
CREATE UNIQUE INDEX "dids_did" ON "dids"("did");
-- ----------------------------------
-- Credentials index
-- ----------------------------------
CREATE UNIQUE INDEX "credentials_cid" ON "credentials"("cid");
34 changes: 34 additions & 0 deletions src/main/resources/db/postgres/V5__create_table_issuers.sql
Original file line number Diff line number Diff line change
@@ -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 "accounts" ("id") MATCH SIMPLE
ON UPDATE CASCADE
ON DELETE CASCADE,
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");
Original file line number Diff line number Diff line change
@@ -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');
Loading