@@ -2,85 +2,20 @@ import type { Knex } from "knex";
22
33export async function up ( knex : Knex ) : Promise < void > {
44 //
5- // public.key_shares
5+ // public.2_users
66 //
7- const keySharesExists = await knex . schema
7+ const usersExists = await knex . schema
88 . withSchema ( "public" )
9- . hasTable ( "key_shares" ) ;
10- if ( ! keySharesExists ) {
11- await knex . schema
12- . withSchema ( "public" )
13- . createTable ( "key_shares" , ( table ) => {
14- table
15- . uuid ( "share_id" )
16- . notNullable ( )
17- . defaultTo ( knex . raw ( "gen_random_uuid()" ) )
18- . primary ( { constraintName : "key_shares_pkey" } ) ;
19- table . uuid ( "wallet_id" ) . notNullable ( ) ;
20- table . binary ( "enc_share" ) . notNullable ( ) ;
21- table . string ( "status" ) . notNullable ( ) ;
22- table
23- . timestamp ( "reshared_at" , { useTz : true } )
24- . notNullable ( )
25- . defaultTo ( knex . fn . now ( ) ) ;
26- table
27- . timestamp ( "created_at" , { useTz : true } )
28- . notNullable ( )
29- . defaultTo ( knex . fn . now ( ) ) ;
30- table
31- . timestamp ( "updated_at" , { useTz : true } )
32- . notNullable ( )
33- . defaultTo ( knex . fn . now ( ) ) ;
34- table . jsonb ( "aux" ) ;
35-
36- table . unique ( [ "wallet_id" ] , {
37- indexName : "key_shares_unique" ,
38- } ) ;
39- } ) ;
40- }
41-
42- //
43- // public.pg_dumps
44- //
45- const pgDumpsExists = await knex . schema
46- . withSchema ( "public" )
47- . hasTable ( "pg_dumps" ) ;
48- if ( ! pgDumpsExists ) {
49- await knex . schema . withSchema ( "public" ) . createTable ( "pg_dumps" , ( table ) => {
50- table
51- . uuid ( "dump_id" )
52- . notNullable ( )
53- . defaultTo ( knex . raw ( "gen_random_uuid()" ) )
54- . primary ( { constraintName : "pg_dumps_pkey" } ) ;
55- table . string ( "status" , 16 ) . notNullable ( ) ;
56- table . string ( "dump_path" , 255 ) ;
57- table . jsonb ( "meta" ) ;
58- table
59- . timestamp ( "created_at" , { useTz : true } )
60- . notNullable ( )
61- . defaultTo ( knex . fn . now ( ) ) ;
62- table
63- . timestamp ( "updated_at" , { useTz : true } )
64- . notNullable ( )
65- . defaultTo ( knex . fn . now ( ) ) ;
66- } ) ;
67- }
68-
69- //
70- // public.users
71- //
72- const usersExists = await knex . schema . withSchema ( "public" ) . hasTable ( "users" ) ;
9+ . hasTable ( "2_users" ) ;
7310 if ( ! usersExists ) {
74- await knex . schema . withSchema ( "public" ) . createTable ( "users " , ( table ) => {
11+ await knex . schema . withSchema ( "public" ) . createTable ( "2_users " , ( table ) => {
7512 table
7613 . uuid ( "user_id" )
7714 . notNullable ( )
7815 . defaultTo ( knex . raw ( "gen_random_uuid()" ) )
79- . primary ( { constraintName : "users_pkey" } ) ;
80- table
81- . string ( "email" , 255 )
82- . notNullable ( )
83- . unique ( { indexName : "users_email_key" } ) ;
16+ . primary ( { constraintName : "2_users_pkey" } ) ;
17+ table . string ( "auth_type" , 64 ) . notNullable ( ) ;
18+ table . string ( "email" , 255 ) . notNullable ( ) ;
8419 table . string ( "status" , 16 ) . notNullable ( ) . defaultTo ( "active" ) ;
8520 table
8621 . timestamp ( "created_at" , { useTz : true } )
@@ -91,28 +26,32 @@ export async function up(knex: Knex): Promise<void> {
9126 . notNullable ( )
9227 . defaultTo ( knex . fn . now ( ) ) ;
9328 table . jsonb ( "aux" ) ;
29+
30+ table . unique ( [ "auth_type" , "email" ] , {
31+ indexName : "2_users_auth_type_email_key" ,
32+ } ) ;
9433 } ) ;
9534 }
9635
9736 //
98- // public.wallets
37+ // public.2_wallets
9938 //
10039 const walletsExists = await knex . schema
10140 . withSchema ( "public" )
102- . hasTable ( "wallets " ) ;
41+ . hasTable ( "2_wallets " ) ;
10342 if ( ! walletsExists ) {
104- await knex . schema . withSchema ( "public" ) . createTable ( "wallets " , ( table ) => {
43+ await knex . schema . withSchema ( "public" ) . createTable ( "2_wallets " , ( table ) => {
10544 table
10645 . uuid ( "wallet_id" )
10746 . notNullable ( )
10847 . defaultTo ( knex . raw ( "gen_random_uuid()" ) )
109- . primary ( { constraintName : "wallets_pkey " } ) ;
48+ . primary ( { constraintName : "2_wallets_pkey " } ) ;
11049 table . uuid ( "user_id" ) . notNullable ( ) ;
11150 table . string ( "curve_type" , 16 ) . notNullable ( ) ;
11251 table
11352 . binary ( "public_key" )
11453 . notNullable ( )
115- . unique ( { indexName : "wallets_public_key_key " } ) ;
54+ . unique ( { indexName : "2_wallets_public_key_key " } ) ;
11655 table
11756 . timestamp ( "created_at" , { useTz : true } )
11857 . notNullable ( )
@@ -126,24 +65,62 @@ export async function up(knex: Knex): Promise<void> {
12665 }
12766
12867 //
129- // public.server_keypairs
68+ // public.2_key_shares
69+ //
70+ const keySharesExists = await knex . schema
71+ . withSchema ( "public" )
72+ . hasTable ( "2_key_shares" ) ;
73+ if ( ! keySharesExists ) {
74+ await knex . schema
75+ . withSchema ( "public" )
76+ . createTable ( "2_key_shares" , ( table ) => {
77+ table
78+ . uuid ( "share_id" )
79+ . notNullable ( )
80+ . defaultTo ( knex . raw ( "gen_random_uuid()" ) )
81+ . primary ( { constraintName : "2_key_shares_pkey" } ) ;
82+ table . uuid ( "wallet_id" ) . notNullable ( ) ;
83+ table . binary ( "enc_share" ) . notNullable ( ) ;
84+ table . string ( "status" ) . notNullable ( ) ;
85+ table
86+ . timestamp ( "reshared_at" , { useTz : true } )
87+ . notNullable ( )
88+ . defaultTo ( knex . fn . now ( ) ) ;
89+ table
90+ . timestamp ( "created_at" , { useTz : true } )
91+ . notNullable ( )
92+ . defaultTo ( knex . fn . now ( ) ) ;
93+ table
94+ . timestamp ( "updated_at" , { useTz : true } )
95+ . notNullable ( )
96+ . defaultTo ( knex . fn . now ( ) ) ;
97+ table . jsonb ( "aux" ) ;
98+
99+ table . unique ( [ "wallet_id" ] , {
100+ indexName : "2_key_shares_unique" ,
101+ } ) ;
102+ } ) ;
103+ }
104+
105+ //
106+ // public.2_server_keypairs
130107 //
131108 const serverKeypairsExists = await knex . schema
132109 . withSchema ( "public" )
133- . hasTable ( "server_keypairs " ) ;
110+ . hasTable ( "2_server_keypairs " ) ;
134111 if ( ! serverKeypairsExists ) {
135112 await knex . schema
136113 . withSchema ( "public" )
137- . createTable ( "server_keypairs " , ( table ) => {
114+ . createTable ( "2_server_keypairs " , ( table ) => {
138115 table
139116 . uuid ( "keypair_id" )
140117 . notNullable ( )
141118 . defaultTo ( knex . raw ( "gen_random_uuid()" ) )
142- . primary ( { constraintName : "server_keypairs_pkey " } ) ;
119+ . primary ( { constraintName : "2_server_keypairs_pkey " } ) ;
143120 table
144121 . specificType ( "version" , "integer generated always as identity" )
145122 . notNullable ( )
146- . unique ( { indexName : "server_keypairs_version_key " } ) ;
123+ . unique ( { indexName : "2_server_keypairs_version_key " } ) ;
147124 table . binary ( "public_key" ) . notNullable ( ) ;
148125 table . text ( "enc_private_key" ) . notNullable ( ) ;
149126 table . boolean ( "is_active" ) . notNullable ( ) . defaultTo ( true ) ;
@@ -159,17 +136,46 @@ export async function up(knex: Knex): Promise<void> {
159136 } ) ;
160137 }
161138
139+ //
140+ // public.2_pg_dumps
141+ //
142+ const pgDumpsExists = await knex . schema
143+ . withSchema ( "public" )
144+ . hasTable ( "2_pg_dumps" ) ;
145+ if ( ! pgDumpsExists ) {
146+ await knex . schema
147+ . withSchema ( "public" )
148+ . createTable ( "2_pg_dumps" , ( table ) => {
149+ table
150+ . uuid ( "dump_id" )
151+ . notNullable ( )
152+ . defaultTo ( knex . raw ( "gen_random_uuid()" ) )
153+ . primary ( { constraintName : "2_pg_dumps_pkey" } ) ;
154+ table . string ( "status" , 16 ) . notNullable ( ) ;
155+ table . string ( "dump_path" , 255 ) ;
156+ table . jsonb ( "meta" ) ;
157+ table
158+ . timestamp ( "created_at" , { useTz : true } )
159+ . notNullable ( )
160+ . defaultTo ( knex . fn . now ( ) ) ;
161+ table
162+ . timestamp ( "updated_at" , { useTz : true } )
163+ . notNullable ( )
164+ . defaultTo ( knex . fn . now ( ) ) ;
165+ } ) ;
166+ }
167+
162168 await knex . raw ( `
163- CREATE INDEX IF NOT EXISTS idx_server_keypairs_is_active
164- ON public.server_keypairs (is_active)
169+ CREATE INDEX IF NOT EXISTS idx_2_server_keypairs_is_active
170+ ON public."2_server_keypairs" (is_active)
165171 WHERE is_active = true
166172 ` ) ;
167173}
168174
169175export async function down ( knex : Knex ) : Promise < void > {
170- await knex . schema . withSchema ( "public" ) . dropTableIfExists ( "server_keypairs " ) ;
171- await knex . schema . withSchema ( "public" ) . dropTableIfExists ( "wallets " ) ;
172- await knex . schema . withSchema ( "public" ) . dropTableIfExists ( "users " ) ;
173- await knex . schema . withSchema ( "public" ) . dropTableIfExists ( "pg_dumps " ) ;
174- await knex . schema . withSchema ( "public" ) . dropTableIfExists ( "key_shares " ) ;
176+ await knex . schema . withSchema ( "public" ) . dropTableIfExists ( "2_users " ) ;
177+ await knex . schema . withSchema ( "public" ) . dropTableIfExists ( "2_wallets " ) ;
178+ await knex . schema . withSchema ( "public" ) . dropTableIfExists ( "2_key_shares " ) ;
179+ await knex . schema . withSchema ( "public" ) . dropTableIfExists ( "2_server_keypairs " ) ;
180+ await knex . schema . withSchema ( "public" ) . dropTableIfExists ( "2_pg_dumps " ) ;
175181}
0 commit comments