mirror of
https://github.com/immich-app/immich
synced 2025-11-07 17:27:20 +00:00
feat: naming strategy (#19848)
* feat: naming strategy * feat: detect renames
This commit is contained in:
parent
1d19d308e2
commit
9e48ae3052
35 changed files with 517 additions and 127 deletions
|
|
@ -1,4 +1,3 @@
|
|||
import { asForeignKeyConstraintName } from 'src/sql-tools/helpers';
|
||||
import { ActionType, ConstraintType, Processor } from 'src/sql-tools/types';
|
||||
|
||||
export const processForeignKeyConstraints: Processor = (ctx, items) => {
|
||||
|
|
@ -46,18 +45,27 @@ export const processForeignKeyConstraints: Processor = (ctx, items) => {
|
|||
continue;
|
||||
}
|
||||
|
||||
const referenceColumns =
|
||||
const referenceTableName = referenceTable.name;
|
||||
const referenceColumnNames =
|
||||
options.referenceColumns || referenceTable.columns.filter(({ primary }) => primary).map(({ name }) => name);
|
||||
|
||||
const name = options.name || asForeignKeyConstraintName(table.name, options.columns);
|
||||
const name =
|
||||
options.name ||
|
||||
ctx.getNameFor({
|
||||
type: 'foreignKey',
|
||||
tableName: table.name,
|
||||
columnNames: options.columns,
|
||||
referenceTableName,
|
||||
referenceColumnNames,
|
||||
});
|
||||
|
||||
table.constraints.push({
|
||||
type: ConstraintType.FOREIGN_KEY,
|
||||
name,
|
||||
tableName: table.name,
|
||||
columnNames: options.columns,
|
||||
referenceTableName: referenceTable.name,
|
||||
referenceColumnNames: referenceColumns,
|
||||
referenceTableName,
|
||||
referenceColumnNames,
|
||||
onUpdate: options.onUpdate as ActionType,
|
||||
onDelete: options.onDelete as ActionType,
|
||||
synchronize: options.synchronize ?? true,
|
||||
|
|
@ -68,8 +76,15 @@ export const processForeignKeyConstraints: Processor = (ctx, items) => {
|
|||
}
|
||||
|
||||
if (options.index || options.indexName || ctx.options.createForeignKeyIndexes) {
|
||||
const indexName =
|
||||
options.indexName ||
|
||||
ctx.getNameFor({
|
||||
type: 'index',
|
||||
tableName: table.name,
|
||||
columnNames: options.columns,
|
||||
});
|
||||
table.indexes.push({
|
||||
name: options.indexName || ctx.asIndexName(table.name, options.columns),
|
||||
name: indexName,
|
||||
tableName: table.name,
|
||||
columnNames: options.columns,
|
||||
unique: false,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue