mirror of
https://github.com/immich-app/immich.git
synced 2025-08-11 09:16:31 -04:00
fix(sql-tools): null default (#20796)
This commit is contained in:
parent
538d5c81ea
commit
2ce4f8dd3b
@ -62,6 +62,23 @@ describe('compareColumns', () => {
|
||||
]);
|
||||
});
|
||||
|
||||
it('should detect a change in default', () => {
|
||||
const source: DatabaseColumn = { ...testColumn, nullable: true };
|
||||
const target: DatabaseColumn = { ...testColumn, nullable: true, default: "''" };
|
||||
const reason = `default is different (null vs '')`;
|
||||
expect(compareColumns.onCompare(source, target)).toEqual([
|
||||
{
|
||||
columnName: 'test',
|
||||
tableName: 'table1',
|
||||
type: 'ColumnAlter',
|
||||
changes: {
|
||||
default: 'NULL',
|
||||
},
|
||||
reason,
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
it('should detect a comment change', () => {
|
||||
const source: DatabaseColumn = { ...testColumn, comment: 'new comment' };
|
||||
const target: DatabaseColumn = { ...testColumn, comment: 'old comment' };
|
||||
|
@ -72,9 +72,9 @@ export const compareColumns = {
|
||||
tableName: source.tableName,
|
||||
columnName: source.name,
|
||||
changes: {
|
||||
default: String(source.default),
|
||||
default: String(source.default ?? 'NULL'),
|
||||
},
|
||||
reason: `default is different (${source.default} vs ${target.default})`,
|
||||
reason: `default is different (${source.default ?? 'null'} vs ${target.default})`,
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -175,7 +175,7 @@ export const isDefaultEqual = (source: DatabaseColumn, target: DatabaseColumn) =
|
||||
|
||||
if (
|
||||
withTypeCast(source.default, getColumnType(source)) === target.default ||
|
||||
source.default === withTypeCast(target.default, getColumnType(target))
|
||||
withTypeCast(target.default, getColumnType(target)) === source.default
|
||||
) {
|
||||
return true;
|
||||
}
|
||||
|
@ -116,6 +116,20 @@ describe(transformColumns.name, () => {
|
||||
}),
|
||||
).toEqual([`ALTER TABLE "table1" ALTER COLUMN "column1" SET DEFAULT uuid_generate_v4();`]);
|
||||
});
|
||||
|
||||
it('should update the default value to NULL', () => {
|
||||
expect(
|
||||
transformColumns(ctx, {
|
||||
type: 'ColumnAlter',
|
||||
tableName: 'table1',
|
||||
columnName: 'column1',
|
||||
changes: {
|
||||
default: 'NULL',
|
||||
},
|
||||
reason: 'unknown',
|
||||
}),
|
||||
).toEqual([`ALTER TABLE "table1" ALTER COLUMN "column1" SET DEFAULT NULL;`]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('ColumnDrop', () => {
|
||||
|
Loading…
x
Reference in New Issue
Block a user