mirror of
https://github.com/immich-app/immich
synced 2025-11-14 17:36:12 +00:00
feat: rename schema (#19891)
This commit is contained in:
parent
33c29e4305
commit
c699df002a
103 changed files with 4378 additions and 3224 deletions
|
|
@ -28,7 +28,7 @@ export const album_user_after_insert = registerFunction({
|
|||
language: 'PLPGSQL',
|
||||
body: `
|
||||
BEGIN
|
||||
UPDATE albums SET "updatedAt" = clock_timestamp(), "updateId" = immich_uuid_v7(clock_timestamp())
|
||||
UPDATE album SET "updatedAt" = clock_timestamp(), "updateId" = immich_uuid_v7(clock_timestamp())
|
||||
WHERE "id" IN (SELECT DISTINCT "albumsId" FROM inserted_rows);
|
||||
RETURN NULL;
|
||||
END`,
|
||||
|
|
@ -80,83 +80,83 @@ export const ll_to_earth_public = registerFunction({
|
|||
body: `SELECT public.cube(public.cube(public.cube(public.earth()*cos(radians(latitude))*cos(radians(longitude))),public.earth()*cos(radians(latitude))*sin(radians(longitude))),public.earth()*sin(radians(latitude)))::public.earth`,
|
||||
});
|
||||
|
||||
export const users_delete_audit = registerFunction({
|
||||
name: 'users_delete_audit',
|
||||
export const user_delete_audit = registerFunction({
|
||||
name: 'user_delete_audit',
|
||||
returnType: 'TRIGGER',
|
||||
language: 'PLPGSQL',
|
||||
body: `
|
||||
BEGIN
|
||||
INSERT INTO users_audit ("userId")
|
||||
INSERT INTO user_audit ("userId")
|
||||
SELECT "id"
|
||||
FROM OLD;
|
||||
RETURN NULL;
|
||||
END`,
|
||||
});
|
||||
|
||||
export const partners_delete_audit = registerFunction({
|
||||
name: 'partners_delete_audit',
|
||||
export const partner_delete_audit = registerFunction({
|
||||
name: 'partner_delete_audit',
|
||||
returnType: 'TRIGGER',
|
||||
language: 'PLPGSQL',
|
||||
body: `
|
||||
BEGIN
|
||||
INSERT INTO partners_audit ("sharedById", "sharedWithId")
|
||||
INSERT INTO partner_audit ("sharedById", "sharedWithId")
|
||||
SELECT "sharedById", "sharedWithId"
|
||||
FROM OLD;
|
||||
RETURN NULL;
|
||||
END`,
|
||||
});
|
||||
|
||||
export const assets_delete_audit = registerFunction({
|
||||
name: 'assets_delete_audit',
|
||||
export const asset_delete_audit = registerFunction({
|
||||
name: 'asset_delete_audit',
|
||||
returnType: 'TRIGGER',
|
||||
language: 'PLPGSQL',
|
||||
body: `
|
||||
BEGIN
|
||||
INSERT INTO assets_audit ("assetId", "ownerId")
|
||||
INSERT INTO asset_audit ("assetId", "ownerId")
|
||||
SELECT "id", "ownerId"
|
||||
FROM OLD;
|
||||
RETURN NULL;
|
||||
END`,
|
||||
});
|
||||
|
||||
export const albums_delete_audit = registerFunction({
|
||||
name: 'albums_delete_audit',
|
||||
export const album_delete_audit = registerFunction({
|
||||
name: 'album_delete_audit',
|
||||
returnType: 'TRIGGER',
|
||||
language: 'PLPGSQL',
|
||||
body: `
|
||||
BEGIN
|
||||
INSERT INTO albums_audit ("albumId", "userId")
|
||||
INSERT INTO album_audit ("albumId", "userId")
|
||||
SELECT "id", "ownerId"
|
||||
FROM OLD;
|
||||
RETURN NULL;
|
||||
END`,
|
||||
});
|
||||
|
||||
export const album_assets_delete_audit = registerFunction({
|
||||
name: 'album_assets_delete_audit',
|
||||
export const album_asset_delete_audit = registerFunction({
|
||||
name: 'album_asset_delete_audit',
|
||||
returnType: 'TRIGGER',
|
||||
language: 'PLPGSQL',
|
||||
body: `
|
||||
BEGIN
|
||||
INSERT INTO album_assets_audit ("albumId", "assetId")
|
||||
INSERT INTO album_asset_audit ("albumId", "assetId")
|
||||
SELECT "albumsId", "assetsId" FROM OLD
|
||||
WHERE "albumsId" IN (SELECT "id" FROM albums WHERE "id" IN (SELECT "albumsId" FROM OLD));
|
||||
WHERE "albumsId" IN (SELECT "id" FROM album WHERE "id" IN (SELECT "albumsId" FROM OLD));
|
||||
RETURN NULL;
|
||||
END`,
|
||||
});
|
||||
|
||||
export const album_users_delete_audit = registerFunction({
|
||||
name: 'album_users_delete_audit',
|
||||
export const album_user_delete_audit = registerFunction({
|
||||
name: 'album_user_delete_audit',
|
||||
returnType: 'TRIGGER',
|
||||
language: 'PLPGSQL',
|
||||
body: `
|
||||
BEGIN
|
||||
INSERT INTO albums_audit ("albumId", "userId")
|
||||
INSERT INTO album_audit ("albumId", "userId")
|
||||
SELECT "albumsId", "usersId"
|
||||
FROM OLD;
|
||||
|
||||
IF pg_trigger_depth() = 1 THEN
|
||||
INSERT INTO album_users_audit ("albumId", "userId")
|
||||
INSERT INTO album_user_audit ("albumId", "userId")
|
||||
SELECT "albumsId", "usersId"
|
||||
FROM OLD;
|
||||
END IF;
|
||||
|
|
@ -165,39 +165,39 @@ export const album_users_delete_audit = registerFunction({
|
|||
END`,
|
||||
});
|
||||
|
||||
export const memories_delete_audit = registerFunction({
|
||||
name: 'memories_delete_audit',
|
||||
export const memory_delete_audit = registerFunction({
|
||||
name: 'memory_delete_audit',
|
||||
returnType: 'TRIGGER',
|
||||
language: 'PLPGSQL',
|
||||
body: `
|
||||
BEGIN
|
||||
INSERT INTO memories_audit ("memoryId", "userId")
|
||||
INSERT INTO memory_audit ("memoryId", "userId")
|
||||
SELECT "id", "ownerId"
|
||||
FROM OLD;
|
||||
RETURN NULL;
|
||||
END`,
|
||||
});
|
||||
|
||||
export const memory_assets_delete_audit = registerFunction({
|
||||
name: 'memory_assets_delete_audit',
|
||||
export const memory_asset_delete_audit = registerFunction({
|
||||
name: 'memory_asset_delete_audit',
|
||||
returnType: 'TRIGGER',
|
||||
language: 'PLPGSQL',
|
||||
body: `
|
||||
BEGIN
|
||||
INSERT INTO memory_assets_audit ("memoryId", "assetId")
|
||||
INSERT INTO memory_asset_audit ("memoryId", "assetId")
|
||||
SELECT "memoriesId", "assetsId" FROM OLD
|
||||
WHERE "memoriesId" IN (SELECT "id" FROM memories WHERE "id" IN (SELECT "memoriesId" FROM OLD));
|
||||
WHERE "memoriesId" IN (SELECT "id" FROM memory WHERE "id" IN (SELECT "memoriesId" FROM OLD));
|
||||
RETURN NULL;
|
||||
END`,
|
||||
});
|
||||
|
||||
export const stacks_delete_audit = registerFunction({
|
||||
name: 'stacks_delete_audit',
|
||||
export const stack_delete_audit = registerFunction({
|
||||
name: 'stack_delete_audit',
|
||||
returnType: 'TRIGGER',
|
||||
language: 'PLPGSQL',
|
||||
body: `
|
||||
BEGIN
|
||||
INSERT INTO stacks_audit ("stackId", "userId")
|
||||
INSERT INTO stack_audit ("stackId", "userId")
|
||||
SELECT "id", "ownerId"
|
||||
FROM OLD;
|
||||
RETURN NULL;
|
||||
|
|
|
|||
|
|
@ -1,20 +1,21 @@
|
|||
import { asset_face_source_type, asset_visibility_enum, assets_status_enum } from 'src/schema/enums';
|
||||
import {
|
||||
album_delete_audit,
|
||||
album_user_after_insert,
|
||||
album_users_delete_audit,
|
||||
albums_delete_audit,
|
||||
assets_delete_audit,
|
||||
album_user_delete_audit,
|
||||
asset_delete_audit,
|
||||
f_concat_ws,
|
||||
f_unaccent,
|
||||
immich_uuid_v7,
|
||||
ll_to_earth_public,
|
||||
memories_delete_audit,
|
||||
memory_assets_delete_audit,
|
||||
partners_delete_audit,
|
||||
memory_asset_delete_audit,
|
||||
memory_delete_audit,
|
||||
partner_delete_audit,
|
||||
person_delete_audit,
|
||||
stacks_delete_audit,
|
||||
stack_delete_audit,
|
||||
updated_at,
|
||||
users_delete_audit,
|
||||
user_delete_audit,
|
||||
user_metadata_audit,
|
||||
} from 'src/schema/functions';
|
||||
import { ActivityTable } from 'src/schema/tables/activity.table';
|
||||
import { AlbumAssetAuditTable } from 'src/schema/tables/album-asset-audit.table';
|
||||
|
|
@ -25,12 +26,12 @@ import { AlbumUserTable } from 'src/schema/tables/album-user.table';
|
|||
import { AlbumTable } from 'src/schema/tables/album.table';
|
||||
import { ApiKeyTable } from 'src/schema/tables/api-key.table';
|
||||
import { AssetAuditTable } from 'src/schema/tables/asset-audit.table';
|
||||
import { AssetExifTable } from 'src/schema/tables/asset-exif.table';
|
||||
import { AssetFaceTable } from 'src/schema/tables/asset-face.table';
|
||||
import { AssetFileTable } from 'src/schema/tables/asset-files.table';
|
||||
import { AssetFileTable } from 'src/schema/tables/asset-file.table';
|
||||
import { AssetJobStatusTable } from 'src/schema/tables/asset-job-status.table';
|
||||
import { AssetTable } from 'src/schema/tables/asset.table';
|
||||
import { AuditTable } from 'src/schema/tables/audit.table';
|
||||
import { ExifTable } from 'src/schema/tables/exif.table';
|
||||
import { FaceSearchTable } from 'src/schema/tables/face-search.table';
|
||||
import { GeodataPlacesTable } from 'src/schema/tables/geodata-places.table';
|
||||
import { LibraryTable } from 'src/schema/tables/library.table';
|
||||
|
|
@ -81,7 +82,7 @@ export class ImmichDatabase {
|
|||
AssetTable,
|
||||
AssetFileTable,
|
||||
AuditTable,
|
||||
ExifTable,
|
||||
AssetExifTable,
|
||||
FaceSearchTable,
|
||||
GeodataPlacesTable,
|
||||
LibraryTable,
|
||||
|
|
@ -120,17 +121,17 @@ export class ImmichDatabase {
|
|||
f_concat_ws,
|
||||
f_unaccent,
|
||||
ll_to_earth_public,
|
||||
users_delete_audit,
|
||||
partners_delete_audit,
|
||||
assets_delete_audit,
|
||||
albums_delete_audit,
|
||||
user_delete_audit,
|
||||
partner_delete_audit,
|
||||
asset_delete_audit,
|
||||
album_delete_audit,
|
||||
album_user_after_insert,
|
||||
album_users_delete_audit,
|
||||
memories_delete_audit,
|
||||
memory_assets_delete_audit,
|
||||
stacks_delete_audit,
|
||||
album_user_delete_audit,
|
||||
memory_delete_audit,
|
||||
memory_asset_delete_audit,
|
||||
stack_delete_audit,
|
||||
person_delete_audit,
|
||||
users_delete_audit,
|
||||
user_metadata_audit,
|
||||
];
|
||||
|
||||
enum = [assets_status_enum, asset_face_source_type, asset_visibility_enum];
|
||||
|
|
@ -144,49 +145,71 @@ export interface Migrations {
|
|||
|
||||
export interface DB {
|
||||
activity: ActivityTable;
|
||||
albums: AlbumTable;
|
||||
albums_audit: AlbumAuditTable;
|
||||
albums_assets_assets: AlbumAssetTable;
|
||||
album_assets_audit: AlbumAssetAuditTable;
|
||||
albums_shared_users_users: AlbumUserTable;
|
||||
album_users_audit: AlbumUserAuditTable;
|
||||
api_keys: ApiKeyTable;
|
||||
asset_faces: AssetFaceTable;
|
||||
asset_files: AssetFileTable;
|
||||
|
||||
album: AlbumTable;
|
||||
album_audit: AlbumAuditTable;
|
||||
album_asset: AlbumAssetTable;
|
||||
album_asset_audit: AlbumAssetAuditTable;
|
||||
album_user: AlbumUserTable;
|
||||
album_user_audit: AlbumUserAuditTable;
|
||||
|
||||
api_key: ApiKeyTable;
|
||||
|
||||
asset: AssetTable;
|
||||
asset_exif: AssetExifTable;
|
||||
asset_face: AssetFaceTable;
|
||||
asset_file: AssetFileTable;
|
||||
asset_job_status: AssetJobStatusTable;
|
||||
asset_stack: StackTable;
|
||||
assets: AssetTable;
|
||||
assets_audit: AssetAuditTable;
|
||||
asset_audit: AssetAuditTable;
|
||||
|
||||
audit: AuditTable;
|
||||
exif: ExifTable;
|
||||
|
||||
face_search: FaceSearchTable;
|
||||
|
||||
geodata_places: GeodataPlacesTable;
|
||||
libraries: LibraryTable;
|
||||
memories: MemoryTable;
|
||||
memories_audit: MemoryAuditTable;
|
||||
memories_assets_assets: MemoryAssetTable;
|
||||
memory_assets_audit: MemoryAssetAuditTable;
|
||||
|
||||
library: LibraryTable;
|
||||
|
||||
memory: MemoryTable;
|
||||
memory_audit: MemoryAuditTable;
|
||||
memory_asset: MemoryAssetTable;
|
||||
memory_asset_audit: MemoryAssetAuditTable;
|
||||
|
||||
migrations: Migrations;
|
||||
notifications: NotificationTable;
|
||||
|
||||
notification: NotificationTable;
|
||||
|
||||
move_history: MoveTable;
|
||||
|
||||
naturalearth_countries: NaturalEarthCountriesTable;
|
||||
partners_audit: PartnerAuditTable;
|
||||
partners: PartnerTable;
|
||||
|
||||
partner: PartnerTable;
|
||||
partner_audit: PartnerAuditTable;
|
||||
|
||||
person: PersonTable;
|
||||
person_audit: PersonAuditTable;
|
||||
sessions: SessionTable;
|
||||
session_sync_checkpoints: SessionSyncCheckpointTable;
|
||||
shared_link__asset: SharedLinkAssetTable;
|
||||
shared_links: SharedLinkTable;
|
||||
|
||||
session: SessionTable;
|
||||
session_sync_checkpoint: SessionSyncCheckpointTable;
|
||||
|
||||
shared_link: SharedLinkTable;
|
||||
shared_link_asset: SharedLinkAssetTable;
|
||||
|
||||
smart_search: SmartSearchTable;
|
||||
stacks_audit: StackAuditTable;
|
||||
|
||||
stack: StackTable;
|
||||
stack_audit: StackAuditTable;
|
||||
|
||||
system_metadata: SystemMetadataTable;
|
||||
|
||||
tag: TagTable;
|
||||
tag_asset: TagAssetTable;
|
||||
tags: TagTable;
|
||||
tags_closure: TagClosureTable;
|
||||
tag_closure: TagClosureTable;
|
||||
|
||||
user: UserTable;
|
||||
user_audit: UserAuditTable;
|
||||
user_metadata: UserMetadataTable;
|
||||
user_metadata_audit: UserMetadataAuditTable;
|
||||
users: UserTable;
|
||||
users_audit: UserAuditTable;
|
||||
|
||||
version_history: VersionHistoryTable;
|
||||
}
|
||||
|
|
|
|||
1200
server/src/schema/migrations/1752267649968-StandardizeNames.ts
Normal file
1200
server/src/schema/migrations/1752267649968-StandardizeNames.ts
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -18,19 +18,18 @@ import {
|
|||
} from 'src/sql-tools';
|
||||
|
||||
@Table('activity')
|
||||
@UpdatedAtTrigger('activity_updated_at')
|
||||
@UpdatedAtTrigger('activity_updatedAt')
|
||||
@Index({
|
||||
name: 'IDX_activity_like',
|
||||
name: 'activity_like_idx',
|
||||
columns: ['assetId', 'userId', 'albumId'],
|
||||
unique: true,
|
||||
where: '("isLiked" = true)',
|
||||
})
|
||||
@Check({
|
||||
name: 'CHK_2ab1e70f113f450eb40c1e3ec8',
|
||||
expression: `("comment" IS NULL AND "isLiked" = true) OR ("comment" IS NOT NULL AND "isLiked" = false)`,
|
||||
name: 'activity_like_check',
|
||||
expression: `(comment IS NULL AND "isLiked" = true) OR (comment IS NOT NULL AND "isLiked" = false)`,
|
||||
})
|
||||
@ForeignKeyConstraint({
|
||||
name: 'fk_activity_album_asset_composite',
|
||||
columns: ['albumId', 'assetId'],
|
||||
referenceTable: () => AlbumAssetTable,
|
||||
referenceColumns: ['albumsId', 'assetsId'],
|
||||
|
|
@ -62,6 +61,6 @@ export class ActivityTable {
|
|||
@Column({ type: 'boolean', default: false })
|
||||
isLiked!: Generated<boolean>;
|
||||
|
||||
@UpdateIdColumn({ indexName: 'IDX_activity_update_id' })
|
||||
@UpdateIdColumn({ index: true })
|
||||
updateId!: Generated<string>;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,22 +2,20 @@ import { PrimaryGeneratedUuidV7Column } from 'src/decorators';
|
|||
import { AlbumTable } from 'src/schema/tables/album.table';
|
||||
import { Column, CreateDateColumn, ForeignKeyColumn, Generated, Table, Timestamp } from 'src/sql-tools';
|
||||
|
||||
@Table('album_assets_audit')
|
||||
@Table('album_asset_audit')
|
||||
export class AlbumAssetAuditTable {
|
||||
@PrimaryGeneratedUuidV7Column()
|
||||
id!: Generated<string>;
|
||||
|
||||
@ForeignKeyColumn(() => AlbumTable, {
|
||||
type: 'uuid',
|
||||
indexName: 'IDX_album_assets_audit_album_id',
|
||||
onDelete: 'CASCADE',
|
||||
onUpdate: 'CASCADE',
|
||||
})
|
||||
albumId!: string;
|
||||
|
||||
@Column({ type: 'uuid', indexName: 'IDX_album_assets_audit_asset_id' })
|
||||
@Column({ type: 'uuid', index: true })
|
||||
assetId!: string;
|
||||
|
||||
@CreateDateColumn({ default: () => 'clock_timestamp()', indexName: 'IDX_album_assets_audit_deleted_at' })
|
||||
@CreateDateColumn({ default: () => 'clock_timestamp()', index: true })
|
||||
deletedAt!: Generated<Timestamp>;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { UpdatedAtTrigger, UpdateIdColumn } from 'src/decorators';
|
||||
import { album_assets_delete_audit } from 'src/schema/functions';
|
||||
import { album_asset_delete_audit } from 'src/schema/functions';
|
||||
import { AlbumTable } from 'src/schema/tables/album.table';
|
||||
import { AssetTable } from 'src/schema/tables/asset.table';
|
||||
import {
|
||||
|
|
@ -12,11 +12,11 @@ import {
|
|||
UpdateDateColumn,
|
||||
} from 'src/sql-tools';
|
||||
|
||||
@Table({ name: 'albums_assets_assets', primaryConstraintName: 'PK_c67bc36fa845fb7b18e0e398180' })
|
||||
@UpdatedAtTrigger('album_assets_updated_at')
|
||||
@Table({ name: 'album_asset' })
|
||||
@UpdatedAtTrigger('album_asset_updatedAt')
|
||||
@AfterDeleteTrigger({
|
||||
scope: 'statement',
|
||||
function: album_assets_delete_audit,
|
||||
function: album_asset_delete_audit,
|
||||
referencingOldTableAs: 'old',
|
||||
when: 'pg_trigger_depth() <= 1',
|
||||
})
|
||||
|
|
@ -33,6 +33,6 @@ export class AlbumAssetTable {
|
|||
@UpdateDateColumn()
|
||||
updatedAt!: Generated<Timestamp>;
|
||||
|
||||
@UpdateIdColumn({ indexName: 'IDX_album_assets_update_id' })
|
||||
@UpdateIdColumn({ index: true })
|
||||
updateId!: Generated<string>;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,17 +1,17 @@
|
|||
import { PrimaryGeneratedUuidV7Column } from 'src/decorators';
|
||||
import { Column, CreateDateColumn, Generated, Table, Timestamp } from 'src/sql-tools';
|
||||
|
||||
@Table('albums_audit')
|
||||
@Table('album_audit')
|
||||
export class AlbumAuditTable {
|
||||
@PrimaryGeneratedUuidV7Column()
|
||||
id!: Generated<string>;
|
||||
|
||||
@Column({ type: 'uuid', indexName: 'IDX_albums_audit_album_id' })
|
||||
@Column({ type: 'uuid', index: true })
|
||||
albumId!: string;
|
||||
|
||||
@Column({ type: 'uuid', indexName: 'IDX_albums_audit_user_id' })
|
||||
@Column({ type: 'uuid', index: true })
|
||||
userId!: string;
|
||||
|
||||
@CreateDateColumn({ default: () => 'clock_timestamp()', indexName: 'IDX_albums_audit_deleted_at' })
|
||||
@CreateDateColumn({ default: () => 'clock_timestamp()', index: true })
|
||||
deletedAt!: Generated<Timestamp>;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,17 +1,17 @@
|
|||
import { PrimaryGeneratedUuidV7Column } from 'src/decorators';
|
||||
import { Column, CreateDateColumn, Generated, Table, Timestamp } from 'src/sql-tools';
|
||||
|
||||
@Table('album_users_audit')
|
||||
@Table('album_user_audit')
|
||||
export class AlbumUserAuditTable {
|
||||
@PrimaryGeneratedUuidV7Column()
|
||||
id!: Generated<string>;
|
||||
|
||||
@Column({ type: 'uuid', indexName: 'IDX_album_users_audit_album_id' })
|
||||
@Column({ type: 'uuid', index: true })
|
||||
albumId!: string;
|
||||
|
||||
@Column({ type: 'uuid', indexName: 'IDX_album_users_audit_user_id' })
|
||||
@Column({ type: 'uuid', index: true })
|
||||
userId!: string;
|
||||
|
||||
@CreateDateColumn({ default: () => 'clock_timestamp()', indexName: 'IDX_album_users_audit_deleted_at' })
|
||||
@CreateDateColumn({ default: () => 'clock_timestamp()', index: true })
|
||||
deletedAt!: Generated<Timestamp>;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { CreateIdColumn, UpdatedAtTrigger, UpdateIdColumn } from 'src/decorators';
|
||||
import { AlbumUserRole } from 'src/enum';
|
||||
import { album_user_after_insert, album_users_delete_audit } from 'src/schema/functions';
|
||||
import { album_user_after_insert, album_user_delete_audit } from 'src/schema/functions';
|
||||
import { AlbumTable } from 'src/schema/tables/album.table';
|
||||
import { UserTable } from 'src/schema/tables/user.table';
|
||||
import {
|
||||
|
|
@ -10,17 +10,14 @@ import {
|
|||
CreateDateColumn,
|
||||
ForeignKeyColumn,
|
||||
Generated,
|
||||
Index,
|
||||
Table,
|
||||
Timestamp,
|
||||
UpdateDateColumn,
|
||||
} from 'src/sql-tools';
|
||||
|
||||
@Table({ name: 'albums_shared_users_users', primaryConstraintName: 'PK_7df55657e0b2e8b626330a0ebc8' })
|
||||
@Table({ name: 'album_user' })
|
||||
// Pre-existing indices from original album <--> user ManyToMany mapping
|
||||
@Index({ name: 'IDX_427c350ad49bd3935a50baab73', columns: ['albumsId'] })
|
||||
@Index({ name: 'IDX_f48513bf9bccefd6ff3ad30bd0', columns: ['usersId'] })
|
||||
@UpdatedAtTrigger('album_users_updated_at')
|
||||
@UpdatedAtTrigger('album_user_updatedAt')
|
||||
@AfterInsertTrigger({
|
||||
name: 'album_user_after_insert',
|
||||
scope: 'statement',
|
||||
|
|
@ -29,7 +26,7 @@ import {
|
|||
})
|
||||
@AfterDeleteTrigger({
|
||||
scope: 'statement',
|
||||
function: album_users_delete_audit,
|
||||
function: album_user_delete_audit,
|
||||
referencingOldTableAs: 'old',
|
||||
when: 'pg_trigger_depth() <= 1',
|
||||
})
|
||||
|
|
@ -53,13 +50,13 @@ export class AlbumUserTable {
|
|||
@Column({ type: 'character varying', default: AlbumUserRole.EDITOR })
|
||||
role!: Generated<AlbumUserRole>;
|
||||
|
||||
@CreateIdColumn({ indexName: 'IDX_album_users_create_id' })
|
||||
@CreateIdColumn({ index: true })
|
||||
createId!: Generated<string>;
|
||||
|
||||
@CreateDateColumn()
|
||||
createdAt!: Generated<Timestamp>;
|
||||
|
||||
@UpdateIdColumn({ indexName: 'IDX_album_users_update_id' })
|
||||
@UpdateIdColumn({ index: true })
|
||||
updateId!: Generated<string>;
|
||||
|
||||
@UpdateDateColumn()
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { UpdatedAtTrigger, UpdateIdColumn } from 'src/decorators';
|
||||
import { AssetOrder } from 'src/enum';
|
||||
import { albums_delete_audit } from 'src/schema/functions';
|
||||
import { album_delete_audit } from 'src/schema/functions';
|
||||
import { AssetTable } from 'src/schema/tables/asset.table';
|
||||
import { UserTable } from 'src/schema/tables/user.table';
|
||||
import {
|
||||
|
|
@ -16,11 +16,11 @@ import {
|
|||
UpdateDateColumn,
|
||||
} from 'src/sql-tools';
|
||||
|
||||
@Table({ name: 'albums', primaryConstraintName: 'PK_7f71c7b5bc7c87b8f94c9a93a00' })
|
||||
@UpdatedAtTrigger('albums_updated_at')
|
||||
@Table({ name: 'album' })
|
||||
@UpdatedAtTrigger('album_updatedAt')
|
||||
@AfterDeleteTrigger({
|
||||
scope: 'statement',
|
||||
function: albums_delete_audit,
|
||||
function: album_delete_audit,
|
||||
referencingOldTableAs: 'old',
|
||||
when: 'pg_trigger_depth() = 0',
|
||||
})
|
||||
|
|
@ -60,6 +60,6 @@ export class AlbumTable {
|
|||
@Column({ default: AssetOrder.DESC })
|
||||
order!: Generated<AssetOrder>;
|
||||
|
||||
@UpdateIdColumn({ indexName: 'IDX_albums_update_id' })
|
||||
@UpdateIdColumn({ index: true })
|
||||
updateId!: Generated<string>;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,8 +12,8 @@ import {
|
|||
UpdateDateColumn,
|
||||
} from 'src/sql-tools';
|
||||
|
||||
@Table('api_keys')
|
||||
@UpdatedAtTrigger('api_keys_updated_at')
|
||||
@Table('api_key')
|
||||
@UpdatedAtTrigger('api_key_updatedAt')
|
||||
export class ApiKeyTable {
|
||||
@PrimaryGeneratedColumn()
|
||||
id!: Generated<string>;
|
||||
|
|
@ -36,6 +36,6 @@ export class ApiKeyTable {
|
|||
@Column({ array: true, type: 'character varying' })
|
||||
permissions!: Permission[];
|
||||
|
||||
@UpdateIdColumn({ indexName: 'IDX_api_keys_update_id' })
|
||||
@UpdateIdColumn({ index: true })
|
||||
updateId!: Generated<string>;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,17 +1,17 @@
|
|||
import { PrimaryGeneratedUuidV7Column } from 'src/decorators';
|
||||
import { Column, CreateDateColumn, Generated, Table, Timestamp } from 'src/sql-tools';
|
||||
|
||||
@Table('assets_audit')
|
||||
@Table('asset_audit')
|
||||
export class AssetAuditTable {
|
||||
@PrimaryGeneratedUuidV7Column()
|
||||
id!: Generated<string>;
|
||||
|
||||
@Column({ type: 'uuid', indexName: 'IDX_assets_audit_asset_id' })
|
||||
@Column({ type: 'uuid', index: true })
|
||||
assetId!: string;
|
||||
|
||||
@Column({ type: 'uuid', indexName: 'IDX_assets_audit_owner_id' })
|
||||
@Column({ type: 'uuid', index: true })
|
||||
ownerId!: string;
|
||||
|
||||
@CreateDateColumn({ default: () => 'clock_timestamp()', indexName: 'IDX_assets_audit_deleted_at' })
|
||||
@CreateDateColumn({ default: () => 'clock_timestamp()', index: true })
|
||||
deletedAt!: Generated<Timestamp>;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,9 +2,9 @@ import { UpdatedAtTrigger, UpdateIdColumn } from 'src/decorators';
|
|||
import { AssetTable } from 'src/schema/tables/asset.table';
|
||||
import { Column, ForeignKeyColumn, Generated, Int8, Table, Timestamp, UpdateDateColumn } from 'src/sql-tools';
|
||||
|
||||
@Table('exif')
|
||||
@UpdatedAtTrigger('asset_exif_updated_at')
|
||||
export class ExifTable {
|
||||
@Table('asset_exif')
|
||||
@UpdatedAtTrigger('asset_exif_updatedAt')
|
||||
export class AssetExifTable {
|
||||
@ForeignKeyColumn(() => AssetTable, { onDelete: 'CASCADE', primary: true })
|
||||
assetId!: string;
|
||||
|
||||
|
|
@ -50,7 +50,7 @@ export class ExifTable {
|
|||
@Column({ type: 'double precision', nullable: true })
|
||||
longitude!: number | null;
|
||||
|
||||
@Column({ type: 'character varying', nullable: true, indexName: 'exif_city' })
|
||||
@Column({ type: 'character varying', nullable: true, index: true })
|
||||
city!: string | null;
|
||||
|
||||
@Column({ type: 'character varying', nullable: true })
|
||||
|
|
@ -68,7 +68,7 @@ export class ExifTable {
|
|||
@Column({ type: 'character varying', nullable: true })
|
||||
exposureTime!: string | null;
|
||||
|
||||
@Column({ type: 'character varying', nullable: true, indexName: 'IDX_live_photo_cid' })
|
||||
@Column({ type: 'character varying', nullable: true, index: true })
|
||||
livePhotoCID!: string | null;
|
||||
|
||||
@Column({ type: 'character varying', nullable: true })
|
||||
|
|
@ -86,7 +86,7 @@ export class ExifTable {
|
|||
@Column({ type: 'integer', nullable: true })
|
||||
bitsPerSample!: number | null;
|
||||
|
||||
@Column({ type: 'character varying', nullable: true, indexName: 'IDX_auto_stack_id' })
|
||||
@Column({ type: 'character varying', nullable: true, index: true })
|
||||
autoStackId!: string | null;
|
||||
|
||||
@Column({ type: 'integer', nullable: true })
|
||||
|
|
@ -95,6 +95,6 @@ export class ExifTable {
|
|||
@UpdateDateColumn({ default: () => 'clock_timestamp()' })
|
||||
updatedAt!: Generated<Date>;
|
||||
|
||||
@UpdateIdColumn({ indexName: 'IDX_asset_exif_update_id' })
|
||||
@UpdateIdColumn({ index: true })
|
||||
updateId!: Generated<string>;
|
||||
}
|
||||
|
|
@ -13,8 +13,9 @@ import {
|
|||
Timestamp,
|
||||
} from 'src/sql-tools';
|
||||
|
||||
@Table({ name: 'asset_faces' })
|
||||
@Index({ name: 'IDX_asset_faces_assetId_personId', columns: ['assetId', 'personId'] })
|
||||
@Table({ name: 'asset_face' })
|
||||
// schemaFromDatabase does not preserve column order
|
||||
@Index({ name: 'asset_face_assetId_personId_idx', columns: ['assetId', 'personId'] })
|
||||
@Index({ columns: ['personId', 'assetId'] })
|
||||
export class AssetFaceTable {
|
||||
@PrimaryGeneratedColumn()
|
||||
|
|
|
|||
|
|
@ -13,18 +13,14 @@ import {
|
|||
UpdateDateColumn,
|
||||
} from 'src/sql-tools';
|
||||
|
||||
@Table('asset_files')
|
||||
@Unique({ name: 'UQ_assetId_type', columns: ['assetId', 'type'] })
|
||||
@UpdatedAtTrigger('asset_files_updated_at')
|
||||
@Table('asset_file')
|
||||
@Unique({ columns: ['assetId', 'type'] })
|
||||
@UpdatedAtTrigger('asset_file_updatedAt')
|
||||
export class AssetFileTable {
|
||||
@PrimaryGeneratedColumn()
|
||||
id!: Generated<string>;
|
||||
|
||||
@ForeignKeyColumn(() => AssetTable, {
|
||||
onDelete: 'CASCADE',
|
||||
onUpdate: 'CASCADE',
|
||||
indexName: 'IDX_asset_files_assetId',
|
||||
})
|
||||
@ForeignKeyColumn(() => AssetTable, { onDelete: 'CASCADE', onUpdate: 'CASCADE' })
|
||||
assetId!: string;
|
||||
|
||||
@CreateDateColumn()
|
||||
|
|
@ -39,6 +35,6 @@ export class AssetFileTable {
|
|||
@Column()
|
||||
path!: string;
|
||||
|
||||
@UpdateIdColumn({ indexName: 'IDX_asset_files_update_id' })
|
||||
@UpdateIdColumn({ index: true })
|
||||
updateId!: Generated<string>;
|
||||
}
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
import { UpdatedAtTrigger, UpdateIdColumn } from 'src/decorators';
|
||||
import { AssetStatus, AssetType, AssetVisibility } from 'src/enum';
|
||||
import { asset_visibility_enum, assets_status_enum } from 'src/schema/enums';
|
||||
import { assets_delete_audit } from 'src/schema/functions';
|
||||
import { asset_delete_audit } from 'src/schema/functions';
|
||||
import { LibraryTable } from 'src/schema/tables/library.table';
|
||||
import { StackTable } from 'src/schema/tables/stack.table';
|
||||
import { UserTable } from 'src/schema/tables/user.table';
|
||||
|
|
@ -20,11 +20,11 @@ import {
|
|||
} from 'src/sql-tools';
|
||||
import { ASSET_CHECKSUM_CONSTRAINT } from 'src/utils/database';
|
||||
|
||||
@Table('assets')
|
||||
@UpdatedAtTrigger('assets_updated_at')
|
||||
@Table('asset')
|
||||
@UpdatedAtTrigger('asset_updatedAt')
|
||||
@AfterDeleteTrigger({
|
||||
scope: 'statement',
|
||||
function: assets_delete_audit,
|
||||
function: asset_delete_audit,
|
||||
referencingOldTableAs: 'old',
|
||||
when: 'pg_trigger_depth() = 0',
|
||||
})
|
||||
|
|
@ -36,23 +36,22 @@ import { ASSET_CHECKSUM_CONSTRAINT } from 'src/utils/database';
|
|||
where: '("libraryId" IS NULL)',
|
||||
})
|
||||
@Index({
|
||||
name: 'UQ_assets_owner_library_checksum' + '',
|
||||
columns: ['ownerId', 'libraryId', 'checksum'],
|
||||
unique: true,
|
||||
where: '("libraryId" IS NOT NULL)',
|
||||
})
|
||||
@Index({
|
||||
name: 'idx_local_date_time',
|
||||
name: 'asset_localDateTime_idx',
|
||||
expression: `(("localDateTime" at time zone 'UTC')::date)`,
|
||||
})
|
||||
@Index({
|
||||
name: 'idx_local_date_time_month',
|
||||
name: 'asset_localDateTime_month_idx',
|
||||
expression: `(date_trunc('MONTH'::text, ("localDateTime" AT TIME ZONE 'UTC'::text)) AT TIME ZONE 'UTC'::text)`,
|
||||
})
|
||||
@Index({ name: 'IDX_originalPath_libraryId', columns: ['originalPath', 'libraryId'] })
|
||||
@Index({ name: 'IDX_asset_id_stackId', columns: ['id', 'stackId'] })
|
||||
@Index({ columns: ['originalPath', 'libraryId'] })
|
||||
@Index({ columns: ['id', 'stackId'] })
|
||||
@Index({
|
||||
name: 'idx_originalfilename_trigram',
|
||||
name: 'asset_originalFilename_trigram_idx',
|
||||
using: 'gin',
|
||||
expression: 'f_unaccent("originalFileName") gin_trgm_ops',
|
||||
})
|
||||
|
|
@ -76,7 +75,7 @@ export class AssetTable {
|
|||
@Column()
|
||||
originalPath!: string;
|
||||
|
||||
@Column({ type: 'timestamp with time zone', indexName: 'idx_asset_file_created_at' })
|
||||
@Column({ type: 'timestamp with time zone', index: true })
|
||||
fileCreatedAt!: Timestamp;
|
||||
|
||||
@Column({ type: 'timestamp with time zone' })
|
||||
|
|
@ -130,13 +129,13 @@ export class AssetTable {
|
|||
@ForeignKeyColumn(() => StackTable, { nullable: true, onDelete: 'SET NULL', onUpdate: 'CASCADE' })
|
||||
stackId!: string | null;
|
||||
|
||||
@Column({ type: 'uuid', nullable: true, indexName: 'IDX_assets_duplicateId' })
|
||||
@Column({ type: 'uuid', nullable: true, index: true })
|
||||
duplicateId!: string | null;
|
||||
|
||||
@Column({ enum: assets_status_enum, default: AssetStatus.ACTIVE })
|
||||
status!: Generated<AssetStatus>;
|
||||
|
||||
@UpdateIdColumn({ indexName: 'IDX_assets_update_id' })
|
||||
@UpdateIdColumn({ index: true })
|
||||
updateId!: Generated<string>;
|
||||
|
||||
@Column({ enum: asset_visibility_enum, default: AssetVisibility.TIMELINE })
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import { DatabaseAction, EntityType } from 'src/enum';
|
|||
import { Column, CreateDateColumn, Generated, Index, PrimaryColumn, Table, Timestamp } from 'src/sql-tools';
|
||||
|
||||
@Table('audit')
|
||||
@Index({ name: 'IDX_ownerId_createdAt', columns: ['ownerId', 'createdAt'] })
|
||||
@Index({ columns: ['ownerId', 'createdAt'] })
|
||||
export class AuditTable {
|
||||
@PrimaryColumn({ type: 'serial', synchronize: false })
|
||||
id!: Generated<number>;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { AssetFaceTable } from 'src/schema/tables/asset-face.table';
|
||||
import { Column, ForeignKeyColumn, Index, Table } from 'src/sql-tools';
|
||||
|
||||
@Table({ name: 'face_search', primaryConstraintName: 'face_search_pkey' })
|
||||
@Table({ name: 'face_search' })
|
||||
@Index({
|
||||
name: 'face_index',
|
||||
using: 'hnsw',
|
||||
|
|
@ -9,11 +9,7 @@ import { Column, ForeignKeyColumn, Index, Table } from 'src/sql-tools';
|
|||
with: 'ef_construction = 300, m = 16',
|
||||
})
|
||||
export class FaceSearchTable {
|
||||
@ForeignKeyColumn(() => AssetFaceTable, {
|
||||
onDelete: 'CASCADE',
|
||||
primary: true,
|
||||
constraintName: 'face_search_faceId_fkey',
|
||||
})
|
||||
@ForeignKeyColumn(() => AssetFaceTable, { onDelete: 'CASCADE', primary: true })
|
||||
faceId!: string;
|
||||
|
||||
@Column({ type: 'vector', length: 512, synchronize: false })
|
||||
|
|
|
|||
|
|
@ -12,8 +12,8 @@ import {
|
|||
UpdateDateColumn,
|
||||
} from 'src/sql-tools';
|
||||
|
||||
@Table('libraries')
|
||||
@UpdatedAtTrigger('libraries_updated_at')
|
||||
@Table('library')
|
||||
@UpdatedAtTrigger('library_updatedAt')
|
||||
export class LibraryTable {
|
||||
@PrimaryGeneratedColumn()
|
||||
id!: Generated<string>;
|
||||
|
|
@ -42,6 +42,6 @@ export class LibraryTable {
|
|||
@Column({ type: 'timestamp with time zone', nullable: true })
|
||||
refreshedAt!: Timestamp | null;
|
||||
|
||||
@UpdateIdColumn({ indexName: 'IDX_libraries_update_id' })
|
||||
@UpdateIdColumn({ index: true })
|
||||
updateId!: Generated<string>;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,22 +2,17 @@ import { PrimaryGeneratedUuidV7Column } from 'src/decorators';
|
|||
import { MemoryTable } from 'src/schema/tables/memory.table';
|
||||
import { Column, CreateDateColumn, ForeignKeyColumn, Table } from 'src/sql-tools';
|
||||
|
||||
@Table('memory_assets_audit')
|
||||
@Table('memory_asset_audit')
|
||||
export class MemoryAssetAuditTable {
|
||||
@PrimaryGeneratedUuidV7Column()
|
||||
id!: string;
|
||||
|
||||
@ForeignKeyColumn(() => MemoryTable, {
|
||||
type: 'uuid',
|
||||
indexName: 'IDX_memory_assets_audit_memory_id',
|
||||
onDelete: 'CASCADE',
|
||||
onUpdate: 'CASCADE',
|
||||
})
|
||||
@ForeignKeyColumn(() => MemoryTable, { type: 'uuid', onDelete: 'CASCADE', onUpdate: 'CASCADE' })
|
||||
memoryId!: string;
|
||||
|
||||
@Column({ type: 'uuid', indexName: 'IDX_memory_assets_audit_asset_id' })
|
||||
@Column({ type: 'uuid', index: true })
|
||||
assetId!: string;
|
||||
|
||||
@CreateDateColumn({ default: () => 'clock_timestamp()', indexName: 'IDX_memory_assets_audit_deleted_at' })
|
||||
@CreateDateColumn({ default: () => 'clock_timestamp()', index: true })
|
||||
deletedAt!: Date;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { UpdatedAtTrigger, UpdateIdColumn } from 'src/decorators';
|
||||
import { memory_assets_delete_audit } from 'src/schema/functions';
|
||||
import { memory_asset_delete_audit } from 'src/schema/functions';
|
||||
import { AssetTable } from 'src/schema/tables/asset.table';
|
||||
import { MemoryTable } from 'src/schema/tables/memory.table';
|
||||
import {
|
||||
|
|
@ -12,11 +12,11 @@ import {
|
|||
UpdateDateColumn,
|
||||
} from 'src/sql-tools';
|
||||
|
||||
@Table('memories_assets_assets')
|
||||
@UpdatedAtTrigger('memory_assets_updated_at')
|
||||
@Table('memory_asset')
|
||||
@UpdatedAtTrigger('memory_asset_updatedAt')
|
||||
@AfterDeleteTrigger({
|
||||
scope: 'statement',
|
||||
function: memory_assets_delete_audit,
|
||||
function: memory_asset_delete_audit,
|
||||
referencingOldTableAs: 'old',
|
||||
when: 'pg_trigger_depth() <= 1',
|
||||
})
|
||||
|
|
@ -33,6 +33,6 @@ export class MemoryAssetTable {
|
|||
@UpdateDateColumn()
|
||||
updatedAt!: Generated<Timestamp>;
|
||||
|
||||
@UpdateIdColumn({ indexName: 'IDX_memory_assets_update_id' })
|
||||
@UpdateIdColumn({ index: true })
|
||||
updateId!: Generated<string>;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,17 +1,17 @@
|
|||
import { PrimaryGeneratedUuidV7Column } from 'src/decorators';
|
||||
import { Column, CreateDateColumn, Generated, Table, Timestamp } from 'src/sql-tools';
|
||||
|
||||
@Table('memories_audit')
|
||||
@Table('memory_audit')
|
||||
export class MemoryAuditTable {
|
||||
@PrimaryGeneratedUuidV7Column()
|
||||
id!: Generated<string>;
|
||||
|
||||
@Column({ type: 'uuid', indexName: 'IDX_memories_audit_memory_id' })
|
||||
@Column({ type: 'uuid', index: true })
|
||||
memoryId!: string;
|
||||
|
||||
@Column({ type: 'uuid', indexName: 'IDX_memories_audit_user_id' })
|
||||
@Column({ type: 'uuid', index: true })
|
||||
userId!: string;
|
||||
|
||||
@CreateDateColumn({ default: () => 'clock_timestamp()', indexName: 'IDX_memories_audit_deleted_at' })
|
||||
@CreateDateColumn({ default: () => 'clock_timestamp()', index: true })
|
||||
deletedAt!: Generated<Timestamp>;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { UpdatedAtTrigger, UpdateIdColumn } from 'src/decorators';
|
||||
import { MemoryType } from 'src/enum';
|
||||
import { memories_delete_audit } from 'src/schema/functions';
|
||||
import { memory_delete_audit } from 'src/schema/functions';
|
||||
import { UserTable } from 'src/schema/tables/user.table';
|
||||
import {
|
||||
AfterDeleteTrigger,
|
||||
|
|
@ -15,11 +15,11 @@ import {
|
|||
UpdateDateColumn,
|
||||
} from 'src/sql-tools';
|
||||
|
||||
@Table('memories')
|
||||
@UpdatedAtTrigger('memories_updated_at')
|
||||
@Table('memory')
|
||||
@UpdatedAtTrigger('memory_updatedAt')
|
||||
@AfterDeleteTrigger({
|
||||
scope: 'statement',
|
||||
function: memories_delete_audit,
|
||||
function: memory_delete_audit,
|
||||
referencingOldTableAs: 'old',
|
||||
when: 'pg_trigger_depth() = 0',
|
||||
})
|
||||
|
|
@ -63,6 +63,6 @@ export class MemoryTable {
|
|||
@Column({ type: 'timestamp with time zone', nullable: true })
|
||||
hideAt!: Timestamp | null;
|
||||
|
||||
@UpdateIdColumn({ indexName: 'IDX_memories_update_id' })
|
||||
@UpdateIdColumn({ index: true })
|
||||
updateId!: Generated<string>;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,8 +13,8 @@ import {
|
|||
UpdateDateColumn,
|
||||
} from 'src/sql-tools';
|
||||
|
||||
@Table('notifications')
|
||||
@UpdatedAtTrigger('notifications_updated_at')
|
||||
@Table('notification')
|
||||
@UpdatedAtTrigger('notification_updatedAt')
|
||||
export class NotificationTable {
|
||||
@PrimaryGeneratedColumn()
|
||||
id!: Generated<string>;
|
||||
|
|
@ -28,7 +28,7 @@ export class NotificationTable {
|
|||
@DeleteDateColumn()
|
||||
deletedAt!: Timestamp | null;
|
||||
|
||||
@UpdateIdColumn({ indexName: 'IDX_notifications_update_id' })
|
||||
@UpdateIdColumn({ index: true })
|
||||
updateId!: Generated<string>;
|
||||
|
||||
@ForeignKeyColumn(() => UserTable, { onDelete: 'CASCADE', onUpdate: 'CASCADE', nullable: true })
|
||||
|
|
|
|||
|
|
@ -1,17 +1,17 @@
|
|||
import { PrimaryGeneratedUuidV7Column } from 'src/decorators';
|
||||
import { Column, CreateDateColumn, Generated, Table, Timestamp } from 'src/sql-tools';
|
||||
|
||||
@Table('partners_audit')
|
||||
@Table('partner_audit')
|
||||
export class PartnerAuditTable {
|
||||
@PrimaryGeneratedUuidV7Column()
|
||||
id!: Generated<string>;
|
||||
|
||||
@Column({ type: 'uuid', indexName: 'IDX_partners_audit_shared_by_id' })
|
||||
@Column({ type: 'uuid', index: true })
|
||||
sharedById!: string;
|
||||
|
||||
@Column({ type: 'uuid', indexName: 'IDX_partners_audit_shared_with_id' })
|
||||
@Column({ type: 'uuid', index: true })
|
||||
sharedWithId!: string;
|
||||
|
||||
@CreateDateColumn({ default: () => 'clock_timestamp()', indexName: 'IDX_partners_audit_deleted_at' })
|
||||
@CreateDateColumn({ default: () => 'clock_timestamp()', index: true })
|
||||
deletedAt!: Generated<Timestamp>;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { CreateIdColumn, UpdatedAtTrigger, UpdateIdColumn } from 'src/decorators';
|
||||
import { partners_delete_audit } from 'src/schema/functions';
|
||||
import { partner_delete_audit } from 'src/schema/functions';
|
||||
import { UserTable } from 'src/schema/tables/user.table';
|
||||
import {
|
||||
AfterDeleteTrigger,
|
||||
|
|
@ -12,11 +12,11 @@ import {
|
|||
UpdateDateColumn,
|
||||
} from 'src/sql-tools';
|
||||
|
||||
@Table('partners')
|
||||
@UpdatedAtTrigger('partners_updated_at')
|
||||
@Table('partner')
|
||||
@UpdatedAtTrigger('partner_updatedAt')
|
||||
@AfterDeleteTrigger({
|
||||
scope: 'statement',
|
||||
function: partners_delete_audit,
|
||||
function: partner_delete_audit,
|
||||
referencingOldTableAs: 'old',
|
||||
when: 'pg_trigger_depth() = 0',
|
||||
})
|
||||
|
|
@ -35,7 +35,7 @@ export class PartnerTable {
|
|||
@CreateDateColumn()
|
||||
createdAt!: Generated<Timestamp>;
|
||||
|
||||
@CreateIdColumn({ indexName: 'IDX_partners_create_id' })
|
||||
@CreateIdColumn({ index: true })
|
||||
createId!: Generated<string>;
|
||||
|
||||
@UpdateDateColumn()
|
||||
|
|
@ -44,6 +44,6 @@ export class PartnerTable {
|
|||
@Column({ type: 'boolean', default: false })
|
||||
inTimeline!: Generated<boolean>;
|
||||
|
||||
@UpdateIdColumn({ indexName: 'IDX_partners_update_id' })
|
||||
@UpdateIdColumn({ index: true })
|
||||
updateId!: Generated<string>;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,12 +6,12 @@ export class PersonAuditTable {
|
|||
@PrimaryGeneratedUuidV7Column()
|
||||
id!: Generated<string>;
|
||||
|
||||
@Column({ type: 'uuid', indexName: 'IDX_person_audit_person_id' })
|
||||
@Column({ type: 'uuid', index: true })
|
||||
personId!: string;
|
||||
|
||||
@Column({ type: 'uuid', indexName: 'IDX_person_audit_owner_id' })
|
||||
@Column({ type: 'uuid', index: true })
|
||||
ownerId!: string;
|
||||
|
||||
@CreateDateColumn({ default: () => 'clock_timestamp()', indexName: 'IDX_person_audit_deleted_at' })
|
||||
@CreateDateColumn({ default: () => 'clock_timestamp()', index: true })
|
||||
deletedAt!: Generated<Timestamp>;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,14 +16,14 @@ import {
|
|||
} from 'src/sql-tools';
|
||||
|
||||
@Table('person')
|
||||
@UpdatedAtTrigger('person_updated_at')
|
||||
@UpdatedAtTrigger('person_updatedAt')
|
||||
@AfterDeleteTrigger({
|
||||
scope: 'statement',
|
||||
function: person_delete_audit,
|
||||
referencingOldTableAs: 'old',
|
||||
when: 'pg_trigger_depth() = 0',
|
||||
})
|
||||
@Check({ name: 'CHK_b0f82b0ed662bfc24fbb58bb45', expression: `"birthDate" <= CURRENT_DATE` })
|
||||
@Check({ name: 'person_birthDate_chk', expression: `"birthDate" <= CURRENT_DATE` })
|
||||
export class PersonTable {
|
||||
@PrimaryGeneratedColumn('uuid')
|
||||
id!: Generated<string>;
|
||||
|
|
@ -58,6 +58,6 @@ export class PersonTable {
|
|||
@Column({ type: 'character varying', nullable: true, default: null })
|
||||
color!: string | null;
|
||||
|
||||
@UpdateIdColumn({ indexName: 'IDX_person_update_id' })
|
||||
@UpdateIdColumn({ index: true })
|
||||
updateId!: Generated<string>;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,8 +11,8 @@ import {
|
|||
UpdateDateColumn,
|
||||
} from 'src/sql-tools';
|
||||
|
||||
@Table({ name: 'sessions', primaryConstraintName: 'PK_48cb6b5c20faa63157b3c1baf7f' })
|
||||
@UpdatedAtTrigger('sessions_updated_at')
|
||||
@Table({ name: 'session' })
|
||||
@UpdatedAtTrigger('session_updatedAt')
|
||||
export class SessionTable {
|
||||
@PrimaryGeneratedColumn()
|
||||
id!: Generated<string>;
|
||||
|
|
@ -42,7 +42,7 @@ export class SessionTable {
|
|||
@Column({ default: '' })
|
||||
deviceOS!: Generated<string>;
|
||||
|
||||
@UpdateIdColumn({ indexName: 'IDX_sessions_update_id' })
|
||||
@UpdateIdColumn({ index: true })
|
||||
updateId!: Generated<string>;
|
||||
|
||||
@Column({ type: 'boolean', default: false })
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import { AssetTable } from 'src/schema/tables/asset.table';
|
|||
import { SharedLinkTable } from 'src/schema/tables/shared-link.table';
|
||||
import { ForeignKeyColumn, Table } from 'src/sql-tools';
|
||||
|
||||
@Table('shared_link__asset')
|
||||
@Table('shared_link_asset')
|
||||
export class SharedLinkAssetTable {
|
||||
@ForeignKeyColumn(() => AssetTable, { onUpdate: 'CASCADE', onDelete: 'CASCADE', primary: true })
|
||||
assetsId!: string;
|
||||
|
|
|
|||
|
|
@ -9,11 +9,9 @@ import {
|
|||
PrimaryGeneratedColumn,
|
||||
Table,
|
||||
Timestamp,
|
||||
Unique,
|
||||
} from 'src/sql-tools';
|
||||
|
||||
@Table('shared_links')
|
||||
@Unique({ name: 'UQ_sharedlink_key', columns: ['key'] })
|
||||
@Table('shared_link')
|
||||
export class SharedLinkTable {
|
||||
@PrimaryGeneratedColumn()
|
||||
id!: Generated<string>;
|
||||
|
|
@ -24,7 +22,7 @@ export class SharedLinkTable {
|
|||
@ForeignKeyColumn(() => UserTable, { onDelete: 'CASCADE', onUpdate: 'CASCADE' })
|
||||
userId!: string;
|
||||
|
||||
@Column({ type: 'bytea', indexName: 'IDX_sharedlink_key' })
|
||||
@Column({ type: 'bytea', index: true, unique: true })
|
||||
key!: Buffer; // use to access the individual asset
|
||||
|
||||
@Column()
|
||||
|
|
@ -39,12 +37,7 @@ export class SharedLinkTable {
|
|||
@Column({ type: 'boolean', default: false })
|
||||
allowUpload!: boolean;
|
||||
|
||||
@ForeignKeyColumn(() => AlbumTable, {
|
||||
nullable: true,
|
||||
onDelete: 'CASCADE',
|
||||
onUpdate: 'CASCADE',
|
||||
indexName: 'IDX_sharedlink_albumId',
|
||||
})
|
||||
@ForeignKeyColumn(() => AlbumTable, { nullable: true, onDelete: 'CASCADE', onUpdate: 'CASCADE' })
|
||||
albumId!: string | null;
|
||||
|
||||
@Column({ type: 'boolean', default: true })
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { AssetTable } from 'src/schema/tables/asset.table';
|
||||
import { Column, ForeignKeyColumn, Index, Table } from 'src/sql-tools';
|
||||
|
||||
@Table({ name: 'smart_search', primaryConstraintName: 'smart_search_pkey' })
|
||||
@Table({ name: 'smart_search' })
|
||||
@Index({
|
||||
name: 'clip_index',
|
||||
using: 'hnsw',
|
||||
|
|
@ -10,11 +10,7 @@ import { Column, ForeignKeyColumn, Index, Table } from 'src/sql-tools';
|
|||
synchronize: false,
|
||||
})
|
||||
export class SmartSearchTable {
|
||||
@ForeignKeyColumn(() => AssetTable, {
|
||||
onDelete: 'CASCADE',
|
||||
primary: true,
|
||||
constraintName: 'smart_search_assetId_fkey',
|
||||
})
|
||||
@ForeignKeyColumn(() => AssetTable, { onDelete: 'CASCADE', primary: true })
|
||||
assetId!: string;
|
||||
|
||||
@Column({ type: 'vector', length: 512, storage: 'external', synchronize: false })
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { PrimaryGeneratedUuidV7Column } from 'src/decorators';
|
||||
import { Column, CreateDateColumn, Generated, Table, Timestamp } from 'src/sql-tools';
|
||||
|
||||
@Table('stacks_audit')
|
||||
@Table('stack_audit')
|
||||
export class StackAuditTable {
|
||||
@PrimaryGeneratedUuidV7Column()
|
||||
id!: Generated<string>;
|
||||
|
|
@ -12,6 +12,6 @@ export class StackAuditTable {
|
|||
@Column({ type: 'uuid' })
|
||||
userId!: string;
|
||||
|
||||
@CreateDateColumn({ default: () => 'clock_timestamp()', indexName: 'IDX_stacks_audit_deleted_at' })
|
||||
@CreateDateColumn({ default: () => 'clock_timestamp()', index: true })
|
||||
deletedAt!: Generated<Timestamp>;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { UpdatedAtTrigger, UpdateIdColumn } from 'src/decorators';
|
||||
import { stacks_delete_audit } from 'src/schema/functions';
|
||||
import { stack_delete_audit } from 'src/schema/functions';
|
||||
import { AssetTable } from 'src/schema/tables/asset.table';
|
||||
import { UserTable } from 'src/schema/tables/user.table';
|
||||
import {
|
||||
|
|
@ -13,11 +13,11 @@ import {
|
|||
UpdateDateColumn,
|
||||
} from 'src/sql-tools';
|
||||
|
||||
@Table('asset_stack')
|
||||
@UpdatedAtTrigger('stacks_updated_at')
|
||||
@Table('stack')
|
||||
@UpdatedAtTrigger('stack_updatedAt')
|
||||
@AfterDeleteTrigger({
|
||||
scope: 'statement',
|
||||
function: stacks_delete_audit,
|
||||
function: stack_delete_audit,
|
||||
referencingOldTableAs: 'old',
|
||||
when: 'pg_trigger_depth() = 0',
|
||||
})
|
||||
|
|
@ -35,11 +35,7 @@ export class StackTable {
|
|||
updateId!: Generated<string>;
|
||||
|
||||
//TODO: Add constraint to ensure primary asset exists in the assets array
|
||||
@ForeignKeyColumn(() => AssetTable, {
|
||||
nullable: false,
|
||||
unique: true,
|
||||
uniqueConstraintName: 'REL_91704e101438fd0653f582426d',
|
||||
})
|
||||
@ForeignKeyColumn(() => AssetTable, { nullable: false, unique: true })
|
||||
primaryAssetId!: string;
|
||||
|
||||
@ForeignKeyColumn(() => UserTable, { onDelete: 'CASCADE', onUpdate: 'CASCADE' })
|
||||
|
|
|
|||
|
|
@ -12,8 +12,8 @@ import {
|
|||
UpdateDateColumn,
|
||||
} from 'src/sql-tools';
|
||||
|
||||
@Table('session_sync_checkpoints')
|
||||
@UpdatedAtTrigger('session_sync_checkpoints_updated_at')
|
||||
@Table('session_sync_checkpoint')
|
||||
@UpdatedAtTrigger('session_sync_checkpoint_updatedAt')
|
||||
export class SessionSyncCheckpointTable {
|
||||
@ForeignKeyColumn(() => SessionTable, { onDelete: 'CASCADE', onUpdate: 'CASCADE', primary: true })
|
||||
sessionId!: string;
|
||||
|
|
@ -30,6 +30,6 @@ export class SessionSyncCheckpointTable {
|
|||
@Column()
|
||||
ack!: string;
|
||||
|
||||
@UpdateIdColumn({ indexName: 'IDX_session_sync_checkpoints_update_id' })
|
||||
@UpdateIdColumn({ index: true })
|
||||
updateId!: Generated<string>;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ import { AssetTable } from 'src/schema/tables/asset.table';
|
|||
import { TagTable } from 'src/schema/tables/tag.table';
|
||||
import { ForeignKeyColumn, Index, Table } from 'src/sql-tools';
|
||||
|
||||
@Index({ name: 'IDX_tag_asset_assetsId_tagsId', columns: ['assetsId', 'tagsId'] })
|
||||
@Index({ columns: ['assetsId', 'tagsId'] })
|
||||
@Table('tag_asset')
|
||||
export class TagAssetTable {
|
||||
@ForeignKeyColumn(() => AssetTable, { onUpdate: 'CASCADE', onDelete: 'CASCADE', primary: true, index: true })
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { TagTable } from 'src/schema/tables/tag.table';
|
||||
import { ForeignKeyColumn, Table } from 'src/sql-tools';
|
||||
|
||||
@Table('tags_closure')
|
||||
@Table('tag_closure')
|
||||
export class TagClosureTable {
|
||||
@ForeignKeyColumn(() => TagTable, { primary: true, onDelete: 'CASCADE', onUpdate: 'NO ACTION', index: true })
|
||||
id_ancestor!: string;
|
||||
|
|
|
|||
|
|
@ -12,8 +12,8 @@ import {
|
|||
UpdateDateColumn,
|
||||
} from 'src/sql-tools';
|
||||
|
||||
@Table('tags')
|
||||
@UpdatedAtTrigger('tags_updated_at')
|
||||
@Table('tag')
|
||||
@UpdatedAtTrigger('tag_updatedAt')
|
||||
@Unique({ columns: ['userId', 'value'] })
|
||||
export class TagTable {
|
||||
@PrimaryGeneratedColumn()
|
||||
|
|
@ -42,6 +42,6 @@ export class TagTable {
|
|||
@ForeignKeyColumn(() => TagTable, { nullable: true, onDelete: 'CASCADE' })
|
||||
parentId!: string | null;
|
||||
|
||||
@UpdateIdColumn({ indexName: 'IDX_tags_update_id' })
|
||||
@UpdateIdColumn({ index: true })
|
||||
updateId!: Generated<string>;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { PrimaryGeneratedUuidV7Column } from 'src/decorators';
|
||||
import { Column, CreateDateColumn, Generated, Table, Timestamp } from 'src/sql-tools';
|
||||
|
||||
@Table('users_audit')
|
||||
@Table('user_audit')
|
||||
export class UserAuditTable {
|
||||
@PrimaryGeneratedUuidV7Column()
|
||||
id!: Generated<string>;
|
||||
|
|
@ -9,6 +9,6 @@ export class UserAuditTable {
|
|||
@Column({ type: 'uuid' })
|
||||
userId!: string;
|
||||
|
||||
@CreateDateColumn({ default: () => 'clock_timestamp()', indexName: 'IDX_users_audit_deleted_at' })
|
||||
@CreateDateColumn({ default: () => 'clock_timestamp()', index: true })
|
||||
deletedAt!: Generated<Timestamp>;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { ColumnType } from 'kysely';
|
||||
import { UpdatedAtTrigger, UpdateIdColumn } from 'src/decorators';
|
||||
import { UserAvatarColor, UserStatus } from 'src/enum';
|
||||
import { users_delete_audit } from 'src/schema/functions';
|
||||
import { user_delete_audit } from 'src/schema/functions';
|
||||
import {
|
||||
AfterDeleteTrigger,
|
||||
Column,
|
||||
|
|
@ -15,15 +15,15 @@ import {
|
|||
UpdateDateColumn,
|
||||
} from 'src/sql-tools';
|
||||
|
||||
@Table('users')
|
||||
@UpdatedAtTrigger('users_updated_at')
|
||||
@Table('user')
|
||||
@UpdatedAtTrigger('user_updatedAt')
|
||||
@AfterDeleteTrigger({
|
||||
scope: 'statement',
|
||||
function: users_delete_audit,
|
||||
function: user_delete_audit,
|
||||
referencingOldTableAs: 'old',
|
||||
when: 'pg_trigger_depth() = 0',
|
||||
})
|
||||
@Index({ name: 'IDX_users_updated_at_asc_id_asc', columns: ['updatedAt', 'id'] })
|
||||
@Index({ columns: ['updatedAt', 'id'] })
|
||||
export class UserTable {
|
||||
@PrimaryGeneratedColumn()
|
||||
id!: Generated<string>;
|
||||
|
|
@ -79,6 +79,6 @@ export class UserTable {
|
|||
@Column({ type: 'timestamp with time zone', default: () => 'now()' })
|
||||
profileChangedAt!: Generated<Timestamp>;
|
||||
|
||||
@UpdateIdColumn({ indexName: 'IDX_users_update_id' })
|
||||
@UpdateIdColumn({ index: true })
|
||||
updateId!: Generated<string>;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue