fix: update to bigint test
This commit is contained in:
parent
1589d11e82
commit
ee3db22c8a
@ -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();
|
||||
});
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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'];
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user