diff --git a/packages/server/modules/gatekeeper/domain/billing.ts b/packages/server/modules/gatekeeper/domain/billing.ts index d76568051..eb19460a4 100644 --- a/packages/server/modules/gatekeeper/domain/billing.ts +++ b/packages/server/modules/gatekeeper/domain/billing.ts @@ -169,3 +169,13 @@ export type ReconcileSubscriptionData = (args: { subscriptionData: SubscriptionDataInput applyProrotation: boolean }) => Promise + +export type WorkspaceSeatType = 'viewer' | 'editor' + +export type WorkspaceSeat = { + workspaceId: string + userId: string + type: WorkspaceSeatType + createdAt: Date + updatedAt: Date +} diff --git a/packages/server/modules/gatekeeper/migrations/20250224141824_create_workspace_seats_table.ts b/packages/server/modules/gatekeeper/migrations/20250224141824_create_workspace_seats_table.ts new file mode 100644 index 000000000..4bef3681e --- /dev/null +++ b/packages/server/modules/gatekeeper/migrations/20250224141824_create_workspace_seats_table.ts @@ -0,0 +1,36 @@ +import { Knex } from 'knex' + +const WORKSPACE_SEATS_TABLE = 'workspace_seats' +const WORKSPACES_TABLE = 'workspaces' +const USERS_TABLE = 'users' + +export async function up(knex: Knex): Promise { + await knex.schema.createTable(WORKSPACE_SEATS_TABLE, (table) => { + table + .text('workspaceId') + .references('id') + .inTable(WORKSPACES_TABLE) + .onDelete('cascade') + .notNullable() + table + .text('userId') + .references('id') + .inTable(USERS_TABLE) + .onDelete('cascade') + .notNullable() + table.text('type').notNullable() + table + .timestamp('createdAt', { precision: 3, useTz: true }) + .defaultTo(knex.fn.now()) + .notNullable() + table + .timestamp('updatedAt', { precision: 3, useTz: true }) + .defaultTo(knex.fn.now()) + .notNullable() + table.primary(['workspaceId', 'userId']) + }) +} + +export async function down(knex: Knex): Promise { + await knex.schema.dropTable(WORKSPACE_SEATS_TABLE) +} diff --git a/packages/server/modules/gatekeeper/repositories/workspaceSeat.ts b/packages/server/modules/gatekeeper/repositories/workspaceSeat.ts new file mode 100644 index 000000000..e69de29bb