refactor: sql-tools (#19717)

This commit is contained in:
Jason Rasmussen 2025-07-03 10:59:17 -04:00 committed by GitHub
parent 484529e61e
commit 6044663e26
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
160 changed files with 1120 additions and 1186 deletions

View file

@ -0,0 +1,29 @@
import { processors } from 'src/sql-tools/processors';
import { getRegisteredItems, resetRegisteredItems } from 'src/sql-tools/register';
import { SchemaBuilder } from 'src/sql-tools/schema-builder';
import { SchemaFromCodeOptions } from 'src/sql-tools/types';
/**
* Load schema from code (decorators, etc)
*/
export const schemaFromCode = (options: SchemaFromCodeOptions = {}) => {
try {
const globalOptions = {
createForeignKeyIndexes: options.createForeignKeyIndexes ?? true,
};
const builder = new SchemaBuilder(options);
const items = getRegisteredItems();
for (const processor of processors) {
processor(builder, items, globalOptions);
}
const newSchema = builder.build();
return newSchema;
} finally {
if (options.reset) {
resetRegisteredItems();
}
}
};