mirror of
https://github.com/docmost/docmost
synced 2025-03-28 21:13:28 +00:00
use uuid7
This commit is contained in:
parent
723928d678
commit
aea37eecda
@ -7,7 +7,7 @@ import {
|
|||||||
prepareFile,
|
prepareFile,
|
||||||
validateFileType,
|
validateFileType,
|
||||||
} from '../attachment.utils';
|
} from '../attachment.utils';
|
||||||
import { v4 as uuid4 } from 'uuid';
|
import { v4 as uuid4, v7 as uuid7 } from 'uuid';
|
||||||
import { AttachmentRepo } from '@docmost/db/repos/attachment/attachment.repo';
|
import { AttachmentRepo } from '@docmost/db/repos/attachment/attachment.repo';
|
||||||
import { AttachmentType, validImageExtensions } from '../attachment.constants';
|
import { AttachmentType, validImageExtensions } from '../attachment.constants';
|
||||||
import { KyselyDB, KyselyTransaction } from '@docmost/db/types/kysely.types';
|
import { KyselyDB, KyselyTransaction } from '@docmost/db/types/kysely.types';
|
||||||
@ -40,7 +40,7 @@ export class AttachmentService {
|
|||||||
const { filePromise, pageId, spaceId, userId, workspaceId } = opts;
|
const { filePromise, pageId, spaceId, userId, workspaceId } = opts;
|
||||||
const preparedFile: PreparedFile = await prepareFile(filePromise);
|
const preparedFile: PreparedFile = await prepareFile(filePromise);
|
||||||
|
|
||||||
const attachmentId = uuid4();
|
const attachmentId = uuid7();
|
||||||
const filePath = `${getAttachmentFolderPath(AttachmentType.File, workspaceId)}/${attachmentId}/${preparedFile.fileName}`;
|
const filePath = `${getAttachmentFolderPath(AttachmentType.File, workspaceId)}/${attachmentId}/${preparedFile.fileName}`;
|
||||||
|
|
||||||
await this.uploadToDrive(filePath, preparedFile.buffer);
|
await this.uploadToDrive(filePath, preparedFile.buffer);
|
||||||
|
@ -7,6 +7,6 @@ export class AddGroupUserDto extends GroupIdDto {
|
|||||||
message: 'you cannot add more than 50 users at a time',
|
message: 'you cannot add more than 50 users at a time',
|
||||||
})
|
})
|
||||||
@ArrayMinSize(1)
|
@ArrayMinSize(1)
|
||||||
@IsUUID(4, { each: true })
|
@IsUUID('all', { each: true })
|
||||||
userIds: string[];
|
userIds: string[];
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ export class CreateGroupDto {
|
|||||||
@IsOptional()
|
@IsOptional()
|
||||||
@IsArray()
|
@IsArray()
|
||||||
@ArrayMaxSize(50)
|
@ArrayMaxSize(50)
|
||||||
@IsUUID(4, { each: true })
|
@IsUUID('all', { each: true })
|
||||||
userIds?: string[];
|
userIds?: string[];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -14,13 +14,13 @@ export class AddSpaceMembersDto extends SpaceIdDto {
|
|||||||
@ArrayMaxSize(25, {
|
@ArrayMaxSize(25, {
|
||||||
message: 'userIds must an array with no more than 25 elements',
|
message: 'userIds must an array with no more than 25 elements',
|
||||||
})
|
})
|
||||||
@IsUUID(4, { each: true })
|
@IsUUID('all', { each: true })
|
||||||
userIds: string[];
|
userIds: string[];
|
||||||
|
|
||||||
@IsArray()
|
@IsArray()
|
||||||
@ArrayMaxSize(25, {
|
@ArrayMaxSize(25, {
|
||||||
message: 'userIds must an array with no more than 25 elements',
|
message: 'userIds must an array with no more than 25 elements',
|
||||||
})
|
})
|
||||||
@IsUUID(4, { each: true })
|
@IsUUID('all', { each: true })
|
||||||
groupIds: string[];
|
groupIds: string[];
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,10 @@
|
|||||||
import { IsOptional, IsString, MaxLength, MinLength } from 'class-validator';
|
import {
|
||||||
|
IsAlphanumeric,
|
||||||
|
IsOptional,
|
||||||
|
IsString,
|
||||||
|
MaxLength,
|
||||||
|
MinLength,
|
||||||
|
} from 'class-validator';
|
||||||
|
|
||||||
export class CreateSpaceDto {
|
export class CreateSpaceDto {
|
||||||
@MinLength(2)
|
@MinLength(2)
|
||||||
@ -12,6 +18,6 @@ export class CreateSpaceDto {
|
|||||||
|
|
||||||
@MinLength(2)
|
@MinLength(2)
|
||||||
@MaxLength(50)
|
@MaxLength(50)
|
||||||
@IsString()
|
@IsAlphanumeric()
|
||||||
slug: string;
|
slug: string;
|
||||||
}
|
}
|
||||||
|
@ -28,7 +28,7 @@ export class InviteUserDto {
|
|||||||
message: 'you cannot add invited users to more than 25 groups at a time',
|
message: 'you cannot add invited users to more than 25 groups at a time',
|
||||||
})
|
})
|
||||||
@ArrayMinSize(0)
|
@ArrayMinSize(0)
|
||||||
@IsUUID(4, { each: true })
|
@IsUUID('all', { each: true })
|
||||||
groupIds: string[];
|
groupIds: string[];
|
||||||
|
|
||||||
@IsEnum(UserRole)
|
@IsEnum(UserRole)
|
||||||
|
@ -0,0 +1,53 @@
|
|||||||
|
import { Kysely, sql } from 'kysely';
|
||||||
|
|
||||||
|
export async function up(db: Kysely<any>): Promise<void> {
|
||||||
|
await sql`
|
||||||
|
/*
|
||||||
|
* MIT License - Copyright (c) 2023-2024 Fabio Lima
|
||||||
|
* Source: https://gist.githubusercontent.com/fabiolimace/515a0440e3e40efeb234e12644a6a346/
|
||||||
|
*/
|
||||||
|
CREATE OR REPLACE FUNCTION gen_uuid_v7() RETURNS uuid AS $$
|
||||||
|
declare
|
||||||
|
v_time numeric := null;
|
||||||
|
|
||||||
|
v_unix_t numeric := null;
|
||||||
|
v_rand_a numeric := null;
|
||||||
|
v_rand_b numeric := null;
|
||||||
|
|
||||||
|
v_unix_t_hex varchar := null;
|
||||||
|
v_rand_a_hex varchar := null;
|
||||||
|
v_rand_b_hex varchar := null;
|
||||||
|
|
||||||
|
v_output_bytes bytea := null;
|
||||||
|
|
||||||
|
c_milli_factor numeric := 10^3::numeric; -- 1000
|
||||||
|
c_micro_factor numeric := 10^6::numeric; -- 1000000
|
||||||
|
c_scale_factor numeric := 4.096::numeric; -- 4.0 * (1024 / 1000)
|
||||||
|
|
||||||
|
c_version bit(64) := x'0000000000007000'; -- RFC-4122 version: b'0111...'
|
||||||
|
c_variant bit(64) := x'8000000000000000'; -- RFC-4122 variant: b'10xx...'
|
||||||
|
|
||||||
|
begin
|
||||||
|
v_time := extract(epoch from clock_timestamp());
|
||||||
|
|
||||||
|
v_unix_t := trunc(v_time * c_milli_factor);
|
||||||
|
v_rand_a := ((v_time * c_micro_factor) - (v_unix_t * c_milli_factor)) * c_scale_factor;
|
||||||
|
v_rand_b := random()::numeric * 2^62::numeric;
|
||||||
|
|
||||||
|
v_unix_t_hex := lpad(to_hex(v_unix_t::bigint), 12, '0');
|
||||||
|
v_rand_a_hex := lpad(to_hex((v_rand_a::bigint::bit(64) | c_version)::bigint), 4, '0');
|
||||||
|
v_rand_b_hex := lpad(to_hex((v_rand_b::bigint::bit(64) | c_variant)::bigint), 16, '0');
|
||||||
|
|
||||||
|
v_output_bytes := decode(v_unix_t_hex || v_rand_a_hex || v_rand_b_hex, 'hex');
|
||||||
|
|
||||||
|
return encode(v_output_bytes, 'hex')::uuid;
|
||||||
|
|
||||||
|
v_output_bytes := decode(v_unix_t_hex || v_rand_a_hex || v_rand_b_hex, 'hex');
|
||||||
|
|
||||||
|
return encode(v_output_bytes, 'hex')::uuid;
|
||||||
|
end $$ LANGUAGE plpgsql;`.execute(db);
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function down(db: Kysely<any>): Promise<void> {
|
||||||
|
await sql`DROP FUNCTION gen_uuid_v7`.execute(db);
|
||||||
|
}
|
@ -5,7 +5,7 @@ export async function up(db: Kysely<any>): Promise<void> {
|
|||||||
await db.schema
|
await db.schema
|
||||||
.createTable('workspaces')
|
.createTable('workspaces')
|
||||||
.addColumn('id', 'uuid', (col) =>
|
.addColumn('id', 'uuid', (col) =>
|
||||||
col.primaryKey().defaultTo(sql`gen_random_uuid()`),
|
col.primaryKey().defaultTo(sql`gen_uuid_v7()`),
|
||||||
)
|
)
|
||||||
.addColumn('name', 'varchar', (col) => col)
|
.addColumn('name', 'varchar', (col) => col)
|
||||||
.addColumn('description', 'varchar', (col) => col)
|
.addColumn('description', 'varchar', (col) => col)
|
||||||
|
@ -4,7 +4,7 @@ export async function up(db: Kysely<any>): Promise<void> {
|
|||||||
await db.schema
|
await db.schema
|
||||||
.createTable('users')
|
.createTable('users')
|
||||||
.addColumn('id', 'uuid', (col) =>
|
.addColumn('id', 'uuid', (col) =>
|
||||||
col.primaryKey().defaultTo(sql`gen_random_uuid()`),
|
col.primaryKey().defaultTo(sql`gen_uuid_v7()`),
|
||||||
)
|
)
|
||||||
.addColumn('name', 'varchar', (col) => col)
|
.addColumn('name', 'varchar', (col) => col)
|
||||||
.addColumn('email', 'varchar', (col) => col.notNull())
|
.addColumn('email', 'varchar', (col) => col.notNull())
|
||||||
|
@ -4,7 +4,7 @@ export async function up(db: Kysely<any>): Promise<void> {
|
|||||||
await db.schema
|
await db.schema
|
||||||
.createTable('groups')
|
.createTable('groups')
|
||||||
.addColumn('id', 'uuid', (col) =>
|
.addColumn('id', 'uuid', (col) =>
|
||||||
col.primaryKey().defaultTo(sql`gen_random_uuid()`),
|
col.primaryKey().defaultTo(sql`gen_uuid_v7()`),
|
||||||
)
|
)
|
||||||
.addColumn('name', 'varchar', (col) => col.notNull())
|
.addColumn('name', 'varchar', (col) => col.notNull())
|
||||||
.addColumn('description', 'text', (col) => col)
|
.addColumn('description', 'text', (col) => col)
|
||||||
@ -19,6 +19,7 @@ export async function up(db: Kysely<any>): Promise<void> {
|
|||||||
.addColumn('updated_at', 'timestamptz', (col) =>
|
.addColumn('updated_at', 'timestamptz', (col) =>
|
||||||
col.notNull().defaultTo(sql`now()`),
|
col.notNull().defaultTo(sql`now()`),
|
||||||
)
|
)
|
||||||
|
.addColumn('deleted_at', 'timestamptz', (col) => col)
|
||||||
.addUniqueConstraint('groups_name_workspace_id_unique', [
|
.addUniqueConstraint('groups_name_workspace_id_unique', [
|
||||||
'name',
|
'name',
|
||||||
'workspace_id',
|
'workspace_id',
|
||||||
@ -29,7 +30,7 @@ export async function up(db: Kysely<any>): Promise<void> {
|
|||||||
await db.schema
|
await db.schema
|
||||||
.createTable('group_users')
|
.createTable('group_users')
|
||||||
.addColumn('id', 'uuid', (col) =>
|
.addColumn('id', 'uuid', (col) =>
|
||||||
col.primaryKey().defaultTo(sql`gen_random_uuid()`),
|
col.primaryKey().defaultTo(sql`gen_uuid_v7()`),
|
||||||
)
|
)
|
||||||
.addColumn('user_id', 'uuid', (col) =>
|
.addColumn('user_id', 'uuid', (col) =>
|
||||||
col.references('users.id').onDelete('cascade').notNull(),
|
col.references('users.id').onDelete('cascade').notNull(),
|
||||||
|
@ -8,7 +8,7 @@ export async function up(db: Kysely<any>): Promise<void> {
|
|||||||
await db.schema
|
await db.schema
|
||||||
.createTable('spaces')
|
.createTable('spaces')
|
||||||
.addColumn('id', 'uuid', (col) =>
|
.addColumn('id', 'uuid', (col) =>
|
||||||
col.primaryKey().defaultTo(sql`gen_random_uuid()`),
|
col.primaryKey().defaultTo(sql`gen_uuid_v7()`),
|
||||||
)
|
)
|
||||||
.addColumn('name', 'varchar', (col) => col)
|
.addColumn('name', 'varchar', (col) => col)
|
||||||
.addColumn('description', 'text', (col) => col)
|
.addColumn('description', 'text', (col) => col)
|
||||||
@ -40,7 +40,7 @@ export async function up(db: Kysely<any>): Promise<void> {
|
|||||||
await db.schema
|
await db.schema
|
||||||
.createTable('space_members')
|
.createTable('space_members')
|
||||||
.addColumn('id', 'uuid', (col) =>
|
.addColumn('id', 'uuid', (col) =>
|
||||||
col.primaryKey().defaultTo(sql`gen_random_uuid()`),
|
col.primaryKey().defaultTo(sql`gen_uuid_v7()`),
|
||||||
)
|
)
|
||||||
.addColumn('user_id', 'uuid', (col) =>
|
.addColumn('user_id', 'uuid', (col) =>
|
||||||
col.references('users.id').onDelete('cascade'),
|
col.references('users.id').onDelete('cascade'),
|
||||||
@ -59,6 +59,7 @@ export async function up(db: Kysely<any>): Promise<void> {
|
|||||||
.addColumn('updated_at', 'timestamptz', (col) =>
|
.addColumn('updated_at', 'timestamptz', (col) =>
|
||||||
col.notNull().defaultTo(sql`now()`),
|
col.notNull().defaultTo(sql`now()`),
|
||||||
)
|
)
|
||||||
|
.addColumn('deleted_at', 'timestamptz', (col) => col)
|
||||||
.addUniqueConstraint('space_members_space_id_user_id_unique', [
|
.addUniqueConstraint('space_members_space_id_user_id_unique', [
|
||||||
'space_id',
|
'space_id',
|
||||||
'user_id',
|
'user_id',
|
||||||
|
@ -4,7 +4,7 @@ export async function up(db: Kysely<any>): Promise<void> {
|
|||||||
await db.schema
|
await db.schema
|
||||||
.createTable('workspace_invitations')
|
.createTable('workspace_invitations')
|
||||||
.addColumn('id', 'uuid', (col) =>
|
.addColumn('id', 'uuid', (col) =>
|
||||||
col.primaryKey().defaultTo(sql`gen_random_uuid()`),
|
col.primaryKey().defaultTo(sql`gen_uuid_v7()`),
|
||||||
)
|
)
|
||||||
.addColumn('email', 'varchar', (col) => col)
|
.addColumn('email', 'varchar', (col) => col)
|
||||||
.addColumn('role', 'varchar', (col) => col.notNull())
|
.addColumn('role', 'varchar', (col) => col.notNull())
|
||||||
|
@ -4,7 +4,7 @@ export async function up(db: Kysely<any>): Promise<void> {
|
|||||||
await db.schema
|
await db.schema
|
||||||
.createTable('pages')
|
.createTable('pages')
|
||||||
.addColumn('id', 'uuid', (col) =>
|
.addColumn('id', 'uuid', (col) =>
|
||||||
col.primaryKey().defaultTo(sql`gen_random_uuid()`),
|
col.primaryKey().defaultTo(sql`gen_uuid_v7()`),
|
||||||
)
|
)
|
||||||
.addColumn('slug_id', 'varchar', (col) => col.notNull())
|
.addColumn('slug_id', 'varchar', (col) => col.notNull())
|
||||||
.addColumn('title', 'varchar', (col) => col)
|
.addColumn('title', 'varchar', (col) => col)
|
||||||
|
@ -4,7 +4,7 @@ export async function up(db: Kysely<any>): Promise<void> {
|
|||||||
await db.schema
|
await db.schema
|
||||||
.createTable('page_history')
|
.createTable('page_history')
|
||||||
.addColumn('id', 'uuid', (col) =>
|
.addColumn('id', 'uuid', (col) =>
|
||||||
col.primaryKey().defaultTo(sql`gen_random_uuid()`),
|
col.primaryKey().defaultTo(sql`gen_uuid_v7()`),
|
||||||
)
|
)
|
||||||
.addColumn('page_id', 'uuid', (col) =>
|
.addColumn('page_id', 'uuid', (col) =>
|
||||||
col.references('pages.id').onDelete('cascade').notNull(),
|
col.references('pages.id').onDelete('cascade').notNull(),
|
||||||
|
@ -4,7 +4,7 @@ export async function up(db: Kysely<any>): Promise<void> {
|
|||||||
await db.schema
|
await db.schema
|
||||||
.createTable('comments')
|
.createTable('comments')
|
||||||
.addColumn('id', 'uuid', (col) =>
|
.addColumn('id', 'uuid', (col) =>
|
||||||
col.primaryKey().defaultTo(sql`gen_random_uuid()`),
|
col.primaryKey().defaultTo(sql`gen_uuid_v7()`),
|
||||||
)
|
)
|
||||||
.addColumn('content', 'jsonb', (col) => col)
|
.addColumn('content', 'jsonb', (col) => col)
|
||||||
.addColumn('selection', 'varchar', (col) => col)
|
.addColumn('selection', 'varchar', (col) => col)
|
||||||
|
@ -4,7 +4,7 @@ export async function up(db: Kysely<any>): Promise<void> {
|
|||||||
await db.schema
|
await db.schema
|
||||||
.createTable('attachments')
|
.createTable('attachments')
|
||||||
.addColumn('id', 'uuid', (col) =>
|
.addColumn('id', 'uuid', (col) =>
|
||||||
col.primaryKey().defaultTo(sql`gen_random_uuid()`),
|
col.primaryKey().defaultTo(sql`gen_uuid_v7()`),
|
||||||
)
|
)
|
||||||
.addColumn('file_name', 'varchar', (col) => col.notNull())
|
.addColumn('file_name', 'varchar', (col) => col.notNull())
|
||||||
.addColumn('file_path', 'varchar', (col) => col.notNull())
|
.addColumn('file_path', 'varchar', (col) => col.notNull())
|
||||||
|
16
pnpm-lock.yaml
generated
16
pnpm-lock.yaml
generated
@ -3914,8 +3914,8 @@ packages:
|
|||||||
'@types/uuid@10.0.0':
|
'@types/uuid@10.0.0':
|
||||||
resolution: {integrity: sha512-7gqG38EyHgyP1S+7+xomFtL+ZNHcKv6DwNaCZmJmo1vgMugyF3TCnXVg4t1uk89mLNwnLtnY3TpOpCOyp1/xHQ==}
|
resolution: {integrity: sha512-7gqG38EyHgyP1S+7+xomFtL+ZNHcKv6DwNaCZmJmo1vgMugyF3TCnXVg4t1uk89mLNwnLtnY3TpOpCOyp1/xHQ==}
|
||||||
|
|
||||||
'@types/validator@13.11.9':
|
'@types/validator@13.12.0':
|
||||||
resolution: {integrity: sha512-FCTsikRozryfayPuiI46QzH3fnrOoctTjvOYZkho9BTFLCOZ2rgZJHMOVgCOfttjPJcgOx52EpkY0CMfy87MIw==}
|
resolution: {integrity: sha512-nH45Lk7oPIJ1RVOF6JgFI6Dy0QpHEzq4QecZhvguxYPDwT8c93prCMqAtiIttm39voZ+DDR+qkNnMpJmMBRqag==}
|
||||||
|
|
||||||
'@types/webpack@5.28.5':
|
'@types/webpack@5.28.5':
|
||||||
resolution: {integrity: sha512-wR87cgvxj3p6D0Crt1r5avwqffqPXUkNlnQ1mjU93G7gCuFjufZR4I6j8cz5g1F1tTYpfOOFvly+cmIQwL9wvw==}
|
resolution: {integrity: sha512-wR87cgvxj3p6D0Crt1r5avwqffqPXUkNlnQ1mjU93G7gCuFjufZR4I6j8cz5g1F1tTYpfOOFvly+cmIQwL9wvw==}
|
||||||
@ -7749,8 +7749,8 @@ packages:
|
|||||||
resolution: {integrity: sha512-YuKoXDAhBYxY7SfOKxHBDoSyENFeW5VvIIQp2TGQuit8gpK6MnWaQelBKxso72DoxTZfZdcP3W90LqpSkgPzLQ==}
|
resolution: {integrity: sha512-YuKoXDAhBYxY7SfOKxHBDoSyENFeW5VvIIQp2TGQuit8gpK6MnWaQelBKxso72DoxTZfZdcP3W90LqpSkgPzLQ==}
|
||||||
engines: {node: ^14.17.0 || ^16.13.0 || >=18.0.0}
|
engines: {node: ^14.17.0 || ^16.13.0 || >=18.0.0}
|
||||||
|
|
||||||
validator@13.11.0:
|
validator@13.12.0:
|
||||||
resolution: {integrity: sha512-Ii+sehpSfZy+At5nPdnyMhx78fEoPDkR2XW/zimHEL3MyGJQOCQ7WeP20jPYRz7ZCpcKLB21NxuXHF3bxjStBQ==}
|
resolution: {integrity: sha512-c1Q0mCiPlgdTVVVIJIrBuxNicYE+t/7oKeI9MWLj3fh/uq2Pxh/3eeWbVZ4OcGW1TUf53At0njHw5SMdA3tmMg==}
|
||||||
engines: {node: '>= 0.10'}
|
engines: {node: '>= 0.10'}
|
||||||
|
|
||||||
vary@1.1.2:
|
vary@1.1.2:
|
||||||
@ -12134,7 +12134,7 @@ snapshots:
|
|||||||
|
|
||||||
'@types/uuid@10.0.0': {}
|
'@types/uuid@10.0.0': {}
|
||||||
|
|
||||||
'@types/validator@13.11.9': {}
|
'@types/validator@13.12.0': {}
|
||||||
|
|
||||||
'@types/webpack@5.28.5(@swc/core@1.3.101(@swc/helpers@0.5.11))(esbuild@0.19.11)':
|
'@types/webpack@5.28.5(@swc/core@1.3.101(@swc/helpers@0.5.11))(esbuild@0.19.11)':
|
||||||
dependencies:
|
dependencies:
|
||||||
@ -12843,9 +12843,9 @@ snapshots:
|
|||||||
|
|
||||||
class-validator@0.14.1:
|
class-validator@0.14.1:
|
||||||
dependencies:
|
dependencies:
|
||||||
'@types/validator': 13.11.9
|
'@types/validator': 13.12.0
|
||||||
libphonenumber-js: 1.10.58
|
libphonenumber-js: 1.10.58
|
||||||
validator: 13.11.0
|
validator: 13.12.0
|
||||||
|
|
||||||
cli-cursor@3.1.0:
|
cli-cursor@3.1.0:
|
||||||
dependencies:
|
dependencies:
|
||||||
@ -16539,7 +16539,7 @@ snapshots:
|
|||||||
dependencies:
|
dependencies:
|
||||||
builtins: 5.0.1
|
builtins: 5.0.1
|
||||||
|
|
||||||
validator@13.11.0: {}
|
validator@13.12.0: {}
|
||||||
|
|
||||||
vary@1.1.2: {}
|
vary@1.1.2: {}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user