-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathworkspace.ts
More file actions
45 lines (43 loc) · 1.66 KB
/
Copy pathworkspace.ts
File metadata and controls
45 lines (43 loc) · 1.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { pgTable, text, timestamp, primaryKey, index } from 'drizzle-orm/pg-core';
/**
* Tenant root. Original Firestore path: namespaces/{handle}.
*
* "Workspace" is the canonical name per PLAN-0001 §1.2; the in-code type
* stays `Namespace` until the follow-up rename PR per PLAN-0001 §4.
* `handle` is the natural primary key (URL slug, today's doc-id).
*
* Members live in a separate table with a composite PK (workspace, uid).
* The standalone `uid` index replaces the Firestore collectionGroup query
* used today by `getUserNamespaces`.
*/
export const workspaces = pgTable('workspaces', {
handle: text('handle').primaryKey(),
type: text('type').notNull(),
displayName: text('display_name').notNull(),
avatarUrl: text('avatar_url'),
icon: text('icon'),
logo: text('logo'),
brandPrimaryColor: text('brand_primary_color'),
brandAccentColor: text('brand_accent_color'),
linkedUserId: text('linked_user_id'),
bio: text('bio'),
createdAt: timestamp('created_at', { withTimezone: true }).notNull().defaultNow(),
updatedAt: timestamp('updated_at', { withTimezone: true }).notNull().defaultNow(),
});
export const workspaceMembers = pgTable(
'workspace_members',
{
workspace: text('workspace')
.notNull()
.references(() => workspaces.handle, { onDelete: 'cascade' }),
uid: text('uid').notNull(),
role: text('role').notNull(),
displayName: text('display_name'),
avatarUrl: text('avatar_url'),
joinedAt: timestamp('joined_at', { withTimezone: true }).notNull().defaultNow(),
},
(table) => ({
pk: primaryKey({ columns: [table.workspace, table.uid] }),
uidIdx: index('workspace_members_uid_idx').on(table.uid),
}),
);