mirror of
https://github.com/Shadowfita/docmost.git
synced 2025-11-13 00:02:30 +10:00
* Fixes
* use lower case db column names * fix signup workspaceId
This commit is contained in:
@ -23,7 +23,7 @@
|
|||||||
"migration:down": "tsx ./src/kysely/migrate.ts down",
|
"migration:down": "tsx ./src/kysely/migrate.ts down",
|
||||||
"migration:latest": "tsx ./src/kysely/migrate.ts latest",
|
"migration:latest": "tsx ./src/kysely/migrate.ts latest",
|
||||||
"migration:redo": "tsx ./src/kysely/migrate.ts redo",
|
"migration:redo": "tsx ./src/kysely/migrate.ts redo",
|
||||||
"migration:codegen": "kysely-codegen --dialect=postgres --env-file=../../.env --out-file=./src/kysely/types/db.d.ts"
|
"migration:codegen": "kysely-codegen --dialect=postgres --camel-case --env-file=../../.env --out-file=./src/kysely/types/db.d.ts"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@aws-sdk/client-s3": "^3.540.0",
|
"@aws-sdk/client-s3": "^3.540.0",
|
||||||
|
|||||||
@ -39,7 +39,13 @@ export class SignupService {
|
|||||||
this.db,
|
this.db,
|
||||||
async (trx) => {
|
async (trx) => {
|
||||||
// create user
|
// create user
|
||||||
const user = await this.userRepo.insertUser(createUserDto, trx);
|
const user = await this.userRepo.insertUser(
|
||||||
|
{
|
||||||
|
...createUserDto,
|
||||||
|
workspaceId: workspaceId,
|
||||||
|
},
|
||||||
|
trx,
|
||||||
|
);
|
||||||
|
|
||||||
// add user to workspace
|
// add user to workspace
|
||||||
await this.workspaceService.addUserToWorkspace(
|
await this.workspaceService.addUserToWorkspace(
|
||||||
@ -88,7 +94,13 @@ export class SignupService {
|
|||||||
async (trx) => {
|
async (trx) => {
|
||||||
// create user
|
// create user
|
||||||
const user = await this.userRepo.insertUser(createAdminUserDto, trx);
|
const user = await this.userRepo.insertUser(createAdminUserDto, trx);
|
||||||
await this.createWorkspace(user, createAdminUserDto.workspaceName, trx);
|
const workspace = await this.createWorkspace(
|
||||||
|
user,
|
||||||
|
createAdminUserDto.workspaceName,
|
||||||
|
trx,
|
||||||
|
);
|
||||||
|
|
||||||
|
user.workspaceId = workspace.id;
|
||||||
return user;
|
return user;
|
||||||
},
|
},
|
||||||
trx,
|
trx,
|
||||||
|
|||||||
@ -64,7 +64,7 @@ export async function removeFromArrayAndSave(
|
|||||||
if (index > -1) {
|
if (index > -1) {
|
||||||
array.splice(index, 1);
|
array.splice(index, 1);
|
||||||
await trx
|
await trx
|
||||||
.updateTable('page_ordering')
|
.updateTable('pageOrdering')
|
||||||
.set(entity)
|
.set(entity)
|
||||||
.where('id', '=', entity.id)
|
.where('id', '=', entity.id)
|
||||||
.execute();
|
.execute();
|
||||||
|
|||||||
@ -62,7 +62,7 @@ export class PageOrderingService {
|
|||||||
// it should save or update right?
|
// it should save or update right?
|
||||||
// await manager.save(spaceOrdering); //TODO: to update or create new record? pretty confusing
|
// await manager.save(spaceOrdering); //TODO: to update or create new record? pretty confusing
|
||||||
await trx
|
await trx
|
||||||
.updateTable('page_ordering')
|
.updateTable('pageOrdering')
|
||||||
.set(spaceOrdering)
|
.set(spaceOrdering)
|
||||||
.where('id', '=', spaceOrdering.id)
|
.where('id', '=', spaceOrdering.id)
|
||||||
.execute();
|
.execute();
|
||||||
@ -109,7 +109,7 @@ export class PageOrderingService {
|
|||||||
// Modify the children list of the new parentPage and save
|
// Modify the children list of the new parentPage and save
|
||||||
orderPageList(parentPageOrdering.childrenIds, dto);
|
orderPageList(parentPageOrdering.childrenIds, dto);
|
||||||
await trx
|
await trx
|
||||||
.updateTable('page_ordering')
|
.updateTable('pageOrdering')
|
||||||
.set(parentPageOrdering)
|
.set(parentPageOrdering)
|
||||||
.where('id', '=', parentPageOrdering.id)
|
.where('id', '=', parentPageOrdering.id)
|
||||||
.execute();
|
.execute();
|
||||||
@ -238,7 +238,7 @@ export class PageOrderingService {
|
|||||||
if (!ordering.childrenIds.includes(childId)) {
|
if (!ordering.childrenIds.includes(childId)) {
|
||||||
ordering.childrenIds.unshift(childId);
|
ordering.childrenIds.unshift(childId);
|
||||||
await trx
|
await trx
|
||||||
.updateTable('page_ordering')
|
.updateTable('pageOrdering')
|
||||||
.set(ordering)
|
.set(ordering)
|
||||||
.where('id', '=', ordering.id)
|
.where('id', '=', ordering.id)
|
||||||
.execute();
|
.execute();
|
||||||
@ -252,7 +252,7 @@ export class PageOrderingService {
|
|||||||
trx: KyselyTransaction,
|
trx: KyselyTransaction,
|
||||||
): Promise<PageOrdering> {
|
): Promise<PageOrdering> {
|
||||||
return trx
|
return trx
|
||||||
.selectFrom('page_ordering')
|
.selectFrom('pageOrdering')
|
||||||
.selectAll()
|
.selectAll()
|
||||||
.where('entityId', '=', entityId)
|
.where('entityId', '=', entityId)
|
||||||
.where('entityType', '=', entityType)
|
.where('entityType', '=', entityType)
|
||||||
@ -267,7 +267,7 @@ export class PageOrderingService {
|
|||||||
trx: KyselyTransaction,
|
trx: KyselyTransaction,
|
||||||
): Promise<PageOrdering> {
|
): Promise<PageOrdering> {
|
||||||
await trx
|
await trx
|
||||||
.insertInto('page_ordering')
|
.insertInto('pageOrdering')
|
||||||
.values({
|
.values({
|
||||||
entityId,
|
entityId,
|
||||||
entityType,
|
entityType,
|
||||||
@ -285,7 +285,7 @@ export class PageOrderingService {
|
|||||||
spaceId: string,
|
spaceId: string,
|
||||||
): Promise<{ id: string; childrenIds: string[]; spaceId: string }> {
|
): Promise<{ id: string; childrenIds: string[]; spaceId: string }> {
|
||||||
return await this.db
|
return await this.db
|
||||||
.selectFrom('page_ordering')
|
.selectFrom('pageOrdering')
|
||||||
.select(['id', 'childrenIds', 'spaceId'])
|
.select(['id', 'childrenIds', 'spaceId'])
|
||||||
.where('entityId', '=', spaceId)
|
.where('entityId', '=', spaceId)
|
||||||
.where('entityType', '=', OrderingEntity.SPACE)
|
.where('entityType', '=', OrderingEntity.SPACE)
|
||||||
|
|||||||
@ -56,7 +56,6 @@ export class WorkspaceService {
|
|||||||
name: createWorkspaceDto.name,
|
name: createWorkspaceDto.name,
|
||||||
hostname: createWorkspaceDto.hostname,
|
hostname: createWorkspaceDto.hostname,
|
||||||
description: createWorkspaceDto.description,
|
description: createWorkspaceDto.description,
|
||||||
creatorId: user.id,
|
|
||||||
},
|
},
|
||||||
trx,
|
trx,
|
||||||
);
|
);
|
||||||
@ -77,9 +76,10 @@ export class WorkspaceService {
|
|||||||
})
|
})
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
// add user to default group
|
// add user to default group created above
|
||||||
await this.groupUserService.addUserToDefaultGroup(
|
await this.groupUserService.addUserToGroup(
|
||||||
user.id,
|
user.id,
|
||||||
|
group.id,
|
||||||
workspace.id,
|
workspace.id,
|
||||||
trx,
|
trx,
|
||||||
);
|
);
|
||||||
|
|||||||
@ -1,7 +1,7 @@
|
|||||||
import { Global, Module } from '@nestjs/common';
|
import { Global, Module } from '@nestjs/common';
|
||||||
import { KyselyModule } from 'nestjs-kysely';
|
import { KyselyModule } from 'nestjs-kysely';
|
||||||
import { EnvironmentService } from '../integrations/environment/environment.service';
|
import { EnvironmentService } from '../integrations/environment/environment.service';
|
||||||
import { LogEvent, PostgresDialect } from 'kysely';
|
import { CamelCasePlugin, LogEvent, PostgresDialect } from 'kysely';
|
||||||
import { Pool } from 'pg';
|
import { Pool } from 'pg';
|
||||||
import { GroupRepo } from '@docmost/db/repos/group/group.repo';
|
import { GroupRepo } from '@docmost/db/repos/group/group.repo';
|
||||||
import { WorkspaceRepo } from '@docmost/db/repos/workspace/workspace.repo';
|
import { WorkspaceRepo } from '@docmost/db/repos/workspace/workspace.repo';
|
||||||
@ -25,8 +25,9 @@ import { AttachmentRepo } from './repos/attachment/attachment.repo';
|
|||||||
dialect: new PostgresDialect({
|
dialect: new PostgresDialect({
|
||||||
pool: new Pool({
|
pool: new Pool({
|
||||||
connectionString: environmentService.getDatabaseURL(),
|
connectionString: environmentService.getDatabaseURL(),
|
||||||
}) as any,
|
}),
|
||||||
}),
|
}),
|
||||||
|
plugins: [new CamelCasePlugin()],
|
||||||
log: (event: LogEvent) => {
|
log: (event: LogEvent) => {
|
||||||
if (environmentService.getEnv() !== 'development') return;
|
if (environmentService.getEnv() !== 'development') return;
|
||||||
if (event.level === 'query') {
|
if (event.level === 'query') {
|
||||||
|
|||||||
@ -11,26 +11,27 @@ export async function up(db: Kysely<any>): Promise<void> {
|
|||||||
.addColumn('description', 'text', (col) => col)
|
.addColumn('description', 'text', (col) => col)
|
||||||
.addColumn('logo', 'varchar', (col) => col)
|
.addColumn('logo', 'varchar', (col) => col)
|
||||||
.addColumn('hostname', 'varchar', (col) => col)
|
.addColumn('hostname', 'varchar', (col) => col)
|
||||||
.addColumn('customDomain', 'varchar', (col) => col)
|
.addColumn('custom_domain', 'varchar', (col) => col)
|
||||||
.addColumn('enableInvite', 'boolean', (col) =>
|
.addColumn('enable_invite', 'boolean', (col) =>
|
||||||
col.defaultTo(true).notNull(),
|
col.defaultTo(true).notNull(),
|
||||||
)
|
)
|
||||||
.addColumn('inviteCode', 'varchar', (col) => col)
|
.addColumn('invite_code', 'varchar', (col) =>
|
||||||
|
col.defaultTo(sql`gen_random_uuid()`),
|
||||||
|
)
|
||||||
.addColumn('settings', 'jsonb', (col) => col)
|
.addColumn('settings', 'jsonb', (col) => col)
|
||||||
.addColumn('defaultRole', 'varchar', (col) =>
|
.addColumn('default_role', 'varchar', (col) =>
|
||||||
col.defaultTo(UserRole.MEMBER).notNull(),
|
col.defaultTo(UserRole.MEMBER).notNull(),
|
||||||
)
|
)
|
||||||
.addColumn('creatorId', 'uuid', (col) => col)
|
.addColumn('default_space_id', 'uuid', (col) => col)
|
||||||
.addColumn('defaultSpaceId', 'uuid', (col) => col)
|
.addColumn('created_at', 'timestamptz', (col) =>
|
||||||
.addColumn('createdAt', 'timestamp', (col) =>
|
|
||||||
col.notNull().defaultTo(sql`now()`),
|
col.notNull().defaultTo(sql`now()`),
|
||||||
)
|
)
|
||||||
.addColumn('updatedAt', 'timestamp', (col) =>
|
.addColumn('updated_at', 'timestamptz', (col) =>
|
||||||
col.notNull().defaultTo(sql`now()`),
|
col.notNull().defaultTo(sql`now()`),
|
||||||
)
|
)
|
||||||
.addColumn('deletedAt', 'timestamp', (col) => col)
|
.addColumn('deleted_at', 'timestamptz', (col) => col)
|
||||||
.addUniqueConstraint('workspaces_hostname_unique', ['hostname'])
|
.addUniqueConstraint('workspaces_hostname_unique', ['hostname'])
|
||||||
.addUniqueConstraint('workspaces_inviteCode_unique', ['inviteCode'])
|
.addUniqueConstraint('workspaces_invite_code_unique', ['invite_code'])
|
||||||
.execute();
|
.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -8,38 +8,32 @@ export async function up(db: Kysely<any>): Promise<void> {
|
|||||||
)
|
)
|
||||||
.addColumn('name', 'varchar', (col) => col)
|
.addColumn('name', 'varchar', (col) => col)
|
||||||
.addColumn('email', 'varchar', (col) => col.notNull())
|
.addColumn('email', 'varchar', (col) => col.notNull())
|
||||||
.addColumn('emailVerifiedAt', 'timestamp', (col) => col)
|
.addColumn('email_verified_at', 'timestamptz', (col) => col)
|
||||||
.addColumn('password', 'varchar', (col) => col.notNull())
|
.addColumn('password', 'varchar', (col) => col.notNull())
|
||||||
.addColumn('avatarUrl', 'varchar', (col) => col)
|
.addColumn('avatar_url', 'varchar', (col) => col)
|
||||||
.addColumn('role', 'varchar', (col) => col)
|
.addColumn('role', 'varchar', (col) => col)
|
||||||
.addColumn('status', 'varchar', (col) => col)
|
.addColumn('status', 'varchar', (col) => col)
|
||||||
.addColumn('workspaceId', 'uuid', (col) =>
|
.addColumn('workspace_id', 'uuid', (col) =>
|
||||||
col.references('workspaces.id').onDelete('cascade'),
|
col.references('workspaces.id').onDelete('cascade'),
|
||||||
)
|
)
|
||||||
.addColumn('locale', 'varchar', (col) => col)
|
.addColumn('locale', 'varchar', (col) => col)
|
||||||
.addColumn('timezone', 'varchar', (col) => col)
|
.addColumn('timezone', 'varchar', (col) => col)
|
||||||
.addColumn('settings', 'jsonb', (col) => col)
|
.addColumn('settings', 'jsonb', (col) => col)
|
||||||
.addColumn('lastActiveAt', 'timestamp', (col) => col)
|
.addColumn('last_active_at', 'timestamptz', (col) => col)
|
||||||
.addColumn('lastLoginAt', 'timestamp', (col) => col)
|
.addColumn('last_login_at', 'timestamptz', (col) => col)
|
||||||
.addColumn('lastLoginIp', 'varchar', (col) => col)
|
.addColumn('created_at', 'timestamptz', (col) =>
|
||||||
.addColumn('createdAt', 'timestamp', (col) =>
|
|
||||||
col.notNull().defaultTo(sql`now()`),
|
col.notNull().defaultTo(sql`now()`),
|
||||||
)
|
)
|
||||||
.addColumn('updatedAt', 'timestamp', (col) =>
|
.addColumn('updated_at', 'timestamptz', (col) =>
|
||||||
col.notNull().defaultTo(sql`now()`),
|
col.notNull().defaultTo(sql`now()`),
|
||||||
)
|
)
|
||||||
.addUniqueConstraint('users_email_workspaceId_unique', [
|
.addUniqueConstraint('users_email_workspace_id_unique', [
|
||||||
'email',
|
'email',
|
||||||
'workspaceId',
|
'workspace_id',
|
||||||
])
|
])
|
||||||
.execute();
|
.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function down(db: Kysely<any>): Promise<void> {
|
export async function down(db: Kysely<any>): Promise<void> {
|
||||||
await db.schema
|
|
||||||
.alterTable('users')
|
|
||||||
.dropConstraint('users_workspaceId_fkey')
|
|
||||||
.execute();
|
|
||||||
|
|
||||||
await db.schema.dropTable('users').execute();
|
await db.schema.dropTable('users').execute();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,35 +8,49 @@ export async function up(db: Kysely<any>): Promise<void> {
|
|||||||
)
|
)
|
||||||
.addColumn('name', 'varchar', (col) => col.notNull())
|
.addColumn('name', 'varchar', (col) => col.notNull())
|
||||||
.addColumn('description', 'text', (col) => col)
|
.addColumn('description', 'text', (col) => col)
|
||||||
.addColumn('isDefault', 'boolean', (col) => col.notNull())
|
.addColumn('is_default', 'boolean', (col) => col.notNull())
|
||||||
.addColumn('workspaceId', 'uuid', (col) =>
|
.addColumn('workspace_id', 'uuid', (col) =>
|
||||||
col.references('workspaces.id').onDelete('cascade').notNull(),
|
col.references('workspaces.id').onDelete('cascade').notNull(),
|
||||||
)
|
)
|
||||||
.addColumn('creatorId', 'uuid', (col) => col.references('users.id'))
|
.addColumn('creator_id', 'uuid', (col) => col.references('users.id'))
|
||||||
.addColumn('createdAt', 'timestamp', (col) =>
|
.addColumn('created_at', 'timestamptz', (col) =>
|
||||||
col.notNull().defaultTo(sql`now()`),
|
col.notNull().defaultTo(sql`now()`),
|
||||||
)
|
)
|
||||||
.addColumn('updatedAt', 'timestamp', (col) =>
|
.addColumn('updated_at', 'timestamptz', (col) =>
|
||||||
col.notNull().defaultTo(sql`now()`),
|
col.notNull().defaultTo(sql`now()`),
|
||||||
)
|
)
|
||||||
.addUniqueConstraint('groups_name_workspaceId_unique', [
|
.addUniqueConstraint('groups_name_workspace_id_unique', [
|
||||||
'name',
|
'name',
|
||||||
'workspaceId',
|
'workspace_id',
|
||||||
])
|
])
|
||||||
|
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
|
await db.schema
|
||||||
|
.createTable('group_users')
|
||||||
|
.addColumn('id', 'uuid', (col) =>
|
||||||
|
col.primaryKey().defaultTo(sql`gen_random_uuid()`),
|
||||||
|
)
|
||||||
|
.addColumn('user_id', 'uuid', (col) =>
|
||||||
|
col.references('users.id').onDelete('cascade').notNull(),
|
||||||
|
)
|
||||||
|
.addColumn('group_id', 'uuid', (col) =>
|
||||||
|
col.references('groups.id').onDelete('cascade').notNull(),
|
||||||
|
)
|
||||||
|
.addColumn('created_at', 'timestamptz', (col) =>
|
||||||
|
col.notNull().defaultTo(sql`now()`),
|
||||||
|
)
|
||||||
|
.addColumn('updated_at', 'timestamptz', (col) =>
|
||||||
|
col.notNull().defaultTo(sql`now()`),
|
||||||
|
)
|
||||||
|
.addUniqueConstraint('group_users_group_id_user_id_unique', [
|
||||||
|
'group_id',
|
||||||
|
'user_id',
|
||||||
|
])
|
||||||
|
.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function down(db: Kysely<any>): Promise<void> {
|
export async function down(db: Kysely<any>): Promise<void> {
|
||||||
await db.schema
|
await db.schema.dropTable('group_users').execute();
|
||||||
.alterTable('groups')
|
|
||||||
.dropConstraint('groups_workspaceId_fkey')
|
|
||||||
.execute();
|
|
||||||
|
|
||||||
await db.schema
|
|
||||||
.alterTable('groups')
|
|
||||||
.dropConstraint('groups_creatorId_fkey')
|
|
||||||
.execute();
|
|
||||||
|
|
||||||
await db.schema.dropTable('groups').execute();
|
await db.schema.dropTable('groups').execute();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,40 +0,0 @@
|
|||||||
import { Kysely, sql } from 'kysely';
|
|
||||||
|
|
||||||
export async function up(db: Kysely<any>): Promise<void> {
|
|
||||||
await db.schema
|
|
||||||
.createTable('group_users')
|
|
||||||
.addColumn('id', 'uuid', (col) =>
|
|
||||||
col.primaryKey().defaultTo(sql`gen_random_uuid()`),
|
|
||||||
)
|
|
||||||
.addColumn('userId', 'uuid', (col) =>
|
|
||||||
col.references('users.id').onDelete('cascade').notNull(),
|
|
||||||
)
|
|
||||||
.addColumn('groupId', 'uuid', (col) =>
|
|
||||||
col.references('groups.id').onDelete('cascade').notNull(),
|
|
||||||
)
|
|
||||||
.addColumn('createdAt', 'timestamp', (col) =>
|
|
||||||
col.notNull().defaultTo(sql`now()`),
|
|
||||||
)
|
|
||||||
.addColumn('updatedAt', 'timestamp', (col) =>
|
|
||||||
col.notNull().defaultTo(sql`now()`),
|
|
||||||
)
|
|
||||||
.addUniqueConstraint('group_users_groupId_userId_unique', [
|
|
||||||
'groupId',
|
|
||||||
'userId',
|
|
||||||
])
|
|
||||||
.execute();
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function down(db: Kysely<any>): Promise<void> {
|
|
||||||
await db.schema
|
|
||||||
.alterTable('group_users')
|
|
||||||
.dropConstraint('group_users_userId_fkey')
|
|
||||||
.execute();
|
|
||||||
|
|
||||||
await db.schema
|
|
||||||
.alterTable('group_users')
|
|
||||||
.dropConstraint('group_users_groupId_fkey')
|
|
||||||
.execute();
|
|
||||||
|
|
||||||
await db.schema.dropTable('group_users').execute();
|
|
||||||
}
|
|
||||||
@ -14,36 +14,64 @@ export async function up(db: Kysely<any>): Promise<void> {
|
|||||||
.addColumn('visibility', 'varchar', (col) =>
|
.addColumn('visibility', 'varchar', (col) =>
|
||||||
col.defaultTo(SpaceVisibility.OPEN).notNull(),
|
col.defaultTo(SpaceVisibility.OPEN).notNull(),
|
||||||
)
|
)
|
||||||
.addColumn('defaultRole', 'varchar', (col) =>
|
.addColumn('default_role', 'varchar', (col) =>
|
||||||
col.defaultTo(SpaceRole.WRITER).notNull(),
|
col.defaultTo(SpaceRole.WRITER).notNull(),
|
||||||
)
|
)
|
||||||
.addColumn('creatorId', 'uuid', (col) => col.references('users.id'))
|
.addColumn('creator_id', 'uuid', (col) => col.references('users.id'))
|
||||||
.addColumn('workspaceId', 'uuid', (col) =>
|
.addColumn('workspace_id', 'uuid', (col) =>
|
||||||
col.references('workspaces.id').onDelete('cascade').notNull(),
|
col.references('workspaces.id').onDelete('cascade').notNull(),
|
||||||
)
|
)
|
||||||
.addColumn('createdAt', 'timestamp', (col) =>
|
.addColumn('created_at', 'timestamptz', (col) =>
|
||||||
col.notNull().defaultTo(sql`now()`),
|
col.notNull().defaultTo(sql`now()`),
|
||||||
)
|
)
|
||||||
.addColumn('updatedAt', 'timestamp', (col) =>
|
.addColumn('updated_at', 'timestamptz', (col) =>
|
||||||
col.notNull().defaultTo(sql`now()`),
|
col.notNull().defaultTo(sql`now()`),
|
||||||
)
|
)
|
||||||
.addUniqueConstraint('spaces_slug_workspaceId_unique', [
|
.addColumn('deleted_at', 'timestamptz', (col) => col)
|
||||||
|
.addUniqueConstraint('spaces_slug_workspace_id_unique', [
|
||||||
'slug',
|
'slug',
|
||||||
'workspaceId',
|
'workspace_id',
|
||||||
])
|
])
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
|
await db.schema
|
||||||
|
.createTable('space_members')
|
||||||
|
.addColumn('id', 'uuid', (col) =>
|
||||||
|
col.primaryKey().defaultTo(sql`gen_random_uuid()`),
|
||||||
|
)
|
||||||
|
.addColumn('user_id', 'uuid', (col) =>
|
||||||
|
col.references('users.id').onDelete('cascade'),
|
||||||
|
)
|
||||||
|
.addColumn('group_id', 'uuid', (col) =>
|
||||||
|
col.references('groups.id').onDelete('cascade'),
|
||||||
|
)
|
||||||
|
.addColumn('space_id', 'uuid', (col) =>
|
||||||
|
col.references('spaces.id').onDelete('cascade').notNull(),
|
||||||
|
)
|
||||||
|
.addColumn('role', 'varchar', (col) => col.notNull())
|
||||||
|
.addColumn('creator_id', 'uuid', (col) => col.references('users.id'))
|
||||||
|
.addColumn('created_at', 'timestamptz', (col) =>
|
||||||
|
col.notNull().defaultTo(sql`now()`),
|
||||||
|
)
|
||||||
|
.addColumn('updated_at', 'timestamptz', (col) =>
|
||||||
|
col.notNull().defaultTo(sql`now()`),
|
||||||
|
)
|
||||||
|
.addUniqueConstraint('space_members_space_id_user_id_unique', [
|
||||||
|
'space_id',
|
||||||
|
'user_id',
|
||||||
|
])
|
||||||
|
.addUniqueConstraint('space_members_space_id_group_id_unique', [
|
||||||
|
'space_id',
|
||||||
|
'group_id',
|
||||||
|
])
|
||||||
|
.addCheckConstraint(
|
||||||
|
'allow_either_user_id_or_group_id_check',
|
||||||
|
sql`(("user_id" IS NOT NULL AND "group_id" IS NULL) OR ("user_id" IS NULL AND "group_id" IS NOT NULL))`,
|
||||||
|
)
|
||||||
|
.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function down(db: Kysely<any>): Promise<void> {
|
export async function down(db: Kysely<any>): Promise<void> {
|
||||||
await db.schema
|
await db.schema.dropTable('space_members').execute();
|
||||||
.alterTable('spaces')
|
|
||||||
.dropConstraint('spaces_creatorId_fkey')
|
|
||||||
.execute();
|
|
||||||
|
|
||||||
await db.schema
|
|
||||||
.alterTable('spaces')
|
|
||||||
.dropConstraint('spaces_workspaceId_fkey')
|
|
||||||
.execute();
|
|
||||||
|
|
||||||
await db.schema.dropTable('spaces').execute();
|
await db.schema.dropTable('spaces').execute();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,62 +0,0 @@
|
|||||||
import { Kysely, sql } from 'kysely';
|
|
||||||
|
|
||||||
export async function up(db: Kysely<any>): Promise<void> {
|
|
||||||
await db.schema
|
|
||||||
.createTable('space_members')
|
|
||||||
.addColumn('id', 'uuid', (col) =>
|
|
||||||
col.primaryKey().defaultTo(sql`gen_random_uuid()`),
|
|
||||||
)
|
|
||||||
.addColumn('userId', 'uuid', (col) =>
|
|
||||||
col.references('users.id').onDelete('cascade'),
|
|
||||||
)
|
|
||||||
.addColumn('groupId', 'uuid', (col) =>
|
|
||||||
col.references('groups.id').onDelete('cascade'),
|
|
||||||
)
|
|
||||||
.addColumn('spaceId', 'uuid', (col) =>
|
|
||||||
col.references('spaces.id').onDelete('cascade').notNull(),
|
|
||||||
)
|
|
||||||
.addColumn('role', 'varchar', (col) => col.notNull())
|
|
||||||
.addColumn('creatorId', 'uuid', (col) => col.references('users.id'))
|
|
||||||
.addColumn('createdAt', 'timestamp', (col) =>
|
|
||||||
col.notNull().defaultTo(sql`now()`),
|
|
||||||
)
|
|
||||||
.addColumn('updatedAt', 'timestamp', (col) =>
|
|
||||||
col.notNull().defaultTo(sql`now()`),
|
|
||||||
)
|
|
||||||
.addUniqueConstraint('space_members_spaceId_userId_unique', [
|
|
||||||
'spaceId',
|
|
||||||
'userId',
|
|
||||||
])
|
|
||||||
.addUniqueConstraint('space_members_spaceId_groupId_unique', [
|
|
||||||
'spaceId',
|
|
||||||
'groupId',
|
|
||||||
])
|
|
||||||
.addCheckConstraint(
|
|
||||||
'allow_either_userId_or_groupId_check',
|
|
||||||
sql`(("userId" IS NOT NULL AND "groupId" IS NULL) OR ("userId" IS NULL AND "groupId" IS NOT NULL))`,
|
|
||||||
)
|
|
||||||
.execute();
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function down(db: Kysely<any>): Promise<void> {
|
|
||||||
await db.schema
|
|
||||||
.alterTable('space_members')
|
|
||||||
.dropConstraint('space_members_userId_fkey')
|
|
||||||
.execute();
|
|
||||||
|
|
||||||
await db.schema
|
|
||||||
.alterTable('space_members')
|
|
||||||
.dropConstraint('space_members_groupId_fkey')
|
|
||||||
.execute();
|
|
||||||
|
|
||||||
await db.schema
|
|
||||||
.alterTable('space_members')
|
|
||||||
.dropConstraint('space_members_spaceId_fkey')
|
|
||||||
.execute();
|
|
||||||
|
|
||||||
await db.schema
|
|
||||||
.alterTable('space_members')
|
|
||||||
.dropConstraint('space_members_creatorId_fkey')
|
|
||||||
.execute();
|
|
||||||
await db.schema.dropTable('space_members').execute();
|
|
||||||
}
|
|
||||||
@ -4,18 +4,8 @@ export async function up(db: Kysely<any>): Promise<void> {
|
|||||||
await db.schema
|
await db.schema
|
||||||
.alterTable('workspaces')
|
.alterTable('workspaces')
|
||||||
.addForeignKeyConstraint(
|
.addForeignKeyConstraint(
|
||||||
'workspaces_creatorId_fkey',
|
'workspaces_default_space_id_fkey',
|
||||||
['creatorId'],
|
['default_space_id'],
|
||||||
'users',
|
|
||||||
['id'],
|
|
||||||
)
|
|
||||||
.execute();
|
|
||||||
|
|
||||||
await db.schema
|
|
||||||
.alterTable('workspaces')
|
|
||||||
.addForeignKeyConstraint(
|
|
||||||
'workspaces_defaultSpaceId_fkey',
|
|
||||||
['defaultSpaceId'],
|
|
||||||
'spaces',
|
'spaces',
|
||||||
['id'],
|
['id'],
|
||||||
)
|
)
|
||||||
@ -26,11 +16,6 @@ export async function up(db: Kysely<any>): Promise<void> {
|
|||||||
export async function down(db: Kysely<any>): Promise<void> {
|
export async function down(db: Kysely<any>): Promise<void> {
|
||||||
await db.schema
|
await db.schema
|
||||||
.alterTable('workspaces')
|
.alterTable('workspaces')
|
||||||
.dropConstraint('workspaces_creatorId_fkey')
|
.dropConstraint('workspaces_default_space_id_fkey')
|
||||||
.execute();
|
|
||||||
|
|
||||||
await db.schema
|
|
||||||
.alterTable('workspaces')
|
|
||||||
.dropConstraint('workspaces_defaultSpaceId_fkey')
|
|
||||||
.execute();
|
.execute();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,31 +6,22 @@ export async function up(db: Kysely<any>): Promise<void> {
|
|||||||
.addColumn('id', 'uuid', (col) =>
|
.addColumn('id', 'uuid', (col) =>
|
||||||
col.primaryKey().defaultTo(sql`gen_random_uuid()`),
|
col.primaryKey().defaultTo(sql`gen_random_uuid()`),
|
||||||
)
|
)
|
||||||
.addColumn('workspaceId', 'uuid', (col) =>
|
.addColumn('workspace_id', 'uuid', (col) =>
|
||||||
col.references('workspaces.id').onDelete('cascade').notNull(),
|
col.references('workspaces.id').onDelete('cascade').notNull(),
|
||||||
)
|
)
|
||||||
.addColumn('invitedById', 'uuid', (col) => col.references('users.id'))
|
.addColumn('invited_by_id', 'uuid', (col) => col.references('users.id'))
|
||||||
.addColumn('email', 'varchar', (col) => col.notNull())
|
.addColumn('email', 'varchar', (col) => col.notNull())
|
||||||
.addColumn('role', 'varchar', (col) => col.notNull())
|
.addColumn('role', 'varchar', (col) => col.notNull())
|
||||||
.addColumn('status', 'varchar', (col) => col)
|
.addColumn('status', 'varchar', (col) => col)
|
||||||
.addColumn('createdAt', 'timestamp', (col) =>
|
.addColumn('created_at', 'timestamptz', (col) =>
|
||||||
col.notNull().defaultTo(sql`now()`),
|
col.notNull().defaultTo(sql`now()`),
|
||||||
)
|
)
|
||||||
.addColumn('updatedAt', 'timestamp', (col) =>
|
.addColumn('updated_at', 'timestamptz', (col) =>
|
||||||
col.notNull().defaultTo(sql`now()`),
|
col.notNull().defaultTo(sql`now()`),
|
||||||
)
|
)
|
||||||
.execute();
|
.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function down(db: Kysely<any>): Promise<void> {
|
export async function down(db: Kysely<any>): Promise<void> {
|
||||||
await db.schema
|
|
||||||
.alterTable('workspace_invitations')
|
|
||||||
.dropConstraint('workspace_invitations_workspaceId_fkey')
|
|
||||||
.execute();
|
|
||||||
|
|
||||||
await db.schema
|
|
||||||
.alterTable('workspace_invitations')
|
|
||||||
.dropConstraint('workspace_invitations_invitedById_fkey')
|
|
||||||
.execute();
|
|
||||||
await db.schema.dropTable('workspace_invitations').execute();
|
await db.schema.dropTable('workspace_invitations').execute();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,37 +8,39 @@ export async function up(db: Kysely<any>): Promise<void> {
|
|||||||
)
|
)
|
||||||
.addColumn('title', 'varchar', (col) => col)
|
.addColumn('title', 'varchar', (col) => col)
|
||||||
.addColumn('icon', 'varchar', (col) => col)
|
.addColumn('icon', 'varchar', (col) => col)
|
||||||
|
.addColumn('key', 'varchar', (col) => col)
|
||||||
.addColumn('content', 'jsonb', (col) => col)
|
.addColumn('content', 'jsonb', (col) => col)
|
||||||
.addColumn('html', 'text', (col) => col)
|
.addColumn('html', 'text', (col) => col)
|
||||||
.addColumn('textContent', 'text', (col) => col)
|
.addColumn('text_content', 'text', (col) => col)
|
||||||
.addColumn('tsv', sql`tsvector`, (col) => col)
|
.addColumn('tsv', sql`tsvector`, (col) => col)
|
||||||
.addColumn('ydoc', 'bytea', (col) => col)
|
.addColumn('ydoc', 'bytea', (col) => col)
|
||||||
.addColumn('slug', 'varchar', (col) => col)
|
.addColumn('slug', 'varchar', (col) => col)
|
||||||
.addColumn('coverPhoto', 'varchar', (col) => col)
|
.addColumn('cover_photo', 'varchar', (col) => col)
|
||||||
.addColumn('editor', 'varchar', (col) => col)
|
.addColumn('editor', 'varchar', (col) => col)
|
||||||
.addColumn('shareId', 'varchar', (col) => col)
|
.addColumn('parent_page_id', 'uuid', (col) =>
|
||||||
.addColumn('parentPageId', 'uuid', (col) =>
|
|
||||||
col.references('pages.id').onDelete('cascade'),
|
col.references('pages.id').onDelete('cascade'),
|
||||||
)
|
)
|
||||||
.addColumn('creatorId', 'uuid', (col) => col.references('users.id'))
|
.addColumn('creator_id', 'uuid', (col) => col.references('users.id'))
|
||||||
.addColumn('lastUpdatedById', 'uuid', (col) => col.references('users.id'))
|
.addColumn('last_updated_by_id', 'uuid', (col) =>
|
||||||
.addColumn('deletedById', 'uuid', (col) => col.references('users.id'))
|
col.references('users.id'),
|
||||||
.addColumn('spaceId', 'uuid', (col) =>
|
)
|
||||||
|
.addColumn('deleted_by_id', 'uuid', (col) => col.references('users.id'))
|
||||||
|
.addColumn('space_id', 'uuid', (col) =>
|
||||||
col.references('spaces.id').onDelete('cascade').notNull(),
|
col.references('spaces.id').onDelete('cascade').notNull(),
|
||||||
)
|
)
|
||||||
.addColumn('workspaceId', 'uuid', (col) =>
|
.addColumn('workspace_id', 'uuid', (col) =>
|
||||||
col.references('workspaces.id').onDelete('cascade').notNull(),
|
col.references('workspaces.id').onDelete('cascade').notNull(),
|
||||||
)
|
)
|
||||||
.addColumn('isLocked', 'boolean', (col) => col.defaultTo(false).notNull())
|
.addColumn('is_locked', 'boolean', (col) => col.defaultTo(false).notNull())
|
||||||
.addColumn('status', 'varchar', (col) => col)
|
.addColumn('status', 'varchar', (col) => col)
|
||||||
.addColumn('publishedAt', 'date', (col) => col)
|
.addColumn('published_at', 'date', (col) => col)
|
||||||
.addColumn('createdAt', 'timestamp', (col) =>
|
.addColumn('created_at', 'timestamptz', (col) =>
|
||||||
col.notNull().defaultTo(sql`now()`),
|
col.notNull().defaultTo(sql`now()`),
|
||||||
)
|
)
|
||||||
.addColumn('updatedAt', 'timestamp', (col) =>
|
.addColumn('updated_at', 'timestamptz', (col) =>
|
||||||
col.notNull().defaultTo(sql`now()`),
|
col.notNull().defaultTo(sql`now()`),
|
||||||
)
|
)
|
||||||
.addColumn('deletedAt', 'timestamp', (col) => col)
|
.addColumn('deleted_at', 'timestamptz', (col) => col)
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
await db.schema
|
await db.schema
|
||||||
@ -52,32 +54,32 @@ export async function up(db: Kysely<any>): Promise<void> {
|
|||||||
export async function down(db: Kysely<any>): Promise<void> {
|
export async function down(db: Kysely<any>): Promise<void> {
|
||||||
await db.schema
|
await db.schema
|
||||||
.alterTable('pages')
|
.alterTable('pages')
|
||||||
.dropConstraint('pages_creatorId_fkey')
|
.dropConstraint('pages_creator_id_fkey')
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
await db.schema
|
await db.schema
|
||||||
.alterTable('pages')
|
.alterTable('pages')
|
||||||
.dropConstraint('pages_lastUpdatedById_fkey')
|
.dropConstraint('pages_last_updated_by_id_fkey')
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
await db.schema
|
await db.schema
|
||||||
.alterTable('pages')
|
.alterTable('pages')
|
||||||
.dropConstraint('pages_deletedById_fkey')
|
.dropConstraint('pages_deleted_by_id_fkey')
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
await db.schema
|
await db.schema
|
||||||
.alterTable('pages')
|
.alterTable('pages')
|
||||||
.dropConstraint('pages_spaceId_fkey')
|
.dropConstraint('pages_space_id_fkey')
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
await db.schema
|
await db.schema
|
||||||
.alterTable('pages')
|
.alterTable('pages')
|
||||||
.dropConstraint('pages_workspaceId_fkey')
|
.dropConstraint('pages_workspace_id_fkey')
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
await db.schema
|
await db.schema
|
||||||
.alterTable('pages')
|
.alterTable('pages')
|
||||||
.dropConstraint('pages_parentPageId_fkey')
|
.dropConstraint('pages_parent_page_id_fkey')
|
||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
await db.schema.dropTable('pages').execute();
|
await db.schema.dropTable('pages').execute();
|
||||||
|
|||||||
@ -6,51 +6,33 @@ export async function up(db: Kysely<any>): Promise<void> {
|
|||||||
.addColumn('id', 'uuid', (col) =>
|
.addColumn('id', 'uuid', (col) =>
|
||||||
col.primaryKey().defaultTo(sql`gen_random_uuid()`),
|
col.primaryKey().defaultTo(sql`gen_random_uuid()`),
|
||||||
)
|
)
|
||||||
.addColumn('pageId', 'uuid', (col) =>
|
.addColumn('page_id', 'uuid', (col) =>
|
||||||
col.references('pages.id').onDelete('cascade').notNull(),
|
col.references('pages.id').onDelete('cascade').notNull(),
|
||||||
)
|
)
|
||||||
.addColumn('title', 'varchar', (col) => col)
|
.addColumn('title', 'varchar', (col) => col)
|
||||||
.addColumn('content', 'jsonb', (col) => col)
|
.addColumn('content', 'jsonb', (col) => col)
|
||||||
.addColumn('slug', 'varchar', (col) => col)
|
.addColumn('slug', 'varchar', (col) => col)
|
||||||
.addColumn('icon', 'varchar', (col) => col)
|
.addColumn('icon', 'varchar', (col) => col)
|
||||||
.addColumn('coverPhoto', 'varchar', (col) => col)
|
.addColumn('cover_photo', 'varchar', (col) => col)
|
||||||
.addColumn('version', 'int4', (col) => col.notNull())
|
.addColumn('version', 'int4', (col) => col.notNull())
|
||||||
.addColumn('lastUpdatedById', 'uuid', (col) => col.references('users.id'))
|
.addColumn('last_updated_by_id', 'uuid', (col) =>
|
||||||
.addColumn('spaceId', 'uuid', (col) =>
|
col.references('users.id'),
|
||||||
|
)
|
||||||
|
.addColumn('space_id', 'uuid', (col) =>
|
||||||
col.references('spaces.id').onDelete('cascade').notNull(),
|
col.references('spaces.id').onDelete('cascade').notNull(),
|
||||||
)
|
)
|
||||||
.addColumn('workspaceId', 'uuid', (col) =>
|
.addColumn('workspace_id', 'uuid', (col) =>
|
||||||
col.references('workspaces.id').onDelete('cascade').notNull(),
|
col.references('workspaces.id').onDelete('cascade').notNull(),
|
||||||
)
|
)
|
||||||
.addColumn('createdAt', 'timestamp', (col) =>
|
.addColumn('created_at', 'timestamptz', (col) =>
|
||||||
col.notNull().defaultTo(sql`now()`),
|
col.notNull().defaultTo(sql`now()`),
|
||||||
)
|
)
|
||||||
.addColumn('updatedAt', 'timestamp', (col) =>
|
.addColumn('updated_at', 'timestamptz', (col) =>
|
||||||
col.notNull().defaultTo(sql`now()`),
|
col.notNull().defaultTo(sql`now()`),
|
||||||
)
|
)
|
||||||
.execute();
|
.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function down(db: Kysely<any>): Promise<void> {
|
export async function down(db: Kysely<any>): Promise<void> {
|
||||||
await db.schema
|
|
||||||
.alterTable('page_history')
|
|
||||||
.dropConstraint('page_history_pageId_fkey')
|
|
||||||
.execute();
|
|
||||||
|
|
||||||
await db.schema
|
|
||||||
.alterTable('page_history')
|
|
||||||
.dropConstraint('page_history_lastUpdatedById_fkey')
|
|
||||||
.execute();
|
|
||||||
|
|
||||||
await db.schema
|
|
||||||
.alterTable('page_history')
|
|
||||||
.dropConstraint('page_history_spaceId_fkey')
|
|
||||||
.execute();
|
|
||||||
|
|
||||||
await db.schema
|
|
||||||
.alterTable('page_history')
|
|
||||||
.dropConstraint('page_history_workspaceId_fkey')
|
|
||||||
.execute();
|
|
||||||
|
|
||||||
await db.schema.dropTable('page_history').execute();
|
await db.schema.dropTable('page_history').execute();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,39 +6,29 @@ export async function up(db: Kysely<any>): Promise<void> {
|
|||||||
.addColumn('id', 'uuid', (col) =>
|
.addColumn('id', 'uuid', (col) =>
|
||||||
col.primaryKey().defaultTo(sql`gen_random_uuid()`),
|
col.primaryKey().defaultTo(sql`gen_random_uuid()`),
|
||||||
)
|
)
|
||||||
.addColumn('entityId', 'uuid', (col) => col.notNull())
|
.addColumn('entity_id', 'uuid', (col) => col.notNull())
|
||||||
.addColumn('entityType', 'varchar', (col) => col.notNull())
|
.addColumn('entity_type', 'varchar', (col) => col.notNull()) // can be page or space
|
||||||
.addColumn('childrenIds', sql`uuid[]`, (col) => col.notNull())
|
.addColumn('children_ids', sql`uuid[]`, (col) => col.notNull())
|
||||||
.addColumn('spaceId', 'uuid', (col) =>
|
.addColumn('space_id', 'uuid', (col) =>
|
||||||
col.references('spaces.id').onDelete('cascade').notNull(),
|
col.references('spaces.id').onDelete('cascade').notNull(),
|
||||||
)
|
)
|
||||||
.addColumn('workspaceId', 'uuid', (col) =>
|
.addColumn('workspace_id', 'uuid', (col) =>
|
||||||
col.references('workspaces.id').onDelete('cascade').notNull(),
|
col.references('workspaces.id').onDelete('cascade').notNull(),
|
||||||
)
|
)
|
||||||
.addColumn('createdAt', 'timestamp', (col) =>
|
.addColumn('created_at', 'timestamptz', (col) =>
|
||||||
col.notNull().defaultTo(sql`now()`),
|
col.notNull().defaultTo(sql`now()`),
|
||||||
)
|
)
|
||||||
.addColumn('updatedAt', 'timestamp', (col) =>
|
.addColumn('updated_at', 'timestamptz', (col) =>
|
||||||
col.notNull().defaultTo(sql`now()`),
|
col.notNull().defaultTo(sql`now()`),
|
||||||
)
|
)
|
||||||
.addColumn('deletedAt', 'timestamp', (col) => col)
|
.addColumn('deleted_at', 'timestamptz', (col) => col)
|
||||||
.addUniqueConstraint('page_ordering_entityId_entityType_unique', [
|
.addUniqueConstraint('page_ordering_entity_id_entity_type_unique', [
|
||||||
'entityId',
|
'entity_id',
|
||||||
'entityType',
|
'entity_type',
|
||||||
])
|
])
|
||||||
.execute();
|
.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function down(db: Kysely<any>): Promise<void> {
|
export async function down(db: Kysely<any>): Promise<void> {
|
||||||
await db.schema
|
|
||||||
.alterTable('page_ordering')
|
|
||||||
.dropConstraint('page_ordering_spaceId_fkey')
|
|
||||||
.execute();
|
|
||||||
|
|
||||||
await db.schema
|
|
||||||
.alterTable('page_ordering')
|
|
||||||
.dropConstraint('page_ordering_workspaceId_fkey')
|
|
||||||
.execute();
|
|
||||||
|
|
||||||
await db.schema.dropTable('page_ordering').execute();
|
await db.schema.dropTable('page_ordering').execute();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -9,44 +9,24 @@ export async function up(db: Kysely<any>): Promise<void> {
|
|||||||
.addColumn('content', 'jsonb', (col) => col)
|
.addColumn('content', 'jsonb', (col) => col)
|
||||||
.addColumn('selection', 'varchar', (col) => col)
|
.addColumn('selection', 'varchar', (col) => col)
|
||||||
.addColumn('type', 'varchar', (col) => col)
|
.addColumn('type', 'varchar', (col) => col)
|
||||||
.addColumn('creatorId', 'uuid', (col) => col.references('users.id'))
|
.addColumn('creator_id', 'uuid', (col) => col.references('users.id'))
|
||||||
.addColumn('pageId', 'uuid', (col) =>
|
.addColumn('page_id', 'uuid', (col) =>
|
||||||
col.references('pages.id').onDelete('cascade').notNull(),
|
col.references('pages.id').onDelete('cascade').notNull(),
|
||||||
)
|
)
|
||||||
.addColumn('parentCommentId', 'uuid', (col) =>
|
.addColumn('parent_comment_id', 'uuid', (col) =>
|
||||||
col.references('comments.id').onDelete('cascade'),
|
col.references('comments.id').onDelete('cascade'),
|
||||||
)
|
)
|
||||||
.addColumn('workspaceId', 'uuid', (col) =>
|
.addColumn('workspace_id', 'uuid', (col) =>
|
||||||
col.references('workspaces.id').notNull(),
|
col.references('workspaces.id').notNull(),
|
||||||
)
|
)
|
||||||
.addColumn('createdAt', 'timestamp', (col) =>
|
.addColumn('created_at', 'timestamptz', (col) =>
|
||||||
col.notNull().defaultTo(sql`now()`),
|
col.notNull().defaultTo(sql`now()`),
|
||||||
)
|
)
|
||||||
.addColumn('editedAt', 'timestamp', (col) => col)
|
.addColumn('edited_at', 'timestamptz', (col) => col)
|
||||||
.addColumn('deletedAt', 'timestamp', (col) => col)
|
.addColumn('deleted_at', 'timestamptz', (col) => col)
|
||||||
.execute();
|
.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function down(db: Kysely<any>): Promise<void> {
|
export async function down(db: Kysely<any>): Promise<void> {
|
||||||
await db.schema
|
|
||||||
.alterTable('comments')
|
|
||||||
.dropConstraint('comments_creatorId_fkey')
|
|
||||||
.execute();
|
|
||||||
|
|
||||||
await db.schema
|
|
||||||
.alterTable('comments')
|
|
||||||
.dropConstraint('comments_pageId_fkey')
|
|
||||||
.execute();
|
|
||||||
|
|
||||||
await db.schema
|
|
||||||
.alterTable('comments')
|
|
||||||
.dropConstraint('comments_parentCommentId_fkey')
|
|
||||||
.execute();
|
|
||||||
|
|
||||||
await db.schema
|
|
||||||
.alterTable('comments')
|
|
||||||
.dropConstraint('comments_workspaceId_fkey')
|
|
||||||
.execute();
|
|
||||||
|
|
||||||
await db.schema.dropTable('comments').execute();
|
await db.schema.dropTable('comments').execute();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -6,50 +6,28 @@ export async function up(db: Kysely<any>): Promise<void> {
|
|||||||
.addColumn('id', 'uuid', (col) =>
|
.addColumn('id', 'uuid', (col) =>
|
||||||
col.primaryKey().defaultTo(sql`gen_random_uuid()`),
|
col.primaryKey().defaultTo(sql`gen_random_uuid()`),
|
||||||
)
|
)
|
||||||
.addColumn('fileName', 'varchar', (col) => col.notNull())
|
.addColumn('file_name', 'varchar', (col) => col.notNull())
|
||||||
.addColumn('filePath', 'varchar', (col) => col.notNull())
|
.addColumn('file_path', 'varchar', (col) => col.notNull())
|
||||||
.addColumn('fileSize', 'int8', (col) => col)
|
.addColumn('file_size', 'int8', (col) => col)
|
||||||
.addColumn('fileExt', 'varchar', (col) => col.notNull())
|
.addColumn('file_ext', 'varchar', (col) => col.notNull())
|
||||||
.addColumn('mimeType', 'varchar', (col) => col)
|
.addColumn('mime_type', 'varchar', (col) => col)
|
||||||
.addColumn('type', 'varchar', (col) => col)
|
.addColumn('type', 'varchar', (col) => col)
|
||||||
.addColumn('creatorId', 'uuid', (col) =>
|
.addColumn('creator_id', 'uuid', (col) =>
|
||||||
col.references('users.id').notNull(),
|
col.references('users.id').notNull(),
|
||||||
)
|
)
|
||||||
.addColumn('pageId', 'uuid', (col) => col.references('pages.id'))
|
.addColumn('page_id', 'uuid', (col) => col.references('pages.id'))
|
||||||
.addColumn('spaceId', 'uuid', (col) => col.references('spaces.id'))
|
.addColumn('space_id', 'uuid', (col) => col.references('spaces.id'))
|
||||||
.addColumn('workspaceId', 'uuid', (col) =>
|
.addColumn('workspace_id', 'uuid', (col) => col.references('workspaces.id'))
|
||||||
col.references('workspaces.id').onDelete('cascade').notNull(),
|
.addColumn('created_at', 'timestamptz', (col) =>
|
||||||
)
|
|
||||||
.addColumn('createdAt', 'timestamp', (col) =>
|
|
||||||
col.notNull().defaultTo(sql`now()`),
|
col.notNull().defaultTo(sql`now()`),
|
||||||
)
|
)
|
||||||
.addColumn('updatedAt', 'timestamp', (col) =>
|
.addColumn('updated_at', 'timestamptz', (col) =>
|
||||||
col.notNull().defaultTo(sql`now()`),
|
col.notNull().defaultTo(sql`now()`),
|
||||||
)
|
)
|
||||||
.addColumn('deletedAt', 'timestamp', (col) => col)
|
.addColumn('deleted_at', 'timestamptz', (col) => col)
|
||||||
.execute();
|
.execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function down(db: Kysely<any>): Promise<void> {
|
export async function down(db: Kysely<any>): Promise<void> {
|
||||||
await db.schema
|
|
||||||
.alterTable('attachments')
|
|
||||||
.dropConstraint('attachments_creatorId_fkey')
|
|
||||||
.execute();
|
|
||||||
|
|
||||||
await db.schema
|
|
||||||
.alterTable('attachments')
|
|
||||||
.dropConstraint('attachments_pageId_fkey')
|
|
||||||
.execute();
|
|
||||||
|
|
||||||
await db.schema
|
|
||||||
.alterTable('attachments')
|
|
||||||
.dropConstraint('attachments_spaceId_fkey')
|
|
||||||
.execute();
|
|
||||||
|
|
||||||
await db.schema
|
|
||||||
.alterTable('attachments')
|
|
||||||
.dropConstraint('attachments_workspaceId_fkey')
|
|
||||||
.execute();
|
|
||||||
|
|
||||||
await db.schema.dropTable('attachments').execute();
|
await db.schema.dropTable('attachments').execute();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,7 +5,7 @@ export async function up(db: Kysely<any>): Promise<void> {
|
|||||||
begin
|
begin
|
||||||
new.tsv :=
|
new.tsv :=
|
||||||
setweight(to_tsvector('english', coalesce(new.title, '')), 'A') ||
|
setweight(to_tsvector('english', coalesce(new.title, '')), 'A') ||
|
||||||
setweight(to_tsvector('english', coalesce(new.\"textContent\", '')), 'B');
|
setweight(to_tsvector('english', coalesce(new.text_content, '')), 'B');
|
||||||
return new;
|
return new;
|
||||||
end;
|
end;
|
||||||
$$ LANGUAGE plpgsql;`.execute(db);
|
$$ LANGUAGE plpgsql;`.execute(db);
|
||||||
|
|||||||
@ -23,7 +23,7 @@ export class GroupUserRepo {
|
|||||||
this.db,
|
this.db,
|
||||||
async (trx) => {
|
async (trx) => {
|
||||||
return await trx
|
return await trx
|
||||||
.selectFrom('group_users')
|
.selectFrom('groupUsers')
|
||||||
.selectAll()
|
.selectAll()
|
||||||
.where('userId', '=', userId)
|
.where('userId', '=', userId)
|
||||||
.where('groupId', '=', groupId)
|
.where('groupId', '=', groupId)
|
||||||
@ -41,7 +41,7 @@ export class GroupUserRepo {
|
|||||||
this.db,
|
this.db,
|
||||||
async (trx) => {
|
async (trx) => {
|
||||||
return await trx
|
return await trx
|
||||||
.insertInto('group_users')
|
.insertInto('groupUsers')
|
||||||
.values(insertableGroupUser)
|
.values(insertableGroupUser)
|
||||||
.returningAll()
|
.returningAll()
|
||||||
.executeTakeFirst();
|
.executeTakeFirst();
|
||||||
@ -57,8 +57,8 @@ export class GroupUserRepo {
|
|||||||
// todo add group member count
|
// todo add group member count
|
||||||
return executeTx(this.db, async (trx) => {
|
return executeTx(this.db, async (trx) => {
|
||||||
const groupUsers = (await trx
|
const groupUsers = (await trx
|
||||||
.selectFrom('group_users')
|
.selectFrom('groupUsers')
|
||||||
.innerJoin('users', 'users.id', 'group_users.userId')
|
.innerJoin('users', 'users.id', 'groupUsers.userId')
|
||||||
.select(sql<User>`users.*` as any)
|
.select(sql<User>`users.*` as any)
|
||||||
.where('groupId', '=', groupId)
|
.where('groupId', '=', groupId)
|
||||||
.limit(paginationOptions.limit)
|
.limit(paginationOptions.limit)
|
||||||
@ -71,7 +71,7 @@ export class GroupUserRepo {
|
|||||||
});
|
});
|
||||||
|
|
||||||
let { count } = await trx
|
let { count } = await trx
|
||||||
.selectFrom('group_users')
|
.selectFrom('groupUsers')
|
||||||
.select((eb) => eb.fn.count('id').as('count'))
|
.select((eb) => eb.fn.count('id').as('count'))
|
||||||
.where('groupId', '=', groupId)
|
.where('groupId', '=', groupId)
|
||||||
.executeTakeFirst();
|
.executeTakeFirst();
|
||||||
@ -84,7 +84,7 @@ export class GroupUserRepo {
|
|||||||
|
|
||||||
async delete(userId: string, groupId: string): Promise<void> {
|
async delete(userId: string, groupId: string): Promise<void> {
|
||||||
await this.db
|
await this.db
|
||||||
.deleteFrom('group_users')
|
.deleteFrom('groupUsers')
|
||||||
.where('userId', '=', userId)
|
.where('userId', '=', userId)
|
||||||
.where('groupId', '=', groupId)
|
.where('groupId', '=', groupId)
|
||||||
.execute();
|
.execute();
|
||||||
|
|||||||
@ -15,7 +15,7 @@ export class PageHistoryRepo {
|
|||||||
|
|
||||||
async findById(pageHistoryId: string): Promise<PageHistory> {
|
async findById(pageHistoryId: string): Promise<PageHistory> {
|
||||||
return await this.db
|
return await this.db
|
||||||
.selectFrom('page_history')
|
.selectFrom('pageHistory')
|
||||||
.selectAll()
|
.selectAll()
|
||||||
.where('id', '=', pageHistoryId)
|
.where('id', '=', pageHistoryId)
|
||||||
.executeTakeFirst();
|
.executeTakeFirst();
|
||||||
@ -30,7 +30,7 @@ export class PageHistoryRepo {
|
|||||||
this.db,
|
this.db,
|
||||||
async (trx) => {
|
async (trx) => {
|
||||||
return await trx
|
return await trx
|
||||||
.updateTable('page_history')
|
.updateTable('pageHistory')
|
||||||
.set(updatablePageHistory)
|
.set(updatablePageHistory)
|
||||||
.where('id', '=', pageHistoryId)
|
.where('id', '=', pageHistoryId)
|
||||||
.execute();
|
.execute();
|
||||||
@ -47,7 +47,7 @@ export class PageHistoryRepo {
|
|||||||
this.db,
|
this.db,
|
||||||
async (trx) => {
|
async (trx) => {
|
||||||
return await trx
|
return await trx
|
||||||
.insertInto('page_history')
|
.insertInto('pageHistory')
|
||||||
.values(insertablePageHistory)
|
.values(insertablePageHistory)
|
||||||
.returningAll()
|
.returningAll()
|
||||||
.executeTakeFirst();
|
.executeTakeFirst();
|
||||||
@ -62,7 +62,7 @@ export class PageHistoryRepo {
|
|||||||
) {
|
) {
|
||||||
return executeTx(this.db, async (trx) => {
|
return executeTx(this.db, async (trx) => {
|
||||||
const pageHistory = await trx
|
const pageHistory = await trx
|
||||||
.selectFrom('page_history as history')
|
.selectFrom('pageHistory as history')
|
||||||
.innerJoin('users as user', 'user.id', 'history.lastUpdatedById')
|
.innerJoin('users as user', 'user.id', 'history.lastUpdatedById')
|
||||||
.select([
|
.select([
|
||||||
'history.id',
|
'history.id',
|
||||||
@ -87,7 +87,7 @@ export class PageHistoryRepo {
|
|||||||
.execute();
|
.execute();
|
||||||
|
|
||||||
let { count } = await trx
|
let { count } = await trx
|
||||||
.selectFrom('page_history')
|
.selectFrom('pageHistory')
|
||||||
.select((eb) => eb.fn.count('id').as('count'))
|
.select((eb) => eb.fn.count('id').as('count'))
|
||||||
.where('pageId', '=', pageId)
|
.where('pageId', '=', pageId)
|
||||||
.executeTakeFirst();
|
.executeTakeFirst();
|
||||||
|
|||||||
@ -10,7 +10,6 @@ import {
|
|||||||
import { sql } from 'kysely';
|
import { sql } from 'kysely';
|
||||||
import { PaginationOptions } from 'src/helpers/pagination/pagination-options';
|
import { PaginationOptions } from 'src/helpers/pagination/pagination-options';
|
||||||
import { OrderingEntity } from 'src/core/page/page.util';
|
import { OrderingEntity } from 'src/core/page/page.util';
|
||||||
import { PageWithOrderingDto } from 'src/core/page/dto/page-with-ordering.dto';
|
|
||||||
|
|
||||||
// TODO: scope to space/workspace
|
// TODO: scope to space/workspace
|
||||||
@Injectable()
|
@Injectable()
|
||||||
@ -23,7 +22,7 @@ export class PageRepo {
|
|||||||
'slug',
|
'slug',
|
||||||
'icon',
|
'icon',
|
||||||
'coverPhoto',
|
'coverPhoto',
|
||||||
'shareId',
|
'key',
|
||||||
'parentPageId',
|
'parentPageId',
|
||||||
'creatorId',
|
'creatorId',
|
||||||
'lastUpdatedById',
|
'lastUpdatedById',
|
||||||
@ -126,7 +125,7 @@ export class PageRepo {
|
|||||||
async getSpaceSidebarPages(spaceId: string, limit: number) {
|
async getSpaceSidebarPages(spaceId: string, limit: number) {
|
||||||
const pages = await this.db
|
const pages = await this.db
|
||||||
.selectFrom('pages as page')
|
.selectFrom('pages as page')
|
||||||
.innerJoin('page_ordering as ordering', 'ordering.entityId', 'page.id')
|
.innerJoin('pageOrdering as ordering', 'ordering.entityId', 'page.id')
|
||||||
.where('ordering.entityType', '=', OrderingEntity.PAGE)
|
.where('ordering.entityType', '=', OrderingEntity.PAGE)
|
||||||
.where('page.spaceId', '=', spaceId)
|
.where('page.spaceId', '=', spaceId)
|
||||||
.select([
|
.select([
|
||||||
|
|||||||
@ -22,7 +22,7 @@ export class SpaceMemberRepo {
|
|||||||
this.db,
|
this.db,
|
||||||
async (trx) => {
|
async (trx) => {
|
||||||
return await trx
|
return await trx
|
||||||
.insertInto('space_members')
|
.insertInto('spaceMembers')
|
||||||
.values(insertableSpaceMember)
|
.values(insertableSpaceMember)
|
||||||
.returningAll()
|
.returningAll()
|
||||||
.executeTakeFirst();
|
.executeTakeFirst();
|
||||||
@ -37,9 +37,9 @@ export class SpaceMemberRepo {
|
|||||||
) {
|
) {
|
||||||
return executeTx(this.db, async (trx) => {
|
return executeTx(this.db, async (trx) => {
|
||||||
const spaceMembers = await trx
|
const spaceMembers = await trx
|
||||||
.selectFrom('space_members')
|
.selectFrom('spaceMembers')
|
||||||
.leftJoin('users', 'users.id', 'space_members.userId')
|
.leftJoin('users', 'users.id', 'spaceMembers.userId')
|
||||||
.leftJoin('groups', 'groups.id', 'space_members.groupId')
|
.leftJoin('groups', 'groups.id', 'spaceMembers.groupId')
|
||||||
.select([
|
.select([
|
||||||
'groups.id as group_id',
|
'groups.id as group_id',
|
||||||
'groups.name as group_name',
|
'groups.name as group_name',
|
||||||
@ -51,10 +51,10 @@ export class SpaceMemberRepo {
|
|||||||
'users.name as user_name',
|
'users.name as user_name',
|
||||||
'users.avatarUrl as user_avatarUrl',
|
'users.avatarUrl as user_avatarUrl',
|
||||||
'users.email as user_email',
|
'users.email as user_email',
|
||||||
'space_members.role',
|
'spaceMembers.role',
|
||||||
])
|
])
|
||||||
.where('spaceId', '=', spaceId)
|
.where('spaceId', '=', spaceId)
|
||||||
.orderBy('space_members.createdAt', 'asc')
|
.orderBy('spaceMembers.createdAt', 'asc')
|
||||||
.limit(paginationOptions.limit)
|
.limit(paginationOptions.limit)
|
||||||
.offset(paginationOptions.offset)
|
.offset(paginationOptions.offset)
|
||||||
.execute();
|
.execute();
|
||||||
@ -87,7 +87,7 @@ export class SpaceMemberRepo {
|
|||||||
});
|
});
|
||||||
|
|
||||||
let { count } = await trx
|
let { count } = await trx
|
||||||
.selectFrom('space_members')
|
.selectFrom('spaceMembers')
|
||||||
.select((eb) => eb.fn.count('id').as('count'))
|
.select((eb) => eb.fn.count('id').as('count'))
|
||||||
.where('spaceId', '=', spaceId)
|
.where('spaceId', '=', spaceId)
|
||||||
.executeTakeFirst();
|
.executeTakeFirst();
|
||||||
@ -106,7 +106,7 @@ export class SpaceMemberRepo {
|
|||||||
* Todo: needs more work. this is a draft
|
* Todo: needs more work. this is a draft
|
||||||
*/
|
*/
|
||||||
async getUserSpaces(userId: string, workspaceId: string) {
|
async getUserSpaces(userId: string, workspaceId: string) {
|
||||||
const rolePriority = sql`CASE "space_members"."role"
|
const rolePriority = sql`CASE "spaceMembers"."role"
|
||||||
WHEN 'owner' THEN 3
|
WHEN 'owner' THEN 3
|
||||||
WHEN 'writer' THEN 2
|
WHEN 'writer' THEN 2
|
||||||
WHEN 'reader' THEN 1
|
WHEN 'reader' THEN 1
|
||||||
@ -114,35 +114,31 @@ export class SpaceMemberRepo {
|
|||||||
|
|
||||||
const subquery = this.db
|
const subquery = this.db
|
||||||
.selectFrom('spaces')
|
.selectFrom('spaces')
|
||||||
.innerJoin('space_members', 'spaces.id', 'space_members.spaceId')
|
.innerJoin('spaceMembers', 'spaces.id', 'spaceMembers.spaceId')
|
||||||
.select([
|
.select([
|
||||||
'spaces.id',
|
'spaces.id',
|
||||||
'spaces.name',
|
'spaces.name',
|
||||||
'spaces.slug',
|
'spaces.slug',
|
||||||
'spaces.icon',
|
'spaces.icon',
|
||||||
'space_members.role',
|
'spaceMembers.role',
|
||||||
rolePriority,
|
rolePriority,
|
||||||
])
|
])
|
||||||
.where('space_members.userId', '=', userId)
|
.where('spaceMembers.userId', '=', userId)
|
||||||
.where('spaces.workspaceId', '=', workspaceId)
|
.where('spaces.workspaceId', '=', workspaceId)
|
||||||
.unionAll(
|
.unionAll(
|
||||||
this.db
|
this.db
|
||||||
.selectFrom('spaces')
|
.selectFrom('spaces')
|
||||||
.innerJoin('space_members', 'spaces.id', 'space_members.spaceId')
|
.innerJoin('spaceMembers', 'spaces.id', 'spaceMembers.spaceId')
|
||||||
.innerJoin(
|
.innerJoin('groupUsers', 'spaceMembers.groupId', 'groupUsers.groupId')
|
||||||
'group_users',
|
|
||||||
'space_members.groupId',
|
|
||||||
'group_users.groupId',
|
|
||||||
)
|
|
||||||
.select([
|
.select([
|
||||||
'spaces.id',
|
'spaces.id',
|
||||||
'spaces.name',
|
'spaces.name',
|
||||||
'spaces.slug',
|
'spaces.slug',
|
||||||
'spaces.icon',
|
'spaces.icon',
|
||||||
'space_members.role',
|
'spaceMembers.role',
|
||||||
rolePriority,
|
rolePriority,
|
||||||
])
|
])
|
||||||
.where('group_users.userId', '=', userId),
|
.where('groupUsers.userId', '=', userId),
|
||||||
)
|
)
|
||||||
.as('membership');
|
.as('membership');
|
||||||
|
|
||||||
@ -194,7 +190,7 @@ export class SpaceMemberRepo {
|
|||||||
spaceId: string,
|
spaceId: string,
|
||||||
workspaceId: string,
|
workspaceId: string,
|
||||||
) {
|
) {
|
||||||
const rolePriority = sql`CASE "space_members"."role"
|
const rolePriority = sql`CASE "spaceMembers"."role"
|
||||||
WHEN 'owner' THEN 3
|
WHEN 'owner' THEN 3
|
||||||
WHEN 'writer' THEN 2
|
WHEN 'writer' THEN 2
|
||||||
WHEN 'reader' THEN 1
|
WHEN 'reader' THEN 1
|
||||||
@ -202,36 +198,32 @@ export class SpaceMemberRepo {
|
|||||||
|
|
||||||
const subquery = this.db
|
const subquery = this.db
|
||||||
.selectFrom('spaces')
|
.selectFrom('spaces')
|
||||||
.innerJoin('space_members', 'spaces.id', 'space_members.spaceId')
|
.innerJoin('spaceMembers', 'spaces.id', 'spaceMembers.spaceId')
|
||||||
.select([
|
.select([
|
||||||
'spaces.id',
|
'spaces.id',
|
||||||
'spaces.name',
|
'spaces.name',
|
||||||
'space_members.role',
|
'spaceMembers.role',
|
||||||
'space_members.userId',
|
'spaceMembers.userId',
|
||||||
rolePriority,
|
rolePriority,
|
||||||
])
|
])
|
||||||
.where('space_members.userId', '=', userId)
|
.where('spaceMembers.userId', '=', userId)
|
||||||
.where('spaces.id', '=', spaceId)
|
.where('spaces.id', '=', spaceId)
|
||||||
.where('spaces.workspaceId', '=', workspaceId)
|
.where('spaces.workspaceId', '=', workspaceId)
|
||||||
.unionAll(
|
.unionAll(
|
||||||
this.db
|
this.db
|
||||||
.selectFrom('spaces')
|
.selectFrom('spaces')
|
||||||
.innerJoin('space_members', 'spaces.id', 'space_members.spaceId')
|
.innerJoin('spaceMembers', 'spaces.id', 'spaceMembers.spaceId')
|
||||||
.innerJoin(
|
.innerJoin('groupUsers', 'spaceMembers.groupId', 'groupUsers.groupId')
|
||||||
'group_users',
|
|
||||||
'space_members.groupId',
|
|
||||||
'group_users.groupId',
|
|
||||||
)
|
|
||||||
.select([
|
.select([
|
||||||
'spaces.id',
|
'spaces.id',
|
||||||
'spaces.name',
|
'spaces.name',
|
||||||
'space_members.role',
|
'spaceMembers.role',
|
||||||
'space_members.userId',
|
'spaceMembers.userId',
|
||||||
rolePriority,
|
rolePriority,
|
||||||
])
|
])
|
||||||
.where('spaces.id', '=', spaceId)
|
.where('spaces.id', '=', spaceId)
|
||||||
.where('spaces.workspaceId', '=', workspaceId)
|
.where('spaces.workspaceId', '=', workspaceId)
|
||||||
.where('group_users.userId', '=', userId),
|
.where('groupUsers.userId', '=', userId),
|
||||||
)
|
)
|
||||||
.as('membership');
|
.as('membership');
|
||||||
|
|
||||||
@ -275,7 +267,7 @@ export class SpaceMemberRepo {
|
|||||||
this.db,
|
this.db,
|
||||||
async (trx) => {
|
async (trx) => {
|
||||||
return await trx
|
return await trx
|
||||||
.selectFrom('space_members')
|
.selectFrom('spaceMembers')
|
||||||
.selectAll()
|
.selectAll()
|
||||||
.where('userId', '=', userId)
|
.where('userId', '=', userId)
|
||||||
.where('groupId', '=', groupId)
|
.where('groupId', '=', groupId)
|
||||||
@ -287,7 +279,7 @@ export class SpaceMemberRepo {
|
|||||||
|
|
||||||
async removeUser(userId: string, spaceId: string): Promise<void> {
|
async removeUser(userId: string, spaceId: string): Promise<void> {
|
||||||
await this.db
|
await this.db
|
||||||
.deleteFrom('space_members')
|
.deleteFrom('spaceMembers')
|
||||||
.where('userId', '=', userId)
|
.where('userId', '=', userId)
|
||||||
.where('spaceId', '=', spaceId)
|
.where('spaceId', '=', spaceId)
|
||||||
.execute();
|
.execute();
|
||||||
@ -295,7 +287,7 @@ export class SpaceMemberRepo {
|
|||||||
|
|
||||||
async removeGroup(groupId: string, spaceId: string): Promise<void> {
|
async removeGroup(groupId: string, spaceId: string): Promise<void> {
|
||||||
await this.db
|
await this.db
|
||||||
.deleteFrom('space_members')
|
.deleteFrom('spaceMembers')
|
||||||
.where('userId', '=', groupId)
|
.where('userId', '=', groupId)
|
||||||
.where('spaceId', '=', spaceId)
|
.where('spaceId', '=', spaceId)
|
||||||
.execute();
|
.execute();
|
||||||
|
|||||||
34
apps/server/src/kysely/types/db.d.ts
vendored
34
apps/server/src/kysely/types/db.d.ts
vendored
@ -1,15 +1,10 @@
|
|||||||
import type { ColumnType } from 'kysely';
|
import type { ColumnType } from "kysely";
|
||||||
|
|
||||||
export type Generated<T> =
|
export type Generated<T> = T extends ColumnType<infer S, infer I, infer U>
|
||||||
T extends ColumnType<infer S, infer I, infer U>
|
? ColumnType<S, I | undefined, U>
|
||||||
? ColumnType<S, I | undefined, U>
|
: ColumnType<T, T | undefined, T>;
|
||||||
: ColumnType<T, T | undefined, T>;
|
|
||||||
|
|
||||||
export type Int8 = ColumnType<
|
export type Int8 = ColumnType<string, bigint | number | string, bigint | number | string>;
|
||||||
string,
|
|
||||||
bigint | number | string,
|
|
||||||
bigint | number | string
|
|
||||||
>;
|
|
||||||
|
|
||||||
export type Json = JsonValue;
|
export type Json = JsonValue;
|
||||||
|
|
||||||
@ -39,7 +34,7 @@ export interface Attachments {
|
|||||||
spaceId: string | null;
|
spaceId: string | null;
|
||||||
type: string | null;
|
type: string | null;
|
||||||
updatedAt: Generated<Timestamp>;
|
updatedAt: Generated<Timestamp>;
|
||||||
workspaceId: string;
|
workspaceId: string | null;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface Comments {
|
export interface Comments {
|
||||||
@ -115,10 +110,10 @@ export interface Pages {
|
|||||||
icon: string | null;
|
icon: string | null;
|
||||||
id: Generated<string>;
|
id: Generated<string>;
|
||||||
isLocked: Generated<boolean>;
|
isLocked: Generated<boolean>;
|
||||||
|
key: string | null;
|
||||||
lastUpdatedById: string | null;
|
lastUpdatedById: string | null;
|
||||||
parentPageId: string | null;
|
parentPageId: string | null;
|
||||||
publishedAt: Timestamp | null;
|
publishedAt: Timestamp | null;
|
||||||
shareId: string | null;
|
|
||||||
slug: string | null;
|
slug: string | null;
|
||||||
spaceId: string;
|
spaceId: string;
|
||||||
status: string | null;
|
status: string | null;
|
||||||
@ -145,6 +140,7 @@ export interface Spaces {
|
|||||||
createdAt: Generated<Timestamp>;
|
createdAt: Generated<Timestamp>;
|
||||||
creatorId: string | null;
|
creatorId: string | null;
|
||||||
defaultRole: Generated<string>;
|
defaultRole: Generated<string>;
|
||||||
|
deletedAt: Timestamp | null;
|
||||||
description: string | null;
|
description: string | null;
|
||||||
icon: string | null;
|
icon: string | null;
|
||||||
id: Generated<string>;
|
id: Generated<string>;
|
||||||
@ -163,7 +159,6 @@ export interface Users {
|
|||||||
id: Generated<string>;
|
id: Generated<string>;
|
||||||
lastActiveAt: Timestamp | null;
|
lastActiveAt: Timestamp | null;
|
||||||
lastLoginAt: Timestamp | null;
|
lastLoginAt: Timestamp | null;
|
||||||
lastLoginIp: string | null;
|
|
||||||
locale: string | null;
|
locale: string | null;
|
||||||
name: string | null;
|
name: string | null;
|
||||||
password: string;
|
password: string;
|
||||||
@ -188,7 +183,6 @@ export interface WorkspaceInvitations {
|
|||||||
|
|
||||||
export interface Workspaces {
|
export interface Workspaces {
|
||||||
createdAt: Generated<Timestamp>;
|
createdAt: Generated<Timestamp>;
|
||||||
creatorId: string | null;
|
|
||||||
customDomain: string | null;
|
customDomain: string | null;
|
||||||
defaultRole: Generated<string>;
|
defaultRole: Generated<string>;
|
||||||
defaultSpaceId: string | null;
|
defaultSpaceId: string | null;
|
||||||
@ -197,7 +191,7 @@ export interface Workspaces {
|
|||||||
enableInvite: Generated<boolean>;
|
enableInvite: Generated<boolean>;
|
||||||
hostname: string | null;
|
hostname: string | null;
|
||||||
id: Generated<string>;
|
id: Generated<string>;
|
||||||
inviteCode: string | null;
|
inviteCode: Generated<string | null>;
|
||||||
logo: string | null;
|
logo: string | null;
|
||||||
name: string | null;
|
name: string | null;
|
||||||
settings: Json | null;
|
settings: Json | null;
|
||||||
@ -207,14 +201,14 @@ export interface Workspaces {
|
|||||||
export interface DB {
|
export interface DB {
|
||||||
attachments: Attachments;
|
attachments: Attachments;
|
||||||
comments: Comments;
|
comments: Comments;
|
||||||
group_users: GroupUsers;
|
|
||||||
groups: Groups;
|
groups: Groups;
|
||||||
page_history: PageHistory;
|
groupUsers: GroupUsers;
|
||||||
page_ordering: PageOrdering;
|
pageHistory: PageHistory;
|
||||||
|
pageOrdering: PageOrdering;
|
||||||
pages: Pages;
|
pages: Pages;
|
||||||
space_members: SpaceMembers;
|
spaceMembers: SpaceMembers;
|
||||||
spaces: Spaces;
|
spaces: Spaces;
|
||||||
users: Users;
|
users: Users;
|
||||||
workspace_invitations: WorkspaceInvitations;
|
workspaceInvitations: WorkspaceInvitations;
|
||||||
workspaces: Workspaces;
|
workspaces: Workspaces;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user