feat: add organization membership data model
This commit is contained in:
@@ -3,9 +3,9 @@ import { idSchema, optionalText, requiredText } from './shared.schema';
|
||||
|
||||
const organizationDetailsSchema = z.object({
|
||||
name: requiredText('Organization name'),
|
||||
workspace: requiredText('Workspace', 120).default('Blueprint Workspace'),
|
||||
addressLine1: optionalText(160),
|
||||
addressLine1: requiredText('Address line 1'),
|
||||
addressLine2: optionalText(160),
|
||||
addressLine3: optionalText(160),
|
||||
city: optionalText(100),
|
||||
region: optionalText(100),
|
||||
postcode: optionalText(24),
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
import { index, sqliteTable, text, uniqueIndex } from 'drizzle-orm/sqlite-core';
|
||||
import { user } from './auth.schema';
|
||||
import { organizations } from './organizations.schema';
|
||||
import { timestamps } from './shared.schema';
|
||||
|
||||
export const organizationMemberships = sqliteTable(
|
||||
'organization_memberships',
|
||||
{
|
||||
id: text('id')
|
||||
.primaryKey()
|
||||
.$defaultFn(() => crypto.randomUUID()),
|
||||
organizationId: text('organization_id')
|
||||
.notNull()
|
||||
.references(() => organizations.id, { onDelete: 'cascade' }),
|
||||
userId: text('user_id')
|
||||
.notNull()
|
||||
.references(() => user.id, { onDelete: 'cascade' }),
|
||||
role: text('role').notNull().default('user'),
|
||||
...timestamps
|
||||
},
|
||||
(table) => [
|
||||
uniqueIndex('organization_memberships_organization_user_unique').on(
|
||||
table.organizationId,
|
||||
table.userId
|
||||
),
|
||||
index('organization_memberships_organization_id_idx').on(table.organizationId),
|
||||
index('organization_memberships_user_id_idx').on(table.userId)
|
||||
]
|
||||
);
|
||||
@@ -6,9 +6,9 @@ export const organizations = sqliteTable('organizations', {
|
||||
.primaryKey()
|
||||
.$defaultFn(() => crypto.randomUUID()),
|
||||
name: text('name').notNull(),
|
||||
workspace: text('workspace').notNull().default('Default Workspace'),
|
||||
addressLine1: text('address_line_1'),
|
||||
addressLine1: text('address_line_1').notNull().default(''),
|
||||
addressLine2: text('address_line_2'),
|
||||
addressLine3: text('address_line_3'),
|
||||
city: text('city'),
|
||||
region: text('region'),
|
||||
postcode: text('postcode'),
|
||||
|
||||
@@ -10,6 +10,7 @@ export const task = sqliteTable('task', {
|
||||
|
||||
export * from './clients.schema';
|
||||
export * from './organizations.schema';
|
||||
export * from './organization-memberships.schema';
|
||||
export * from './addresses.schema';
|
||||
export * from './contacts.schema';
|
||||
export * from './rooms.schema';
|
||||
|
||||
Reference in New Issue
Block a user