@canton-network/core-wallet-store-sql 2.3.0 → 2.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bootstrap.d.ts +7 -2
- package/dist/bootstrap.d.ts.map +1 -1
- package/dist/cli.d.ts +5 -1
- package/dist/cli.d.ts.map +1 -1
- package/dist/index.js +45 -21
- package/dist/index.js.map +1 -1
- package/dist/migrations/001-init.js +16 -67
- package/dist/migrations/001-init.js.map +1 -0
- package/dist/migrations/002-add-transaction-timestamps.js +11 -18
- package/dist/migrations/002-add-transaction-timestamps.js.map +1 -0
- package/dist/migrations/003-add-transaction-origin.js +9 -10
- package/dist/migrations/003-add-transaction-origin.js.map +1 -0
- package/dist/migrations/004-add-session-id.js +9 -7
- package/dist/migrations/004-add-session-id.js.map +1 -0
- package/dist/migrations/005-add-wallet-disabled-reason.js +10 -11
- package/dist/migrations/005-add-wallet-disabled-reason.js.map +1 -0
- package/dist/migrations/006-change-wallet-primary-key-to-composite.js +51 -116
- package/dist/migrations/006-change-wallet-primary-key-to-composite.js.map +1 -0
- package/dist/migrations/007-add-unique-primary-per-network.js +14 -26
- package/dist/migrations/007-add-unique-primary-per-network.js.map +1 -0
- package/dist/migrations/008-add-transaction-external-tx-id.js +10 -14
- package/dist/migrations/008-add-transaction-external-tx-id.js.map +1 -0
- package/dist/migrations/009-add-wallet-rights-columns.js +29 -36
- package/dist/migrations/009-add-wallet-rights-columns.js.map +1 -0
- package/dist/migrations/010-add-transaction-network-id.js +33 -71
- package/dist/migrations/010-add-transaction-network-id.js.map +1 -0
- package/dist/migrations/011-add-transaction-id-primary-key.js +41 -79
- package/dist/migrations/011-add-transaction-id-primary-key.js.map +1 -0
- package/dist/migrations/012-add-messages-to-sign.js +10 -25
- package/dist/migrations/012-add-messages-to-sign.js.map +1 -0
- package/dist/migrations/013-add-api-key.js +8 -16
- package/dist/migrations/013-add-api-key.js.map +1 -0
- package/dist/migrations/014-add-service-account-column.js +9 -13
- package/dist/migrations/014-add-service-account-column.js.map +1 -0
- package/dist/migrations/015-add-origin-field-session.js +22 -33
- package/dist/migrations/015-add-origin-field-session.js.map +1 -0
- package/dist/migrations/016-add-failure-reason-and-awaiting-signature.js +13 -17
- package/dist/migrations/016-add-failure-reason-and-awaiting-signature.js.map +1 -0
- package/dist/migrations/017-make-idp-issuer-nullable.js +38 -80
- package/dist/migrations/017-make-idp-issuer-nullable.js.map +1 -0
- package/dist/migrations/018-add-wallet-is-auth-party.js +8 -9
- package/dist/migrations/018-add-wallet-is-auth-party.js.map +1 -0
- package/dist/migrations/019-make-session-access-token-nullable.js +39 -64
- package/dist/migrations/019-make-session-access-token-nullable.js.map +1 -0
- package/dist/migrations/020-add-message-external-tx-id-and-failure-reason.js +10 -20
- package/dist/migrations/020-add-message-external-tx-id-and-failure-reason.js.map +1 -0
- package/dist/migrations/021-add-message-kind.js +8 -9
- package/dist/migrations/021-add-message-kind.js.map +1 -0
- package/dist/schema.d.ts +3 -3
- package/dist/schema.d.ts.map +1 -1
- package/dist/store-sql.d.ts.map +1 -1
- package/dist/utils-BAU4kQB4.js +13 -0
- package/dist/utils-BAU4kQB4.js.map +1 -0
- package/package.json +8 -8
- package/dist/schema.js +0 -299
- package/dist/utils.js +0 -13
|
@@ -1,20 +1,13 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
.alterTable('transactions')
|
|
7
|
-
.addColumn('created_at', 'text')
|
|
8
|
-
.execute();
|
|
9
|
-
await db.schema
|
|
10
|
-
.alterTable('transactions')
|
|
11
|
-
.addColumn('signed_at', 'text')
|
|
12
|
-
.execute();
|
|
1
|
+
// src/migrations/002-add-transaction-timestamps.ts
|
|
2
|
+
async function up(db) {
|
|
3
|
+
console.log("Adding createdAt and signedAt columns to transactions table");
|
|
4
|
+
await db.schema.alterTable("transactions").addColumn("created_at", "text").execute();
|
|
5
|
+
await db.schema.alterTable("transactions").addColumn("signed_at", "text").execute();
|
|
13
6
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
.alterTable('transactions')
|
|
18
|
-
.dropColumn('created_at')
|
|
19
|
-
.execute();
|
|
7
|
+
async function down(db) {
|
|
8
|
+
await db.schema.alterTable("transactions").dropColumn("signed_at").execute();
|
|
9
|
+
await db.schema.alterTable("transactions").dropColumn("created_at").execute();
|
|
20
10
|
}
|
|
11
|
+
export { down, up };
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=002-add-transaction-timestamps.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"002-add-transaction-timestamps.js","names":[],"sources":["../../src/migrations/002-add-transaction-timestamps.ts"],"sourcesContent":["// Copyright (c) 2025-2026 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { Kysely } from 'kysely'\nimport type { DB } from '../schema.js'\n\nexport async function up(db: Kysely<DB>): Promise<void> {\n console.log('Adding createdAt and signedAt columns to transactions table')\n\n await db.schema\n .alterTable('transactions')\n .addColumn('created_at', 'text')\n .execute()\n\n await db.schema\n .alterTable('transactions')\n .addColumn('signed_at', 'text')\n .execute()\n}\n\nexport async function down(db: Kysely<DB>): Promise<void> {\n await db.schema.alterTable('transactions').dropColumn('signed_at').execute()\n\n await db.schema\n .alterTable('transactions')\n .dropColumn('created_at')\n .execute()\n}\n"],"mappings":";AAMA,eAAsB,GAAG,IAA+B;CACpD,QAAQ,IAAI,6DAA6D;CAEzE,MAAM,GAAG,OACJ,WAAW,cAAc,CAAC,CAC1B,UAAU,cAAc,MAAM,CAAC,CAC/B,QAAQ;CAEb,MAAM,GAAG,OACJ,WAAW,cAAc,CAAC,CAC1B,UAAU,aAAa,MAAM,CAAC,CAC9B,QAAQ;AACjB;AAEA,eAAsB,KAAK,IAA+B;CACtD,MAAM,GAAG,OAAO,WAAW,cAAc,CAAC,CAAC,WAAW,WAAW,CAAC,CAAC,QAAQ;CAE3E,MAAM,GAAG,OACJ,WAAW,cAAc,CAAC,CAC1B,WAAW,YAAY,CAAC,CACxB,QAAQ;AACjB"}
|
|
@@ -1,12 +1,11 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
await db.schema
|
|
6
|
-
.alterTable('transactions')
|
|
7
|
-
.addColumn('origin', 'text')
|
|
8
|
-
.execute();
|
|
1
|
+
// src/migrations/003-add-transaction-origin.ts
|
|
2
|
+
async function up(db) {
|
|
3
|
+
console.log("Adding origin column to transactions table");
|
|
4
|
+
await db.schema.alterTable("transactions").addColumn("origin", "text").execute();
|
|
9
5
|
}
|
|
10
|
-
|
|
11
|
-
|
|
6
|
+
async function down(db) {
|
|
7
|
+
await db.schema.alterTable("transactions").dropColumn("origin").execute();
|
|
12
8
|
}
|
|
9
|
+
export { down, up };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=003-add-transaction-origin.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"003-add-transaction-origin.js","names":[],"sources":["../../src/migrations/003-add-transaction-origin.ts"],"sourcesContent":["// Copyright (c) 2025-2026 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { Kysely } from 'kysely'\nimport type { DB } from '../schema.js'\n\nexport async function up(db: Kysely<DB>): Promise<void> {\n console.log('Adding origin column to transactions table')\n\n await db.schema\n .alterTable('transactions')\n .addColumn('origin', 'text')\n .execute()\n}\n\nexport async function down(db: Kysely<DB>): Promise<void> {\n await db.schema.alterTable('transactions').dropColumn('origin').execute()\n}\n"],"mappings":";AAMA,eAAsB,GAAG,IAA+B;CACpD,QAAQ,IAAI,4CAA4C;CAExD,MAAM,GAAG,OACJ,WAAW,cAAc,CAAC,CAC1B,UAAU,UAAU,MAAM,CAAC,CAC3B,QAAQ;AACjB;AAEA,eAAsB,KAAK,IAA+B;CACtD,MAAM,GAAG,OAAO,WAAW,cAAc,CAAC,CAAC,WAAW,QAAQ,CAAC,CAAC,QAAQ;AAC5E"}
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
await db.schema.alterTable('sessions').addColumn('id', 'text').execute();
|
|
1
|
+
// src/migrations/004-add-session-id.ts
|
|
2
|
+
async function up(db) {
|
|
3
|
+
console.log("Adding session ID column to session table");
|
|
4
|
+
await db.schema.alterTable("sessions").addColumn("id", "text").execute();
|
|
6
5
|
}
|
|
7
|
-
|
|
8
|
-
|
|
6
|
+
async function down(db) {
|
|
7
|
+
await db.schema.alterTable("sessions").dropColumn("id").execute();
|
|
9
8
|
}
|
|
9
|
+
export { down, up };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=004-add-session-id.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"004-add-session-id.js","names":[],"sources":["../../src/migrations/004-add-session-id.ts"],"sourcesContent":["// Copyright (c) 2025-2026 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { Kysely } from 'kysely'\nimport type { DB } from '../schema.js'\n\nexport async function up(db: Kysely<DB>): Promise<void> {\n console.log('Adding session ID column to session table')\n\n await db.schema.alterTable('sessions').addColumn('id', 'text').execute()\n}\n\nexport async function down(db: Kysely<DB>): Promise<void> {\n await db.schema.alterTable('sessions').dropColumn('id').execute()\n}\n"],"mappings":";AAMA,eAAsB,GAAG,IAA+B;CACpD,QAAQ,IAAI,2CAA2C;CAEvD,MAAM,GAAG,OAAO,WAAW,UAAU,CAAC,CAAC,UAAU,MAAM,MAAM,CAAC,CAAC,QAAQ;AAC3E;AAEA,eAAsB,KAAK,IAA+B;CACtD,MAAM,GAAG,OAAO,WAAW,UAAU,CAAC,CAAC,WAAW,IAAI,CAAC,CAAC,QAAQ;AACpE"}
|
|
@@ -1,13 +1,12 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
.alterTable('wallets')
|
|
6
|
-
.addColumn('disabled', 'integer', (col) => col.notNull().defaultTo(0))
|
|
7
|
-
.execute();
|
|
8
|
-
await db.schema.alterTable('wallets').addColumn('reason', 'text').execute();
|
|
1
|
+
// src/migrations/005-add-wallet-disabled-reason.ts
|
|
2
|
+
async function up(db) {
|
|
3
|
+
await db.schema.alterTable("wallets").addColumn("disabled", "integer", (col) => col.notNull().defaultTo(0)).execute();
|
|
4
|
+
await db.schema.alterTable("wallets").addColumn("reason", "text").execute();
|
|
9
5
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
async function down(db) {
|
|
7
|
+
await db.schema.alterTable("wallets").dropColumn("reason").execute();
|
|
8
|
+
await db.schema.alterTable("wallets").dropColumn("disabled").execute();
|
|
13
9
|
}
|
|
10
|
+
export { down, up };
|
|
11
|
+
|
|
12
|
+
//# sourceMappingURL=005-add-wallet-disabled-reason.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"005-add-wallet-disabled-reason.js","names":[],"sources":["../../src/migrations/005-add-wallet-disabled-reason.ts"],"sourcesContent":["// Copyright (c) 2025-2026 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { Kysely } from 'kysely'\nimport type { DB } from '../schema.js'\n\nexport async function up(db: Kysely<DB>): Promise<void> {\n await db.schema\n .alterTable('wallets')\n .addColumn('disabled', 'integer', (col) => col.notNull().defaultTo(0))\n .execute()\n\n await db.schema.alterTable('wallets').addColumn('reason', 'text').execute()\n}\n\nexport async function down(db: Kysely<DB>): Promise<void> {\n await db.schema.alterTable('wallets').dropColumn('reason').execute()\n\n await db.schema.alterTable('wallets').dropColumn('disabled').execute()\n}\n"],"mappings":";AAMA,eAAsB,GAAG,IAA+B;CACpD,MAAM,GAAG,OACJ,WAAW,SAAS,CAAC,CACrB,UAAU,YAAY,YAAY,QAAQ,IAAI,QAAQ,CAAC,CAAC,UAAU,CAAC,CAAC,CAAC,CACrE,QAAQ;CAEb,MAAM,GAAG,OAAO,WAAW,SAAS,CAAC,CAAC,UAAU,UAAU,MAAM,CAAC,CAAC,QAAQ;AAC9E;AAEA,eAAsB,KAAK,IAA+B;CACtD,MAAM,GAAG,OAAO,WAAW,SAAS,CAAC,CAAC,WAAW,QAAQ,CAAC,CAAC,QAAQ;CAEnE,MAAM,GAAG,OAAO,WAAW,SAAS,CAAC,CAAC,WAAW,UAAU,CAAC,CAAC,QAAQ;AACzE"}
|
|
@@ -1,33 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import { isPostgres } from '../utils.js';
|
|
1
|
+
import { t as isPostgres } from "../utils-BAU4kQB4.js";
|
|
2
|
+
import { sql } from "kysely";
|
|
3
|
+
// src/migrations/006-change-wallet-primary-key-to-composite.ts
|
|
5
4
|
async function tableExists(db, tableName, isPg) {
|
|
6
|
-
|
|
7
|
-
const result = await sql `
|
|
5
|
+
if (isPg) return (await sql`
|
|
8
6
|
SELECT EXISTS (
|
|
9
7
|
SELECT FROM information_schema.tables
|
|
10
8
|
WHERE table_schema = 'public'
|
|
11
9
|
AND table_name = ${tableName}
|
|
12
10
|
) AS exists
|
|
13
|
-
`.execute(db);
|
|
14
|
-
|
|
15
|
-
}
|
|
16
|
-
else {
|
|
17
|
-
const result = await sql `
|
|
11
|
+
`.execute(db)).rows[0]?.exists ?? false;
|
|
12
|
+
else return (await sql`
|
|
18
13
|
SELECT name
|
|
19
14
|
FROM sqlite_master
|
|
20
15
|
WHERE type='table' AND name = ${tableName}
|
|
21
|
-
`.execute(db);
|
|
22
|
-
return result.rows.length > 0;
|
|
23
|
-
}
|
|
16
|
+
`.execute(db)).rows.length > 0;
|
|
24
17
|
}
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
// PostgreSQL: Change PK to (party_id, network_id, user_id)
|
|
29
|
-
// Check if composite PK already exists
|
|
30
|
-
const pkCheck = await sql `
|
|
18
|
+
async function up(db) {
|
|
19
|
+
if (await isPostgres(db)) {
|
|
20
|
+
if (!(await sql`
|
|
31
21
|
SELECT EXISTS (
|
|
32
22
|
SELECT 1
|
|
33
23
|
FROM pg_constraint c
|
|
@@ -35,10 +25,8 @@ export async function up(db) {
|
|
|
35
25
|
AND c.contype = 'p'
|
|
36
26
|
AND pg_get_constraintdef(c.oid) ILIKE 'PRIMARY KEY (party_id, network_id, user_id)%'
|
|
37
27
|
) AS exists
|
|
38
|
-
`.execute(db)
|
|
39
|
-
|
|
40
|
-
// Drop existing PK if it exists
|
|
41
|
-
await sql `
|
|
28
|
+
`.execute(db)).rows[0]?.exists) {
|
|
29
|
+
await sql`
|
|
42
30
|
DO $$
|
|
43
31
|
DECLARE pk_name text;
|
|
44
32
|
BEGIN
|
|
@@ -51,61 +39,33 @@ export async function up(db) {
|
|
|
51
39
|
END IF;
|
|
52
40
|
END $$;
|
|
53
41
|
`.execute(db);
|
|
54
|
-
|
|
55
|
-
const nullCheck = await sql `
|
|
42
|
+
if ((await sql`
|
|
56
43
|
SELECT EXISTS (
|
|
57
44
|
SELECT 1 FROM public.wallets
|
|
58
45
|
WHERE network_id IS NULL OR user_id IS NULL
|
|
59
46
|
) AS has_nulls
|
|
60
|
-
`.execute(db);
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
// Set columns as NOT NULL
|
|
65
|
-
await sql `ALTER TABLE public.wallets ALTER COLUMN network_id SET NOT NULL`.execute(db);
|
|
66
|
-
await sql `ALTER TABLE public.wallets ALTER COLUMN user_id SET NOT NULL`.execute(db);
|
|
67
|
-
// Add composite primary key
|
|
68
|
-
await sql `
|
|
47
|
+
`.execute(db)).rows[0]?.has_nulls) throw new Error("Cannot add composite PK: wallets.network_id or user_id has NULLs");
|
|
48
|
+
await sql`ALTER TABLE public.wallets ALTER COLUMN network_id SET NOT NULL`.execute(db);
|
|
49
|
+
await sql`ALTER TABLE public.wallets ALTER COLUMN user_id SET NOT NULL`.execute(db);
|
|
50
|
+
await sql`
|
|
69
51
|
ALTER TABLE public.wallets
|
|
70
52
|
ADD CONSTRAINT wallets_pkey PRIMARY KEY (party_id, network_id, user_id)
|
|
71
53
|
`.execute(db);
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
await db.schema
|
|
88
|
-
.createTable('wallets_new')
|
|
89
|
-
.addColumn('party_id', 'text', (col) => col.notNull())
|
|
90
|
-
.addColumn('network_id', 'text', (col) => col.references('networks.id').onDelete('cascade').notNull())
|
|
91
|
-
.addColumn('primary', 'boolean', (col) => col.notNull().defaultTo(false))
|
|
92
|
-
.addColumn('hint', 'text', (col) => col.notNull())
|
|
93
|
-
.addColumn('public_key', 'text', (col) => col.notNull())
|
|
94
|
-
.addColumn('namespace', 'text', (col) => col.notNull())
|
|
95
|
-
.addColumn('user_id', 'text', (col) => col.notNull())
|
|
96
|
-
.addColumn('signing_provider_id', 'text', (col) => col.notNull())
|
|
97
|
-
.addColumn('status', 'text')
|
|
98
|
-
.addColumn('external_tx_id', 'text')
|
|
99
|
-
.addColumn('topology_transactions', 'text')
|
|
100
|
-
.addColumn('disabled', 'integer', (col) => col.notNull().defaultTo(0))
|
|
101
|
-
.addColumn('reason', 'text')
|
|
102
|
-
.addPrimaryKeyConstraint('wallets_pk', [
|
|
103
|
-
'party_id',
|
|
104
|
-
'network_id',
|
|
105
|
-
'user_id',
|
|
106
|
-
])
|
|
107
|
-
.execute();
|
|
108
|
-
await sql `
|
|
54
|
+
}
|
|
55
|
+
} else {
|
|
56
|
+
await db.schema.dropTable("wallets_new").ifExists().execute();
|
|
57
|
+
const hasWallets = await tableExists(db, "wallets", false);
|
|
58
|
+
const hasWalletsNew = await tableExists(db, "wallets_new", false);
|
|
59
|
+
if (!hasWallets && hasWalletsNew) {
|
|
60
|
+
await db.schema.alterTable("wallets_new").renameTo("wallets").execute();
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
await db.schema.createTable("wallets_new").addColumn("party_id", "text", (col) => col.notNull()).addColumn("network_id", "text", (col) => col.references("networks.id").onDelete("cascade").notNull()).addColumn("primary", "boolean", (col) => col.notNull().defaultTo(false)).addColumn("hint", "text", (col) => col.notNull()).addColumn("public_key", "text", (col) => col.notNull()).addColumn("namespace", "text", (col) => col.notNull()).addColumn("user_id", "text", (col) => col.notNull()).addColumn("signing_provider_id", "text", (col) => col.notNull()).addColumn("status", "text").addColumn("external_tx_id", "text").addColumn("topology_transactions", "text").addColumn("disabled", "integer", (col) => col.notNull().defaultTo(0)).addColumn("reason", "text").addPrimaryKeyConstraint("wallets_pk", [
|
|
64
|
+
"party_id",
|
|
65
|
+
"network_id",
|
|
66
|
+
"user_id"
|
|
67
|
+
]).execute();
|
|
68
|
+
await sql`
|
|
109
69
|
INSERT INTO wallets_new (
|
|
110
70
|
party_id, network_id, "primary", hint, public_key, namespace,
|
|
111
71
|
user_id, signing_provider_id, status, external_tx_id,
|
|
@@ -117,18 +77,14 @@ export async function up(db) {
|
|
|
117
77
|
topology_transactions, COALESCE(disabled, 0) AS disabled, reason
|
|
118
78
|
FROM wallets
|
|
119
79
|
`.execute(db);
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
80
|
+
await db.schema.dropTable("wallets").execute();
|
|
81
|
+
await db.schema.alterTable("wallets_new").renameTo("wallets").execute();
|
|
82
|
+
}
|
|
123
83
|
}
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
return;
|
|
129
|
-
// PostgreSQL: Use ALTER TABLE to revert to single primary key
|
|
130
|
-
// drop the composite primary key
|
|
131
|
-
await sql `
|
|
84
|
+
async function down(db) {
|
|
85
|
+
if (await isPostgres(db)) {
|
|
86
|
+
if (!await tableExists(db, "wallets", true)) return;
|
|
87
|
+
await sql`
|
|
132
88
|
DO $$
|
|
133
89
|
DECLARE
|
|
134
90
|
pk_name text;
|
|
@@ -144,9 +100,7 @@ export async function down(db) {
|
|
|
144
100
|
END IF;
|
|
145
101
|
END $$;
|
|
146
102
|
`.execute(db);
|
|
147
|
-
|
|
148
|
-
// Use ROW_NUMBER() to keep the first inserted row (using ctid as proxy for insertion order)
|
|
149
|
-
await sql `
|
|
103
|
+
await sql`
|
|
150
104
|
WITH ranked AS (
|
|
151
105
|
SELECT party_id, network_id, user_id,
|
|
152
106
|
ROW_NUMBER() OVER (PARTITION BY party_id ORDER BY ctid) as rn
|
|
@@ -159,39 +113,17 @@ export async function down(db) {
|
|
|
159
113
|
AND w.user_id = r.user_id
|
|
160
114
|
AND r.rn > 1
|
|
161
115
|
`.execute(db);
|
|
162
|
-
|
|
163
|
-
await sql `
|
|
116
|
+
await sql`
|
|
164
117
|
ALTER TABLE public.wallets
|
|
165
118
|
ALTER COLUMN network_id DROP NOT NULL
|
|
166
119
|
`.execute(db);
|
|
167
|
-
|
|
168
|
-
await sql `
|
|
120
|
+
await sql`
|
|
169
121
|
ALTER TABLE public.wallets
|
|
170
122
|
ADD CONSTRAINT wallets_pkey PRIMARY KEY (party_id)
|
|
171
123
|
`.execute(db);
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
// Create old table structure with single primary key
|
|
176
|
-
await db.schema
|
|
177
|
-
.createTable('wallets_new')
|
|
178
|
-
.addColumn('party_id', 'text', (col) => col.primaryKey())
|
|
179
|
-
.addColumn('network_id', 'text', (col) => col.references('networks.id').onDelete('cascade'))
|
|
180
|
-
.addColumn('primary', 'boolean', (col) => col.notNull().defaultTo(false))
|
|
181
|
-
.addColumn('hint', 'text', (col) => col.notNull())
|
|
182
|
-
.addColumn('public_key', 'text', (col) => col.notNull())
|
|
183
|
-
.addColumn('namespace', 'text', (col) => col.notNull())
|
|
184
|
-
.addColumn('user_id', 'text', (col) => col.notNull())
|
|
185
|
-
.addColumn('signing_provider_id', 'text', (col) => col.notNull())
|
|
186
|
-
.addColumn('status', 'text')
|
|
187
|
-
.addColumn('external_tx_id', 'text')
|
|
188
|
-
.addColumn('topology_transactions', 'text')
|
|
189
|
-
.addColumn('disabled', 'integer', (col) => col.notNull().defaultTo(0))
|
|
190
|
-
.addColumn('reason', 'text')
|
|
191
|
-
.execute();
|
|
192
|
-
// Keep only one wallet per party_id (data loss if duplicates exist)
|
|
193
|
-
// Use ROW_NUMBER() to keep the first inserted row (using rowid as insertion order)
|
|
194
|
-
await sql `
|
|
124
|
+
} else {
|
|
125
|
+
await db.schema.createTable("wallets_new").addColumn("party_id", "text", (col) => col.primaryKey()).addColumn("network_id", "text", (col) => col.references("networks.id").onDelete("cascade")).addColumn("primary", "boolean", (col) => col.notNull().defaultTo(false)).addColumn("hint", "text", (col) => col.notNull()).addColumn("public_key", "text", (col) => col.notNull()).addColumn("namespace", "text", (col) => col.notNull()).addColumn("user_id", "text", (col) => col.notNull()).addColumn("signing_provider_id", "text", (col) => col.notNull()).addColumn("status", "text").addColumn("external_tx_id", "text").addColumn("topology_transactions", "text").addColumn("disabled", "integer", (col) => col.notNull().defaultTo(0)).addColumn("reason", "text").execute();
|
|
126
|
+
await sql`
|
|
195
127
|
INSERT INTO wallets_new (
|
|
196
128
|
party_id, network_id, "primary", hint, public_key, namespace,
|
|
197
129
|
user_id, signing_provider_id, status, external_tx_id,
|
|
@@ -208,7 +140,10 @@ export async function down(db) {
|
|
|
208
140
|
) ranked
|
|
209
141
|
WHERE rn = 1
|
|
210
142
|
`.execute(db);
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
143
|
+
await db.schema.dropTable("wallets").execute();
|
|
144
|
+
await db.schema.alterTable("wallets_new").renameTo("wallets").execute();
|
|
145
|
+
}
|
|
214
146
|
}
|
|
147
|
+
export { down, up };
|
|
148
|
+
|
|
149
|
+
//# sourceMappingURL=006-change-wallet-primary-key-to-composite.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"006-change-wallet-primary-key-to-composite.js","names":[],"sources":["../../src/migrations/006-change-wallet-primary-key-to-composite.ts"],"sourcesContent":["// Copyright (c) 2025-2026 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { type Kysely, sql } from 'kysely'\nimport type { DB } from '../schema.js'\nimport { isPostgres } from '../utils.js'\n\nasync function tableExists(\n db: Kysely<DB>,\n tableName: string,\n isPg: boolean\n): Promise<boolean> {\n if (isPg) {\n const result = await sql<{ exists: boolean }>`\n SELECT EXISTS (\n SELECT FROM information_schema.tables\n WHERE table_schema = 'public'\n AND table_name = ${tableName}\n ) AS exists\n `.execute(db)\n return result.rows[0]?.exists ?? false\n } else {\n const result = await sql<{ name: string }>`\n SELECT name\n FROM sqlite_master\n WHERE type='table' AND name = ${tableName}\n `.execute(db)\n return result.rows.length > 0\n }\n}\n\nexport async function up(db: Kysely<DB>): Promise<void> {\n const isPg = await isPostgres(db)\n\n if (isPg) {\n // PostgreSQL: Change PK to (party_id, network_id, user_id)\n // Check if composite PK already exists\n const pkCheck = await sql<{ exists: boolean }>`\n SELECT EXISTS (\n SELECT 1\n FROM pg_constraint c\n WHERE c.conrelid = 'public.wallets'::regclass\n AND c.contype = 'p'\n AND pg_get_constraintdef(c.oid) ILIKE 'PRIMARY KEY (party_id, network_id, user_id)%'\n ) AS exists\n `.execute(db)\n\n if (!pkCheck.rows[0]?.exists) {\n // Drop existing PK if it exists\n await sql`\n DO $$\n DECLARE pk_name text;\n BEGIN\n SELECT c.conname INTO pk_name\n FROM pg_constraint c\n WHERE c.conrelid = 'public.wallets'::regclass\n AND c.contype = 'p';\n IF pk_name IS NOT NULL THEN\n EXECUTE format('ALTER TABLE public.wallets DROP CONSTRAINT %I', pk_name);\n END IF;\n END $$;\n `.execute(db)\n\n // Ensure no NULLs in required columns\n const nullCheck = await sql<{ has_nulls: boolean }>`\n SELECT EXISTS (\n SELECT 1 FROM public.wallets\n WHERE network_id IS NULL OR user_id IS NULL\n ) AS has_nulls\n `.execute(db)\n\n if (nullCheck.rows[0]?.has_nulls) {\n throw new Error(\n 'Cannot add composite PK: wallets.network_id or user_id has NULLs'\n )\n }\n\n // Set columns as NOT NULL\n await sql`ALTER TABLE public.wallets ALTER COLUMN network_id SET NOT NULL`.execute(\n db\n )\n await sql`ALTER TABLE public.wallets ALTER COLUMN user_id SET NOT NULL`.execute(\n db\n )\n\n // Add composite primary key\n await sql`\n ALTER TABLE public.wallets\n ADD CONSTRAINT wallets_pkey PRIMARY KEY (party_id, network_id, user_id)\n `.execute(db)\n }\n } else {\n // SQLite: Recreate table (SQLite doesn't support altering primary keys)\n // Drop temporary table if it exists\n await db.schema.dropTable('wallets_new').ifExists().execute()\n\n const hasWallets = await tableExists(db, 'wallets', false)\n const hasWalletsNew = await tableExists(db, 'wallets_new', false)\n\n if (!hasWallets && hasWalletsNew) {\n await db.schema\n .alterTable('wallets_new')\n .renameTo('wallets')\n .execute()\n return\n }\n\n await db.schema\n .createTable('wallets_new')\n .addColumn('party_id', 'text', (col) => col.notNull())\n .addColumn('network_id', 'text', (col) =>\n col.references('networks.id').onDelete('cascade').notNull()\n )\n .addColumn('primary', 'boolean', (col) =>\n col.notNull().defaultTo(false)\n )\n .addColumn('hint', 'text', (col) => col.notNull())\n .addColumn('public_key', 'text', (col) => col.notNull())\n .addColumn('namespace', 'text', (col) => col.notNull())\n .addColumn('user_id', 'text', (col) => col.notNull())\n .addColumn('signing_provider_id', 'text', (col) => col.notNull())\n .addColumn('status', 'text')\n .addColumn('external_tx_id', 'text')\n .addColumn('topology_transactions', 'text')\n .addColumn('disabled', 'integer', (col) =>\n col.notNull().defaultTo(0)\n )\n .addColumn('reason', 'text')\n .addPrimaryKeyConstraint('wallets_pk', [\n 'party_id',\n 'network_id',\n 'user_id',\n ])\n .execute()\n\n await sql`\n INSERT INTO wallets_new (\n party_id, network_id, \"primary\", hint, public_key, namespace,\n user_id, signing_provider_id, status, external_tx_id,\n topology_transactions, disabled, reason\n )\n SELECT\n party_id, network_id, \"primary\", hint, public_key, namespace,\n user_id, signing_provider_id, status, external_tx_id,\n topology_transactions, COALESCE(disabled, 0) AS disabled, reason\n FROM wallets\n `.execute(db)\n\n await db.schema.dropTable('wallets').execute()\n await db.schema.alterTable('wallets_new').renameTo('wallets').execute()\n }\n}\n\nexport async function down(db: Kysely<DB>): Promise<void> {\n const isPg = await isPostgres(db)\n\n if (isPg) {\n if (!(await tableExists(db, 'wallets', true))) return\n\n // PostgreSQL: Use ALTER TABLE to revert to single primary key\n // drop the composite primary key\n await sql`\n DO $$\n DECLARE\n pk_name text;\n BEGIN\n SELECT c.conname\n INTO pk_name\n FROM pg_constraint c\n WHERE c.conrelid = 'public.wallets'::regclass\n AND c.contype = 'p';\n\n IF pk_name IS NOT NULL THEN\n EXECUTE format('ALTER TABLE public.wallets DROP CONSTRAINT %I', pk_name);\n END IF;\n END $$;\n `.execute(db)\n\n // Keep only one wallet per party_id (data loss if duplicates exist)\n // Use ROW_NUMBER() to keep the first inserted row (using ctid as proxy for insertion order)\n await sql`\n WITH ranked AS (\n SELECT party_id, network_id, user_id,\n ROW_NUMBER() OVER (PARTITION BY party_id ORDER BY ctid) as rn\n FROM public.wallets\n )\n DELETE FROM public.wallets w\n USING ranked r\n WHERE w.party_id = r.party_id\n AND w.network_id = r.network_id\n AND w.user_id = r.user_id\n AND r.rn > 1\n `.execute(db)\n\n // Make network_id nullable again\n await sql`\n ALTER TABLE public.wallets\n ALTER COLUMN network_id DROP NOT NULL\n `.execute(db)\n\n // Add back single-column PK on party_id\n await sql`\n ALTER TABLE public.wallets\n ADD CONSTRAINT wallets_pkey PRIMARY KEY (party_id)\n `.execute(db)\n } else {\n // SQLite: Recreate table with single primary key\n // Create old table structure with single primary key\n await db.schema\n .createTable('wallets_new')\n .addColumn('party_id', 'text', (col) => col.primaryKey())\n .addColumn('network_id', 'text', (col) =>\n col.references('networks.id').onDelete('cascade')\n )\n .addColumn('primary', 'boolean', (col) =>\n col.notNull().defaultTo(false)\n )\n .addColumn('hint', 'text', (col) => col.notNull())\n .addColumn('public_key', 'text', (col) => col.notNull())\n .addColumn('namespace', 'text', (col) => col.notNull())\n .addColumn('user_id', 'text', (col) => col.notNull())\n .addColumn('signing_provider_id', 'text', (col) => col.notNull())\n .addColumn('status', 'text')\n .addColumn('external_tx_id', 'text')\n .addColumn('topology_transactions', 'text')\n .addColumn('disabled', 'integer', (col) =>\n col.notNull().defaultTo(0)\n )\n .addColumn('reason', 'text')\n .execute()\n\n // Keep only one wallet per party_id (data loss if duplicates exist)\n // Use ROW_NUMBER() to keep the first inserted row (using rowid as insertion order)\n await sql`\n INSERT INTO wallets_new (\n party_id, network_id, \"primary\", hint, public_key, namespace,\n user_id, signing_provider_id, status, external_tx_id,\n topology_transactions, disabled, reason\n )\n SELECT\n party_id, network_id, \"primary\", hint, public_key, namespace,\n user_id, signing_provider_id, status, external_tx_id,\n topology_transactions, disabled, reason\n FROM (\n SELECT *,\n ROW_NUMBER() OVER (PARTITION BY party_id ORDER BY rowid) as rn\n FROM wallets\n ) ranked\n WHERE rn = 1\n `.execute(db)\n\n await db.schema.dropTable('wallets').execute()\n await db.schema.alterTable('wallets_new').renameTo('wallets').execute()\n }\n}\n"],"mappings":"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"}
|
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
// Cleanup duplicate primary wallets (keep first per network/user)
|
|
8
|
-
if (isPg) {
|
|
9
|
-
// PostgreSQL
|
|
10
|
-
await sql `
|
|
1
|
+
import { t as isPostgres } from "../utils-BAU4kQB4.js";
|
|
2
|
+
import { sql } from "kysely";
|
|
3
|
+
// src/migrations/007-add-unique-primary-per-network.ts
|
|
4
|
+
async function up(db) {
|
|
5
|
+
const isPg = await isPostgres(db);
|
|
6
|
+
if (isPg) await sql`
|
|
11
7
|
UPDATE wallets w
|
|
12
8
|
SET "primary" = false
|
|
13
9
|
FROM (
|
|
@@ -22,10 +18,7 @@ export async function up(db) {
|
|
|
22
18
|
AND ranked.rn > 1
|
|
23
19
|
AND w."primary" = true
|
|
24
20
|
`.execute(db);
|
|
25
|
-
|
|
26
|
-
else {
|
|
27
|
-
// SQLite
|
|
28
|
-
await sql `
|
|
21
|
+
else await sql`
|
|
29
22
|
UPDATE wallets
|
|
30
23
|
SET "primary" = 0
|
|
31
24
|
WHERE rowid NOT IN (
|
|
@@ -36,27 +29,22 @@ export async function up(db) {
|
|
|
36
29
|
)
|
|
37
30
|
AND "primary" = 1
|
|
38
31
|
`.execute(db);
|
|
39
|
-
|
|
40
|
-
// Ensure only one primary wallet per network per user
|
|
41
|
-
if (isPg) {
|
|
42
|
-
// PostgreSQL
|
|
43
|
-
await sql `
|
|
32
|
+
if (isPg) await sql`
|
|
44
33
|
CREATE UNIQUE INDEX IF NOT EXISTS wallets_one_primary_per_network_user
|
|
45
34
|
ON wallets(network_id, user_id)
|
|
46
35
|
WHERE "primary" = true
|
|
47
36
|
`.execute(db);
|
|
48
|
-
|
|
49
|
-
else {
|
|
50
|
-
// SQLite
|
|
51
|
-
await sql `
|
|
37
|
+
else await sql`
|
|
52
38
|
CREATE UNIQUE INDEX IF NOT EXISTS wallets_one_primary_per_network_user
|
|
53
39
|
ON wallets(network_id, user_id)
|
|
54
40
|
WHERE "primary" = 1
|
|
55
41
|
`.execute(db);
|
|
56
|
-
}
|
|
57
42
|
}
|
|
58
|
-
|
|
59
|
-
|
|
43
|
+
async function down(db) {
|
|
44
|
+
await sql`
|
|
60
45
|
DROP INDEX IF EXISTS wallets_one_primary_per_network_user
|
|
61
46
|
`.execute(db);
|
|
62
47
|
}
|
|
48
|
+
export { down, up };
|
|
49
|
+
|
|
50
|
+
//# sourceMappingURL=007-add-unique-primary-per-network.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"007-add-unique-primary-per-network.js","names":[],"sources":["../../src/migrations/007-add-unique-primary-per-network.ts"],"sourcesContent":["// Copyright (c) 2025-2026 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport { type Kysely, sql } from 'kysely'\nimport type { DB } from '../schema.js'\nimport { isPostgres } from '../utils.js'\n\nexport async function up(db: Kysely<DB>): Promise<void> {\n const isPg = await isPostgres(db)\n\n // Cleanup duplicate primary wallets (keep first per network/user)\n if (isPg) {\n // PostgreSQL\n await sql`\n UPDATE wallets w\n SET \"primary\" = false\n FROM (\n SELECT party_id, network_id, user_id,\n ROW_NUMBER() OVER (PARTITION BY network_id, user_id ORDER BY party_id) as rn\n FROM wallets\n WHERE \"primary\" = true\n ) ranked\n WHERE w.party_id = ranked.party_id\n AND w.network_id = ranked.network_id\n AND w.user_id = ranked.user_id\n AND ranked.rn > 1\n AND w.\"primary\" = true\n `.execute(db)\n } else {\n // SQLite\n await sql`\n UPDATE wallets\n SET \"primary\" = 0\n WHERE rowid NOT IN (\n SELECT MIN(rowid)\n FROM wallets\n WHERE \"primary\" = 1\n GROUP BY network_id, user_id\n )\n AND \"primary\" = 1\n `.execute(db)\n }\n\n // Ensure only one primary wallet per network per user\n if (isPg) {\n // PostgreSQL\n await sql`\n CREATE UNIQUE INDEX IF NOT EXISTS wallets_one_primary_per_network_user\n ON wallets(network_id, user_id)\n WHERE \"primary\" = true\n `.execute(db)\n } else {\n // SQLite\n await sql`\n CREATE UNIQUE INDEX IF NOT EXISTS wallets_one_primary_per_network_user\n ON wallets(network_id, user_id)\n WHERE \"primary\" = 1\n `.execute(db)\n }\n}\n\nexport async function down(db: Kysely<DB>): Promise<void> {\n await sql`\n DROP INDEX IF EXISTS wallets_one_primary_per_network_user\n `.execute(db)\n}\n"],"mappings":";;;AAOA,eAAsB,GAAG,IAA+B;CACpD,MAAM,OAAO,MAAM,WAAW,EAAE;CAGhC,IAAI,MAEA,MAAM,GAAG;;;;;;;;;;;;;;UAcP,QAAQ,EAAE;MAGZ,MAAM,GAAG;;;;;;;;;;UAUP,QAAQ,EAAE;CAIhB,IAAI,MAEA,MAAM,GAAG;;;;UAIP,QAAQ,EAAE;MAGZ,MAAM,GAAG;;;;UAIP,QAAQ,EAAE;AAEpB;AAEA,eAAsB,KAAK,IAA+B;CACtD,MAAM,GAAG;;MAEP,QAAQ,EAAE;AAChB"}
|
|
@@ -1,16 +1,12 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
await db.schema
|
|
6
|
-
.alterTable('transactions')
|
|
7
|
-
.addColumn('external_tx_id', 'text')
|
|
8
|
-
.execute();
|
|
1
|
+
// src/migrations/008-add-transaction-external-tx-id.ts
|
|
2
|
+
async function up(db) {
|
|
3
|
+
console.log("Adding external_tx_id column to transactions table");
|
|
4
|
+
await db.schema.alterTable("transactions").addColumn("external_tx_id", "text").execute();
|
|
9
5
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
.alterTable('transactions')
|
|
14
|
-
.dropColumn('external_tx_id')
|
|
15
|
-
.execute();
|
|
6
|
+
async function down(db) {
|
|
7
|
+
console.log("Dropping external_tx_id column from transactions table");
|
|
8
|
+
await db.schema.alterTable("transactions").dropColumn("external_tx_id").execute();
|
|
16
9
|
}
|
|
10
|
+
export { down, up };
|
|
11
|
+
|
|
12
|
+
//# sourceMappingURL=008-add-transaction-external-tx-id.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"008-add-transaction-external-tx-id.js","names":[],"sources":["../../src/migrations/008-add-transaction-external-tx-id.ts"],"sourcesContent":["// Copyright (c) 2025-2026 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { Kysely } from 'kysely'\nimport type { DB } from '../schema.js'\n\nexport async function up(db: Kysely<DB>): Promise<void> {\n console.log('Adding external_tx_id column to transactions table')\n\n await db.schema\n .alterTable('transactions')\n .addColumn('external_tx_id', 'text')\n .execute()\n}\n\nexport async function down(db: Kysely<DB>): Promise<void> {\n console.log('Dropping external_tx_id column from transactions table')\n\n await db.schema\n .alterTable('transactions')\n .dropColumn('external_tx_id')\n .execute()\n}\n"],"mappings":";AAMA,eAAsB,GAAG,IAA+B;CACpD,QAAQ,IAAI,oDAAoD;CAEhE,MAAM,GAAG,OACJ,WAAW,cAAc,CAAC,CAC1B,UAAU,kBAAkB,MAAM,CAAC,CACnC,QAAQ;AACjB;AAEA,eAAsB,KAAK,IAA+B;CACtD,QAAQ,IAAI,wDAAwD;CAEpE,MAAM,GAAG,OACJ,WAAW,cAAc,CAAC,CAC1B,WAAW,gBAAgB,CAAC,CAC5B,QAAQ;AACjB"}
|
|
@@ -1,38 +1,31 @@
|
|
|
1
|
-
//
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
.addColumn('user_id', 'text', (col) => col.notNull())
|
|
24
|
-
.addColumn('network_id', 'text', (col) => col.notNull())
|
|
25
|
-
.addColumn('right', 'text', (col) => col.notNull())
|
|
26
|
-
.addPrimaryKeyConstraint('user_rights_pk', [
|
|
27
|
-
'user_id',
|
|
28
|
-
'network_id',
|
|
29
|
-
'right',
|
|
30
|
-
])
|
|
31
|
-
.addForeignKeyConstraint('user_rights_network_fk', ['network_id'], 'networks', ['id'], (cb) => cb.onDelete('cascade'))
|
|
32
|
-
.execute();
|
|
1
|
+
// src/migrations/009-add-wallet-rights-columns.ts
|
|
2
|
+
async function up(db) {
|
|
3
|
+
console.log("Creating normalized rights tables");
|
|
4
|
+
await db.schema.createTable("user_party_rights").ifNotExists().addColumn("user_id", "text", (col) => col.notNull()).addColumn("network_id", "text", (col) => col.notNull()).addColumn("party_id", "text", (col) => col.notNull()).addColumn("right", "text", (col) => col.notNull()).addPrimaryKeyConstraint("user_party_rights_pk", [
|
|
5
|
+
"user_id",
|
|
6
|
+
"network_id",
|
|
7
|
+
"party_id",
|
|
8
|
+
"right"
|
|
9
|
+
]).addForeignKeyConstraint("user_party_rights_wallet_fk", [
|
|
10
|
+
"party_id",
|
|
11
|
+
"network_id",
|
|
12
|
+
"user_id"
|
|
13
|
+
], "wallets", [
|
|
14
|
+
"party_id",
|
|
15
|
+
"network_id",
|
|
16
|
+
"user_id"
|
|
17
|
+
], (cb) => cb.onDelete("cascade")).execute();
|
|
18
|
+
await db.schema.createTable("user_rights").ifNotExists().addColumn("user_id", "text", (col) => col.notNull()).addColumn("network_id", "text", (col) => col.notNull()).addColumn("right", "text", (col) => col.notNull()).addPrimaryKeyConstraint("user_rights_pk", [
|
|
19
|
+
"user_id",
|
|
20
|
+
"network_id",
|
|
21
|
+
"right"
|
|
22
|
+
]).addForeignKeyConstraint("user_rights_network_fk", ["network_id"], "networks", ["id"], (cb) => cb.onDelete("cascade")).execute();
|
|
33
23
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
24
|
+
async function down(db) {
|
|
25
|
+
console.log("Dropping normalized rights tables");
|
|
26
|
+
await db.schema.dropTable("user_rights").ifExists().execute();
|
|
27
|
+
await db.schema.dropTable("user_party_rights").ifExists().execute();
|
|
38
28
|
}
|
|
29
|
+
export { down, up };
|
|
30
|
+
|
|
31
|
+
//# sourceMappingURL=009-add-wallet-rights-columns.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"009-add-wallet-rights-columns.js","names":[],"sources":["../../src/migrations/009-add-wallet-rights-columns.ts"],"sourcesContent":["// Copyright (c) 2025-2026 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved.\n// SPDX-License-Identifier: Apache-2.0\n\nimport type { Kysely } from 'kysely'\nimport type { DB } from '../schema.js'\n\nexport async function up(db: Kysely<DB>): Promise<void> {\n console.log('Creating normalized rights tables')\n\n await db.schema\n .createTable('user_party_rights')\n .ifNotExists()\n .addColumn('user_id', 'text', (col) => col.notNull())\n .addColumn('network_id', 'text', (col) => col.notNull())\n .addColumn('party_id', 'text', (col) => col.notNull())\n .addColumn('right', 'text', (col) => col.notNull())\n .addPrimaryKeyConstraint('user_party_rights_pk', [\n 'user_id',\n 'network_id',\n 'party_id',\n 'right',\n ])\n .addForeignKeyConstraint(\n 'user_party_rights_wallet_fk',\n ['party_id', 'network_id', 'user_id'],\n 'wallets',\n ['party_id', 'network_id', 'user_id'],\n (cb) => cb.onDelete('cascade')\n )\n .execute()\n\n await db.schema\n .createTable('user_rights')\n .ifNotExists()\n .addColumn('user_id', 'text', (col) => col.notNull())\n .addColumn('network_id', 'text', (col) => col.notNull())\n .addColumn('right', 'text', (col) => col.notNull())\n .addPrimaryKeyConstraint('user_rights_pk', [\n 'user_id',\n 'network_id',\n 'right',\n ])\n .addForeignKeyConstraint(\n 'user_rights_network_fk',\n ['network_id'],\n 'networks',\n ['id'],\n (cb) => cb.onDelete('cascade')\n )\n .execute()\n}\n\nexport async function down(db: Kysely<DB>): Promise<void> {\n console.log('Dropping normalized rights tables')\n\n await db.schema.dropTable('user_rights').ifExists().execute()\n await db.schema.dropTable('user_party_rights').ifExists().execute()\n}\n"],"mappings":";AAMA,eAAsB,GAAG,IAA+B;CACpD,QAAQ,IAAI,mCAAmC;CAE/C,MAAM,GAAG,OACJ,YAAY,mBAAmB,CAAC,CAChC,YAAY,CAAC,CACb,UAAU,WAAW,SAAS,QAAQ,IAAI,QAAQ,CAAC,CAAC,CACpD,UAAU,cAAc,SAAS,QAAQ,IAAI,QAAQ,CAAC,CAAC,CACvD,UAAU,YAAY,SAAS,QAAQ,IAAI,QAAQ,CAAC,CAAC,CACrD,UAAU,SAAS,SAAS,QAAQ,IAAI,QAAQ,CAAC,CAAC,CAClD,wBAAwB,wBAAwB;EAC7C;EACA;EACA;EACA;CACJ,CAAC,CAAC,CACD,wBACG,+BACA;EAAC;EAAY;EAAc;CAAS,GACpC,WACA;EAAC;EAAY;EAAc;CAAS,IACnC,OAAO,GAAG,SAAS,SAAS,CACjC,CAAC,CACA,QAAQ;CAEb,MAAM,GAAG,OACJ,YAAY,aAAa,CAAC,CAC1B,YAAY,CAAC,CACb,UAAU,WAAW,SAAS,QAAQ,IAAI,QAAQ,CAAC,CAAC,CACpD,UAAU,cAAc,SAAS,QAAQ,IAAI,QAAQ,CAAC,CAAC,CACvD,UAAU,SAAS,SAAS,QAAQ,IAAI,QAAQ,CAAC,CAAC,CAClD,wBAAwB,kBAAkB;EACvC;EACA;EACA;CACJ,CAAC,CAAC,CACD,wBACG,0BACA,CAAC,YAAY,GACb,YACA,CAAC,IAAI,IACJ,OAAO,GAAG,SAAS,SAAS,CACjC,CAAC,CACA,QAAQ;AACjB;AAEA,eAAsB,KAAK,IAA+B;CACtD,QAAQ,IAAI,mCAAmC;CAE/C,MAAM,GAAG,OAAO,UAAU,aAAa,CAAC,CAAC,SAAS,CAAC,CAAC,QAAQ;CAC5D,MAAM,GAAG,OAAO,UAAU,mBAAmB,CAAC,CAAC,SAAS,CAAC,CAAC,QAAQ;AACtE"}
|