mirror of
https://github.com/immich-app/immich
synced 2025-11-07 17:27:20 +00:00
feat: schema diff sql tools (#17116)
This commit is contained in:
parent
3fde5a8328
commit
4b4bcd23f4
132 changed files with 5837 additions and 1246 deletions
41
server/test/sql-tools/check-constraint-default-name.stub.ts
Normal file
41
server/test/sql-tools/check-constraint-default-name.stub.ts
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
import { Check, Column, DatabaseConstraintType, 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 = {
|
||||
name: 'public',
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
columns: [
|
||||
{
|
||||
name: 'id',
|
||||
tableName: 'table1',
|
||||
type: 'uuid',
|
||||
nullable: false,
|
||||
isArray: false,
|
||||
primary: false,
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
constraints: [
|
||||
{
|
||||
type: DatabaseConstraintType.CHECK,
|
||||
name: 'CHK_8d2ecfd49b984941f6b2589799',
|
||||
tableName: 'table1',
|
||||
expression: '1=1',
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
warnings: [],
|
||||
};
|
||||
41
server/test/sql-tools/check-constraint-override-name.stub.ts
Normal file
41
server/test/sql-tools/check-constraint-override-name.stub.ts
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
import { Check, Column, DatabaseConstraintType, 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 = {
|
||||
name: 'public',
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
columns: [
|
||||
{
|
||||
name: 'id',
|
||||
tableName: 'table1',
|
||||
type: 'uuid',
|
||||
nullable: false,
|
||||
isArray: false,
|
||||
primary: false,
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
constraints: [
|
||||
{
|
||||
type: DatabaseConstraintType.CHECK,
|
||||
name: 'CHK_test',
|
||||
tableName: 'table1',
|
||||
expression: '1=1',
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
warnings: [],
|
||||
};
|
||||
33
server/test/sql-tools/column-default-boolean.stub.ts
Normal file
33
server/test/sql-tools/column-default-boolean.stub.ts
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
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 = {
|
||||
name: 'public',
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
columns: [
|
||||
{
|
||||
name: 'column1',
|
||||
tableName: 'table1',
|
||||
type: 'boolean',
|
||||
nullable: false,
|
||||
isArray: false,
|
||||
primary: false,
|
||||
synchronize: true,
|
||||
default: 'true',
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
constraints: [],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
warnings: [],
|
||||
};
|
||||
35
server/test/sql-tools/column-default-date.stub.ts
Normal file
35
server/test/sql-tools/column-default-date.stub.ts
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
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 = {
|
||||
name: 'public',
|
||||
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: [],
|
||||
constraints: [],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
warnings: [],
|
||||
};
|
||||
33
server/test/sql-tools/column-default-function.stub.ts
Normal file
33
server/test/sql-tools/column-default-function.stub.ts
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
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 = {
|
||||
name: 'public',
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
columns: [
|
||||
{
|
||||
name: 'column1',
|
||||
tableName: 'table1',
|
||||
type: 'character varying',
|
||||
nullable: false,
|
||||
isArray: false,
|
||||
primary: false,
|
||||
synchronize: true,
|
||||
default: 'now()',
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
constraints: [],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
warnings: [],
|
||||
};
|
||||
32
server/test/sql-tools/column-default-null.stub.ts
Normal file
32
server/test/sql-tools/column-default-null.stub.ts
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
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 = {
|
||||
name: 'public',
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
columns: [
|
||||
{
|
||||
name: 'column1',
|
||||
tableName: 'table1',
|
||||
type: 'character varying',
|
||||
nullable: true,
|
||||
isArray: false,
|
||||
primary: false,
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
constraints: [],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
warnings: [],
|
||||
};
|
||||
33
server/test/sql-tools/column-default-number.stub.ts
Normal file
33
server/test/sql-tools/column-default-number.stub.ts
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
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 = {
|
||||
name: 'public',
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
columns: [
|
||||
{
|
||||
name: 'column1',
|
||||
tableName: 'table1',
|
||||
type: 'integer',
|
||||
nullable: false,
|
||||
isArray: false,
|
||||
primary: false,
|
||||
synchronize: true,
|
||||
default: '0',
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
constraints: [],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
warnings: [],
|
||||
};
|
||||
33
server/test/sql-tools/column-default-string.stub.ts
Normal file
33
server/test/sql-tools/column-default-string.stub.ts
Normal file
|
|
@ -0,0 +1,33 @@
|
|||
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 = {
|
||||
name: 'public',
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
columns: [
|
||||
{
|
||||
name: 'column1',
|
||||
tableName: 'table1',
|
||||
type: 'character varying',
|
||||
nullable: false,
|
||||
isArray: false,
|
||||
primary: false,
|
||||
synchronize: true,
|
||||
default: "'foo'",
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
constraints: [],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
warnings: [],
|
||||
};
|
||||
39
server/test/sql-tools/column-enum-name.stub.ts
Normal file
39
server/test/sql-tools/column-enum-name.stub.ts
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
import { Column, DatabaseSchema, Table } from 'src/sql-tools';
|
||||
|
||||
enum Test {
|
||||
Foo = 'foo',
|
||||
Bar = 'bar',
|
||||
}
|
||||
|
||||
@Table()
|
||||
export class Table1 {
|
||||
@Column({ enum: Test })
|
||||
column1!: string;
|
||||
}
|
||||
|
||||
export const description = 'should use a default enum naming convention';
|
||||
export const schema: DatabaseSchema = {
|
||||
name: 'public',
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
columns: [
|
||||
{
|
||||
name: 'column1',
|
||||
tableName: 'table1',
|
||||
type: 'enum',
|
||||
enumName: 'table1_column1_enum',
|
||||
enumValues: ['foo', 'bar'],
|
||||
nullable: false,
|
||||
isArray: false,
|
||||
primary: false,
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
constraints: [],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
warnings: [],
|
||||
};
|
||||
41
server/test/sql-tools/column-index-name-default.ts
Normal file
41
server/test/sql-tools/column-index-name-default.ts
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
import { Column, ColumnIndex, DatabaseSchema, Table } from 'src/sql-tools';
|
||||
|
||||
@Table()
|
||||
export class Table1 {
|
||||
@ColumnIndex()
|
||||
@Column()
|
||||
column1!: string;
|
||||
}
|
||||
|
||||
export const description = 'should create a column with an index';
|
||||
export const schema: DatabaseSchema = {
|
||||
name: 'public',
|
||||
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,
|
||||
},
|
||||
],
|
||||
constraints: [],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
warnings: [],
|
||||
};
|
||||
32
server/test/sql-tools/column-inferred-nullable.stub.ts
Normal file
32
server/test/sql-tools/column-inferred-nullable.stub.ts
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
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 = {
|
||||
name: 'public',
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
columns: [
|
||||
{
|
||||
name: 'column1',
|
||||
tableName: 'table1',
|
||||
type: 'character varying',
|
||||
nullable: true,
|
||||
isArray: false,
|
||||
primary: false,
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
constraints: [],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
warnings: [],
|
||||
};
|
||||
32
server/test/sql-tools/column-name-default.stub.ts
Normal file
32
server/test/sql-tools/column-name-default.stub.ts
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
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 = {
|
||||
name: 'public',
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
columns: [
|
||||
{
|
||||
name: 'column1',
|
||||
tableName: 'table1',
|
||||
type: 'character varying',
|
||||
nullable: false,
|
||||
isArray: false,
|
||||
primary: false,
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
constraints: [],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
warnings: [],
|
||||
};
|
||||
32
server/test/sql-tools/column-name-override.stub.ts
Normal file
32
server/test/sql-tools/column-name-override.stub.ts
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
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 = {
|
||||
name: 'public',
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
columns: [
|
||||
{
|
||||
name: 'column-1',
|
||||
tableName: 'table1',
|
||||
type: 'character varying',
|
||||
nullable: false,
|
||||
isArray: false,
|
||||
primary: false,
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
constraints: [],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
warnings: [],
|
||||
};
|
||||
32
server/test/sql-tools/column-name-string.stub.ts
Normal file
32
server/test/sql-tools/column-name-string.stub.ts
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
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 = {
|
||||
name: 'public',
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
columns: [
|
||||
{
|
||||
name: 'column-1',
|
||||
tableName: 'table1',
|
||||
type: 'character varying',
|
||||
nullable: false,
|
||||
isArray: false,
|
||||
primary: false,
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
constraints: [],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
warnings: [],
|
||||
};
|
||||
32
server/test/sql-tools/column-nullable.stub.ts
Normal file
32
server/test/sql-tools/column-nullable.stub.ts
Normal file
|
|
@ -0,0 +1,32 @@
|
|||
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 = {
|
||||
name: 'public',
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
columns: [
|
||||
{
|
||||
name: 'column1',
|
||||
tableName: 'table1',
|
||||
type: 'character varying',
|
||||
nullable: true,
|
||||
isArray: false,
|
||||
primary: false,
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
constraints: [],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
warnings: [],
|
||||
};
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
import { Column, DatabaseConstraintType, 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 = {
|
||||
name: 'public',
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
columns: [
|
||||
{
|
||||
name: 'id',
|
||||
tableName: 'table1',
|
||||
type: 'uuid',
|
||||
nullable: false,
|
||||
isArray: false,
|
||||
primary: false,
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
constraints: [
|
||||
{
|
||||
type: DatabaseConstraintType.UNIQUE,
|
||||
name: 'UQ_b249cc64cf63b8a22557cdc8537',
|
||||
tableName: 'table1',
|
||||
columnNames: ['id'],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
warnings: [],
|
||||
};
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
import { Column, DatabaseConstraintType, 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 = {
|
||||
name: 'public',
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
columns: [
|
||||
{
|
||||
name: 'id',
|
||||
tableName: 'table1',
|
||||
type: 'uuid',
|
||||
nullable: false,
|
||||
isArray: false,
|
||||
primary: false,
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
constraints: [
|
||||
{
|
||||
type: DatabaseConstraintType.UNIQUE,
|
||||
name: 'UQ_test',
|
||||
tableName: 'table1',
|
||||
columnNames: ['id'],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
warnings: [],
|
||||
};
|
||||
73
server/test/sql-tools/foreign-key-inferred-type.stub.ts
Normal file
73
server/test/sql-tools/foreign-key-inferred-type.stub.ts
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
import { DatabaseConstraintType, 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 = {
|
||||
name: 'public',
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
columns: [
|
||||
{
|
||||
name: 'id',
|
||||
tableName: 'table1',
|
||||
type: 'uuid',
|
||||
nullable: false,
|
||||
isArray: false,
|
||||
primary: true,
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
constraints: [
|
||||
{
|
||||
type: DatabaseConstraintType.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: [],
|
||||
constraints: [
|
||||
{
|
||||
type: DatabaseConstraintType.FOREIGN_KEY,
|
||||
name: 'FK_3fcca5cc563abf256fc346e3ff4',
|
||||
tableName: 'table2',
|
||||
columnNames: ['parentId'],
|
||||
referenceColumnNames: ['id'],
|
||||
referenceTableName: 'table1',
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
warnings: [],
|
||||
};
|
||||
|
|
@ -0,0 +1,80 @@
|
|||
import { DatabaseConstraintType, 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 = {
|
||||
name: 'public',
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
columns: [
|
||||
{
|
||||
name: 'id',
|
||||
tableName: 'table1',
|
||||
type: 'uuid',
|
||||
nullable: false,
|
||||
isArray: false,
|
||||
primary: true,
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
constraints: [
|
||||
{
|
||||
type: DatabaseConstraintType.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: [],
|
||||
constraints: [
|
||||
{
|
||||
type: DatabaseConstraintType.FOREIGN_KEY,
|
||||
name: 'FK_3fcca5cc563abf256fc346e3ff4',
|
||||
tableName: 'table2',
|
||||
columnNames: ['parentId'],
|
||||
referenceColumnNames: ['id'],
|
||||
referenceTableName: 'table1',
|
||||
synchronize: true,
|
||||
},
|
||||
{
|
||||
type: DatabaseConstraintType.UNIQUE,
|
||||
name: 'REL_3fcca5cc563abf256fc346e3ff',
|
||||
tableName: 'table2',
|
||||
columnNames: ['parentId'],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
warnings: [],
|
||||
};
|
||||
41
server/test/sql-tools/index-name-default.stub.ts
Normal file
41
server/test/sql-tools/index-name-default.stub.ts
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
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 = {
|
||||
name: 'public',
|
||||
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,
|
||||
},
|
||||
],
|
||||
constraints: [],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
warnings: [],
|
||||
};
|
||||
41
server/test/sql-tools/index-name-override.stub.ts
Normal file
41
server/test/sql-tools/index-name-override.stub.ts
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
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 = {
|
||||
name: 'public',
|
||||
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,
|
||||
},
|
||||
],
|
||||
constraints: [],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
warnings: [],
|
||||
};
|
||||
41
server/test/sql-tools/index-with-where.stub copy.ts
Normal file
41
server/test/sql-tools/index-with-where.stub copy.ts
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
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 = {
|
||||
name: 'public',
|
||||
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,
|
||||
},
|
||||
],
|
||||
constraints: [],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
warnings: [],
|
||||
};
|
||||
42
server/test/sql-tools/index-with-where.stub.ts
Normal file
42
server/test/sql-tools/index-with-where.stub.ts
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
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 = {
|
||||
name: 'public',
|
||||
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,
|
||||
},
|
||||
],
|
||||
constraints: [],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
warnings: [],
|
||||
};
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
import { DatabaseConstraintType, 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 = {
|
||||
name: 'public',
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
columns: [
|
||||
{
|
||||
name: 'id',
|
||||
tableName: 'table1',
|
||||
type: 'uuid',
|
||||
nullable: false,
|
||||
isArray: false,
|
||||
primary: true,
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
constraints: [
|
||||
{
|
||||
type: DatabaseConstraintType.PRIMARY_KEY,
|
||||
name: 'PK_b249cc64cf63b8a22557cdc8537',
|
||||
tableName: 'table1',
|
||||
columnNames: ['id'],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
warnings: [],
|
||||
};
|
||||
|
|
@ -0,0 +1,40 @@
|
|||
import { DatabaseConstraintType, 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 = {
|
||||
name: 'public',
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
columns: [
|
||||
{
|
||||
name: 'id',
|
||||
tableName: 'table1',
|
||||
type: 'uuid',
|
||||
nullable: false,
|
||||
isArray: false,
|
||||
primary: true,
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
constraints: [
|
||||
{
|
||||
type: DatabaseConstraintType.PRIMARY_KEY,
|
||||
name: 'PK_test',
|
||||
tableName: 'table1',
|
||||
columnNames: ['id'],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
warnings: [],
|
||||
};
|
||||
19
server/test/sql-tools/table-name-default.stub.ts
Normal file
19
server/test/sql-tools/table-name-default.stub.ts
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
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 = {
|
||||
name: 'public',
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
columns: [],
|
||||
indexes: [],
|
||||
constraints: [],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
warnings: [],
|
||||
};
|
||||
19
server/test/sql-tools/table-name-override.stub.ts
Normal file
19
server/test/sql-tools/table-name-override.stub.ts
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
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 = {
|
||||
name: 'public',
|
||||
tables: [
|
||||
{
|
||||
name: 'table-1',
|
||||
columns: [],
|
||||
indexes: [],
|
||||
constraints: [],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
warnings: [],
|
||||
};
|
||||
19
server/test/sql-tools/table-name-string-option.stub.ts
Normal file
19
server/test/sql-tools/table-name-string-option.stub.ts
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
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 = {
|
||||
name: 'public',
|
||||
tables: [
|
||||
{
|
||||
name: 'table-1',
|
||||
columns: [],
|
||||
indexes: [],
|
||||
constraints: [],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
warnings: [],
|
||||
};
|
||||
41
server/test/sql-tools/unique-constraint-name-default.stub.ts
Normal file
41
server/test/sql-tools/unique-constraint-name-default.stub.ts
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
import { Column, DatabaseConstraintType, 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 = {
|
||||
name: 'public',
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
columns: [
|
||||
{
|
||||
name: 'id',
|
||||
tableName: 'table1',
|
||||
type: 'uuid',
|
||||
nullable: false,
|
||||
isArray: false,
|
||||
primary: false,
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
constraints: [
|
||||
{
|
||||
type: DatabaseConstraintType.UNIQUE,
|
||||
name: 'UQ_b249cc64cf63b8a22557cdc8537',
|
||||
tableName: 'table1',
|
||||
columnNames: ['id'],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
warnings: [],
|
||||
};
|
||||
|
|
@ -0,0 +1,41 @@
|
|||
import { Column, DatabaseConstraintType, 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 = {
|
||||
name: 'public',
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
columns: [
|
||||
{
|
||||
name: 'id',
|
||||
tableName: 'table1',
|
||||
type: 'uuid',
|
||||
nullable: false,
|
||||
isArray: false,
|
||||
primary: false,
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
constraints: [
|
||||
{
|
||||
type: DatabaseConstraintType.UNIQUE,
|
||||
name: 'UQ_test',
|
||||
tableName: 'table1',
|
||||
columnNames: ['id'],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
warnings: [],
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue