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
160 changed files with 1120 additions and 1186 deletions

View File

@@ -0,0 +1,33 @@
import { Kysely } from 'kysely';
import { PostgresJSDialect } from 'kysely-postgres-js';
import { Sql } from 'postgres';
import { readers } from 'src/sql-tools/readers';
import { DatabaseSchema, PostgresDB, SchemaFromDatabaseOptions } from 'src/sql-tools/types';
/**
* Load schema from a database url
*/
export const schemaFromDatabase = async (
postgres: Sql,
options: SchemaFromDatabaseOptions = {},
): Promise<DatabaseSchema> => {
const schema: DatabaseSchema = {
databaseName: 'immich',
schemaName: options.schemaName || 'public',
parameters: [],
functions: [],
enums: [],
extensions: [],
tables: [],
warnings: [],
};
const db = new Kysely<PostgresDB>({ dialect: new PostgresJSDialect({ postgres }) });
for (const reader of readers) {
await reader(schema, db);
}
await db.destroy();
return schema;
};