|
|
@ -50,6 +50,16 @@ export enum Altered { |
|
|
|
UPDATE_COLUMN = 8, |
|
|
|
UPDATE_COLUMN = 8, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// generate unique foreign key constraint name for foreign key
|
|
|
|
|
|
|
|
const generateFkConstraintName = (parent: TableType, child: TableType) => { |
|
|
|
|
|
|
|
const constraintName = `fk_${parent.table_name |
|
|
|
|
|
|
|
.replace(/\W+/g, '_') |
|
|
|
|
|
|
|
.slice(0, 10)}_${child.table_name |
|
|
|
|
|
|
|
.replace(/\W+/g, '_') |
|
|
|
|
|
|
|
.slice(0, 10)}_${randomID(15)}`;
|
|
|
|
|
|
|
|
return constraintName; |
|
|
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
async function createHmAndBtColumn( |
|
|
|
async function createHmAndBtColumn( |
|
|
|
child: Model, |
|
|
|
child: Model, |
|
|
|
parent: Model, |
|
|
|
parent: Model, |
|
|
@ -316,6 +326,7 @@ export async function columnAdd( |
|
|
|
onUpdate: 'NO ACTION', |
|
|
|
onUpdate: 'NO ACTION', |
|
|
|
type: 'real', |
|
|
|
type: 'real', |
|
|
|
parentColumn: parent.primaryKey.column_name, |
|
|
|
parentColumn: parent.primaryKey.column_name, |
|
|
|
|
|
|
|
foreignKeyName: generateFkConstraintName(parent, child), //generateFkConstraintName()
|
|
|
|
}); |
|
|
|
}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -407,6 +418,7 @@ export async function columnAdd( |
|
|
|
parentTable: parent.table_name, |
|
|
|
parentTable: parent.table_name, |
|
|
|
parentColumn: parentPK.column_name, |
|
|
|
parentColumn: parentPK.column_name, |
|
|
|
type: 'real', |
|
|
|
type: 'real', |
|
|
|
|
|
|
|
foreignKeyName: generateFkConstraintName(parent, child), |
|
|
|
}; |
|
|
|
}; |
|
|
|
const rel2Args = { |
|
|
|
const rel2Args = { |
|
|
|
...req.body, |
|
|
|
...req.body, |
|
|
@ -415,6 +427,7 @@ export async function columnAdd( |
|
|
|
parentTable: child.table_name, |
|
|
|
parentTable: child.table_name, |
|
|
|
parentColumn: childPK.column_name, |
|
|
|
parentColumn: childPK.column_name, |
|
|
|
type: 'real', |
|
|
|
type: 'real', |
|
|
|
|
|
|
|
foreignKeyName: generateFkConstraintName(parent, child), |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
await sqlMgr.sqlOpPlus(base, 'relationCreate', rel1Args); |
|
|
|
await sqlMgr.sqlOpPlus(base, 'relationCreate', rel1Args); |
|
|
|