diff --git a/packages/plugins/collection-manager/src/__tests__/http-api/collections.test.ts b/packages/plugins/collection-manager/src/__tests__/http-api/collections.test.ts index 208c4faac..e7da82ed0 100644 --- a/packages/plugins/collection-manager/src/__tests__/http-api/collections.test.ts +++ b/packages/plugins/collection-manager/src/__tests__/http-api/collections.test.ts @@ -97,7 +97,7 @@ describe('collections repository', () => { const testCollection = app.db.getCollection('test'); - const tableInfo = await app.db.sequelize.getQueryInterface().describeTable(testCollection.model.tableName); + const tableInfo = await app.db.sequelize.getQueryInterface().describeTable(testCollection.addSchemaTableName()); expect(tableInfo['field']).toBeDefined(); }); diff --git a/packages/plugins/collection-manager/src/__tests__/migrations/update-id-to-bigint.test.ts b/packages/plugins/collection-manager/src/__tests__/migrations/update-id-to-bigint.test.ts index e972925f2..363b705d5 100644 --- a/packages/plugins/collection-manager/src/__tests__/migrations/update-id-to-bigint.test.ts +++ b/packages/plugins/collection-manager/src/__tests__/migrations/update-id-to-bigint.test.ts @@ -68,17 +68,16 @@ excludeSqlite()('update id to bigint test', () => { await db.sync(); const assertBigInt = async (collectionName, fieldName) => { - const tableInfo = await db.sequelize - .getQueryInterface() - .describeTable( - db.getCollection(collectionName) ? db.getCollection(collectionName).model.tableName : collectionName, - ); + const tableName = db.getCollection(collectionName) + ? db.getCollection(collectionName).addSchemaTableName() + : collectionName; + + const tableInfo = await db.sequelize.getQueryInterface().describeTable(tableName); if (db.options.underscored) { fieldName = lodash.snakeCase(fieldName); } - console.log(`${collectionName}, ${fieldName}`, tableInfo[fieldName].type); expect(tableInfo[fieldName].type).toBe('BIGINT'); }; @@ -92,7 +91,7 @@ excludeSqlite()('update id to bigint test', () => { let usersTableInfo = await db.sequelize .getQueryInterface() - .describeTable(db.getCollection('users').model.tableName); + .describeTable(db.getCollection('users').addSchemaTableName()); assertInteger(usersTableInfo.id.type); diff --git a/packages/plugins/collection-manager/src/migrations/20221121111113-update-id-to-bigint.ts b/packages/plugins/collection-manager/src/migrations/20221121111113-update-id-to-bigint.ts index 48e7cabbe..d7563aa05 100644 --- a/packages/plugins/collection-manager/src/migrations/20221121111113-update-id-to-bigint.ts +++ b/packages/plugins/collection-manager/src/migrations/20221121111113-update-id-to-bigint.ts @@ -34,6 +34,8 @@ export default class UpdateIdToBigIntMigrator extends Migration { let sql; const tableName = model.tableName; + const addSchemaTableName = db.utils.addSchema(tableName); + const quoteTableName = db.utils.quoteTable(addSchemaTableName); const collection = db.modelCollection.get(model); @@ -52,7 +54,7 @@ export default class UpdateIdToBigIntMigrator extends Migration { if (model.rawAttributes[fieldName].type instanceof DataTypes.INTEGER) { if (db.inDialect('postgres')) { - sql = `ALTER TABLE "${tableName}" ALTER COLUMN "${columnName}" SET DATA TYPE BIGINT;`; + sql = `ALTER TABLE ${quoteTableName} ALTER COLUMN "${columnName}" SET DATA TYPE BIGINT;`; } else if (db.inDialect('mysql')) { const dataTypeOrOptions = model.rawAttributes[fieldName]; const attributeName = fieldName; @@ -70,7 +72,7 @@ export default class UpdateIdToBigIntMigrator extends Migration { }, ); - sql = queryGenerator.changeColumnQuery(tableName, query); + sql = queryGenerator.changeColumnQuery(addSchemaTableName, query); sql = sql.replace(' PRIMARY KEY;', ' ;'); } @@ -85,7 +87,7 @@ export default class UpdateIdToBigIntMigrator extends Migration { } if (db.inDialect('postgres')) { - const sequenceQuery = `SELECT pg_get_serial_sequence('"${model.tableName}"', '${columnName}');`; + const sequenceQuery = `SELECT pg_get_serial_sequence('${quoteTableName}', '${columnName}');`; const [result] = await this.sequelize.query(sequenceQuery, {}); const sequenceName = result[0]['pg_get_serial_sequence'];