feat(workspaces): add workspace slug support (#2982)

* feat(workspaces): add workspace slug support

* chore(workspaces): lint

* feat(workspaces): add slug validation and generation

* fix(workspaces): test lint miss
This commit is contained in:
Gergő Jedlicska
2024-09-18 13:29:36 +02:00
committed by GitHub
parent 56d392424d
commit 00c01db923
25 changed files with 518 additions and 82 deletions
@@ -22,6 +22,7 @@ export type WorkspaceInviteResourceTarget = InviteResourceTarget<
export type Workspace = {
id: string
name: string
slug: string
description: string | null
createdAt: Date
updatedAt: Date
@@ -0,0 +1,17 @@
import { Knex } from 'knex'
export async function up(knex: Knex): Promise<void> {
await knex.schema.alterTable('workspaces', (table) => {
table
.text('slug')
.notNullable()
.defaultTo(knex.raw('substring(md5(random()::text), 0, 15)')) // lets generate a random thing here to make it not nullable
.unique() // this also adds an index to the col
})
}
export async function down(knex: Knex): Promise<void> {
await knex.schema.alterTable('workspaces', (table) => {
table.dropColumn('slug')
})
}