feat: extension, triggers, functions, comments, parameters management in sql-tools (#17269)
feat: sql-tools extension, triggers, functions, comments, parameters
This commit is contained in:
@@ -9,7 +9,12 @@ export class Table1 {
|
||||
|
||||
export const description = 'should create a check constraint with a default name';
|
||||
export const schema: DatabaseSchema = {
|
||||
name: 'public',
|
||||
name: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
@@ -25,6 +30,7 @@ export const schema: DatabaseSchema = {
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
triggers: [],
|
||||
constraints: [
|
||||
{
|
||||
type: DatabaseConstraintType.CHECK,
|
||||
|
||||
@@ -9,7 +9,12 @@ export class Table1 {
|
||||
|
||||
export const description = 'should create a check constraint with a specific name';
|
||||
export const schema: DatabaseSchema = {
|
||||
name: 'public',
|
||||
name: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
@@ -25,6 +30,7 @@ export const schema: DatabaseSchema = {
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
triggers: [],
|
||||
constraints: [
|
||||
{
|
||||
type: DatabaseConstraintType.CHECK,
|
||||
|
||||
39
server/test/sql-tools/column-create-date.stub.ts
Normal file
39
server/test/sql-tools/column-create-date.stub.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
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 = {
|
||||
name: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
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: [],
|
||||
};
|
||||
@@ -8,7 +8,12 @@ export class Table1 {
|
||||
|
||||
export const description = 'should register a table with a column with a default value (boolean)';
|
||||
export const schema: DatabaseSchema = {
|
||||
name: 'public',
|
||||
name: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
@@ -25,6 +30,7 @@ export const schema: DatabaseSchema = {
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
triggers: [],
|
||||
constraints: [],
|
||||
synchronize: true,
|
||||
},
|
||||
|
||||
@@ -10,7 +10,12 @@ export class Table1 {
|
||||
|
||||
export const description = 'should register a table with a column with a default value (date)';
|
||||
export const schema: DatabaseSchema = {
|
||||
name: 'public',
|
||||
name: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
@@ -27,6 +32,7 @@ export const schema: DatabaseSchema = {
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
triggers: [],
|
||||
constraints: [],
|
||||
synchronize: true,
|
||||
},
|
||||
|
||||
@@ -8,7 +8,12 @@ export class Table1 {
|
||||
|
||||
export const description = 'should register a table with a column with a default function';
|
||||
export const schema: DatabaseSchema = {
|
||||
name: 'public',
|
||||
name: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
@@ -25,6 +30,7 @@ export const schema: DatabaseSchema = {
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
triggers: [],
|
||||
constraints: [],
|
||||
synchronize: true,
|
||||
},
|
||||
|
||||
@@ -8,7 +8,12 @@ export class Table1 {
|
||||
|
||||
export const description = 'should register a nullable column from a default of null';
|
||||
export const schema: DatabaseSchema = {
|
||||
name: 'public',
|
||||
name: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
@@ -24,6 +29,7 @@ export const schema: DatabaseSchema = {
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
triggers: [],
|
||||
constraints: [],
|
||||
synchronize: true,
|
||||
},
|
||||
|
||||
@@ -8,7 +8,12 @@ export class Table1 {
|
||||
|
||||
export const description = 'should register a table with a column with a default value (number)';
|
||||
export const schema: DatabaseSchema = {
|
||||
name: 'public',
|
||||
name: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
@@ -25,6 +30,7 @@ export const schema: DatabaseSchema = {
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
triggers: [],
|
||||
constraints: [],
|
||||
synchronize: true,
|
||||
},
|
||||
|
||||
@@ -8,7 +8,12 @@ export class Table1 {
|
||||
|
||||
export const description = 'should register a table with a column with a default value (string)';
|
||||
export const schema: DatabaseSchema = {
|
||||
name: 'public',
|
||||
name: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
@@ -25,6 +30,7 @@ export const schema: DatabaseSchema = {
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
triggers: [],
|
||||
constraints: [],
|
||||
synchronize: true,
|
||||
},
|
||||
|
||||
38
server/test/sql-tools/column-delete-date.stub.ts
Normal file
38
server/test/sql-tools/column-delete-date.stub.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
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 = {
|
||||
name: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
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: [],
|
||||
};
|
||||
52
server/test/sql-tools/column-enum-type.stub.ts
Normal file
52
server/test/sql-tools/column-enum-type.stub.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
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 = {
|
||||
name: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [
|
||||
{
|
||||
name: 'test_enum',
|
||||
values: ['foo', 'bar'],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
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: [],
|
||||
};
|
||||
47
server/test/sql-tools/column-generated-identity.ts
Normal file
47
server/test/sql-tools/column-generated-identity.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import { DatabaseConstraintType, 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 = {
|
||||
name: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
columns: [
|
||||
{
|
||||
name: 'column1',
|
||||
tableName: 'table1',
|
||||
type: 'integer',
|
||||
identity: true,
|
||||
nullable: false,
|
||||
isArray: false,
|
||||
primary: true,
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
triggers: [],
|
||||
constraints: [
|
||||
{
|
||||
type: DatabaseConstraintType.PRIMARY_KEY,
|
||||
name: 'PK_50c4f9905061b1e506d38a2a380',
|
||||
tableName: 'table1',
|
||||
columnNames: ['column1'],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
warnings: [],
|
||||
};
|
||||
47
server/test/sql-tools/column-generated-uuid.stub.ts
Normal file
47
server/test/sql-tools/column-generated-uuid.stub.ts
Normal file
@@ -0,0 +1,47 @@
|
||||
import { DatabaseConstraintType, 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 = {
|
||||
name: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
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: DatabaseConstraintType.PRIMARY_KEY,
|
||||
name: 'PK_50c4f9905061b1e506d38a2a380',
|
||||
tableName: 'table1',
|
||||
columnNames: ['column1'],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
warnings: [],
|
||||
};
|
||||
@@ -9,7 +9,12 @@ export class Table1 {
|
||||
|
||||
export const description = 'should create a column with an index';
|
||||
export const schema: DatabaseSchema = {
|
||||
name: 'public',
|
||||
name: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
@@ -33,6 +38,7 @@ export const schema: DatabaseSchema = {
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
triggers: [],
|
||||
constraints: [],
|
||||
synchronize: true,
|
||||
},
|
||||
|
||||
@@ -8,7 +8,12 @@ export class Table1 {
|
||||
|
||||
export const description = 'should infer nullable from the default value';
|
||||
export const schema: DatabaseSchema = {
|
||||
name: 'public',
|
||||
name: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
@@ -24,6 +29,7 @@ export const schema: DatabaseSchema = {
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
triggers: [],
|
||||
constraints: [],
|
||||
synchronize: true,
|
||||
},
|
||||
|
||||
@@ -8,7 +8,12 @@ export class Table1 {
|
||||
|
||||
export const description = 'should register a table with a column with a default name';
|
||||
export const schema: DatabaseSchema = {
|
||||
name: 'public',
|
||||
name: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
@@ -24,6 +29,7 @@ export const schema: DatabaseSchema = {
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
triggers: [],
|
||||
constraints: [],
|
||||
synchronize: true,
|
||||
},
|
||||
|
||||
@@ -8,7 +8,12 @@ export class Table1 {
|
||||
|
||||
export const description = 'should register a table with a column with a specific name';
|
||||
export const schema: DatabaseSchema = {
|
||||
name: 'public',
|
||||
name: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
@@ -24,6 +29,7 @@ export const schema: DatabaseSchema = {
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
triggers: [],
|
||||
constraints: [],
|
||||
synchronize: true,
|
||||
},
|
||||
|
||||
@@ -8,7 +8,12 @@ export class Table1 {
|
||||
|
||||
export const description = 'should register a table with a column with a specific name';
|
||||
export const schema: DatabaseSchema = {
|
||||
name: 'public',
|
||||
name: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
@@ -24,6 +29,7 @@ export const schema: DatabaseSchema = {
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
triggers: [],
|
||||
constraints: [],
|
||||
synchronize: true,
|
||||
},
|
||||
|
||||
@@ -8,7 +8,12 @@ export class Table1 {
|
||||
|
||||
export const description = 'should set nullable correctly';
|
||||
export const schema: DatabaseSchema = {
|
||||
name: 'public',
|
||||
name: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
@@ -24,6 +29,7 @@ export const schema: DatabaseSchema = {
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
triggers: [],
|
||||
constraints: [],
|
||||
synchronize: true,
|
||||
},
|
||||
|
||||
@@ -1,19 +1,19 @@
|
||||
import { Column, DatabaseSchema, Table } from 'src/sql-tools';
|
||||
|
||||
enum Test {
|
||||
Foo = 'foo',
|
||||
Bar = 'bar',
|
||||
}
|
||||
|
||||
@Table()
|
||||
export class Table1 {
|
||||
@Column({ enum: Test })
|
||||
@Column({ length: 2 })
|
||||
column1!: string;
|
||||
}
|
||||
|
||||
export const description = 'should use a default enum naming convention';
|
||||
export const description = 'should use create a string column with a fixed length';
|
||||
export const schema: DatabaseSchema = {
|
||||
name: 'public',
|
||||
name: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
@@ -21,9 +21,8 @@ export const schema: DatabaseSchema = {
|
||||
{
|
||||
name: 'column1',
|
||||
tableName: 'table1',
|
||||
type: 'enum',
|
||||
enumName: 'table1_column1_enum',
|
||||
enumValues: ['foo', 'bar'],
|
||||
type: 'character varying',
|
||||
length: 2,
|
||||
nullable: false,
|
||||
isArray: false,
|
||||
primary: false,
|
||||
@@ -31,6 +30,7 @@ export const schema: DatabaseSchema = {
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
triggers: [],
|
||||
constraints: [],
|
||||
synchronize: true,
|
||||
},
|
||||
@@ -8,7 +8,12 @@ export class Table1 {
|
||||
|
||||
export const description = 'should create a unique key constraint with a default name';
|
||||
export const schema: DatabaseSchema = {
|
||||
name: 'public',
|
||||
name: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
@@ -24,6 +29,7 @@ export const schema: DatabaseSchema = {
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
triggers: [],
|
||||
constraints: [
|
||||
{
|
||||
type: DatabaseConstraintType.UNIQUE,
|
||||
|
||||
@@ -8,7 +8,12 @@ export class Table1 {
|
||||
|
||||
export const description = 'should create a unique key constraint with a specific name';
|
||||
export const schema: DatabaseSchema = {
|
||||
name: 'public',
|
||||
name: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
@@ -24,6 +29,7 @@ export const schema: DatabaseSchema = {
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
triggers: [],
|
||||
constraints: [
|
||||
{
|
||||
type: DatabaseConstraintType.UNIQUE,
|
||||
|
||||
39
server/test/sql-tools/column-update-date.stub.ts
Normal file
39
server/test/sql-tools/column-update-date.stub.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
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 = {
|
||||
name: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
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: [],
|
||||
};
|
||||
@@ -14,7 +14,12 @@ export class Table2 {
|
||||
|
||||
export const description = 'should infer the column type from the reference column';
|
||||
export const schema: DatabaseSchema = {
|
||||
name: 'public',
|
||||
name: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
@@ -30,6 +35,7 @@ export const schema: DatabaseSchema = {
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
triggers: [],
|
||||
constraints: [
|
||||
{
|
||||
type: DatabaseConstraintType.PRIMARY_KEY,
|
||||
@@ -55,6 +61,7 @@ export const schema: DatabaseSchema = {
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
triggers: [],
|
||||
constraints: [
|
||||
{
|
||||
type: DatabaseConstraintType.FOREIGN_KEY,
|
||||
|
||||
@@ -14,7 +14,12 @@ export class Table2 {
|
||||
|
||||
export const description = 'should create a foreign key constraint with a unique constraint';
|
||||
export const schema: DatabaseSchema = {
|
||||
name: 'public',
|
||||
name: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
@@ -30,6 +35,7 @@ export const schema: DatabaseSchema = {
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
triggers: [],
|
||||
constraints: [
|
||||
{
|
||||
type: DatabaseConstraintType.PRIMARY_KEY,
|
||||
@@ -55,6 +61,7 @@ export const schema: DatabaseSchema = {
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
triggers: [],
|
||||
constraints: [
|
||||
{
|
||||
type: DatabaseConstraintType.FOREIGN_KEY,
|
||||
|
||||
@@ -9,7 +9,12 @@ export class Table1 {
|
||||
|
||||
export const description = 'should create an index with a default name';
|
||||
export const schema: DatabaseSchema = {
|
||||
name: 'public',
|
||||
name: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
@@ -33,6 +38,7 @@ export const schema: DatabaseSchema = {
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
triggers: [],
|
||||
constraints: [],
|
||||
synchronize: true,
|
||||
},
|
||||
|
||||
@@ -9,7 +9,12 @@ export class Table1 {
|
||||
|
||||
export const description = 'should create an index with a specific name';
|
||||
export const schema: DatabaseSchema = {
|
||||
name: 'public',
|
||||
name: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
@@ -33,6 +38,7 @@ export const schema: DatabaseSchema = {
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
triggers: [],
|
||||
constraints: [],
|
||||
synchronize: true,
|
||||
},
|
||||
|
||||
@@ -9,7 +9,12 @@ export class Table1 {
|
||||
|
||||
export const description = 'should create an index based off of an expression';
|
||||
export const schema: DatabaseSchema = {
|
||||
name: 'public',
|
||||
name: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
@@ -33,6 +38,7 @@ export const schema: DatabaseSchema = {
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
triggers: [],
|
||||
constraints: [],
|
||||
synchronize: true,
|
||||
},
|
||||
|
||||
@@ -9,7 +9,12 @@ export class Table1 {
|
||||
|
||||
export const description = 'should create an index with a where clause';
|
||||
export const schema: DatabaseSchema = {
|
||||
name: 'public',
|
||||
name: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
@@ -34,6 +39,7 @@ export const schema: DatabaseSchema = {
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
triggers: [],
|
||||
constraints: [],
|
||||
synchronize: true,
|
||||
},
|
||||
|
||||
@@ -8,7 +8,12 @@ export class Table1 {
|
||||
|
||||
export const description = 'should add a primary key constraint to the table with a default name';
|
||||
export const schema: DatabaseSchema = {
|
||||
name: 'public',
|
||||
name: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
@@ -24,6 +29,7 @@ export const schema: DatabaseSchema = {
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
triggers: [],
|
||||
constraints: [
|
||||
{
|
||||
type: DatabaseConstraintType.PRIMARY_KEY,
|
||||
|
||||
@@ -8,7 +8,12 @@ export class Table1 {
|
||||
|
||||
export const description = 'should add a primary key constraint to the table with a specific name';
|
||||
export const schema: DatabaseSchema = {
|
||||
name: 'public',
|
||||
name: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
@@ -24,6 +29,7 @@ export const schema: DatabaseSchema = {
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
triggers: [],
|
||||
constraints: [
|
||||
{
|
||||
type: DatabaseConstraintType.PRIMARY_KEY,
|
||||
|
||||
@@ -5,12 +5,18 @@ export class Table1 {}
|
||||
|
||||
export const description = 'should register a table with a default name';
|
||||
export const schema: DatabaseSchema = {
|
||||
name: 'public',
|
||||
name: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
columns: [],
|
||||
indexes: [],
|
||||
triggers: [],
|
||||
constraints: [],
|
||||
synchronize: true,
|
||||
},
|
||||
|
||||
@@ -5,12 +5,18 @@ export class Table1 {}
|
||||
|
||||
export const description = 'should register a table with a specific name';
|
||||
export const schema: DatabaseSchema = {
|
||||
name: 'public',
|
||||
name: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
tables: [
|
||||
{
|
||||
name: 'table-1',
|
||||
columns: [],
|
||||
indexes: [],
|
||||
triggers: [],
|
||||
constraints: [],
|
||||
synchronize: true,
|
||||
},
|
||||
|
||||
@@ -5,12 +5,18 @@ export class Table1 {}
|
||||
|
||||
export const description = 'should register a table with a specific name';
|
||||
export const schema: DatabaseSchema = {
|
||||
name: 'public',
|
||||
name: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
tables: [
|
||||
{
|
||||
name: 'table-1',
|
||||
columns: [],
|
||||
indexes: [],
|
||||
triggers: [],
|
||||
constraints: [],
|
||||
synchronize: true,
|
||||
},
|
||||
|
||||
46
server/test/sql-tools/trigger-after-delete.stub.ts
Normal file
46
server/test/sql-tools/trigger-after-delete.stub.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
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 = {
|
||||
name: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [expect.any(Object)],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
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: [],
|
||||
};
|
||||
46
server/test/sql-tools/trigger-before-update.stub.ts
Normal file
46
server/test/sql-tools/trigger-before-update.stub.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
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 = {
|
||||
name: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [expect.any(Object)],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
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: [],
|
||||
};
|
||||
41
server/test/sql-tools/trigger-name-default.stub.ts
Normal file
41
server/test/sql-tools/trigger-name-default.stub.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
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 = {
|
||||
name: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
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: [],
|
||||
};
|
||||
42
server/test/sql-tools/trigger-name-override.stub.ts
Normal file
42
server/test/sql-tools/trigger-name-override.stub.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
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 = {
|
||||
name: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
columns: [],
|
||||
indexes: [],
|
||||
triggers: [
|
||||
{
|
||||
name: 'trigger1',
|
||||
tableName: 'table1',
|
||||
functionName: 'function1',
|
||||
actions: ['insert'],
|
||||
scope: 'row',
|
||||
timing: 'before',
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
constraints: [],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
warnings: [],
|
||||
};
|
||||
@@ -9,7 +9,12 @@ export class Table1 {
|
||||
|
||||
export const description = 'should add a unique constraint to the table with a default name';
|
||||
export const schema: DatabaseSchema = {
|
||||
name: 'public',
|
||||
name: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
@@ -25,6 +30,7 @@ export const schema: DatabaseSchema = {
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
triggers: [],
|
||||
constraints: [
|
||||
{
|
||||
type: DatabaseConstraintType.UNIQUE,
|
||||
|
||||
@@ -9,7 +9,12 @@ export class Table1 {
|
||||
|
||||
export const description = 'should add a unique constraint to the table with a specific name';
|
||||
export const schema: DatabaseSchema = {
|
||||
name: 'public',
|
||||
name: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
tables: [
|
||||
{
|
||||
name: 'table1',
|
||||
@@ -25,6 +30,7 @@ export const schema: DatabaseSchema = {
|
||||
},
|
||||
],
|
||||
indexes: [],
|
||||
triggers: [],
|
||||
constraints: [
|
||||
{
|
||||
type: DatabaseConstraintType.UNIQUE,
|
||||
|
||||
Reference in New Issue
Block a user