mirror of
https://github.com/immich-app/immich.git
synced 2026-05-18 03:10:24 +03:00
Merge remote-tracking branch 'origin/main' into feat/integrity-checks-izzy
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { Selectable } from 'kysely';
|
||||
import { AssetEditAction } from 'src/dtos/editing.dto';
|
||||
import { AssetEditAction, AssetEditActionItem } from 'src/dtos/editing.dto';
|
||||
import { AssetEditTable } from 'src/schema/tables/asset-edit.table';
|
||||
import { AssetFactory } from 'test/factories/asset.factory';
|
||||
import { build } from 'test/factories/builder.factory';
|
||||
@@ -33,6 +33,6 @@ export class AssetEditFactory {
|
||||
}
|
||||
|
||||
build() {
|
||||
return { ...this.value } as Selectable<AssetEditTable<AssetEditAction.Crop>>;
|
||||
return { ...this.value } as Omit<Selectable<AssetEditTable>, 'action' | 'parameters'> & AssetEditActionItem;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ export class AssetFileFactory {
|
||||
path: `/data/12/34/thumbs/${id.slice(0, 2)}/${id.slice(2, 4)}/${id}${isEdited ? '_edited' : ''}.jpg`,
|
||||
updateId: newUuidV7(),
|
||||
isProgressive: false,
|
||||
isTransparent: false,
|
||||
isEdited,
|
||||
...dto,
|
||||
});
|
||||
|
||||
@@ -6,7 +6,7 @@ import { Stats } from 'node:fs';
|
||||
import { Writable } from 'node:stream';
|
||||
import { AssetFace } from 'src/database';
|
||||
import { AuthDto, LoginResponseDto } from 'src/dtos/auth.dto';
|
||||
import { AssetEditActionListDto } from 'src/dtos/editing.dto';
|
||||
import { AssetEditActionItem, AssetEditsCreateDto } from 'src/dtos/editing.dto';
|
||||
import {
|
||||
AlbumUserRole,
|
||||
AssetType,
|
||||
@@ -283,8 +283,8 @@ export class MediumTestContext<S extends BaseService = BaseService> {
|
||||
return { tagsAssets, result };
|
||||
}
|
||||
|
||||
async newEdits(assetId: string, dto: AssetEditActionListDto) {
|
||||
const edits = await this.get(AssetEditRepository).replaceAll(assetId, dto.edits);
|
||||
async newEdits(assetId: string, dto: AssetEditsCreateDto) {
|
||||
const edits = await this.get(AssetEditRepository).replaceAll(assetId, dto.edits as AssetEditActionItem[]);
|
||||
return { edits };
|
||||
}
|
||||
}
|
||||
@@ -636,7 +636,7 @@ const personInsert = (person: Partial<Insertable<PersonTable>> & { ownerId: stri
|
||||
};
|
||||
};
|
||||
|
||||
const sha256 = (value: string) => createHash('sha256').update(value).digest('base64');
|
||||
const sha256 = (value: string) => createHash('sha256').update(value).digest();
|
||||
|
||||
const sessionInsert = ({
|
||||
id = newUuid(),
|
||||
|
||||
@@ -887,15 +887,16 @@ describe(AssetService.name, () => {
|
||||
await ctx.newExif({ assetId: asset.id, exifImageHeight: 42, exifImageWidth: 69, orientation: '1' });
|
||||
|
||||
const editAction = { action: AssetEditAction.Rotate, parameters: { angle: 90 } } as const;
|
||||
const editResponse = { ...editAction, id: expect.any(String) };
|
||||
await expect(sut.editAsset(auth, asset.id, { edits: [editAction] })).resolves.toEqual({
|
||||
assetId: asset.id,
|
||||
edits: [editAction],
|
||||
edits: [editResponse],
|
||||
});
|
||||
|
||||
await expect(ctx.get(AssetRepository).getById(asset.id)).resolves.toEqual(
|
||||
expect.objectContaining({ isEdited: true }),
|
||||
);
|
||||
await expect(ctx.get(AssetEditRepository).getAll(asset.id)).resolves.toEqual([editAction]);
|
||||
await expect(ctx.get(AssetEditRepository).getAll(asset.id)).resolves.toEqual([editResponse]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -97,3 +97,134 @@ describe(SyncEntityType.AssetFaceV1, () => {
|
||||
await ctx.assertSyncIsComplete(auth, [SyncRequestType.AssetFacesV1]);
|
||||
});
|
||||
});
|
||||
|
||||
describe(SyncEntityType.AssetFaceV2, () => {
|
||||
it('should detect and sync the first asset face', async () => {
|
||||
const { auth, ctx } = await setup();
|
||||
const { asset } = await ctx.newAsset({ ownerId: auth.user.id });
|
||||
const { person } = await ctx.newPerson({ ownerId: auth.user.id });
|
||||
const { assetFace } = await ctx.newAssetFace({ assetId: asset.id, personId: person.id });
|
||||
|
||||
const response = await ctx.syncStream(auth, [SyncRequestType.AssetFacesV2]);
|
||||
expect(response).toEqual([
|
||||
{
|
||||
ack: expect.any(String),
|
||||
data: expect.objectContaining({
|
||||
id: assetFace.id,
|
||||
assetId: asset.id,
|
||||
personId: person.id,
|
||||
imageWidth: assetFace.imageWidth,
|
||||
imageHeight: assetFace.imageHeight,
|
||||
boundingBoxX1: assetFace.boundingBoxX1,
|
||||
boundingBoxY1: assetFace.boundingBoxY1,
|
||||
boundingBoxX2: assetFace.boundingBoxX2,
|
||||
boundingBoxY2: assetFace.boundingBoxY2,
|
||||
sourceType: assetFace.sourceType,
|
||||
}),
|
||||
type: 'AssetFaceV2',
|
||||
},
|
||||
expect.objectContaining({ type: SyncEntityType.SyncCompleteV1 }),
|
||||
]);
|
||||
|
||||
await ctx.syncAckAll(auth, response);
|
||||
await ctx.assertSyncIsComplete(auth, [SyncRequestType.AssetFacesV2]);
|
||||
});
|
||||
|
||||
it('should detect and sync a deleted asset face', async () => {
|
||||
const { auth, ctx } = await setup();
|
||||
const personRepo = ctx.get(PersonRepository);
|
||||
const { asset } = await ctx.newAsset({ ownerId: auth.user.id });
|
||||
const { assetFace } = await ctx.newAssetFace({ assetId: asset.id });
|
||||
await personRepo.deleteAssetFace(assetFace.id);
|
||||
|
||||
const response = await ctx.syncStream(auth, [SyncRequestType.AssetFacesV2]);
|
||||
expect(response).toEqual([
|
||||
{
|
||||
ack: expect.any(String),
|
||||
data: {
|
||||
assetFaceId: assetFace.id,
|
||||
},
|
||||
type: 'AssetFaceDeleteV1',
|
||||
},
|
||||
expect.objectContaining({ type: SyncEntityType.SyncCompleteV1 }),
|
||||
]);
|
||||
|
||||
await ctx.syncAckAll(auth, response);
|
||||
await ctx.assertSyncIsComplete(auth, [SyncRequestType.AssetFacesV2]);
|
||||
});
|
||||
|
||||
it('should not sync an asset face or asset face delete for an unrelated user', async () => {
|
||||
const { auth, ctx } = await setup();
|
||||
const personRepo = ctx.get(PersonRepository);
|
||||
const { user: user2 } = await ctx.newUser();
|
||||
const { session } = await ctx.newSession({ userId: user2.id });
|
||||
const { asset } = await ctx.newAsset({ ownerId: user2.id });
|
||||
const { assetFace } = await ctx.newAssetFace({ assetId: asset.id });
|
||||
const auth2 = factory.auth({ session, user: user2 });
|
||||
|
||||
expect(await ctx.syncStream(auth2, [SyncRequestType.AssetFacesV2])).toEqual([
|
||||
expect.objectContaining({ type: SyncEntityType.AssetFaceV2 }),
|
||||
expect.objectContaining({ type: SyncEntityType.SyncCompleteV1 }),
|
||||
]);
|
||||
await ctx.assertSyncIsComplete(auth, [SyncRequestType.AssetFacesV2]);
|
||||
|
||||
await personRepo.deleteAssetFace(assetFace.id);
|
||||
|
||||
expect(await ctx.syncStream(auth2, [SyncRequestType.AssetFacesV2])).toEqual([
|
||||
expect.objectContaining({ type: SyncEntityType.AssetFaceDeleteV1 }),
|
||||
expect.objectContaining({ type: SyncEntityType.SyncCompleteV1 }),
|
||||
]);
|
||||
await ctx.assertSyncIsComplete(auth, [SyncRequestType.AssetFacesV2]);
|
||||
});
|
||||
|
||||
it('should contain the deletedAt and isVisible fields in AssetFaceV2', async () => {
|
||||
const { auth, ctx } = await setup();
|
||||
const personRepo = ctx.get(PersonRepository);
|
||||
const { asset } = await ctx.newAsset({ ownerId: auth.user.id });
|
||||
const { person } = await ctx.newPerson({ ownerId: auth.user.id });
|
||||
const { assetFace } = await ctx.newAssetFace({ assetId: asset.id, personId: person.id });
|
||||
|
||||
let response = await ctx.syncStream(auth, [SyncRequestType.AssetFacesV2]);
|
||||
expect(response).toEqual([
|
||||
{
|
||||
ack: expect.any(String),
|
||||
data: expect.objectContaining({
|
||||
id: assetFace.id,
|
||||
assetId: asset.id,
|
||||
personId: person.id,
|
||||
imageWidth: assetFace.imageWidth,
|
||||
imageHeight: assetFace.imageHeight,
|
||||
boundingBoxX1: assetFace.boundingBoxX1,
|
||||
boundingBoxY1: assetFace.boundingBoxY1,
|
||||
boundingBoxX2: assetFace.boundingBoxX2,
|
||||
boundingBoxY2: assetFace.boundingBoxY2,
|
||||
sourceType: assetFace.sourceType,
|
||||
deletedAt: null,
|
||||
isVisible: true,
|
||||
}),
|
||||
type: 'AssetFaceV2',
|
||||
},
|
||||
expect.objectContaining({ type: SyncEntityType.SyncCompleteV1 }),
|
||||
]);
|
||||
|
||||
await ctx.syncAckAll(auth, response);
|
||||
await ctx.assertSyncIsComplete(auth, [SyncRequestType.AssetFacesV2]);
|
||||
|
||||
await personRepo.deleteAssetFace(assetFace.id);
|
||||
|
||||
response = await ctx.syncStream(auth, [SyncRequestType.AssetFacesV2]);
|
||||
expect(response).toEqual([
|
||||
{
|
||||
ack: expect.any(String),
|
||||
data: {
|
||||
assetFaceId: assetFace.id,
|
||||
},
|
||||
type: 'AssetFaceDeleteV1',
|
||||
},
|
||||
expect.objectContaining({ type: SyncEntityType.SyncCompleteV1 }),
|
||||
]);
|
||||
|
||||
await ctx.syncAckAll(auth, response);
|
||||
await ctx.assertSyncIsComplete(auth, [SyncRequestType.AssetFacesV2]);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -8,7 +8,7 @@ export const newCryptoRepositoryMock = (): Mocked<RepositoryInterface<CryptoRepo
|
||||
randomBytes: vitest.fn().mockReturnValue(Buffer.from('random-bytes', 'utf8')),
|
||||
compareBcrypt: vitest.fn().mockReturnValue(true),
|
||||
hashBcrypt: vitest.fn().mockImplementation((input) => Promise.resolve(`${input} (hashed)`)),
|
||||
hashSha256: vitest.fn().mockImplementation((input) => `${input} (hashed)`),
|
||||
hashSha256: vitest.fn().mockImplementation((input) => Buffer.from(`${input} (hashed)`)),
|
||||
verifySha256: vitest.fn().mockImplementation(() => true),
|
||||
hashSha1: vitest.fn().mockImplementation((input) => Buffer.from(`${input.toString()} (hashed)`)),
|
||||
hashFile: vitest.fn().mockImplementation((input) => `${input} (file-hashed)`),
|
||||
|
||||
@@ -12,6 +12,6 @@ export const newMediaRepositoryMock = (): Mocked<RepositoryInterface<MediaReposi
|
||||
extract: vitest.fn().mockResolvedValue(null),
|
||||
probe: vitest.fn(),
|
||||
transcode: vitest.fn(),
|
||||
getImageDimensions: vitest.fn(),
|
||||
getImageMetadata: vitest.fn(),
|
||||
};
|
||||
};
|
||||
|
||||
@@ -148,7 +148,7 @@ const sessionFactory = (session: Partial<Session> = {}) => ({
|
||||
updateId: newUuidV7(),
|
||||
deviceOS: 'android',
|
||||
deviceType: 'mobile',
|
||||
token: 'abc123',
|
||||
token: Buffer.from('abc123'),
|
||||
parentId: null,
|
||||
expiresAt: null,
|
||||
userId: newUuid(),
|
||||
|
||||
@@ -1,48 +0,0 @@
|
||||
import { Check, Column, ConstraintType, DatabaseSchema, Table } from 'src/sql-tools';
|
||||
|
||||
@Table()
|
||||
@Check({ expression: '1=1' })
|
||||
export class Table1 {
|
||||
@Column({ type: 'uuid' })
|
||||
id!: string;
|
||||
}
|
||||
|
||||
export const description = 'should create a check constraint with a default name';
|
||||
export const schema: DatabaseSchema = {
|
||||
databaseName: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
overrides: [],
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
columns: [
|
||||
{
|
||||
name: 'id',
|
||||
tableName: 'table1',
|
||||
type: 'uuid',
|
||||
nullable: false,
|
||||
isArray: false,
|
||||
primary: false,
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
triggers: [],
|
||||
constraints: [
|
||||
{
|
||||
type: ConstraintType.CHECK,
|
||||
name: 'CHK_8d2ecfd49b984941f6b2589799',
|
||||
tableName: 'table1',
|
||||
expression: '1=1',
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
warnings: [],
|
||||
};
|
||||
@@ -1,48 +0,0 @@
|
||||
import { Check, Column, ConstraintType, DatabaseSchema, Table } from 'src/sql-tools';
|
||||
|
||||
@Table()
|
||||
@Check({ name: 'CHK_test', expression: '1=1' })
|
||||
export class Table1 {
|
||||
@Column({ type: 'uuid' })
|
||||
id!: string;
|
||||
}
|
||||
|
||||
export const description = 'should create a check constraint with a specific name';
|
||||
export const schema: DatabaseSchema = {
|
||||
databaseName: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
overrides: [],
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
columns: [
|
||||
{
|
||||
name: 'id',
|
||||
tableName: 'table1',
|
||||
type: 'uuid',
|
||||
nullable: false,
|
||||
isArray: false,
|
||||
primary: false,
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
triggers: [],
|
||||
constraints: [
|
||||
{
|
||||
type: ConstraintType.CHECK,
|
||||
name: 'CHK_test',
|
||||
tableName: 'table1',
|
||||
expression: '1=1',
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
warnings: [],
|
||||
};
|
||||
@@ -1,40 +0,0 @@
|
||||
import { CreateDateColumn, DatabaseSchema, Table } from 'src/sql-tools';
|
||||
|
||||
@Table()
|
||||
export class Table1 {
|
||||
@CreateDateColumn()
|
||||
createdAt!: string;
|
||||
}
|
||||
|
||||
export const description = 'should register a table with an created at date column';
|
||||
export const schema: DatabaseSchema = {
|
||||
databaseName: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
overrides: [],
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
columns: [
|
||||
{
|
||||
name: 'createdAt',
|
||||
tableName: 'table1',
|
||||
type: 'timestamp with time zone',
|
||||
default: 'now()',
|
||||
nullable: false,
|
||||
isArray: false,
|
||||
primary: false,
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
triggers: [],
|
||||
constraints: [],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
warnings: [],
|
||||
};
|
||||
@@ -1,40 +0,0 @@
|
||||
import { Column, DatabaseSchema, Table } from 'src/sql-tools';
|
||||
|
||||
@Table()
|
||||
export class Table1 {
|
||||
@Column({ type: 'character varying', array: true, default: [] })
|
||||
column1!: string[];
|
||||
}
|
||||
|
||||
export const description = 'should register a table with a column with a default value (array)';
|
||||
export const schema: DatabaseSchema = {
|
||||
databaseName: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
overrides: [],
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
columns: [
|
||||
{
|
||||
name: 'column1',
|
||||
tableName: 'table1',
|
||||
type: 'character varying',
|
||||
nullable: false,
|
||||
isArray: true,
|
||||
primary: false,
|
||||
synchronize: true,
|
||||
default: "'{}'",
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
triggers: [],
|
||||
constraints: [],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
warnings: [],
|
||||
};
|
||||
@@ -1,40 +0,0 @@
|
||||
import { Column, DatabaseSchema, Table } from 'src/sql-tools';
|
||||
|
||||
@Table()
|
||||
export class Table1 {
|
||||
@Column({ type: 'boolean', default: true })
|
||||
column1!: boolean;
|
||||
}
|
||||
|
||||
export const description = 'should register a table with a column with a default value (boolean)';
|
||||
export const schema: DatabaseSchema = {
|
||||
databaseName: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
overrides: [],
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
columns: [
|
||||
{
|
||||
name: 'column1',
|
||||
tableName: 'table1',
|
||||
type: 'boolean',
|
||||
nullable: false,
|
||||
isArray: false,
|
||||
primary: false,
|
||||
synchronize: true,
|
||||
default: 'true',
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
triggers: [],
|
||||
constraints: [],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
warnings: [],
|
||||
};
|
||||
@@ -1,42 +0,0 @@
|
||||
import { Column, DatabaseSchema, Table } from 'src/sql-tools';
|
||||
|
||||
const date = new Date(2023, 0, 1);
|
||||
|
||||
@Table()
|
||||
export class Table1 {
|
||||
@Column({ type: 'character varying', default: date })
|
||||
column1!: string;
|
||||
}
|
||||
|
||||
export const description = 'should register a table with a column with a default value (date)';
|
||||
export const schema: DatabaseSchema = {
|
||||
databaseName: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
overrides: [],
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
columns: [
|
||||
{
|
||||
name: 'column1',
|
||||
tableName: 'table1',
|
||||
type: 'character varying',
|
||||
nullable: false,
|
||||
isArray: false,
|
||||
primary: false,
|
||||
synchronize: true,
|
||||
default: "'2023-01-01T00:00:00.000Z'",
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
triggers: [],
|
||||
constraints: [],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
warnings: [],
|
||||
};
|
||||
@@ -1,40 +0,0 @@
|
||||
import { Column, DatabaseSchema, Table } from 'src/sql-tools';
|
||||
|
||||
@Table()
|
||||
export class Table1 {
|
||||
@Column({ type: 'character varying', default: () => 'now()' })
|
||||
column1!: string;
|
||||
}
|
||||
|
||||
export const description = 'should register a table with a column with a default function';
|
||||
export const schema: DatabaseSchema = {
|
||||
databaseName: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
overrides: [],
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
columns: [
|
||||
{
|
||||
name: 'column1',
|
||||
tableName: 'table1',
|
||||
type: 'character varying',
|
||||
nullable: false,
|
||||
isArray: false,
|
||||
primary: false,
|
||||
synchronize: true,
|
||||
default: 'now()',
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
triggers: [],
|
||||
constraints: [],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
warnings: [],
|
||||
};
|
||||
@@ -1,39 +0,0 @@
|
||||
import { Column, DatabaseSchema, Table } from 'src/sql-tools';
|
||||
|
||||
@Table()
|
||||
export class Table1 {
|
||||
@Column({ type: 'character varying', default: null })
|
||||
column1!: string;
|
||||
}
|
||||
|
||||
export const description = 'should register a nullable column from a default of null';
|
||||
export const schema: DatabaseSchema = {
|
||||
databaseName: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
overrides: [],
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
columns: [
|
||||
{
|
||||
name: 'column1',
|
||||
tableName: 'table1',
|
||||
type: 'character varying',
|
||||
nullable: true,
|
||||
isArray: false,
|
||||
primary: false,
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
triggers: [],
|
||||
constraints: [],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
warnings: [],
|
||||
};
|
||||
@@ -1,40 +0,0 @@
|
||||
import { Column, DatabaseSchema, Table } from 'src/sql-tools';
|
||||
|
||||
@Table()
|
||||
export class Table1 {
|
||||
@Column({ type: 'integer', default: 0 })
|
||||
column1!: string;
|
||||
}
|
||||
|
||||
export const description = 'should register a table with a column with a default value (number)';
|
||||
export const schema: DatabaseSchema = {
|
||||
databaseName: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
overrides: [],
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
columns: [
|
||||
{
|
||||
name: 'column1',
|
||||
tableName: 'table1',
|
||||
type: 'integer',
|
||||
nullable: false,
|
||||
isArray: false,
|
||||
primary: false,
|
||||
synchronize: true,
|
||||
default: '0',
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
triggers: [],
|
||||
constraints: [],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
warnings: [],
|
||||
};
|
||||
@@ -1,40 +0,0 @@
|
||||
import { Column, DatabaseSchema, Table } from 'src/sql-tools';
|
||||
|
||||
@Table()
|
||||
export class Table1 {
|
||||
@Column({ type: 'character varying', default: 'foo' })
|
||||
column1!: string;
|
||||
}
|
||||
|
||||
export const description = 'should register a table with a column with a default value (string)';
|
||||
export const schema: DatabaseSchema = {
|
||||
databaseName: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
overrides: [],
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
columns: [
|
||||
{
|
||||
name: 'column1',
|
||||
tableName: 'table1',
|
||||
type: 'character varying',
|
||||
nullable: false,
|
||||
isArray: false,
|
||||
primary: false,
|
||||
synchronize: true,
|
||||
default: "'foo'",
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
triggers: [],
|
||||
constraints: [],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
warnings: [],
|
||||
};
|
||||
@@ -1,39 +0,0 @@
|
||||
import { DatabaseSchema, DeleteDateColumn, Table } from 'src/sql-tools';
|
||||
|
||||
@Table()
|
||||
export class Table1 {
|
||||
@DeleteDateColumn()
|
||||
deletedAt!: string;
|
||||
}
|
||||
|
||||
export const description = 'should register a table with a deleted at date column';
|
||||
export const schema: DatabaseSchema = {
|
||||
databaseName: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
overrides: [],
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
columns: [
|
||||
{
|
||||
name: 'deletedAt',
|
||||
tableName: 'table1',
|
||||
type: 'timestamp with time zone',
|
||||
nullable: true,
|
||||
isArray: false,
|
||||
primary: false,
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
triggers: [],
|
||||
constraints: [],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
warnings: [],
|
||||
};
|
||||
@@ -1,53 +0,0 @@
|
||||
import { Column, DatabaseSchema, registerEnum, Table } from 'src/sql-tools';
|
||||
|
||||
enum Test {
|
||||
Foo = 'foo',
|
||||
Bar = 'bar',
|
||||
}
|
||||
|
||||
const test_enum = registerEnum({ name: 'test_enum', values: Object.values(Test) });
|
||||
|
||||
@Table()
|
||||
export class Table1 {
|
||||
@Column({ enum: test_enum })
|
||||
column1!: string;
|
||||
}
|
||||
|
||||
export const description = 'should accept an enum type';
|
||||
export const schema: DatabaseSchema = {
|
||||
databaseName: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [
|
||||
{
|
||||
name: 'test_enum',
|
||||
values: ['foo', 'bar'],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
overrides: [],
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
columns: [
|
||||
{
|
||||
name: 'column1',
|
||||
tableName: 'table1',
|
||||
type: 'enum',
|
||||
enumName: 'test_enum',
|
||||
nullable: false,
|
||||
isArray: false,
|
||||
primary: false,
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
triggers: [],
|
||||
constraints: [],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
warnings: [],
|
||||
};
|
||||
@@ -1,48 +0,0 @@
|
||||
import { ConstraintType, DatabaseSchema, PrimaryGeneratedColumn, Table } from 'src/sql-tools';
|
||||
|
||||
@Table()
|
||||
export class Table1 {
|
||||
@PrimaryGeneratedColumn({ strategy: 'identity' })
|
||||
column1!: string;
|
||||
}
|
||||
|
||||
export const description = 'should register a table with a generated identity column';
|
||||
export const schema: DatabaseSchema = {
|
||||
databaseName: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
overrides: [],
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
columns: [
|
||||
{
|
||||
name: 'column1',
|
||||
tableName: 'table1',
|
||||
type: 'integer',
|
||||
identity: true,
|
||||
nullable: false,
|
||||
isArray: false,
|
||||
primary: true,
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
triggers: [],
|
||||
constraints: [
|
||||
{
|
||||
type: ConstraintType.PRIMARY_KEY,
|
||||
name: 'PK_50c4f9905061b1e506d38a2a380',
|
||||
tableName: 'table1',
|
||||
columnNames: ['column1'],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
warnings: [],
|
||||
};
|
||||
@@ -1,48 +0,0 @@
|
||||
import { ConstraintType, DatabaseSchema, PrimaryGeneratedColumn, Table } from 'src/sql-tools';
|
||||
|
||||
@Table()
|
||||
export class Table1 {
|
||||
@PrimaryGeneratedColumn({ strategy: 'uuid' })
|
||||
column1!: string;
|
||||
}
|
||||
|
||||
export const description = 'should register a table with a primary generated uuid column';
|
||||
export const schema: DatabaseSchema = {
|
||||
databaseName: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
overrides: [],
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
columns: [
|
||||
{
|
||||
name: 'column1',
|
||||
tableName: 'table1',
|
||||
type: 'uuid',
|
||||
default: 'uuid_generate_v4()',
|
||||
nullable: false,
|
||||
isArray: false,
|
||||
primary: true,
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
triggers: [],
|
||||
constraints: [
|
||||
{
|
||||
type: ConstraintType.PRIMARY_KEY,
|
||||
name: 'PK_50c4f9905061b1e506d38a2a380',
|
||||
tableName: 'table1',
|
||||
columnNames: ['column1'],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
warnings: [],
|
||||
};
|
||||
@@ -1,47 +0,0 @@
|
||||
import { Column, DatabaseSchema, Table } from 'src/sql-tools';
|
||||
|
||||
@Table()
|
||||
export class Table1 {
|
||||
@Column({ index: true })
|
||||
column1!: string;
|
||||
}
|
||||
|
||||
export const description = 'should create a column with an index';
|
||||
export const schema: DatabaseSchema = {
|
||||
databaseName: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
overrides: [],
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
columns: [
|
||||
{
|
||||
name: 'column1',
|
||||
tableName: 'table1',
|
||||
type: 'character varying',
|
||||
nullable: false,
|
||||
isArray: false,
|
||||
primary: false,
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
indexes: [
|
||||
{
|
||||
name: 'IDX_50c4f9905061b1e506d38a2a38',
|
||||
columnNames: ['column1'],
|
||||
tableName: 'table1',
|
||||
unique: false,
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
triggers: [],
|
||||
constraints: [],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
warnings: [],
|
||||
};
|
||||
@@ -1,47 +0,0 @@
|
||||
import { Column, DatabaseSchema, Table } from 'src/sql-tools';
|
||||
|
||||
@Table()
|
||||
export class Table1 {
|
||||
@Column({ indexName: 'IDX_test' })
|
||||
column1!: string;
|
||||
}
|
||||
|
||||
export const description = 'should create a column with an index if a name is provided';
|
||||
export const schema: DatabaseSchema = {
|
||||
databaseName: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
overrides: [],
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
columns: [
|
||||
{
|
||||
name: 'column1',
|
||||
tableName: 'table1',
|
||||
type: 'character varying',
|
||||
nullable: false,
|
||||
isArray: false,
|
||||
primary: false,
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
indexes: [
|
||||
{
|
||||
name: 'IDX_test',
|
||||
columnNames: ['column1'],
|
||||
tableName: 'table1',
|
||||
unique: false,
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
triggers: [],
|
||||
constraints: [],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
warnings: [],
|
||||
};
|
||||
@@ -1,39 +0,0 @@
|
||||
import { Column, DatabaseSchema, Table } from 'src/sql-tools';
|
||||
|
||||
@Table()
|
||||
export class Table1 {
|
||||
@Column({ default: null })
|
||||
column1!: string;
|
||||
}
|
||||
|
||||
export const description = 'should infer nullable from the default value';
|
||||
export const schema: DatabaseSchema = {
|
||||
databaseName: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
overrides: [],
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
columns: [
|
||||
{
|
||||
name: 'column1',
|
||||
tableName: 'table1',
|
||||
type: 'character varying',
|
||||
nullable: true,
|
||||
isArray: false,
|
||||
primary: false,
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
triggers: [],
|
||||
constraints: [],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
warnings: [],
|
||||
};
|
||||
@@ -1,39 +0,0 @@
|
||||
import { Column, DatabaseSchema, Table } from 'src/sql-tools';
|
||||
|
||||
@Table()
|
||||
export class Table1 {
|
||||
@Column()
|
||||
column1!: string;
|
||||
}
|
||||
|
||||
export const description = 'should register a table with a column with a default name';
|
||||
export const schema: DatabaseSchema = {
|
||||
databaseName: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
overrides: [],
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
columns: [
|
||||
{
|
||||
name: 'column1',
|
||||
tableName: 'table1',
|
||||
type: 'character varying',
|
||||
nullable: false,
|
||||
isArray: false,
|
||||
primary: false,
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
triggers: [],
|
||||
constraints: [],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
warnings: [],
|
||||
};
|
||||
@@ -1,39 +0,0 @@
|
||||
import { Column, DatabaseSchema, Table } from 'src/sql-tools';
|
||||
|
||||
@Table()
|
||||
export class Table1 {
|
||||
@Column({ name: 'column-1' })
|
||||
column1!: string;
|
||||
}
|
||||
|
||||
export const description = 'should register a table with a column with a specific name';
|
||||
export const schema: DatabaseSchema = {
|
||||
databaseName: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
overrides: [],
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
columns: [
|
||||
{
|
||||
name: 'column-1',
|
||||
tableName: 'table1',
|
||||
type: 'character varying',
|
||||
nullable: false,
|
||||
isArray: false,
|
||||
primary: false,
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
triggers: [],
|
||||
constraints: [],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
warnings: [],
|
||||
};
|
||||
@@ -1,39 +0,0 @@
|
||||
import { Column, DatabaseSchema, Table } from 'src/sql-tools';
|
||||
|
||||
@Table()
|
||||
export class Table1 {
|
||||
@Column('column-1')
|
||||
column1!: string;
|
||||
}
|
||||
|
||||
export const description = 'should register a table with a column with a specific name';
|
||||
export const schema: DatabaseSchema = {
|
||||
databaseName: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
overrides: [],
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
columns: [
|
||||
{
|
||||
name: 'column-1',
|
||||
tableName: 'table1',
|
||||
type: 'character varying',
|
||||
nullable: false,
|
||||
isArray: false,
|
||||
primary: false,
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
triggers: [],
|
||||
constraints: [],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
warnings: [],
|
||||
};
|
||||
@@ -1,39 +0,0 @@
|
||||
import { Column, DatabaseSchema, Table } from 'src/sql-tools';
|
||||
|
||||
@Table()
|
||||
export class Table1 {
|
||||
@Column({ nullable: true })
|
||||
column1!: string;
|
||||
}
|
||||
|
||||
export const description = 'should set nullable correctly';
|
||||
export const schema: DatabaseSchema = {
|
||||
databaseName: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
overrides: [],
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
columns: [
|
||||
{
|
||||
name: 'column1',
|
||||
tableName: 'table1',
|
||||
type: 'character varying',
|
||||
nullable: true,
|
||||
isArray: false,
|
||||
primary: false,
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
triggers: [],
|
||||
constraints: [],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
warnings: [],
|
||||
};
|
||||
@@ -1,40 +0,0 @@
|
||||
import { Column, DatabaseSchema, Table } from 'src/sql-tools';
|
||||
|
||||
@Table()
|
||||
export class Table1 {
|
||||
@Column({ length: 2 })
|
||||
column1!: string;
|
||||
}
|
||||
|
||||
export const description = 'should use create a string column with a fixed length';
|
||||
export const schema: DatabaseSchema = {
|
||||
databaseName: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
overrides: [],
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
columns: [
|
||||
{
|
||||
name: 'column1',
|
||||
tableName: 'table1',
|
||||
type: 'character varying',
|
||||
length: 2,
|
||||
nullable: false,
|
||||
isArray: false,
|
||||
primary: false,
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
triggers: [],
|
||||
constraints: [],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
warnings: [],
|
||||
};
|
||||
@@ -1,47 +0,0 @@
|
||||
import { Column, ConstraintType, DatabaseSchema, Table } from 'src/sql-tools';
|
||||
|
||||
@Table()
|
||||
export class Table1 {
|
||||
@Column({ type: 'uuid', unique: true })
|
||||
id!: string;
|
||||
}
|
||||
|
||||
export const description = 'should create a unique key constraint with a default name';
|
||||
export const schema: DatabaseSchema = {
|
||||
databaseName: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
overrides: [],
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
columns: [
|
||||
{
|
||||
name: 'id',
|
||||
tableName: 'table1',
|
||||
type: 'uuid',
|
||||
nullable: false,
|
||||
isArray: false,
|
||||
primary: false,
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
triggers: [],
|
||||
constraints: [
|
||||
{
|
||||
type: ConstraintType.UNIQUE,
|
||||
name: 'UQ_b249cc64cf63b8a22557cdc8537',
|
||||
tableName: 'table1',
|
||||
columnNames: ['id'],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
warnings: [],
|
||||
};
|
||||
@@ -1,47 +0,0 @@
|
||||
import { Column, ConstraintType, DatabaseSchema, Table } from 'src/sql-tools';
|
||||
|
||||
@Table()
|
||||
export class Table1 {
|
||||
@Column({ type: 'uuid', unique: true, uniqueConstraintName: 'UQ_test' })
|
||||
id!: string;
|
||||
}
|
||||
|
||||
export const description = 'should create a unique key constraint with a specific name';
|
||||
export const schema: DatabaseSchema = {
|
||||
databaseName: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
overrides: [],
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
columns: [
|
||||
{
|
||||
name: 'id',
|
||||
tableName: 'table1',
|
||||
type: 'uuid',
|
||||
nullable: false,
|
||||
isArray: false,
|
||||
primary: false,
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
triggers: [],
|
||||
constraints: [
|
||||
{
|
||||
type: ConstraintType.UNIQUE,
|
||||
name: 'UQ_test',
|
||||
tableName: 'table1',
|
||||
columnNames: ['id'],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
warnings: [],
|
||||
};
|
||||
@@ -1,40 +0,0 @@
|
||||
import { DatabaseSchema, Table, UpdateDateColumn } from 'src/sql-tools';
|
||||
|
||||
@Table()
|
||||
export class Table1 {
|
||||
@UpdateDateColumn()
|
||||
updatedAt!: string;
|
||||
}
|
||||
|
||||
export const description = 'should register a table with an updated at date column';
|
||||
export const schema: DatabaseSchema = {
|
||||
databaseName: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
overrides: [],
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
columns: [
|
||||
{
|
||||
name: 'updatedAt',
|
||||
tableName: 'table1',
|
||||
type: 'timestamp with time zone',
|
||||
default: 'now()',
|
||||
nullable: false,
|
||||
isArray: false,
|
||||
primary: false,
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
triggers: [],
|
||||
constraints: [],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
warnings: [],
|
||||
};
|
||||
@@ -1,7 +0,0 @@
|
||||
import { Table } from 'src/sql-tools';
|
||||
|
||||
@Table({ name: 'table-1' })
|
||||
@Table({ name: 'table-2' })
|
||||
export class Table1 {}
|
||||
|
||||
export const message = 'Table table-2 has already been registered';
|
||||
@@ -1,118 +0,0 @@
|
||||
import { Column, ConstraintType, DatabaseSchema, ForeignKeyConstraint, PrimaryColumn, Table } from 'src/sql-tools';
|
||||
|
||||
@Table()
|
||||
export class Table1 {
|
||||
@PrimaryColumn({ type: 'uuid' })
|
||||
id1!: string;
|
||||
|
||||
@PrimaryColumn({ type: 'uuid' })
|
||||
id2!: string;
|
||||
}
|
||||
|
||||
@Table()
|
||||
@ForeignKeyConstraint({
|
||||
columns: ['parentId1', 'parentId2'],
|
||||
referenceTable: () => Table1,
|
||||
referenceColumns: ['id2', 'id1'],
|
||||
})
|
||||
export class Table2 {
|
||||
@Column({ type: 'uuid' })
|
||||
parentId1!: string;
|
||||
|
||||
@Column({ type: 'uuid' })
|
||||
parentId2!: string;
|
||||
}
|
||||
|
||||
export const description = 'should create a foreign key constraint to the target table';
|
||||
export const schema: DatabaseSchema = {
|
||||
databaseName: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
overrides: [],
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
columns: [
|
||||
{
|
||||
name: 'id1',
|
||||
tableName: 'table1',
|
||||
type: 'uuid',
|
||||
nullable: false,
|
||||
isArray: false,
|
||||
primary: true,
|
||||
synchronize: true,
|
||||
},
|
||||
{
|
||||
name: 'id2',
|
||||
tableName: 'table1',
|
||||
type: 'uuid',
|
||||
nullable: false,
|
||||
isArray: false,
|
||||
primary: true,
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
triggers: [],
|
||||
constraints: [
|
||||
{
|
||||
type: ConstraintType.PRIMARY_KEY,
|
||||
name: 'PK_e457e8b1301b7bc06ef78188ee4',
|
||||
tableName: 'table1',
|
||||
columnNames: ['id1', 'id2'],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
synchronize: true,
|
||||
},
|
||||
{
|
||||
name: 'table2',
|
||||
columns: [
|
||||
{
|
||||
name: 'parentId1',
|
||||
tableName: 'table2',
|
||||
type: 'uuid',
|
||||
nullable: false,
|
||||
isArray: false,
|
||||
primary: false,
|
||||
synchronize: true,
|
||||
},
|
||||
{
|
||||
name: 'parentId2',
|
||||
tableName: 'table2',
|
||||
type: 'uuid',
|
||||
nullable: false,
|
||||
isArray: false,
|
||||
primary: false,
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
indexes: [
|
||||
{
|
||||
name: 'IDX_aed36d04470eba20161aa8b1dc',
|
||||
tableName: 'table2',
|
||||
columnNames: ['parentId1', 'parentId2'],
|
||||
unique: false,
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
triggers: [],
|
||||
constraints: [
|
||||
{
|
||||
type: ConstraintType.FOREIGN_KEY,
|
||||
name: 'FK_aed36d04470eba20161aa8b1dc6',
|
||||
tableName: 'table2',
|
||||
columnNames: ['parentId1', 'parentId2'],
|
||||
referenceColumnNames: ['id2', 'id1'],
|
||||
referenceTableName: 'table1',
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
warnings: [],
|
||||
};
|
||||
@@ -1,72 +0,0 @@
|
||||
import { Column, ConstraintType, DatabaseSchema, ForeignKeyConstraint, PrimaryColumn, Table } from 'src/sql-tools';
|
||||
|
||||
@Table()
|
||||
export class Table1 {
|
||||
@PrimaryColumn({ type: 'uuid' })
|
||||
id!: string;
|
||||
}
|
||||
|
||||
@Table()
|
||||
@ForeignKeyConstraint({ columns: ['parentId2'], referenceTable: () => Table1 })
|
||||
export class Table2 {
|
||||
@Column({ type: 'uuid' })
|
||||
parentId!: string;
|
||||
}
|
||||
|
||||
export const description = 'should warn against missing column in foreign key constraint';
|
||||
export const schema: DatabaseSchema = {
|
||||
databaseName: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
overrides: [],
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
columns: [
|
||||
{
|
||||
name: 'id',
|
||||
tableName: 'table1',
|
||||
type: 'uuid',
|
||||
nullable: false,
|
||||
isArray: false,
|
||||
primary: true,
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
triggers: [],
|
||||
constraints: [
|
||||
{
|
||||
type: ConstraintType.PRIMARY_KEY,
|
||||
name: 'PK_b249cc64cf63b8a22557cdc8537',
|
||||
tableName: 'table1',
|
||||
columnNames: ['id'],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
synchronize: true,
|
||||
},
|
||||
{
|
||||
name: 'table2',
|
||||
columns: [
|
||||
{
|
||||
name: 'parentId',
|
||||
tableName: 'table2',
|
||||
type: 'uuid',
|
||||
nullable: false,
|
||||
isArray: false,
|
||||
primary: false,
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
triggers: [],
|
||||
constraints: [],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
warnings: ['[@ForeignKeyConstraint.columns] Unable to find column (Table2.parentId2)'],
|
||||
};
|
||||
@@ -1,72 +0,0 @@
|
||||
import { Column, ConstraintType, DatabaseSchema, ForeignKeyConstraint, PrimaryColumn, Table } from 'src/sql-tools';
|
||||
|
||||
@Table()
|
||||
export class Table1 {
|
||||
@PrimaryColumn({ type: 'uuid' })
|
||||
id!: string;
|
||||
}
|
||||
|
||||
@Table()
|
||||
@ForeignKeyConstraint({ columns: ['parentId'], referenceTable: () => Table1, referenceColumns: ['foo'] })
|
||||
export class Table2 {
|
||||
@Column({ type: 'uuid' })
|
||||
parentId!: string;
|
||||
}
|
||||
|
||||
export const description = 'should warn against missing reference column in foreign key constraint';
|
||||
export const schema: DatabaseSchema = {
|
||||
databaseName: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
overrides: [],
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
columns: [
|
||||
{
|
||||
name: 'id',
|
||||
tableName: 'table1',
|
||||
type: 'uuid',
|
||||
nullable: false,
|
||||
isArray: false,
|
||||
primary: true,
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
triggers: [],
|
||||
constraints: [
|
||||
{
|
||||
type: ConstraintType.PRIMARY_KEY,
|
||||
name: 'PK_b249cc64cf63b8a22557cdc8537',
|
||||
tableName: 'table1',
|
||||
columnNames: ['id'],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
synchronize: true,
|
||||
},
|
||||
{
|
||||
name: 'table2',
|
||||
columns: [
|
||||
{
|
||||
name: 'parentId',
|
||||
tableName: 'table2',
|
||||
type: 'uuid',
|
||||
nullable: false,
|
||||
isArray: false,
|
||||
primary: false,
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
triggers: [],
|
||||
constraints: [],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
warnings: ['[@ForeignKeyConstraint.referenceColumns] Unable to find column (Table1.foo)'],
|
||||
};
|
||||
@@ -1,45 +0,0 @@
|
||||
import { Column, DatabaseSchema, ForeignKeyConstraint, Table } from 'src/sql-tools';
|
||||
|
||||
class Foo {}
|
||||
|
||||
@Table()
|
||||
@ForeignKeyConstraint({
|
||||
columns: ['parentId'],
|
||||
referenceTable: () => Foo,
|
||||
})
|
||||
export class Table1 {
|
||||
@Column()
|
||||
parentId!: string;
|
||||
}
|
||||
|
||||
export const description = 'should warn against missing reference table';
|
||||
export const schema: DatabaseSchema = {
|
||||
databaseName: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
overrides: [],
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
columns: [
|
||||
{
|
||||
name: 'parentId',
|
||||
tableName: 'table1',
|
||||
type: 'character varying',
|
||||
nullable: false,
|
||||
isArray: false,
|
||||
primary: false,
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
triggers: [],
|
||||
constraints: [],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
warnings: ['[@ForeignKeyConstraint.referenceTable] Unable to find table (Foo)'],
|
||||
};
|
||||
@@ -1,114 +0,0 @@
|
||||
import { Column, ConstraintType, DatabaseSchema, ForeignKeyConstraint, PrimaryColumn, Table } from 'src/sql-tools';
|
||||
|
||||
@Table()
|
||||
export class Table1 {
|
||||
@PrimaryColumn({ type: 'uuid' })
|
||||
id1!: string;
|
||||
|
||||
@PrimaryColumn({ type: 'uuid' })
|
||||
id2!: string;
|
||||
}
|
||||
|
||||
@Table()
|
||||
@ForeignKeyConstraint({ columns: ['parentId1', 'parentId2'], referenceTable: () => Table1 })
|
||||
export class Table2 {
|
||||
@Column({ type: 'uuid' })
|
||||
parentId1!: string;
|
||||
|
||||
@Column({ type: 'uuid' })
|
||||
parentId2!: string;
|
||||
}
|
||||
|
||||
export const description = 'should create a foreign key constraint to the target table';
|
||||
export const schema: DatabaseSchema = {
|
||||
databaseName: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
overrides: [],
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
columns: [
|
||||
{
|
||||
name: 'id1',
|
||||
tableName: 'table1',
|
||||
type: 'uuid',
|
||||
nullable: false,
|
||||
isArray: false,
|
||||
primary: true,
|
||||
synchronize: true,
|
||||
},
|
||||
{
|
||||
name: 'id2',
|
||||
tableName: 'table1',
|
||||
type: 'uuid',
|
||||
nullable: false,
|
||||
isArray: false,
|
||||
primary: true,
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
triggers: [],
|
||||
constraints: [
|
||||
{
|
||||
type: ConstraintType.PRIMARY_KEY,
|
||||
name: 'PK_e457e8b1301b7bc06ef78188ee4',
|
||||
tableName: 'table1',
|
||||
columnNames: ['id1', 'id2'],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
synchronize: true,
|
||||
},
|
||||
{
|
||||
name: 'table2',
|
||||
columns: [
|
||||
{
|
||||
name: 'parentId1',
|
||||
tableName: 'table2',
|
||||
type: 'uuid',
|
||||
nullable: false,
|
||||
isArray: false,
|
||||
primary: false,
|
||||
synchronize: true,
|
||||
},
|
||||
{
|
||||
name: 'parentId2',
|
||||
tableName: 'table2',
|
||||
type: 'uuid',
|
||||
nullable: false,
|
||||
isArray: false,
|
||||
primary: false,
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
indexes: [
|
||||
{
|
||||
name: 'IDX_aed36d04470eba20161aa8b1dc',
|
||||
tableName: 'table2',
|
||||
columnNames: ['parentId1', 'parentId2'],
|
||||
unique: false,
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
triggers: [],
|
||||
constraints: [
|
||||
{
|
||||
type: ConstraintType.FOREIGN_KEY,
|
||||
name: 'FK_aed36d04470eba20161aa8b1dc6',
|
||||
tableName: 'table2',
|
||||
columnNames: ['parentId1', 'parentId2'],
|
||||
referenceColumnNames: ['id1', 'id2'],
|
||||
referenceTableName: 'table1',
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
warnings: [],
|
||||
};
|
||||
@@ -1,82 +0,0 @@
|
||||
import { Column, ConstraintType, DatabaseSchema, ForeignKeyConstraint, PrimaryColumn, Table } from 'src/sql-tools';
|
||||
|
||||
@Table()
|
||||
export class Table1 {
|
||||
@PrimaryColumn({ type: 'uuid' })
|
||||
id!: string;
|
||||
}
|
||||
|
||||
@Table()
|
||||
@ForeignKeyConstraint({ columns: ['parentId'], referenceTable: () => Table1, index: false })
|
||||
export class Table2 {
|
||||
@Column({ type: 'uuid' })
|
||||
parentId!: string;
|
||||
}
|
||||
|
||||
export const description = 'should create a foreign key constraint to the target table without an index';
|
||||
export const schema: DatabaseSchema = {
|
||||
databaseName: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
overrides: [],
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
columns: [
|
||||
{
|
||||
name: 'id',
|
||||
tableName: 'table1',
|
||||
type: 'uuid',
|
||||
nullable: false,
|
||||
isArray: false,
|
||||
primary: true,
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
triggers: [],
|
||||
constraints: [
|
||||
{
|
||||
type: ConstraintType.PRIMARY_KEY,
|
||||
name: 'PK_b249cc64cf63b8a22557cdc8537',
|
||||
tableName: 'table1',
|
||||
columnNames: ['id'],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
synchronize: true,
|
||||
},
|
||||
{
|
||||
name: 'table2',
|
||||
columns: [
|
||||
{
|
||||
name: 'parentId',
|
||||
tableName: 'table2',
|
||||
type: 'uuid',
|
||||
nullable: false,
|
||||
isArray: false,
|
||||
primary: false,
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
triggers: [],
|
||||
constraints: [
|
||||
{
|
||||
type: ConstraintType.FOREIGN_KEY,
|
||||
name: 'FK_3fcca5cc563abf256fc346e3ff4',
|
||||
tableName: 'table2',
|
||||
columnNames: ['parentId'],
|
||||
referenceColumnNames: ['id'],
|
||||
referenceTableName: 'table1',
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
warnings: [],
|
||||
};
|
||||
@@ -1,86 +0,0 @@
|
||||
import { Column, ConstraintType, DatabaseSchema, ForeignKeyConstraint, Table } from 'src/sql-tools';
|
||||
|
||||
@Table()
|
||||
export class Table1 {
|
||||
@Column()
|
||||
foo!: string;
|
||||
}
|
||||
|
||||
@Table()
|
||||
@ForeignKeyConstraint({
|
||||
columns: ['bar'],
|
||||
referenceTable: () => Table1,
|
||||
referenceColumns: ['foo'],
|
||||
})
|
||||
export class Table2 {
|
||||
@Column()
|
||||
bar!: string;
|
||||
}
|
||||
|
||||
export const description = 'should create a foreign key constraint to the target table without a primary key';
|
||||
export const schema: DatabaseSchema = {
|
||||
databaseName: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
overrides: [],
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
columns: [
|
||||
{
|
||||
name: 'foo',
|
||||
tableName: 'table1',
|
||||
type: 'character varying',
|
||||
nullable: false,
|
||||
isArray: false,
|
||||
primary: false,
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
triggers: [],
|
||||
constraints: [],
|
||||
synchronize: true,
|
||||
},
|
||||
{
|
||||
name: 'table2',
|
||||
columns: [
|
||||
{
|
||||
name: 'bar',
|
||||
tableName: 'table2',
|
||||
type: 'character varying',
|
||||
nullable: false,
|
||||
isArray: false,
|
||||
primary: false,
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
indexes: [
|
||||
{
|
||||
name: 'IDX_7d9c784c98d12365d198d52e4e',
|
||||
tableName: 'table2',
|
||||
columnNames: ['bar'],
|
||||
unique: false,
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
triggers: [],
|
||||
constraints: [
|
||||
{
|
||||
type: ConstraintType.FOREIGN_KEY,
|
||||
name: 'FK_7d9c784c98d12365d198d52e4e6',
|
||||
tableName: 'table2',
|
||||
columnNames: ['bar'],
|
||||
referenceTableName: 'table1',
|
||||
referenceColumnNames: ['foo'],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
warnings: [],
|
||||
};
|
||||
@@ -1,90 +0,0 @@
|
||||
import { Column, ConstraintType, DatabaseSchema, ForeignKeyConstraint, PrimaryColumn, Table } from 'src/sql-tools';
|
||||
|
||||
@Table()
|
||||
export class Table1 {
|
||||
@PrimaryColumn({ type: 'uuid' })
|
||||
id!: string;
|
||||
}
|
||||
|
||||
@Table()
|
||||
@ForeignKeyConstraint({ columns: ['parentId'], referenceTable: () => Table1 })
|
||||
export class Table2 {
|
||||
@Column({ type: 'uuid' })
|
||||
parentId!: string;
|
||||
}
|
||||
|
||||
export const description = 'should create a foreign key constraint to the target table';
|
||||
export const schema: DatabaseSchema = {
|
||||
databaseName: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
overrides: [],
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
columns: [
|
||||
{
|
||||
name: 'id',
|
||||
tableName: 'table1',
|
||||
type: 'uuid',
|
||||
nullable: false,
|
||||
isArray: false,
|
||||
primary: true,
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
triggers: [],
|
||||
constraints: [
|
||||
{
|
||||
type: ConstraintType.PRIMARY_KEY,
|
||||
name: 'PK_b249cc64cf63b8a22557cdc8537',
|
||||
tableName: 'table1',
|
||||
columnNames: ['id'],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
synchronize: true,
|
||||
},
|
||||
{
|
||||
name: 'table2',
|
||||
columns: [
|
||||
{
|
||||
name: 'parentId',
|
||||
tableName: 'table2',
|
||||
type: 'uuid',
|
||||
nullable: false,
|
||||
isArray: false,
|
||||
primary: false,
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
indexes: [
|
||||
{
|
||||
name: 'IDX_3fcca5cc563abf256fc346e3ff',
|
||||
tableName: 'table2',
|
||||
columnNames: ['parentId'],
|
||||
unique: false,
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
triggers: [],
|
||||
constraints: [
|
||||
{
|
||||
type: ConstraintType.FOREIGN_KEY,
|
||||
name: 'FK_3fcca5cc563abf256fc346e3ff4',
|
||||
tableName: 'table2',
|
||||
columnNames: ['parentId'],
|
||||
referenceColumnNames: ['id'],
|
||||
referenceTableName: 'table1',
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
warnings: [],
|
||||
};
|
||||
@@ -1,89 +0,0 @@
|
||||
import { ConstraintType, DatabaseSchema, ForeignKeyColumn, PrimaryColumn, Table } from 'src/sql-tools';
|
||||
|
||||
@Table()
|
||||
export class Table1 {
|
||||
@PrimaryColumn({ type: 'uuid' })
|
||||
id!: string;
|
||||
}
|
||||
|
||||
@Table()
|
||||
export class Table2 {
|
||||
@ForeignKeyColumn(() => Table1, {})
|
||||
parentId!: string;
|
||||
}
|
||||
|
||||
export const description = 'should infer the column type from the reference column';
|
||||
export const schema: DatabaseSchema = {
|
||||
databaseName: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
overrides: [],
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
columns: [
|
||||
{
|
||||
name: 'id',
|
||||
tableName: 'table1',
|
||||
type: 'uuid',
|
||||
nullable: false,
|
||||
isArray: false,
|
||||
primary: true,
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
triggers: [],
|
||||
constraints: [
|
||||
{
|
||||
type: ConstraintType.PRIMARY_KEY,
|
||||
name: 'PK_b249cc64cf63b8a22557cdc8537',
|
||||
tableName: 'table1',
|
||||
columnNames: ['id'],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
synchronize: true,
|
||||
},
|
||||
{
|
||||
name: 'table2',
|
||||
columns: [
|
||||
{
|
||||
name: 'parentId',
|
||||
tableName: 'table2',
|
||||
type: 'uuid',
|
||||
nullable: false,
|
||||
isArray: false,
|
||||
primary: false,
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
indexes: [
|
||||
{
|
||||
name: 'IDX_3fcca5cc563abf256fc346e3ff',
|
||||
tableName: 'table2',
|
||||
columnNames: ['parentId'],
|
||||
unique: false,
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
triggers: [],
|
||||
constraints: [
|
||||
{
|
||||
type: ConstraintType.FOREIGN_KEY,
|
||||
name: 'FK_3fcca5cc563abf256fc346e3ff4',
|
||||
tableName: 'table2',
|
||||
columnNames: ['parentId'],
|
||||
referenceColumnNames: ['id'],
|
||||
referenceTableName: 'table1',
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
warnings: [],
|
||||
};
|
||||
@@ -1,96 +0,0 @@
|
||||
import { ConstraintType, DatabaseSchema, ForeignKeyColumn, PrimaryColumn, Table } from 'src/sql-tools';
|
||||
|
||||
@Table()
|
||||
export class Table1 {
|
||||
@PrimaryColumn({ type: 'uuid' })
|
||||
id!: string;
|
||||
}
|
||||
|
||||
@Table()
|
||||
export class Table2 {
|
||||
@ForeignKeyColumn(() => Table1, { unique: true })
|
||||
parentId!: string;
|
||||
}
|
||||
|
||||
export const description = 'should create a foreign key constraint with a unique constraint';
|
||||
export const schema: DatabaseSchema = {
|
||||
databaseName: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
overrides: [],
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
columns: [
|
||||
{
|
||||
name: 'id',
|
||||
tableName: 'table1',
|
||||
type: 'uuid',
|
||||
nullable: false,
|
||||
isArray: false,
|
||||
primary: true,
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
triggers: [],
|
||||
constraints: [
|
||||
{
|
||||
type: ConstraintType.PRIMARY_KEY,
|
||||
name: 'PK_b249cc64cf63b8a22557cdc8537',
|
||||
tableName: 'table1',
|
||||
columnNames: ['id'],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
synchronize: true,
|
||||
},
|
||||
{
|
||||
name: 'table2',
|
||||
columns: [
|
||||
{
|
||||
name: 'parentId',
|
||||
tableName: 'table2',
|
||||
type: 'uuid',
|
||||
nullable: false,
|
||||
isArray: false,
|
||||
primary: false,
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
indexes: [
|
||||
{
|
||||
name: 'IDX_3fcca5cc563abf256fc346e3ff',
|
||||
tableName: 'table2',
|
||||
columnNames: ['parentId'],
|
||||
unique: false,
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
triggers: [],
|
||||
constraints: [
|
||||
{
|
||||
type: ConstraintType.FOREIGN_KEY,
|
||||
name: 'FK_3fcca5cc563abf256fc346e3ff4',
|
||||
tableName: 'table2',
|
||||
columnNames: ['parentId'],
|
||||
referenceColumnNames: ['id'],
|
||||
referenceTableName: 'table1',
|
||||
synchronize: true,
|
||||
},
|
||||
{
|
||||
type: ConstraintType.UNIQUE,
|
||||
name: 'UQ_3fcca5cc563abf256fc346e3ff4',
|
||||
tableName: 'table2',
|
||||
columnNames: ['parentId'],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
warnings: [],
|
||||
};
|
||||
@@ -1,48 +0,0 @@
|
||||
import { Column, DatabaseSchema, Index, Table } from 'src/sql-tools';
|
||||
|
||||
@Table()
|
||||
@Index({ columns: ['id'] })
|
||||
export class Table1 {
|
||||
@Column({ type: 'uuid' })
|
||||
id!: string;
|
||||
}
|
||||
|
||||
export const description = 'should create an index with a default name';
|
||||
export const schema: DatabaseSchema = {
|
||||
databaseName: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
overrides: [],
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
columns: [
|
||||
{
|
||||
name: 'id',
|
||||
tableName: 'table1',
|
||||
type: 'uuid',
|
||||
nullable: false,
|
||||
isArray: false,
|
||||
primary: false,
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
indexes: [
|
||||
{
|
||||
name: 'IDX_b249cc64cf63b8a22557cdc853',
|
||||
tableName: 'table1',
|
||||
unique: false,
|
||||
columnNames: ['id'],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
triggers: [],
|
||||
constraints: [],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
warnings: [],
|
||||
};
|
||||
@@ -1,48 +0,0 @@
|
||||
import { Column, DatabaseSchema, Index, Table } from 'src/sql-tools';
|
||||
|
||||
@Table()
|
||||
@Index({ name: 'IDX_test', columns: ['id'] })
|
||||
export class Table1 {
|
||||
@Column({ type: 'uuid' })
|
||||
id!: string;
|
||||
}
|
||||
|
||||
export const description = 'should create an index with a specific name';
|
||||
export const schema: DatabaseSchema = {
|
||||
databaseName: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
overrides: [],
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
columns: [
|
||||
{
|
||||
name: 'id',
|
||||
tableName: 'table1',
|
||||
type: 'uuid',
|
||||
nullable: false,
|
||||
isArray: false,
|
||||
primary: false,
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
indexes: [
|
||||
{
|
||||
name: 'IDX_test',
|
||||
tableName: 'table1',
|
||||
unique: false,
|
||||
columnNames: ['id'],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
triggers: [],
|
||||
constraints: [],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
warnings: [],
|
||||
};
|
||||
@@ -1,48 +0,0 @@
|
||||
import { Column, DatabaseSchema, Index, Table } from 'src/sql-tools';
|
||||
|
||||
@Table()
|
||||
@Index({ expression: '"id" IS NOT NULL' })
|
||||
export class Table1 {
|
||||
@Column({ nullable: true })
|
||||
column1!: string;
|
||||
}
|
||||
|
||||
export const description = 'should create an index based off of an expression';
|
||||
export const schema: DatabaseSchema = {
|
||||
databaseName: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
overrides: [],
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
columns: [
|
||||
{
|
||||
name: 'column1',
|
||||
tableName: 'table1',
|
||||
type: 'character varying',
|
||||
nullable: true,
|
||||
isArray: false,
|
||||
primary: false,
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
indexes: [
|
||||
{
|
||||
name: 'IDX_376788d186160c4faa5aaaef63',
|
||||
tableName: 'table1',
|
||||
unique: false,
|
||||
expression: '"id" IS NOT NULL',
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
triggers: [],
|
||||
constraints: [],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
warnings: [],
|
||||
};
|
||||
@@ -1,49 +0,0 @@
|
||||
import { Column, DatabaseSchema, Index, Table } from 'src/sql-tools';
|
||||
|
||||
@Table()
|
||||
@Index({ columns: ['id'], where: '"id" IS NOT NULL' })
|
||||
export class Table1 {
|
||||
@Column({ nullable: true })
|
||||
column1!: string;
|
||||
}
|
||||
|
||||
export const description = 'should create an index with a where clause';
|
||||
export const schema: DatabaseSchema = {
|
||||
databaseName: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
overrides: [],
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
columns: [
|
||||
{
|
||||
name: 'column1',
|
||||
tableName: 'table1',
|
||||
type: 'character varying',
|
||||
nullable: true,
|
||||
isArray: false,
|
||||
primary: false,
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
indexes: [
|
||||
{
|
||||
name: 'IDX_9f4e073964c0395f51f9b39900',
|
||||
tableName: 'table1',
|
||||
unique: false,
|
||||
columnNames: ['id'],
|
||||
where: '"id" IS NOT NULL',
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
triggers: [],
|
||||
constraints: [],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
warnings: [],
|
||||
};
|
||||
@@ -1,47 +0,0 @@
|
||||
import { ConstraintType, DatabaseSchema, PrimaryColumn, Table } from 'src/sql-tools';
|
||||
|
||||
@Table()
|
||||
export class Table1 {
|
||||
@PrimaryColumn({ type: 'uuid' })
|
||||
id!: string;
|
||||
}
|
||||
|
||||
export const description = 'should add a primary key constraint to the table with a default name';
|
||||
export const schema: DatabaseSchema = {
|
||||
databaseName: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
overrides: [],
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
columns: [
|
||||
{
|
||||
name: 'id',
|
||||
tableName: 'table1',
|
||||
type: 'uuid',
|
||||
nullable: false,
|
||||
isArray: false,
|
||||
primary: true,
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
triggers: [],
|
||||
constraints: [
|
||||
{
|
||||
type: ConstraintType.PRIMARY_KEY,
|
||||
name: 'PK_b249cc64cf63b8a22557cdc8537',
|
||||
tableName: 'table1',
|
||||
columnNames: ['id'],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
warnings: [],
|
||||
};
|
||||
@@ -1,47 +0,0 @@
|
||||
import { ConstraintType, DatabaseSchema, PrimaryColumn, Table } from 'src/sql-tools';
|
||||
|
||||
@Table({ primaryConstraintName: 'PK_test' })
|
||||
export class Table1 {
|
||||
@PrimaryColumn({ type: 'uuid' })
|
||||
id!: string;
|
||||
}
|
||||
|
||||
export const description = 'should add a primary key constraint to the table with a specific name';
|
||||
export const schema: DatabaseSchema = {
|
||||
databaseName: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
overrides: [],
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
columns: [
|
||||
{
|
||||
name: 'id',
|
||||
tableName: 'table1',
|
||||
type: 'uuid',
|
||||
nullable: false,
|
||||
isArray: false,
|
||||
primary: true,
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
triggers: [],
|
||||
constraints: [
|
||||
{
|
||||
type: ConstraintType.PRIMARY_KEY,
|
||||
name: 'PK_test',
|
||||
tableName: 'table1',
|
||||
columnNames: ['id'],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
warnings: [],
|
||||
};
|
||||
@@ -1,26 +0,0 @@
|
||||
import { DatabaseSchema, Table } from 'src/sql-tools';
|
||||
|
||||
@Table()
|
||||
export class Table1 {}
|
||||
|
||||
export const description = 'should register a table with a default name';
|
||||
export const schema: DatabaseSchema = {
|
||||
databaseName: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
overrides: [],
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
columns: [],
|
||||
indexes: [],
|
||||
triggers: [],
|
||||
constraints: [],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
warnings: [],
|
||||
};
|
||||
@@ -1,26 +0,0 @@
|
||||
import { DatabaseSchema, Table } from 'src/sql-tools';
|
||||
|
||||
@Table({ name: 'table-1' })
|
||||
export class Table1 {}
|
||||
|
||||
export const description = 'should register a table with a specific name';
|
||||
export const schema: DatabaseSchema = {
|
||||
databaseName: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
overrides: [],
|
||||
tables: [
|
||||
{
|
||||
name: 'table-1',
|
||||
columns: [],
|
||||
indexes: [],
|
||||
triggers: [],
|
||||
constraints: [],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
warnings: [],
|
||||
};
|
||||
@@ -1,26 +0,0 @@
|
||||
import { DatabaseSchema, Table } from 'src/sql-tools';
|
||||
|
||||
@Table('table-1')
|
||||
export class Table1 {}
|
||||
|
||||
export const description = 'should register a table with a specific name';
|
||||
export const schema: DatabaseSchema = {
|
||||
databaseName: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
overrides: [],
|
||||
tables: [
|
||||
{
|
||||
name: 'table-1',
|
||||
columns: [],
|
||||
indexes: [],
|
||||
triggers: [],
|
||||
constraints: [],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
warnings: [],
|
||||
};
|
||||
@@ -1,47 +0,0 @@
|
||||
import { AfterDeleteTrigger, DatabaseSchema, registerFunction, Table } from 'src/sql-tools';
|
||||
|
||||
const test_fn = registerFunction({
|
||||
name: 'test_fn',
|
||||
body: 'SELECT 1;',
|
||||
returnType: 'character varying',
|
||||
});
|
||||
|
||||
@Table()
|
||||
@AfterDeleteTrigger({
|
||||
name: 'my_trigger',
|
||||
function: test_fn,
|
||||
scope: 'row',
|
||||
})
|
||||
export class Table1 {}
|
||||
|
||||
export const description = 'should create a trigger';
|
||||
export const schema: DatabaseSchema = {
|
||||
databaseName: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [expect.any(Object)],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
overrides: [],
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
columns: [],
|
||||
indexes: [],
|
||||
triggers: [
|
||||
{
|
||||
name: 'my_trigger',
|
||||
functionName: 'test_fn',
|
||||
tableName: 'table1',
|
||||
timing: 'after',
|
||||
scope: 'row',
|
||||
actions: ['delete'],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
constraints: [],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
warnings: [],
|
||||
};
|
||||
@@ -1,47 +0,0 @@
|
||||
import { BeforeUpdateTrigger, DatabaseSchema, registerFunction, Table } from 'src/sql-tools';
|
||||
|
||||
const test_fn = registerFunction({
|
||||
name: 'test_fn',
|
||||
body: 'SELECT 1;',
|
||||
returnType: 'character varying',
|
||||
});
|
||||
|
||||
@Table()
|
||||
@BeforeUpdateTrigger({
|
||||
name: 'my_trigger',
|
||||
function: test_fn,
|
||||
scope: 'row',
|
||||
})
|
||||
export class Table1 {}
|
||||
|
||||
export const description = 'should create a trigger ';
|
||||
export const schema: DatabaseSchema = {
|
||||
databaseName: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [expect.any(Object)],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
overrides: [],
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
columns: [],
|
||||
indexes: [],
|
||||
triggers: [
|
||||
{
|
||||
name: 'my_trigger',
|
||||
functionName: 'test_fn',
|
||||
tableName: 'table1',
|
||||
timing: 'before',
|
||||
scope: 'row',
|
||||
actions: ['update'],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
constraints: [],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
warnings: [],
|
||||
};
|
||||
@@ -1,42 +0,0 @@
|
||||
import { DatabaseSchema, Table, Trigger } from 'src/sql-tools';
|
||||
|
||||
@Table()
|
||||
@Trigger({
|
||||
timing: 'before',
|
||||
actions: ['insert'],
|
||||
scope: 'row',
|
||||
functionName: 'function1',
|
||||
})
|
||||
export class Table1 {}
|
||||
|
||||
export const description = 'should register a trigger with a default name';
|
||||
export const schema: DatabaseSchema = {
|
||||
databaseName: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
overrides: [],
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
columns: [],
|
||||
indexes: [],
|
||||
triggers: [
|
||||
{
|
||||
name: 'TR_ca71832b10b77ed600ef05df631',
|
||||
tableName: 'table1',
|
||||
functionName: 'function1',
|
||||
actions: ['insert'],
|
||||
scope: 'row',
|
||||
timing: 'before',
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
constraints: [],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
warnings: [],
|
||||
};
|
||||
@@ -1,43 +0,0 @@
|
||||
import { DatabaseSchema, Table, Trigger } from 'src/sql-tools';
|
||||
|
||||
@Table()
|
||||
@Trigger({
|
||||
name: 'trigger1',
|
||||
timing: 'before',
|
||||
actions: ['insert'],
|
||||
scope: 'row',
|
||||
functionName: 'function1',
|
||||
})
|
||||
export class Table1 {}
|
||||
|
||||
export const description = 'should a trigger with a specific name';
|
||||
export const schema: DatabaseSchema = {
|
||||
databaseName: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
overrides: [],
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
columns: [],
|
||||
indexes: [],
|
||||
triggers: [
|
||||
{
|
||||
name: 'trigger1',
|
||||
tableName: 'table1',
|
||||
functionName: 'function1',
|
||||
actions: ['insert'],
|
||||
scope: 'row',
|
||||
timing: 'before',
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
constraints: [],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
warnings: [],
|
||||
};
|
||||
@@ -1,48 +0,0 @@
|
||||
import { Column, ConstraintType, DatabaseSchema, Table, Unique } from 'src/sql-tools';
|
||||
|
||||
@Table()
|
||||
@Unique({ columns: ['id'] })
|
||||
export class Table1 {
|
||||
@Column({ type: 'uuid' })
|
||||
id!: string;
|
||||
}
|
||||
|
||||
export const description = 'should add a unique constraint to the table with a default name';
|
||||
export const schema: DatabaseSchema = {
|
||||
databaseName: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
overrides: [],
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
columns: [
|
||||
{
|
||||
name: 'id',
|
||||
tableName: 'table1',
|
||||
type: 'uuid',
|
||||
nullable: false,
|
||||
isArray: false,
|
||||
primary: false,
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
triggers: [],
|
||||
constraints: [
|
||||
{
|
||||
type: ConstraintType.UNIQUE,
|
||||
name: 'UQ_b249cc64cf63b8a22557cdc8537',
|
||||
tableName: 'table1',
|
||||
columnNames: ['id'],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
warnings: [],
|
||||
};
|
||||
@@ -1,48 +0,0 @@
|
||||
import { Column, ConstraintType, DatabaseSchema, Table, Unique } from 'src/sql-tools';
|
||||
|
||||
@Table()
|
||||
@Unique({ name: 'UQ_test', columns: ['id'] })
|
||||
export class Table1 {
|
||||
@Column({ type: 'uuid' })
|
||||
id!: string;
|
||||
}
|
||||
|
||||
export const description = 'should add a unique constraint to the table with a specific name';
|
||||
export const schema: DatabaseSchema = {
|
||||
databaseName: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
overrides: [],
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
columns: [
|
||||
{
|
||||
name: 'id',
|
||||
tableName: 'table1',
|
||||
type: 'uuid',
|
||||
nullable: false,
|
||||
isArray: false,
|
||||
primary: false,
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
triggers: [],
|
||||
constraints: [
|
||||
{
|
||||
type: ConstraintType.UNIQUE,
|
||||
name: 'UQ_test',
|
||||
tableName: 'table1',
|
||||
columnNames: ['id'],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
warnings: [],
|
||||
};
|
||||
@@ -1,3 +1,4 @@
|
||||
import { createPostgres, DatabaseConnectionParams } from '@immich/sql-tools';
|
||||
import { CallHandler, ExecutionContext, Provider, ValidationPipe } from '@nestjs/common';
|
||||
import { APP_GUARD, APP_PIPE } from '@nestjs/core';
|
||||
import { transformException } from '@nestjs/platform-express/multer/multer/multer.utils';
|
||||
@@ -9,7 +10,6 @@ import multer from 'multer';
|
||||
import { ChildProcessWithoutNullStreams } from 'node:child_process';
|
||||
import { Duplex, Readable, Writable } from 'node:stream';
|
||||
import { PNG } from 'pngjs';
|
||||
import postgres from 'postgres';
|
||||
import { UploadFieldName } from 'src/dtos/asset-media.dto';
|
||||
import { AssetUploadInterceptor } from 'src/middleware/asset-upload.interceptor';
|
||||
import { AuthGuard } from 'src/middleware/auth.guard';
|
||||
@@ -71,7 +71,7 @@ import { DB } from 'src/schema';
|
||||
import { AuthService } from 'src/services/auth.service';
|
||||
import { BaseService } from 'src/services/base.service';
|
||||
import { RepositoryInterface } from 'src/types';
|
||||
import { asPostgresConnectionConfig, getKyselyConfig } from 'src/utils/database';
|
||||
import { getKyselyConfig } from 'src/utils/database';
|
||||
import { IAccessRepositoryMock, newAccessRepositoryMock } from 'test/repositories/access.repository.mock';
|
||||
import { newAssetRepositoryMock } from 'test/repositories/asset.repository.mock';
|
||||
import { newConfigRepositoryMock } from 'test/repositories/config.repository.mock';
|
||||
@@ -449,13 +449,8 @@ const withDatabase = (url: string, name: string) => url.replace(`/${templateName
|
||||
|
||||
export const getKyselyDB = async (suffix?: string): Promise<Kysely<DB>> => {
|
||||
const testUrl = process.env.IMMICH_TEST_POSTGRES_URL!;
|
||||
const sql = postgres({
|
||||
...asPostgresConnectionConfig({
|
||||
connectionType: 'url',
|
||||
url: withDatabase(testUrl, 'postgres'),
|
||||
}),
|
||||
max: 1,
|
||||
});
|
||||
const connection = { connectionType: 'url', url: withDatabase(testUrl, 'postgres') } as DatabaseConnectionParams;
|
||||
const sql = createPostgres({ maxConnections: 1, connection });
|
||||
|
||||
const randomSuffix = Math.random().toString(36).slice(2, 7);
|
||||
const dbName = `immich_${suffix ?? randomSuffix}`;
|
||||
|
||||
Reference in New Issue
Block a user