mirror of
https://github.com/immich-app/immich
synced 2025-10-17 18:19:27 +00:00
feat(server): sql-tools support for class level composite fk (#19242)
* feat: support for class level composite fk * chore: clean up --------- Co-authored-by: Jason Rasmussen <jason@rasm.me>
This commit is contained in:
parent
de81006367
commit
0a9a520ed2
19 changed files with 865 additions and 30 deletions
|
|
@ -0,0 +1,85 @@
|
|||
import { Column, DatabaseConstraintType, 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 = {
|
||||
name: 'postgres',
|
||||
schemaName: 'public',
|
||||
functions: [],
|
||||
enums: [],
|
||||
extensions: [],
|
||||
parameters: [],
|
||||
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: DatabaseConstraintType.FOREIGN_KEY,
|
||||
name: 'FK_7d9c784c98d12365d198d52e4e6',
|
||||
tableName: 'table2',
|
||||
columnNames: ['bar'],
|
||||
referenceTableName: 'table1',
|
||||
referenceColumnNames: ['foo'],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
synchronize: true,
|
||||
},
|
||||
],
|
||||
warnings: [],
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue