mirror of
https://github.com/nocobase/nocobase.git
synced 2026-09-24 16:02:20 +08:00
Merge branch 'main' into next
This commit is contained in:
@@ -48,4 +48,23 @@ describe('list view', () => {
|
||||
expect(results.find((item) => item.name === 'test1')).toBeTruthy();
|
||||
expect(results.find((item) => item.name === 'test2')).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should list view when schema passed', async () => {
|
||||
if (!db.options.schema) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (db.inDialect('postgres')) {
|
||||
await db.prepare();
|
||||
}
|
||||
|
||||
const viewName = 'schema_test';
|
||||
const schema = db.options.schema || process.env.USER_SCHEMA || process.env.DB_COLLECTION_MANAGER_SCHEMA || 'public';
|
||||
const newViewName = schema ? `${schema}.${viewName}` : viewName;
|
||||
await db.sequelize.query(`DROP VIEW IF EXISTS ${newViewName}`);
|
||||
await db.sequelize.query(`CREATE VIEW ${newViewName} AS SELECT 3`);
|
||||
|
||||
const results = await db.queryInterface.listViews({ schema: db.options.schema });
|
||||
expect(results.find((item) => item.name === viewName)).toBeTruthy();
|
||||
});
|
||||
});
|
||||
|
||||
@@ -107,8 +107,8 @@ export default class PostgresQueryInterface extends QueryInterface {
|
||||
return results[0]['exists'];
|
||||
}
|
||||
|
||||
async listViews() {
|
||||
const targetSchema = this.db.options?.schema || 'public';
|
||||
async listViews(options?: { schema?: string }) {
|
||||
const targetSchema = options?.schema || this.db.options?.schema || 'public';
|
||||
|
||||
const sql = targetSchema
|
||||
? `
|
||||
|
||||
@@ -25,7 +25,7 @@ export default abstract class QueryInterface {
|
||||
|
||||
abstract collectionTableExists(collection: Collection, options?: Transactionable): Promise<boolean>;
|
||||
|
||||
abstract listViews();
|
||||
abstract listViews(options?: { schema?: string });
|
||||
|
||||
abstract viewDef(viewName: string): Promise<string>;
|
||||
|
||||
|
||||
@@ -52,7 +52,9 @@ export default {
|
||||
|
||||
list: async function (ctx, next) {
|
||||
const db = ctx.app.db as Database;
|
||||
const dbViews = await db.queryInterface.listViews();
|
||||
const dbViews = await db.queryInterface.listViews({
|
||||
schema: db.options?.schema || process.env.DB_SCHEMA || process.env.COLLECTION_MANAGER_SCHEMA || 'public',
|
||||
});
|
||||
|
||||
const viewCollections = Array.from(db.collections.values()).filter((collection) => collection.isView());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user