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:
@@ -22,6 +22,7 @@ export type WorkspaceInviteResourceTarget = InviteResourceTarget<
|
||||
export type Workspace = {
|
||||
id: string
|
||||
name: string
|
||||
slug: string
|
||||
description: string | null
|
||||
createdAt: Date
|
||||
updatedAt: Date
|
||||
|
||||
+17
@@ -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')
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user