mirror of
https://github.com/immich-app/immich.git
synced 2025-12-26 09:14:58 +03:00
refactor: sql-tools (#19717)
This commit is contained in:
28
server/src/sql-tools/processors/table.processor.ts
Normal file
28
server/src/sql-tools/processors/table.processor.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { asSnakeCase } from 'src/sql-tools/helpers';
|
||||
import { Processor } from 'src/sql-tools/types';
|
||||
|
||||
export const processTables: Processor = (builder, items) => {
|
||||
for (const {
|
||||
item: { options, object },
|
||||
} of items.filter((item) => item.type === 'table')) {
|
||||
const test = builder.getTableByObject(object);
|
||||
if (test) {
|
||||
throw new Error(
|
||||
`Table ${test.name} has already been registered. Does ${object.name} have two @Table() decorators?`,
|
||||
);
|
||||
}
|
||||
|
||||
builder.addTable(
|
||||
{
|
||||
name: options.name || asSnakeCase(object.name),
|
||||
columns: [],
|
||||
constraints: [],
|
||||
indexes: [],
|
||||
triggers: [],
|
||||
synchronize: options.synchronize ?? true,
|
||||
},
|
||||
options,
|
||||
object,
|
||||
);
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user