fix: migration error

This commit is contained in:
chenos 2023-03-12 14:08:43 +08:00
parent aece9015aa
commit cb97c7ae5c

View File

@ -4,15 +4,6 @@ import { FieldModel } from '../models';
export default class extends Migration { export default class extends Migration {
async up() { async up() {
const migratedFieldsCount = await this.db.getRepository('fields').count({
filter: {
'options.uiSchema': { $exists: true },
},
});
if (migratedFieldsCount > 0) {
return;
}
const transaction = await this.db.sequelize.transaction(); const transaction = await this.db.sequelize.transaction();
@ -53,6 +44,10 @@ export default class extends Migration {
transaction, transaction,
}); });
if (!uiSchemaRecord) {
continue;
}
const uiSchema = uiSchemaRecord.get('schema'); const uiSchema = uiSchemaRecord.get('schema');
fieldRecord.set('uiSchema', uiSchema); fieldRecord.set('uiSchema', uiSchema);
@ -68,11 +63,9 @@ export default class extends Migration {
try { try {
await migrateFieldsSchema(this.db.getCollection('fields')); await migrateFieldsSchema(this.db.getCollection('fields'));
if (this.db.getCollection('fieldsHistory')) { if (this.db.getCollection('fieldsHistory')) {
await migrateFieldsSchema(this.db.getCollection('fieldsHistory')); await migrateFieldsSchema(this.db.getCollection('fieldsHistory'));
} }
await transaction.commit(); await transaction.commit();
} catch (error) { } catch (error) {
await transaction.rollback(); await transaction.rollback();