mirror of
https://github.com/immich-app/immich
synced 2026-08-29 13:15:45 +00:00
refactor: sql-tools readers (#19672)
This commit is contained in:
parent
15da0d5a71
commit
c435bdb5d3
12 changed files with 538 additions and 562 deletions
36
server/src/sql-tools/from-database/readers/comment.reader.ts
Normal file
36
server/src/sql-tools/from-database/readers/comment.reader.ts
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
import { DatabaseReader } from 'src/sql-tools/from-database/readers/type';
|
||||
|
||||
export const readComments: DatabaseReader = async (schema, db) => {
|
||||
const comments = await db
|
||||
.selectFrom('pg_description as d')
|
||||
.innerJoin('pg_class as c', 'd.objoid', 'c.oid')
|
||||
.leftJoin('pg_attribute as a', (join) =>
|
||||
join.onRef('a.attrelid', '=', 'c.oid').onRef('a.attnum', '=', 'd.objsubid'),
|
||||
)
|
||||
.select([
|
||||
'c.relname as object_name',
|
||||
'c.relkind as object_type',
|
||||
'd.description as value',
|
||||
'a.attname as column_name',
|
||||
])
|
||||
.where('d.description', 'is not', null)
|
||||
.orderBy('object_type')
|
||||
.orderBy('object_name')
|
||||
.execute();
|
||||
|
||||
for (const comment of comments) {
|
||||
if (comment.object_type === 'r') {
|
||||
const table = schema.tables.find((table) => table.name === comment.object_name);
|
||||
if (!table) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (comment.column_name) {
|
||||
const column = table.columns.find(({ name }) => name === comment.column_name);
|
||||
if (column) {
|
||||
column.comment = comment.value;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
Loading…
Add table
Add a link
Reference in a new issue