From ca6f2da63f681d2c00f42ffcf0eecea3b0ef4119 Mon Sep 17 00:00:00 2001 From: Alessandro Magionami Date: Tue, 25 Feb 2025 10:22:08 +0100 Subject: [PATCH] chore(gatekeeper): add workspace_seats table and types --- .../modules/gatekeeper/domain/billing.ts | 10 ++++++ ...0224141824_create_workspace_seats_table.ts | 36 +++++++++++++++++++ .../gatekeeper/repositories/workspaceSeat.ts | 0 3 files changed, 46 insertions(+) create mode 100644 packages/server/modules/gatekeeper/migrations/20250224141824_create_workspace_seats_table.ts create mode 100644 packages/server/modules/gatekeeper/repositories/workspaceSeat.ts 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