fix: update to bigint (#1117)
* fix: update sequence and foreignKey * chore: rename migration * fix: single foreign field update * fix: update bigint * fix: rename Co-authored-by: chenos <chenlinxh@gmail.com>
This commit is contained in:
parent
f4e850059a
commit
d72123c5b0
@ -12,12 +12,6 @@ export default class UpdateIdToBigIntMigrator extends Migration {
|
|||||||
name: 'id',
|
name: 'id',
|
||||||
type: 'integer',
|
type: 'integer',
|
||||||
},
|
},
|
||||||
{
|
|
||||||
options: {
|
|
||||||
isForeignKey: true,
|
|
||||||
},
|
|
||||||
type: 'integer',
|
|
||||||
},
|
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
values: {
|
values: {
|
||||||
@ -39,6 +33,7 @@ export default class UpdateIdToBigIntMigrator extends Migration {
|
|||||||
let sql;
|
let sql;
|
||||||
|
|
||||||
const tableName = model.tableName;
|
const tableName = model.tableName;
|
||||||
|
|
||||||
if (model.rawAttributes[fieldName].type instanceof DataTypes.INTEGER) {
|
if (model.rawAttributes[fieldName].type instanceof DataTypes.INTEGER) {
|
||||||
if (db.inDialect('postgres')) {
|
if (db.inDialect('postgres')) {
|
||||||
sql = `ALTER TABLE "${tableName}" ALTER COLUMN "${fieldName}" SET DATA TYPE BIGINT;`;
|
sql = `ALTER TABLE "${tableName}" ALTER COLUMN "${fieldName}" SET DATA TYPE BIGINT;`;
|
||||||
@ -66,7 +61,7 @@ export default class UpdateIdToBigIntMigrator extends Migration {
|
|||||||
try {
|
try {
|
||||||
await this.sequelize.query(sql, {});
|
await this.sequelize.query(sql, {});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (err.message.includes('does not exist')) {
|
if (err.message.includes('does not exist') || err.message.includes('cannot alter inherited column')) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
throw err;
|
throw err;
|
||||||
@ -99,6 +94,24 @@ export default class UpdateIdToBigIntMigrator extends Migration {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const singleForeignFields = await db.getCollection('fields').repository.find({
|
||||||
|
filter: {
|
||||||
|
options: {
|
||||||
|
isForeignKey: true,
|
||||||
|
},
|
||||||
|
type: 'integer',
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
for (const field of singleForeignFields) {
|
||||||
|
const collection = db.getCollection(field.get('collectionName'));
|
||||||
|
if (!collection) {
|
||||||
|
console.log('collection not found', field.get('collectionName'));
|
||||||
|
}
|
||||||
|
|
||||||
|
await updateToBigInt(collection.model, field.get('name'));
|
||||||
|
}
|
||||||
|
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
this.app.db.sequelize.modelManager.forEachModel((model) => {
|
this.app.db.sequelize.modelManager.forEachModel((model) => {
|
||||||
models.push(model);
|
models.push(model);
|
Loading…
Reference in New Issue
Block a user