mirror of
https://github.com/morten-olsen/reservoir.git
synced 2026-02-08 01:46:24 +01:00
fix: use view recreate
This commit is contained in:
@@ -75,19 +75,22 @@ class ViewsService {
|
|||||||
const dbService = this.#services.get(DatabaseService);
|
const dbService = this.#services.get(DatabaseService);
|
||||||
const db = await dbService.getInstance();
|
const db = await dbService.getInstance();
|
||||||
const subquery = db.raw(query);
|
const subquery = db.raw(query);
|
||||||
await db.schema.createViewOrReplace(name, (view) => {
|
await db.transaction(async (trx) => {
|
||||||
// view.columns(columns);
|
await trx.schema.dropViewIfExists(name);
|
||||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
await trx.schema.createViewOrReplace(name, (view) => {
|
||||||
view.as(subquery as any);
|
// view.columns(columns);
|
||||||
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||||
|
view.as(subquery as any);
|
||||||
|
});
|
||||||
|
if (description) {
|
||||||
|
const sql = trx.raw(`COMMENT ON VIEW ?? IS ?;`, [name, description]);
|
||||||
|
await trx.raw(sql.toQuery());
|
||||||
|
}
|
||||||
|
for (const [columnName, info] of Object.entries(columns)) {
|
||||||
|
const sql = trx.raw(`COMMENT ON COLUMN ??.?? IS ?;`, [name, columnName, info.description || null]);
|
||||||
|
await trx.raw(sql.toQuery());
|
||||||
|
}
|
||||||
});
|
});
|
||||||
if (description) {
|
|
||||||
const sql = db.raw(`COMMENT ON VIEW ?? IS ?;`, [name, description]);
|
|
||||||
await db.raw(sql.toQuery());
|
|
||||||
}
|
|
||||||
for (const [columnName, info] of Object.entries(columns)) {
|
|
||||||
const sql = db.raw(`COMMENT ON COLUMN ??.?? IS ?;`, [name, columnName, info.description || null]);
|
|
||||||
await db.raw(sql.toQuery());
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
public remove = async (name: string) => {
|
public remove = async (name: string) => {
|
||||||
|
|||||||
Reference in New Issue
Block a user