mirror of
https://github.com/immich-app/immich
synced 2025-11-14 17:36:12 +00:00
feat: naming strategy (#19848)
* feat: naming strategy * feat: detect renames
This commit is contained in:
parent
1d19d308e2
commit
9e48ae3052
35 changed files with 517 additions and 127 deletions
|
|
@ -9,7 +9,13 @@ import { ConfigRepository } from 'src/repositories/config.repository';
|
|||
import { DatabaseRepository } from 'src/repositories/database.repository';
|
||||
import { LoggingRepository } from 'src/repositories/logging.repository';
|
||||
import 'src/schema';
|
||||
import { schemaDiff, schemaFromCode, schemaFromDatabase } from 'src/sql-tools';
|
||||
import {
|
||||
DefaultNamingStrategy,
|
||||
HashNamingStrategy,
|
||||
schemaDiff,
|
||||
schemaFromCode,
|
||||
schemaFromDatabase,
|
||||
} from 'src/sql-tools';
|
||||
import { asPostgresConnectionConfig, getKyselyConfig } from 'src/utils/database';
|
||||
|
||||
const main = async () => {
|
||||
|
|
@ -107,7 +113,22 @@ const compare = async () => {
|
|||
const { database } = configRepository.getEnv();
|
||||
const db = postgres(asPostgresConnectionConfig(database.config));
|
||||
|
||||
const source = schemaFromCode({ overrides: true });
|
||||
const tables = new Set<string>();
|
||||
const preferred = new DefaultNamingStrategy();
|
||||
const fallback = new HashNamingStrategy();
|
||||
|
||||
const source = schemaFromCode({
|
||||
overrides: true,
|
||||
namingStrategy: {
|
||||
getName(item) {
|
||||
if ('tableName' in item && tables.has(item.tableName)) {
|
||||
return preferred.getName(item);
|
||||
}
|
||||
|
||||
return fallback.getName(item);
|
||||
},
|
||||
},
|
||||
});
|
||||
const target = await schemaFromDatabase(db, {});
|
||||
|
||||
console.log(source.warnings.join('\n'));
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue