feat(workspacesCore): initial module migration
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
import { Workspace } from '@/modules/workspaces/domain/types'
|
||||
|
||||
export const WorkspaceEvents = {
|
||||
Created: 'created'
|
||||
} as const
|
||||
|
||||
export type WorkspaceEvents = (typeof WorkspaceEvents)[keyof typeof WorkspaceEvents]
|
||||
|
||||
type WorkspaceCreatedPayload = Workspace & {
|
||||
createdByUserId: string
|
||||
}
|
||||
|
||||
export type WorkspaceEventsPayloads = {
|
||||
[WorkspaceEvents.Created]: WorkspaceCreatedPayload
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
import { Knex } from 'knex'
|
||||
|
||||
export async function up(knex: Knex): Promise<void> {
|
||||
await knex.schema.createTable('workspaces', (table) => {
|
||||
table.text('id').primary()
|
||||
table.text('name').notNullable()
|
||||
table.text('description')
|
||||
table.timestamp('createdAt', { precision: 3, useTz: true }).notNullable()
|
||||
table.timestamp('updatedAt', { precision: 3, useTz: true }).notNullable()
|
||||
table.text('createdByUserId').references('id').inTable('users').onDelete('set null')
|
||||
table.text('logoUrl')
|
||||
})
|
||||
await knex.schema.alterTable('streams', (table) => {
|
||||
table.string('workspaceId').references('id').inTable('workspaces')
|
||||
})
|
||||
await knex.schema.createTable('workspace_acl', (table) => {
|
||||
table.text('userId').references('id').inTable('users').onDelete('cascade')
|
||||
table.text('workspaceId').references('id').inTable('workspaces').onDelete('cascade')
|
||||
table.primary(['userId', 'workspaceId'])
|
||||
table
|
||||
.text('role')
|
||||
.references('name')
|
||||
.inTable('user_roles')
|
||||
.notNullable()
|
||||
.onDelete('cascade')
|
||||
})
|
||||
}
|
||||
|
||||
export async function down(knex: Knex): Promise<void> {
|
||||
await knex.schema.alterTable('streams', (table) => {
|
||||
table.dropColumn('workspaceId')
|
||||
})
|
||||
await knex.schema.dropTable('workspace_acl')
|
||||
await knex.schema.dropTable('workspaces')
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import { initializeModuleEventEmitter } from '@/modules/shared/services/moduleEventEmitterSetup'
|
||||
import {
|
||||
WorkspaceEvents,
|
||||
WorkspaceEventsPayloads
|
||||
} from '@/modules/workspacesCore/domain/events'
|
||||
|
||||
const { emit, listen } = initializeModuleEventEmitter<WorkspaceEventsPayloads>({
|
||||
moduleName: 'workspaces'
|
||||
})
|
||||
|
||||
export const WorkspacesEmitter = { emit, listen, events: WorkspaceEvents }
|
||||
Reference in New Issue
Block a user