@minion-stack/db 0.3.0 → 0.3.1

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.
@@ -0,0 +1,262 @@
1
+ /**
2
+ * Supabase-backed registry of Minion gateway servers.
3
+ * Mirrors Turso `servers`. legacy_server_id preserves the old Turso text PK
4
+ * so Turso log/event rows (which still carry the old id) can join here.
5
+ */
6
+ export declare const gateway: import("drizzle-orm/pg-core").PgTableWithColumns<{
7
+ name: "gateway";
8
+ schema: undefined;
9
+ columns: {
10
+ id: import("drizzle-orm/pg-core").PgColumn<{
11
+ name: "id";
12
+ tableName: "gateway";
13
+ dataType: "string";
14
+ columnType: "PgUUID";
15
+ data: string;
16
+ driverParam: string;
17
+ notNull: true;
18
+ hasDefault: true;
19
+ isPrimaryKey: true;
20
+ isAutoincrement: false;
21
+ hasRuntimeDefault: false;
22
+ enumValues: undefined;
23
+ baseColumn: never;
24
+ identity: undefined;
25
+ generated: undefined;
26
+ }, {}, {}>;
27
+ legacyServerId: import("drizzle-orm/pg-core").PgColumn<{
28
+ name: "legacy_server_id";
29
+ tableName: "gateway";
30
+ dataType: "string";
31
+ columnType: "PgText";
32
+ data: string;
33
+ driverParam: string;
34
+ notNull: false;
35
+ hasDefault: false;
36
+ isPrimaryKey: false;
37
+ isAutoincrement: false;
38
+ hasRuntimeDefault: false;
39
+ enumValues: [string, ...string[]];
40
+ baseColumn: never;
41
+ identity: undefined;
42
+ generated: undefined;
43
+ }, {}, {}>;
44
+ name: import("drizzle-orm/pg-core").PgColumn<{
45
+ name: "name";
46
+ tableName: "gateway";
47
+ dataType: "string";
48
+ columnType: "PgText";
49
+ data: string;
50
+ driverParam: string;
51
+ notNull: true;
52
+ hasDefault: false;
53
+ isPrimaryKey: false;
54
+ isAutoincrement: false;
55
+ hasRuntimeDefault: false;
56
+ enumValues: [string, ...string[]];
57
+ baseColumn: never;
58
+ identity: undefined;
59
+ generated: undefined;
60
+ }, {}, {}>;
61
+ url: import("drizzle-orm/pg-core").PgColumn<{
62
+ name: "url";
63
+ tableName: "gateway";
64
+ dataType: "string";
65
+ columnType: "PgText";
66
+ data: string;
67
+ driverParam: string;
68
+ notNull: true;
69
+ hasDefault: false;
70
+ isPrimaryKey: false;
71
+ isAutoincrement: false;
72
+ hasRuntimeDefault: false;
73
+ enumValues: [string, ...string[]];
74
+ baseColumn: never;
75
+ identity: undefined;
76
+ generated: undefined;
77
+ }, {}, {}>;
78
+ tokenCiphertext: import("drizzle-orm/pg-core").PgColumn<{
79
+ name: "token_ciphertext";
80
+ tableName: "gateway";
81
+ dataType: "string";
82
+ columnType: "PgText";
83
+ data: string;
84
+ driverParam: string;
85
+ notNull: true;
86
+ hasDefault: true;
87
+ isPrimaryKey: false;
88
+ isAutoincrement: false;
89
+ hasRuntimeDefault: false;
90
+ enumValues: [string, ...string[]];
91
+ baseColumn: never;
92
+ identity: undefined;
93
+ generated: undefined;
94
+ }, {}, {}>;
95
+ tokenIv: import("drizzle-orm/pg-core").PgColumn<{
96
+ name: "token_iv";
97
+ tableName: "gateway";
98
+ dataType: "string";
99
+ columnType: "PgText";
100
+ data: string;
101
+ driverParam: string;
102
+ notNull: true;
103
+ hasDefault: true;
104
+ isPrimaryKey: false;
105
+ isAutoincrement: false;
106
+ hasRuntimeDefault: false;
107
+ enumValues: [string, ...string[]];
108
+ baseColumn: never;
109
+ identity: undefined;
110
+ generated: undefined;
111
+ }, {}, {}>;
112
+ authMode: import("drizzle-orm/pg-core").PgColumn<{
113
+ name: "auth_mode";
114
+ tableName: "gateway";
115
+ dataType: "string";
116
+ columnType: "PgText";
117
+ data: "token" | "none";
118
+ driverParam: string;
119
+ notNull: true;
120
+ hasDefault: true;
121
+ isPrimaryKey: false;
122
+ isAutoincrement: false;
123
+ hasRuntimeDefault: false;
124
+ enumValues: ["token", "none"];
125
+ baseColumn: never;
126
+ identity: undefined;
127
+ generated: undefined;
128
+ }, {}, {}>;
129
+ lastConnectedAt: import("drizzle-orm/pg-core").PgColumn<{
130
+ name: "last_connected_at";
131
+ tableName: "gateway";
132
+ dataType: "date";
133
+ columnType: "PgTimestamp";
134
+ data: Date;
135
+ driverParam: string;
136
+ notNull: false;
137
+ hasDefault: false;
138
+ isPrimaryKey: false;
139
+ isAutoincrement: false;
140
+ hasRuntimeDefault: false;
141
+ enumValues: undefined;
142
+ baseColumn: never;
143
+ identity: undefined;
144
+ generated: undefined;
145
+ }, {}, {}>;
146
+ createdAt: import("drizzle-orm/pg-core").PgColumn<{
147
+ name: "created_at";
148
+ tableName: "gateway";
149
+ dataType: "date";
150
+ columnType: "PgTimestamp";
151
+ data: Date;
152
+ driverParam: string;
153
+ notNull: true;
154
+ hasDefault: true;
155
+ isPrimaryKey: false;
156
+ isAutoincrement: false;
157
+ hasRuntimeDefault: false;
158
+ enumValues: undefined;
159
+ baseColumn: never;
160
+ identity: undefined;
161
+ generated: undefined;
162
+ }, {}, {}>;
163
+ updatedAt: import("drizzle-orm/pg-core").PgColumn<{
164
+ name: "updated_at";
165
+ tableName: "gateway";
166
+ dataType: "date";
167
+ columnType: "PgTimestamp";
168
+ data: Date;
169
+ driverParam: string;
170
+ notNull: true;
171
+ hasDefault: true;
172
+ isPrimaryKey: false;
173
+ isAutoincrement: false;
174
+ hasRuntimeDefault: false;
175
+ enumValues: undefined;
176
+ baseColumn: never;
177
+ identity: undefined;
178
+ generated: undefined;
179
+ }, {}, {}>;
180
+ };
181
+ dialect: "pg";
182
+ }>;
183
+ /**
184
+ * Per-user gateway link. Mirrors Turso `user_servers`.
185
+ * profile_id references profiles.id (== auth.users.id).
186
+ */
187
+ export declare const userGateway: import("drizzle-orm/pg-core").PgTableWithColumns<{
188
+ name: "user_gateway";
189
+ schema: undefined;
190
+ columns: {
191
+ profileId: import("drizzle-orm/pg-core").PgColumn<{
192
+ name: "profile_id";
193
+ tableName: "user_gateway";
194
+ dataType: "string";
195
+ columnType: "PgUUID";
196
+ data: string;
197
+ driverParam: string;
198
+ notNull: true;
199
+ hasDefault: false;
200
+ isPrimaryKey: false;
201
+ isAutoincrement: false;
202
+ hasRuntimeDefault: false;
203
+ enumValues: undefined;
204
+ baseColumn: never;
205
+ identity: undefined;
206
+ generated: undefined;
207
+ }, {}, {}>;
208
+ gatewayId: import("drizzle-orm/pg-core").PgColumn<{
209
+ name: "gateway_id";
210
+ tableName: "user_gateway";
211
+ dataType: "string";
212
+ columnType: "PgUUID";
213
+ data: string;
214
+ driverParam: string;
215
+ notNull: true;
216
+ hasDefault: false;
217
+ isPrimaryKey: false;
218
+ isAutoincrement: false;
219
+ hasRuntimeDefault: false;
220
+ enumValues: undefined;
221
+ baseColumn: never;
222
+ identity: undefined;
223
+ generated: undefined;
224
+ }, {}, {}>;
225
+ isDefault: import("drizzle-orm/pg-core").PgColumn<{
226
+ name: "is_default";
227
+ tableName: "user_gateway";
228
+ dataType: "boolean";
229
+ columnType: "PgBoolean";
230
+ data: boolean;
231
+ driverParam: boolean;
232
+ notNull: true;
233
+ hasDefault: true;
234
+ isPrimaryKey: false;
235
+ isAutoincrement: false;
236
+ hasRuntimeDefault: false;
237
+ enumValues: undefined;
238
+ baseColumn: never;
239
+ identity: undefined;
240
+ generated: undefined;
241
+ }, {}, {}>;
242
+ createdAt: import("drizzle-orm/pg-core").PgColumn<{
243
+ name: "created_at";
244
+ tableName: "user_gateway";
245
+ dataType: "date";
246
+ columnType: "PgTimestamp";
247
+ data: Date;
248
+ driverParam: string;
249
+ notNull: true;
250
+ hasDefault: true;
251
+ isPrimaryKey: false;
252
+ isAutoincrement: false;
253
+ hasRuntimeDefault: false;
254
+ enumValues: undefined;
255
+ baseColumn: never;
256
+ identity: undefined;
257
+ generated: undefined;
258
+ }, {}, {}>;
259
+ };
260
+ dialect: "pg";
261
+ }>;
262
+ //# sourceMappingURL=gateway.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gateway.d.ts","sourceRoot":"","sources":["../../../src/pg/schema/gateway.ts"],"names":[],"mappings":"AAGA;;;;GAIG;AACH,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAclB,CAAC;AAEH;;;GAGG;AACH,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAQtB,CAAC"}
@@ -0,0 +1,36 @@
1
+ import { pgTable, uuid, text, boolean, timestamp, primaryKey, index, uniqueIndex } from 'drizzle-orm/pg-core';
2
+ import { profiles } from './profiles.js';
3
+ /**
4
+ * Supabase-backed registry of Minion gateway servers.
5
+ * Mirrors Turso `servers`. legacy_server_id preserves the old Turso text PK
6
+ * so Turso log/event rows (which still carry the old id) can join here.
7
+ */
8
+ export const gateway = pgTable('gateway', {
9
+ id: uuid('id').primaryKey().defaultRandom(),
10
+ legacyServerId: text('legacy_server_id'),
11
+ name: text('name').notNull(),
12
+ url: text('url').notNull(),
13
+ tokenCiphertext: text('token_ciphertext').notNull().default(''),
14
+ tokenIv: text('token_iv').notNull().default(''),
15
+ authMode: text('auth_mode', { enum: ['token', 'none'] }).notNull().default('token'),
16
+ lastConnectedAt: timestamp('last_connected_at', { withTimezone: true }),
17
+ createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),
18
+ updatedAt: timestamp('updated_at', { withTimezone: true }).notNull().defaultNow(),
19
+ }, (t) => [
20
+ uniqueIndex('gateway_uniq_url').on(t.url),
21
+ index('idx_gateway_legacy').on(t.legacyServerId),
22
+ ]);
23
+ /**
24
+ * Per-user gateway link. Mirrors Turso `user_servers`.
25
+ * profile_id references profiles.id (== auth.users.id).
26
+ */
27
+ export const userGateway = pgTable('user_gateway', {
28
+ profileId: uuid('profile_id').notNull().references(() => profiles.id, { onDelete: 'cascade' }),
29
+ gatewayId: uuid('gateway_id').notNull().references(() => gateway.id, { onDelete: 'cascade' }),
30
+ isDefault: boolean('is_default').notNull().default(false),
31
+ createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),
32
+ }, (t) => [
33
+ primaryKey({ columns: [t.profileId, t.gatewayId] }),
34
+ index('idx_user_gateway_gateway').on(t.gatewayId),
35
+ ]);
36
+ //# sourceMappingURL=gateway.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"gateway.js","sourceRoot":"","sources":["../../../src/pg/schema/gateway.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,KAAK,EAAE,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAC9G,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC;;;;GAIG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,OAAO,CAAC,SAAS,EAAE;IACxC,EAAE,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,CAAC,aAAa,EAAE;IAC3C,cAAc,EAAE,IAAI,CAAC,kBAAkB,CAAC;IACxC,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC,CAAC,OAAO,EAAE;IAC5B,GAAG,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,OAAO,EAAE;IAC1B,eAAe,EAAE,IAAI,CAAC,kBAAkB,CAAC,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC;IAC/D,OAAO,EAAE,IAAI,CAAC,UAAU,CAAC,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,EAAE,CAAC;IAC/C,QAAQ,EAAE,IAAI,CAAC,WAAW,EAAE,EAAE,IAAI,EAAE,CAAC,OAAO,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,OAAO,CAAC;IACnF,eAAe,EAAE,SAAS,CAAC,mBAAmB,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC;IACvE,SAAS,EAAE,SAAS,CAAC,YAAY,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,UAAU,EAAE;IACjF,SAAS,EAAE,SAAS,CAAC,YAAY,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,UAAU,EAAE;CAClF,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC;IACR,WAAW,CAAC,kBAAkB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC;IACzC,KAAK,CAAC,oBAAoB,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,cAAc,CAAC;CACjD,CAAC,CAAC;AAEH;;;GAGG;AACH,MAAM,CAAC,MAAM,WAAW,GAAG,OAAO,CAAC,cAAc,EAAE;IACjD,SAAS,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC,OAAO,EAAE,CAAC,UAAU,CAAC,GAAG,EAAE,CAAC,QAAQ,CAAC,EAAE,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC;IAC9F,SAAS,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC,OAAO,EAAE,CAAC,UAAU,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,EAAE,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC;IAC7F,SAAS,EAAE,OAAO,CAAC,YAAY,CAAC,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC;IACzD,SAAS,EAAE,SAAS,CAAC,YAAY,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,UAAU,EAAE;CAClF,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC;IACR,UAAU,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,SAAS,EAAE,CAAC,CAAC,SAAS,CAAC,EAAE,CAAC;IACnD,KAAK,CAAC,0BAA0B,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC;CAClD,CAAC,CAAC"}
@@ -1,6 +1,8 @@
1
1
  export { profiles } from './profiles.js';
2
2
  export { userIdentities } from './user-identities.js';
3
+ export { joinRequest, joinLink } from './join.js';
3
4
  export { mapGoogleIdentity } from '../identity-mapper.js';
4
5
  export type { GoTrueUserLike, GoogleGrant, MappedProfile, MappedIdentity, } from '../identity-mapper.js';
5
6
  export { sealSecret, openSecret } from '../crypto.js';
7
+ export { gateway, userGateway } from './gateway.js';
6
8
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/pg/schema/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAGtD,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,YAAY,EACV,cAAc,EACd,WAAW,EACX,aAAa,EACb,cAAc,GACf,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/pg/schema/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAGlD,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAC1D,YAAY,EACV,cAAc,EACd,WAAW,EACX,aAAa,EACb,cAAc,GACf,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC"}
@@ -1,6 +1,8 @@
1
1
  export { profiles } from './profiles.js';
2
2
  export { userIdentities } from './user-identities.js';
3
+ export { joinRequest, joinLink } from './join.js';
3
4
  // Identity helpers (consumed by minion_site auth path)
4
5
  export { mapGoogleIdentity } from '../identity-mapper.js';
5
6
  export { sealSecret, openSecret } from '../crypto.js';
7
+ export { gateway, userGateway } from './gateway.js';
6
8
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/pg/schema/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAEtD,uDAAuD;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAO1D,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/pg/schema/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,WAAW,CAAC;AAElD,uDAAuD;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAO1D,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AACtD,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC"}
@@ -0,0 +1,406 @@
1
+ export declare const joinRequest: import("drizzle-orm/pg-core").PgTableWithColumns<{
2
+ name: "join_request";
3
+ schema: undefined;
4
+ columns: {
5
+ id: import("drizzle-orm/pg-core").PgColumn<{
6
+ name: "id";
7
+ tableName: "join_request";
8
+ dataType: "string";
9
+ columnType: "PgUUID";
10
+ data: string;
11
+ driverParam: string;
12
+ notNull: true;
13
+ hasDefault: true;
14
+ isPrimaryKey: true;
15
+ isAutoincrement: false;
16
+ hasRuntimeDefault: false;
17
+ enumValues: undefined;
18
+ baseColumn: never;
19
+ identity: undefined;
20
+ generated: undefined;
21
+ }, {}, {}>;
22
+ supabaseId: import("drizzle-orm/pg-core").PgColumn<{
23
+ name: "supabase_id";
24
+ tableName: "join_request";
25
+ dataType: "string";
26
+ columnType: "PgUUID";
27
+ data: string;
28
+ driverParam: string;
29
+ notNull: true;
30
+ hasDefault: false;
31
+ isPrimaryKey: false;
32
+ isAutoincrement: false;
33
+ hasRuntimeDefault: false;
34
+ enumValues: undefined;
35
+ baseColumn: never;
36
+ identity: undefined;
37
+ generated: undefined;
38
+ }, {}, {}>;
39
+ userId: import("drizzle-orm/pg-core").PgColumn<{
40
+ name: "user_id";
41
+ tableName: "join_request";
42
+ dataType: "string";
43
+ columnType: "PgText";
44
+ data: string;
45
+ driverParam: string;
46
+ notNull: true;
47
+ hasDefault: false;
48
+ isPrimaryKey: false;
49
+ isAutoincrement: false;
50
+ hasRuntimeDefault: false;
51
+ enumValues: [string, ...string[]];
52
+ baseColumn: never;
53
+ identity: undefined;
54
+ generated: undefined;
55
+ }, {}, {}>;
56
+ email: import("drizzle-orm/pg-core").PgColumn<{
57
+ name: "email";
58
+ tableName: "join_request";
59
+ dataType: "string";
60
+ columnType: "PgText";
61
+ data: string;
62
+ driverParam: string;
63
+ notNull: true;
64
+ hasDefault: false;
65
+ isPrimaryKey: false;
66
+ isAutoincrement: false;
67
+ hasRuntimeDefault: false;
68
+ enumValues: [string, ...string[]];
69
+ baseColumn: never;
70
+ identity: undefined;
71
+ generated: undefined;
72
+ }, {}, {}>;
73
+ displayName: import("drizzle-orm/pg-core").PgColumn<{
74
+ name: "display_name";
75
+ tableName: "join_request";
76
+ dataType: "string";
77
+ columnType: "PgText";
78
+ data: string;
79
+ driverParam: string;
80
+ notNull: false;
81
+ hasDefault: false;
82
+ isPrimaryKey: false;
83
+ isAutoincrement: false;
84
+ hasRuntimeDefault: false;
85
+ enumValues: [string, ...string[]];
86
+ baseColumn: never;
87
+ identity: undefined;
88
+ generated: undefined;
89
+ }, {}, {}>;
90
+ message: import("drizzle-orm/pg-core").PgColumn<{
91
+ name: "message";
92
+ tableName: "join_request";
93
+ dataType: "string";
94
+ columnType: "PgText";
95
+ data: string;
96
+ driverParam: string;
97
+ notNull: false;
98
+ hasDefault: false;
99
+ isPrimaryKey: false;
100
+ isAutoincrement: false;
101
+ hasRuntimeDefault: false;
102
+ enumValues: [string, ...string[]];
103
+ baseColumn: never;
104
+ identity: undefined;
105
+ generated: undefined;
106
+ }, {}, {}>;
107
+ status: import("drizzle-orm/pg-core").PgColumn<{
108
+ name: "status";
109
+ tableName: "join_request";
110
+ dataType: "string";
111
+ columnType: "PgText";
112
+ data: "pending" | "approved" | "denied";
113
+ driverParam: string;
114
+ notNull: true;
115
+ hasDefault: true;
116
+ isPrimaryKey: false;
117
+ isAutoincrement: false;
118
+ hasRuntimeDefault: false;
119
+ enumValues: ["pending", "approved", "denied"];
120
+ baseColumn: never;
121
+ identity: undefined;
122
+ generated: undefined;
123
+ }, {}, {}>;
124
+ organizationId: import("drizzle-orm/pg-core").PgColumn<{
125
+ name: "organization_id";
126
+ tableName: "join_request";
127
+ dataType: "string";
128
+ columnType: "PgText";
129
+ data: string;
130
+ driverParam: string;
131
+ notNull: true;
132
+ hasDefault: false;
133
+ isPrimaryKey: false;
134
+ isAutoincrement: false;
135
+ hasRuntimeDefault: false;
136
+ enumValues: [string, ...string[]];
137
+ baseColumn: never;
138
+ identity: undefined;
139
+ generated: undefined;
140
+ }, {}, {}>;
141
+ requestedRole: import("drizzle-orm/pg-core").PgColumn<{
142
+ name: "requested_role";
143
+ tableName: "join_request";
144
+ dataType: "string";
145
+ columnType: "PgText";
146
+ data: "user" | "admin" | "super_admin";
147
+ driverParam: string;
148
+ notNull: true;
149
+ hasDefault: true;
150
+ isPrimaryKey: false;
151
+ isAutoincrement: false;
152
+ hasRuntimeDefault: false;
153
+ enumValues: ["user", "admin", "super_admin"];
154
+ baseColumn: never;
155
+ identity: undefined;
156
+ generated: undefined;
157
+ }, {}, {}>;
158
+ reviewedBy: import("drizzle-orm/pg-core").PgColumn<{
159
+ name: "reviewed_by";
160
+ tableName: "join_request";
161
+ dataType: "string";
162
+ columnType: "PgText";
163
+ data: string;
164
+ driverParam: string;
165
+ notNull: false;
166
+ hasDefault: false;
167
+ isPrimaryKey: false;
168
+ isAutoincrement: false;
169
+ hasRuntimeDefault: false;
170
+ enumValues: [string, ...string[]];
171
+ baseColumn: never;
172
+ identity: undefined;
173
+ generated: undefined;
174
+ }, {}, {}>;
175
+ reviewedAt: import("drizzle-orm/pg-core").PgColumn<{
176
+ name: "reviewed_at";
177
+ tableName: "join_request";
178
+ dataType: "date";
179
+ columnType: "PgTimestamp";
180
+ data: Date;
181
+ driverParam: string;
182
+ notNull: false;
183
+ hasDefault: false;
184
+ isPrimaryKey: false;
185
+ isAutoincrement: false;
186
+ hasRuntimeDefault: false;
187
+ enumValues: undefined;
188
+ baseColumn: never;
189
+ identity: undefined;
190
+ generated: undefined;
191
+ }, {}, {}>;
192
+ createdAt: import("drizzle-orm/pg-core").PgColumn<{
193
+ name: "created_at";
194
+ tableName: "join_request";
195
+ dataType: "date";
196
+ columnType: "PgTimestamp";
197
+ data: Date;
198
+ driverParam: string;
199
+ notNull: true;
200
+ hasDefault: true;
201
+ isPrimaryKey: false;
202
+ isAutoincrement: false;
203
+ hasRuntimeDefault: false;
204
+ enumValues: undefined;
205
+ baseColumn: never;
206
+ identity: undefined;
207
+ generated: undefined;
208
+ }, {}, {}>;
209
+ updatedAt: import("drizzle-orm/pg-core").PgColumn<{
210
+ name: "updated_at";
211
+ tableName: "join_request";
212
+ dataType: "date";
213
+ columnType: "PgTimestamp";
214
+ data: Date;
215
+ driverParam: string;
216
+ notNull: true;
217
+ hasDefault: true;
218
+ isPrimaryKey: false;
219
+ isAutoincrement: false;
220
+ hasRuntimeDefault: false;
221
+ enumValues: undefined;
222
+ baseColumn: never;
223
+ identity: undefined;
224
+ generated: undefined;
225
+ }, {}, {}>;
226
+ };
227
+ dialect: "pg";
228
+ }>;
229
+ export declare const joinLink: import("drizzle-orm/pg-core").PgTableWithColumns<{
230
+ name: "join_link";
231
+ schema: undefined;
232
+ columns: {
233
+ id: import("drizzle-orm/pg-core").PgColumn<{
234
+ name: "id";
235
+ tableName: "join_link";
236
+ dataType: "string";
237
+ columnType: "PgUUID";
238
+ data: string;
239
+ driverParam: string;
240
+ notNull: true;
241
+ hasDefault: true;
242
+ isPrimaryKey: true;
243
+ isAutoincrement: false;
244
+ hasRuntimeDefault: false;
245
+ enumValues: undefined;
246
+ baseColumn: never;
247
+ identity: undefined;
248
+ generated: undefined;
249
+ }, {}, {}>;
250
+ token: import("drizzle-orm/pg-core").PgColumn<{
251
+ name: "token";
252
+ tableName: "join_link";
253
+ dataType: "string";
254
+ columnType: "PgText";
255
+ data: string;
256
+ driverParam: string;
257
+ notNull: true;
258
+ hasDefault: false;
259
+ isPrimaryKey: false;
260
+ isAutoincrement: false;
261
+ hasRuntimeDefault: false;
262
+ enumValues: [string, ...string[]];
263
+ baseColumn: never;
264
+ identity: undefined;
265
+ generated: undefined;
266
+ }, {}, {}>;
267
+ organizationId: import("drizzle-orm/pg-core").PgColumn<{
268
+ name: "organization_id";
269
+ tableName: "join_link";
270
+ dataType: "string";
271
+ columnType: "PgText";
272
+ data: string;
273
+ driverParam: string;
274
+ notNull: true;
275
+ hasDefault: false;
276
+ isPrimaryKey: false;
277
+ isAutoincrement: false;
278
+ hasRuntimeDefault: false;
279
+ enumValues: [string, ...string[]];
280
+ baseColumn: never;
281
+ identity: undefined;
282
+ generated: undefined;
283
+ }, {}, {}>;
284
+ role: import("drizzle-orm/pg-core").PgColumn<{
285
+ name: "role";
286
+ tableName: "join_link";
287
+ dataType: "string";
288
+ columnType: "PgText";
289
+ data: "user" | "admin" | "super_admin";
290
+ driverParam: string;
291
+ notNull: true;
292
+ hasDefault: false;
293
+ isPrimaryKey: false;
294
+ isAutoincrement: false;
295
+ hasRuntimeDefault: false;
296
+ enumValues: ["user", "admin", "super_admin"];
297
+ baseColumn: never;
298
+ identity: undefined;
299
+ generated: undefined;
300
+ }, {}, {}>;
301
+ createdBy: import("drizzle-orm/pg-core").PgColumn<{
302
+ name: "created_by";
303
+ tableName: "join_link";
304
+ dataType: "string";
305
+ columnType: "PgText";
306
+ data: string;
307
+ driverParam: string;
308
+ notNull: true;
309
+ hasDefault: false;
310
+ isPrimaryKey: false;
311
+ isAutoincrement: false;
312
+ hasRuntimeDefault: false;
313
+ enumValues: [string, ...string[]];
314
+ baseColumn: never;
315
+ identity: undefined;
316
+ generated: undefined;
317
+ }, {}, {}>;
318
+ expiresAt: import("drizzle-orm/pg-core").PgColumn<{
319
+ name: "expires_at";
320
+ tableName: "join_link";
321
+ dataType: "date";
322
+ columnType: "PgTimestamp";
323
+ data: Date;
324
+ driverParam: string;
325
+ notNull: false;
326
+ hasDefault: false;
327
+ isPrimaryKey: false;
328
+ isAutoincrement: false;
329
+ hasRuntimeDefault: false;
330
+ enumValues: undefined;
331
+ baseColumn: never;
332
+ identity: undefined;
333
+ generated: undefined;
334
+ }, {}, {}>;
335
+ maxUses: import("drizzle-orm/pg-core").PgColumn<{
336
+ name: "max_uses";
337
+ tableName: "join_link";
338
+ dataType: "number";
339
+ columnType: "PgInteger";
340
+ data: number;
341
+ driverParam: string | number;
342
+ notNull: false;
343
+ hasDefault: false;
344
+ isPrimaryKey: false;
345
+ isAutoincrement: false;
346
+ hasRuntimeDefault: false;
347
+ enumValues: undefined;
348
+ baseColumn: never;
349
+ identity: undefined;
350
+ generated: undefined;
351
+ }, {}, {}>;
352
+ usesCount: import("drizzle-orm/pg-core").PgColumn<{
353
+ name: "uses_count";
354
+ tableName: "join_link";
355
+ dataType: "number";
356
+ columnType: "PgInteger";
357
+ data: number;
358
+ driverParam: string | number;
359
+ notNull: true;
360
+ hasDefault: true;
361
+ isPrimaryKey: false;
362
+ isAutoincrement: false;
363
+ hasRuntimeDefault: false;
364
+ enumValues: undefined;
365
+ baseColumn: never;
366
+ identity: undefined;
367
+ generated: undefined;
368
+ }, {}, {}>;
369
+ revoked: import("drizzle-orm/pg-core").PgColumn<{
370
+ name: "revoked";
371
+ tableName: "join_link";
372
+ dataType: "boolean";
373
+ columnType: "PgBoolean";
374
+ data: boolean;
375
+ driverParam: boolean;
376
+ notNull: true;
377
+ hasDefault: true;
378
+ isPrimaryKey: false;
379
+ isAutoincrement: false;
380
+ hasRuntimeDefault: false;
381
+ enumValues: undefined;
382
+ baseColumn: never;
383
+ identity: undefined;
384
+ generated: undefined;
385
+ }, {}, {}>;
386
+ createdAt: import("drizzle-orm/pg-core").PgColumn<{
387
+ name: "created_at";
388
+ tableName: "join_link";
389
+ dataType: "date";
390
+ columnType: "PgTimestamp";
391
+ data: Date;
392
+ driverParam: string;
393
+ notNull: true;
394
+ hasDefault: true;
395
+ isPrimaryKey: false;
396
+ isAutoincrement: false;
397
+ hasRuntimeDefault: false;
398
+ enumValues: undefined;
399
+ baseColumn: never;
400
+ identity: undefined;
401
+ generated: undefined;
402
+ }, {}, {}>;
403
+ };
404
+ dialect: "pg";
405
+ }>;
406
+ //# sourceMappingURL=join.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"join.d.ts","sourceRoot":"","sources":["../../../src/pg/schema/join.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAkBtB,CAAC;AAEH,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAYnB,CAAC"}
@@ -0,0 +1,37 @@
1
+ import { pgTable, uuid, text, integer, boolean, timestamp } from 'drizzle-orm/pg-core';
2
+ // Partial unique index (one open request per user/org) is created in the
3
+ // hand-written migration (Task 5), since the WHERE-predicate form isn't
4
+ // expressed cleanly here. Keep this table definition free of an index callback.
5
+ export const joinRequest = pgTable('join_request', {
6
+ id: uuid('id').primaryKey().defaultRandom(),
7
+ // GoTrue auth.users.id (== profiles.id). The requester's Supabase identity.
8
+ supabaseId: uuid('supabase_id').notNull(),
9
+ // Bridged hub id (profiles.legacy_user_id ?? supabaseId) — the value used as the
10
+ // Turso `member.user_id` key when the request is approved. Distinct from supabase_id.
11
+ userId: text('user_id').notNull(),
12
+ email: text('email').notNull(),
13
+ displayName: text('display_name'),
14
+ message: text('message'),
15
+ status: text('status', { enum: ['pending', 'approved', 'denied'] }).notNull().default('pending'),
16
+ // Turso organization id (cross-DB reference; orgs live in Turso, so no PG FK).
17
+ organizationId: text('organization_id').notNull(),
18
+ requestedRole: text('requested_role', { enum: ['user', 'admin', 'super_admin'] }).notNull().default('user'),
19
+ reviewedBy: text('reviewed_by'),
20
+ reviewedAt: timestamp('reviewed_at', { withTimezone: true }),
21
+ createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),
22
+ updatedAt: timestamp('updated_at', { withTimezone: true }).notNull().defaultNow(),
23
+ });
24
+ export const joinLink = pgTable('join_link', {
25
+ id: uuid('id').primaryKey().defaultRandom(),
26
+ token: text('token').notNull().unique(),
27
+ // Turso organization id (cross-DB reference; orgs live in Turso, so no PG FK).
28
+ organizationId: text('organization_id').notNull(),
29
+ role: text('role', { enum: ['user', 'admin', 'super_admin'] }).notNull(),
30
+ createdBy: text('created_by').notNull(),
31
+ expiresAt: timestamp('expires_at', { withTimezone: true }),
32
+ maxUses: integer('max_uses'),
33
+ usesCount: integer('uses_count').notNull().default(0),
34
+ revoked: boolean('revoked').notNull().default(false),
35
+ createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),
36
+ });
37
+ //# sourceMappingURL=join.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"join.js","sourceRoot":"","sources":["../../../src/pg/schema/join.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEvF,yEAAyE;AACzE,wEAAwE;AACxE,gFAAgF;AAChF,MAAM,CAAC,MAAM,WAAW,GAAG,OAAO,CAAC,cAAc,EAAE;IACjD,EAAE,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,CAAC,aAAa,EAAE;IAC3C,4EAA4E;IAC5E,UAAU,EAAE,IAAI,CAAC,aAAa,CAAC,CAAC,OAAO,EAAE;IACzC,iFAAiF;IACjF,sFAAsF;IACtF,MAAM,EAAE,IAAI,CAAC,SAAS,CAAC,CAAC,OAAO,EAAE;IACjC,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE;IAC9B,WAAW,EAAE,IAAI,CAAC,cAAc,CAAC;IACjC,OAAO,EAAE,IAAI,CAAC,SAAS,CAAC;IACxB,MAAM,EAAE,IAAI,CAAC,QAAQ,EAAE,EAAE,IAAI,EAAE,CAAC,SAAS,EAAE,UAAU,EAAE,QAAQ,CAAC,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,SAAS,CAAC;IAChG,+EAA+E;IAC/E,cAAc,EAAE,IAAI,CAAC,iBAAiB,CAAC,CAAC,OAAO,EAAE;IACjD,aAAa,EAAE,IAAI,CAAC,gBAAgB,EAAE,EAAE,IAAI,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,aAAa,CAAC,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,MAAM,CAAC;IAC3G,UAAU,EAAE,IAAI,CAAC,aAAa,CAAC;IAC/B,UAAU,EAAE,SAAS,CAAC,aAAa,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC;IAC5D,SAAS,EAAE,SAAS,CAAC,YAAY,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,UAAU,EAAE;IACjF,SAAS,EAAE,SAAS,CAAC,YAAY,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,UAAU,EAAE;CAClF,CAAC,CAAC;AAEH,MAAM,CAAC,MAAM,QAAQ,GAAG,OAAO,CAAC,WAAW,EAAE;IAC3C,EAAE,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,CAAC,aAAa,EAAE;IAC3C,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE,CAAC,MAAM,EAAE;IACvC,+EAA+E;IAC/E,cAAc,EAAE,IAAI,CAAC,iBAAiB,CAAC,CAAC,OAAO,EAAE;IACjD,IAAI,EAAE,IAAI,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,aAAa,CAAC,EAAE,CAAC,CAAC,OAAO,EAAE;IACxE,SAAS,EAAE,IAAI,CAAC,YAAY,CAAC,CAAC,OAAO,EAAE;IACvC,SAAS,EAAE,SAAS,CAAC,YAAY,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC;IAC1D,OAAO,EAAE,OAAO,CAAC,UAAU,CAAC;IAC5B,SAAS,EAAE,OAAO,CAAC,YAAY,CAAC,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;IACrD,OAAO,EAAE,OAAO,CAAC,SAAS,CAAC,CAAC,OAAO,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC;IACpD,SAAS,EAAE,SAAS,CAAC,YAAY,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,UAAU,EAAE;CAClF,CAAC,CAAC"}
@@ -94,6 +94,23 @@ export declare const profiles: import("drizzle-orm/pg-core").PgTableWithColumns<
94
94
  identity: undefined;
95
95
  generated: undefined;
96
96
  }, {}, {}>;
97
+ legacyUserId: import("drizzle-orm/pg-core").PgColumn<{
98
+ name: "legacy_user_id";
99
+ tableName: "profiles";
100
+ dataType: "string";
101
+ columnType: "PgText";
102
+ data: string;
103
+ driverParam: string;
104
+ notNull: false;
105
+ hasDefault: false;
106
+ isPrimaryKey: false;
107
+ isAutoincrement: false;
108
+ hasRuntimeDefault: false;
109
+ enumValues: [string, ...string[]];
110
+ baseColumn: never;
111
+ identity: undefined;
112
+ generated: undefined;
113
+ }, {}, {}>;
97
114
  createdAt: import("drizzle-orm/pg-core").PgColumn<{
98
115
  name: "created_at";
99
116
  tableName: "profiles";
@@ -1 +1 @@
1
- {"version":3,"file":"profiles.d.ts","sourceRoot":"","sources":["../../../src/pg/schema/profiles.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAUnB,CAAC"}
1
+ {"version":3,"file":"profiles.d.ts","sourceRoot":"","sources":["../../../src/pg/schema/profiles.ts"],"names":[],"mappings":"AAEA;;;;;;GAMG;AACH,eAAO,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAanB,CAAC"}
@@ -14,6 +14,9 @@ export const profiles = pgTable('profiles', {
14
14
  .notNull()
15
15
  .default('user'),
16
16
  personalAgentId: text('personal_agent_id'),
17
+ // Better Auth `user.id` (text) this profile was migrated from. Null for
18
+ // users created natively in Supabase. Lets Phase 2 remap legacy FKs.
19
+ legacyUserId: text('legacy_user_id'),
17
20
  createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),
18
21
  updatedAt: timestamp('updated_at', { withTimezone: true }).notNull().defaultNow(),
19
22
  });
@@ -1 +1 @@
1
- {"version":3,"file":"profiles.js","sourceRoot":"","sources":["../../../src/pg/schema/profiles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAErE;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,OAAO,CAAC,UAAU,EAAE;IAC1C,EAAE,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,EAAE,mBAAmB;IAChD,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE;IAC9B,WAAW,EAAE,IAAI,CAAC,cAAc,CAAC;IACjC,IAAI,EAAE,IAAI,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC;SAC5C,OAAO,EAAE;SACT,OAAO,CAAC,MAAM,CAAC;IAClB,eAAe,EAAE,IAAI,CAAC,mBAAmB,CAAC;IAC1C,SAAS,EAAE,SAAS,CAAC,YAAY,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,UAAU,EAAE;IACjF,SAAS,EAAE,SAAS,CAAC,YAAY,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,UAAU,EAAE;CAClF,CAAC,CAAC"}
1
+ {"version":3,"file":"profiles.js","sourceRoot":"","sources":["../../../src/pg/schema/profiles.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAErE;;;;;;GAMG;AACH,MAAM,CAAC,MAAM,QAAQ,GAAG,OAAO,CAAC,UAAU,EAAE;IAC1C,EAAE,EAAE,IAAI,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,EAAE,mBAAmB;IAChD,KAAK,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC,OAAO,EAAE;IAC9B,WAAW,EAAE,IAAI,CAAC,cAAc,CAAC;IACjC,IAAI,EAAE,IAAI,CAAC,MAAM,EAAE,EAAE,IAAI,EAAE,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,CAAC;SAC5C,OAAO,EAAE;SACT,OAAO,CAAC,MAAM,CAAC;IAClB,eAAe,EAAE,IAAI,CAAC,mBAAmB,CAAC;IAC1C,wEAAwE;IACxE,qEAAqE;IACrE,YAAY,EAAE,IAAI,CAAC,gBAAgB,CAAC;IACpC,SAAS,EAAE,SAAS,CAAC,YAAY,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,UAAU,EAAE;IACjF,SAAS,EAAE,SAAS,CAAC,YAAY,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE,CAAC,CAAC,OAAO,EAAE,CAAC,UAAU,EAAE;CAClF,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@minion-stack/db",
3
- "version": "0.3.0",
3
+ "version": "0.3.1",
4
4
  "description": "Drizzle ORM schema for the Minion shared database (LibSQL/Turso).",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -45,23 +45,24 @@
45
45
  "src",
46
46
  "README.md"
47
47
  ],
48
+ "scripts": {
49
+ "build": "tsc",
50
+ "prepublishOnly": "tsc",
51
+ "typecheck": "tsc --noEmit",
52
+ "lint": "oxlint src",
53
+ "db:pg:generate": "drizzle-kit generate --config=drizzle.pg.config.ts",
54
+ "test": "vitest run"
55
+ },
48
56
  "peerDependencies": {
49
57
  "drizzle-orm": ">=0.45.0"
50
58
  },
51
59
  "devDependencies": {
60
+ "@minion-stack/tsconfig": "workspace:*",
52
61
  "@paralleldrive/cuid2": "^3.3.0",
53
62
  "drizzle-kit": "^0.31.9",
54
63
  "drizzle-orm": "^0.45.1",
55
64
  "oxlint": "^1.66.0",
56
65
  "typescript": "^5.0.0",
57
- "vitest": "^2.1.9",
58
- "@minion-stack/tsconfig": "0.1.0"
59
- },
60
- "scripts": {
61
- "build": "tsc",
62
- "typecheck": "tsc --noEmit",
63
- "lint": "oxlint src",
64
- "db:pg:generate": "drizzle-kit generate --config=drizzle.pg.config.ts",
65
- "test": "vitest run"
66
+ "vitest": "^2.1.9"
66
67
  }
67
- }
68
+ }
@@ -0,0 +1,37 @@
1
+ import { pgTable, uuid, text, boolean, timestamp, primaryKey, index, uniqueIndex } from 'drizzle-orm/pg-core';
2
+ import { profiles } from './profiles.js';
3
+
4
+ /**
5
+ * Supabase-backed registry of Minion gateway servers.
6
+ * Mirrors Turso `servers`. legacy_server_id preserves the old Turso text PK
7
+ * so Turso log/event rows (which still carry the old id) can join here.
8
+ */
9
+ export const gateway = pgTable('gateway', {
10
+ id: uuid('id').primaryKey().defaultRandom(),
11
+ legacyServerId: text('legacy_server_id'),
12
+ name: text('name').notNull(),
13
+ url: text('url').notNull(),
14
+ tokenCiphertext: text('token_ciphertext').notNull().default(''),
15
+ tokenIv: text('token_iv').notNull().default(''),
16
+ authMode: text('auth_mode', { enum: ['token', 'none'] }).notNull().default('token'),
17
+ lastConnectedAt: timestamp('last_connected_at', { withTimezone: true }),
18
+ createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),
19
+ updatedAt: timestamp('updated_at', { withTimezone: true }).notNull().defaultNow(),
20
+ }, (t) => [
21
+ uniqueIndex('gateway_uniq_url').on(t.url),
22
+ index('idx_gateway_legacy').on(t.legacyServerId),
23
+ ]);
24
+
25
+ /**
26
+ * Per-user gateway link. Mirrors Turso `user_servers`.
27
+ * profile_id references profiles.id (== auth.users.id).
28
+ */
29
+ export const userGateway = pgTable('user_gateway', {
30
+ profileId: uuid('profile_id').notNull().references(() => profiles.id, { onDelete: 'cascade' }),
31
+ gatewayId: uuid('gateway_id').notNull().references(() => gateway.id, { onDelete: 'cascade' }),
32
+ isDefault: boolean('is_default').notNull().default(false),
33
+ createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),
34
+ }, (t) => [
35
+ primaryKey({ columns: [t.profileId, t.gatewayId] }),
36
+ index('idx_user_gateway_gateway').on(t.gatewayId),
37
+ ]);
@@ -1,5 +1,6 @@
1
1
  export { profiles } from './profiles.js';
2
2
  export { userIdentities } from './user-identities.js';
3
+ export { joinRequest, joinLink } from './join.js';
3
4
 
4
5
  // Identity helpers (consumed by minion_site auth path)
5
6
  export { mapGoogleIdentity } from '../identity-mapper.js';
@@ -10,3 +11,4 @@ export type {
10
11
  MappedIdentity,
11
12
  } from '../identity-mapper.js';
12
13
  export { sealSecret, openSecret } from '../crypto.js';
14
+ export { gateway, userGateway } from './gateway.js';
@@ -0,0 +1,38 @@
1
+ import { pgTable, uuid, text, integer, boolean, timestamp } from 'drizzle-orm/pg-core';
2
+
3
+ // Partial unique index (one open request per user/org) is created in the
4
+ // hand-written migration (Task 5), since the WHERE-predicate form isn't
5
+ // expressed cleanly here. Keep this table definition free of an index callback.
6
+ export const joinRequest = pgTable('join_request', {
7
+ id: uuid('id').primaryKey().defaultRandom(),
8
+ // GoTrue auth.users.id (== profiles.id). The requester's Supabase identity.
9
+ supabaseId: uuid('supabase_id').notNull(),
10
+ // Bridged hub id (profiles.legacy_user_id ?? supabaseId) — the value used as the
11
+ // Turso `member.user_id` key when the request is approved. Distinct from supabase_id.
12
+ userId: text('user_id').notNull(),
13
+ email: text('email').notNull(),
14
+ displayName: text('display_name'),
15
+ message: text('message'),
16
+ status: text('status', { enum: ['pending', 'approved', 'denied'] }).notNull().default('pending'),
17
+ // Turso organization id (cross-DB reference; orgs live in Turso, so no PG FK).
18
+ organizationId: text('organization_id').notNull(),
19
+ requestedRole: text('requested_role', { enum: ['user', 'admin', 'super_admin'] }).notNull().default('user'),
20
+ reviewedBy: text('reviewed_by'),
21
+ reviewedAt: timestamp('reviewed_at', { withTimezone: true }),
22
+ createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),
23
+ updatedAt: timestamp('updated_at', { withTimezone: true }).notNull().defaultNow(),
24
+ });
25
+
26
+ export const joinLink = pgTable('join_link', {
27
+ id: uuid('id').primaryKey().defaultRandom(),
28
+ token: text('token').notNull().unique(),
29
+ // Turso organization id (cross-DB reference; orgs live in Turso, so no PG FK).
30
+ organizationId: text('organization_id').notNull(),
31
+ role: text('role', { enum: ['user', 'admin', 'super_admin'] }).notNull(),
32
+ createdBy: text('created_by').notNull(),
33
+ expiresAt: timestamp('expires_at', { withTimezone: true }),
34
+ maxUses: integer('max_uses'),
35
+ usesCount: integer('uses_count').notNull().default(0),
36
+ revoked: boolean('revoked').notNull().default(false),
37
+ createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),
38
+ });
@@ -15,6 +15,9 @@ export const profiles = pgTable('profiles', {
15
15
  .notNull()
16
16
  .default('user'),
17
17
  personalAgentId: text('personal_agent_id'),
18
+ // Better Auth `user.id` (text) this profile was migrated from. Null for
19
+ // users created natively in Supabase. Lets Phase 2 remap legacy FKs.
20
+ legacyUserId: text('legacy_user_id'),
18
21
  createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),
19
22
  updatedAt: timestamp('updated_at', { withTimezone: true }).notNull().defaultNow(),
20
23
  });