mirror of
https://github.com/immich-app/immich.git
synced 2025-12-25 01:11:43 +03:00
feat: sql-tools overrides (#19796)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import { Kysely } from 'kysely';
|
||||
import { PostgresJSDialect } from 'kysely-postgres-js';
|
||||
import { Sql } from 'postgres';
|
||||
import { ReaderContext } from 'src/sql-tools/contexts/reader-context';
|
||||
import { readers } from 'src/sql-tools/readers';
|
||||
import { DatabaseSchema, PostgresDB, SchemaFromDatabaseOptions } from 'src/sql-tools/types';
|
||||
|
||||
@@ -11,23 +12,16 @@ 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);
|
||||
const ctx = new ReaderContext(options);
|
||||
|
||||
try {
|
||||
for (const reader of readers) {
|
||||
await reader(ctx, db);
|
||||
}
|
||||
|
||||
return ctx.build();
|
||||
} finally {
|
||||
await db.destroy();
|
||||
}
|
||||
|
||||
await db.destroy();
|
||||
|
||||
return schema;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user