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

Commit ebf80a2

Browse files
chore: pr66 (#74)
* Database schema update (postgres) * Add docker-compose options for Postgres DB # Conflicts: # docker-compose/docker-compose.yaml * chore: minor consistency related updates --------- Co-authored-by: Happy2C0de <[email protected]>
1 parent a1e314d commit ebf80a2

7 files changed

+201
-36
lines changed

docker-compose/docker-compose.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
services:
2+
# postgresdb: # Uncomment to connect a Postgres DB
3+
# image: postgres
4+
# environment:
5+
# POSTGRES_PASSWORD: secret
26
wallet-backend:
37
image: waltid/wallet-backend:latest
48
volumes:
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
# database = "db.postgres"
12
database = "db.sqlite"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
hikariDataSource {
2+
jdbcUrl = "jdbc:postgresql://postgresdb:5432/postgres"
3+
driverClassName = "org.postgresql.Driver"
4+
username = "postgres"
5+
password = "secret"
6+
transactionIsolation = "TRANSACTION_SERIALIZABLE"
7+
maximumPoolSize = 5
8+
autoCommit = false
9+
dataSource {
10+
journalMode = WAL
11+
fullColumnNames = false
12+
}
13+
}

src/main/resources/db/postgres/V1__create_tables_account_email_wallet_accountwallet_walletoperationhistories.sql

+36-36
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,40 @@
33
-- ----------------------------------
44
CREATE TABLE IF NOT EXISTS "emails"
55
(
6-
id uuid NOT NULL,
7-
email text COLLATE pg_catalog."default" NOT NULL,
8-
password text COLLATE pg_catalog."default" NOT NULL,
9-
CONSTRAINT "emails_pkey" PRIMARY KEY (id),
10-
CONSTRAINT email UNIQUE (email)
6+
"id" UUID NOT NULL,
7+
"email" TEXT COLLATE pg_catalog."default" NOT NULL,
8+
"password" TEXT COLLATE pg_catalog."default" NOT NULL,
9+
CONSTRAINT "emails_pkey" PRIMARY KEY ("id"),
10+
CONSTRAINT "email" UNIQUE ("email")
1111
);
1212
-- ----------------------------------
1313
-- Wallets table
1414
-- ----------------------------------
1515
CREATE TABLE IF NOT EXISTS "wallets"
1616
(
17-
id uuid NOT NULL,
18-
address text COLLATE pg_catalog."default" NOT NULL,
19-
ecosystem text COLLATE pg_catalog."default" NOT NULL,
20-
CONSTRAINT wallets_pkey PRIMARY KEY (id),
21-
CONSTRAINT address UNIQUE (address)
17+
"id" UUID NOT NULL,
18+
"address" TEXT COLLATE pg_catalog."default" NOT NULL,
19+
"ecosystem" TEXT COLLATE pg_catalog."default" NOT NULL,
20+
CONSTRAINT "wallets_pkey" PRIMARY KEY ("id"),
21+
CONSTRAINT "address" UNIQUE ("address")
2222
);
2323
-- ----------------------------------
2424
-- Accounts table
2525
-- ----------------------------------
2626
CREATE TABLE IF NOT EXISTS "accounts"
2727
(
28-
id uuid NOT NULL,
29-
email uuid NULL,
30-
wallet uuid NULL,
31-
CONSTRAINT accounts_pkey PRIMARY KEY (id),
32-
CONSTRAINT accounts_email_wallet_unique UNIQUE (email, wallet)
33-
INCLUDE(email, wallet),
34-
CONSTRAINT account_email_fk FOREIGN KEY (email)
35-
REFERENCES public.emails (id) MATCH SIMPLE
28+
"id" UUID NOT NULL,
29+
"email" UUID NULL,
30+
"wallet" UUID NULL,
31+
CONSTRAINT "accounts_pkey" PRIMARY KEY ("id"),
32+
CONSTRAINT "accounts_email_wallet_unique" UNIQUE ("email", "wallet")
33+
INCLUDE("email", "wallet"),
34+
CONSTRAINT "account_email_fk" FOREIGN KEY ("email")
35+
REFERENCES "emails" ("id") MATCH SIMPLE
3636
ON UPDATE CASCADE
3737
ON DELETE CASCADE,
38-
CONSTRAINT account_wallet_fk FOREIGN KEY (wallet)
39-
REFERENCES public.wallets (id) MATCH SIMPLE
38+
CONSTRAINT "account_wallet_fk" FOREIGN KEY ("wallet")
39+
REFERENCES "wallets" ("id") MATCH SIMPLE
4040
ON UPDATE CASCADE
4141
ON DELETE CASCADE
4242
);
@@ -45,16 +45,16 @@ CREATE TABLE IF NOT EXISTS "accounts"
4545
-- ----------------------------------
4646
CREATE TABLE IF NOT EXISTS "account_wallets"
4747
(
48-
id uuid NOT NULL,
49-
account uuid NOT NULL,
50-
wallet uuid NOT NULL,
51-
CONSTRAINT account_wallets_pkey PRIMARY KEY (id),
52-
CONSTRAINT account_wallets_account_fk FOREIGN KEY (account)
53-
REFERENCES "accounts" (id) MATCH SIMPLE
48+
"id" UUID NOT NULL,
49+
"account" UUID NOT NULL,
50+
"wallet" UUID NOT NULL,
51+
CONSTRAINT "account_wallets_pkey" PRIMARY KEY ("id"),
52+
CONSTRAINT "account_wallets_account_fk" FOREIGN KEY ("account")
53+
REFERENCES "accounts" ("id") MATCH SIMPLE
5454
ON UPDATE CASCADE
5555
ON DELETE CASCADE,
56-
CONSTRAINT account_wallets_wallet_fk FOREIGN KEY (wallet)
57-
REFERENCES "wallets" (id) MATCH SIMPLE
56+
CONSTRAINT "account_wallets_wallet_fk" FOREIGN KEY ("wallet")
57+
REFERENCES "wallets" ("id") MATCH SIMPLE
5858
ON UPDATE CASCADE
5959
ON DELETE CASCADE
6060
);
@@ -63,14 +63,14 @@ CREATE TABLE IF NOT EXISTS "account_wallets"
6363
-- ----------------------------------
6464
CREATE TABLE IF NOT EXISTS "wallet_operation_histories"
6565
(
66-
id uuid NOT NULL,
67-
account uuid NOT NULL,
68-
"timestamp" text COLLATE pg_catalog."default" NOT NULL,
69-
operation text COLLATE pg_catalog."default" NOT NULL,
70-
data text COLLATE pg_catalog."default" NOT NULL,
71-
CONSTRAINT wallet_operation_histories_pkey PRIMARY KEY (id),
72-
CONSTRAINT wallet_operation_histories_account_fk FOREIGN KEY (account)
73-
REFERENCES "accounts" (id) MATCH SIMPLE
66+
"id" UUID NOT NULL,
67+
"account" UUID NOT NULL,
68+
"timestamp" TEXT COLLATE pg_catalog."default" NOT NULL,
69+
"operation" TEXT COLLATE pg_catalog."default" NOT NULL,
70+
"data" TEXT COLLATE pg_catalog."default" NOT NULL,
71+
CONSTRAINT "wallet_operation_histories_pkey" PRIMARY KEY ("id"),
72+
CONSTRAINT "wallet_operation_histories_account_fk" FOREIGN KEY ("account")
73+
REFERENCES "accounts" ("id") MATCH SIMPLE
7474
ON UPDATE CASCADE
7575
ON DELETE CASCADE
7676
);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
-- ----------------------------------
2+
-- Keys table
3+
-- ----------------------------------
4+
CREATE TABLE IF NOT EXISTS "keys"
5+
(
6+
"id" UUID NOT NULL,
7+
"kid" TEXT COLLATE pg_catalog."default" NOT NULL,
8+
"document" TEXT COLLATE pg_catalog."default" NOT NULL,
9+
CONSTRAINT "keys_pkey" PRIMARY KEY ("id")
10+
);
11+
-- ----------------------------------
12+
-- Dids table
13+
-- ----------------------------------
14+
CREATE TABLE IF NOT EXISTS "dids"
15+
(
16+
"id" UUID NOT NULL,
17+
"did" TEXT COLLATE pg_catalog."default" NOT NULL,
18+
"document" TEXT COLLATE pg_catalog."default" NOT NULL,
19+
"key" UUID NOT NULL,
20+
CONSTRAINT "dids_pkey" PRIMARY KEY ("id"),
21+
CONSTRAINT "did_key_fk" FOREIGN KEY ("key")
22+
REFERENCES "keys" ("id") MATCH SIMPLE
23+
ON UPDATE CASCADE
24+
ON DELETE CASCADE
25+
);
26+
-- ----------------------------------
27+
-- Credentials table
28+
-- ----------------------------------
29+
CREATE TABLE IF NOT EXISTS "credentials"
30+
(
31+
"id" UUID NOT NULL,
32+
"cid" TEXT COLLATE pg_catalog."default" NOT NULL,
33+
"document" TEXT COLLATE pg_catalog."default" NOT NULL,
34+
CONSTRAINT "credentials_pkey" PRIMARY KEY ("id")
35+
);
36+
-- ----------------------------------
37+
-- AccountKeys table
38+
-- ----------------------------------
39+
CREATE TABLE IF NOT EXISTS "account_keys"
40+
(
41+
"id" UUID NOT NULL,
42+
"account" UUID NOT NULL,
43+
"key" UUID NOT NULL,
44+
CONSTRAINT "account_keys_pkey" PRIMARY KEY ("id"),
45+
CONSTRAINT "account_keys_account_fk" FOREIGN KEY ("account")
46+
REFERENCES "accounts" ("id") MATCH SIMPLE
47+
ON UPDATE CASCADE
48+
ON DELETE CASCADE,
49+
CONSTRAINT "account_keys_key_fk" FOREIGN KEY (key)
50+
REFERENCES "keys" ("id") MATCH SIMPLE
51+
ON UPDATE CASCADE
52+
ON DELETE CASCADE
53+
);
54+
-- ----------------------------------
55+
-- AccountDids table
56+
-- ----------------------------------
57+
CREATE TABLE IF NOT EXISTS "account_dids"
58+
(
59+
"id" UUID NOT NULL,
60+
"account" UUID NOT NULL,
61+
"did" UUID NOT NULL,
62+
"alias" TEXT COLLATE pg_catalog."default" NOT NULL,
63+
"default" BOOLEAN NOT NULL DEFAULT FALSE,
64+
CONSTRAINT "account_dids_pkey" PRIMARY KEY ("id"),
65+
CONSTRAINT "account_dids_account_fk" FOREIGN KEY ("account")
66+
REFERENCES "accounts" ("id") MATCH SIMPLE
67+
ON UPDATE CASCADE
68+
ON DELETE CASCADE,
69+
CONSTRAINT "account_dids_did_fk" FOREIGN KEY ("did")
70+
REFERENCES "dids" ("id") MATCH SIMPLE
71+
ON UPDATE CASCADE
72+
ON DELETE CASCADE
73+
);
74+
-- ----------------------------------
75+
-- AccountCredentials table
76+
-- ----------------------------------
77+
CREATE TABLE IF NOT EXISTS "account_credentials"
78+
(
79+
"id" UUID NOT NULL,
80+
"account" UUID NOT NULL,
81+
"credential" UUID NOT NULL,
82+
CONSTRAINT "account_credentials_pkey" PRIMARY KEY (id),
83+
CONSTRAINT "account_credentials_account_fk" FOREIGN KEY ("account")
84+
REFERENCES "accounts" ("id") MATCH SIMPLE
85+
ON UPDATE CASCADE
86+
ON DELETE CASCADE,
87+
CONSTRAINT "account_credentials_credential_fk" FOREIGN KEY ("credential")
88+
REFERENCES "credentials" ("id") MATCH SIMPLE
89+
ON UPDATE CASCADE
90+
ON DELETE CASCADE
91+
);
92+
-- ----------------------------------
93+
-- Keys index
94+
-- ----------------------------------
95+
CREATE UNIQUE INDEX "keys_kid" ON "keys"("kid");
96+
-- ----------------------------------
97+
-- Dids index
98+
-- ----------------------------------
99+
CREATE UNIQUE INDEX "dids_did" ON "dids"("did");
100+
-- ----------------------------------
101+
-- Credentials index
102+
-- ----------------------------------
103+
CREATE UNIQUE INDEX "credentials_cid" ON "credentials"("cid");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
-- ----------------------------------
2+
-- Issuers table
3+
-- ----------------------------------
4+
CREATE TABLE IF NOT EXISTS "issuers"
5+
(
6+
"id" UUID NOT NULL,
7+
"name" TEXT COLLATE pg_catalog."default" NOT NULL,
8+
"description" TEXT COLLATE pg_catalog."default" NOT NULL,
9+
"ui" TEXT COLLATE pg_catalog."default" NOT NULL,
10+
"configuration" TEXT COLLATE pg_catalog."default" NOT NULL,
11+
CONSTRAINT "issuers_pkey" PRIMARY KEY ("id")
12+
);
13+
-- ----------------------------------
14+
-- AccountIssuers table
15+
-- ----------------------------------
16+
CREATE TABLE IF NOT EXISTS "account_issuers"
17+
(
18+
"id" UUID NOT NULL,
19+
"account" UUID NOT NULL,
20+
"issuer" UUID NOT NULL,
21+
CONSTRAINT "account_issuers_pkey" PRIMARY KEY ("id"),
22+
CONSTRAINT "account_issuers_account_fk" FOREIGN KEY ("account")
23+
REFERENCES "accounts" ("id") MATCH SIMPLE
24+
ON UPDATE CASCADE
25+
ON DELETE CASCADE,
26+
CONSTRAINT "account_issuers_issuer_fk" FOREIGN KEY (issuer)
27+
REFERENCES "issuers" ("id") MATCH SIMPLE
28+
ON UPDATE CASCADE
29+
ON DELETE CASCADE
30+
);
31+
-- ----------------------------------
32+
-- AccountIssuers unique index
33+
-- ----------------------------------
34+
CREATE UNIQUE INDEX "account_issuers_account_issuer" ON "account_issuers"("account", "issuer");
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
-- ----------------------------------
2+
-- Insert issuers table
3+
-- ----------------------------------
4+
INSERT INTO public."issuers" ("id", "name", "description", "ui", "configuration")
5+
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');
6+
-- ----------------------------------
7+
-- Insert account-issuers table
8+
-- ----------------------------------
9+
INSERT INTO public."account_issuers" ("id", "account", "issuer")
10+
VALUES ('3FAD4023-9E97-4DD0-8B42-9471517757EF'::UUID, 'C59A7223-BF89-A04A-97B2-7C4F121F83B1', '6B638061-E4C6-4636-B4E4-F4BE2FCA582C');

0 commit comments

Comments
 (0)