fix: migration error

This commit is contained in:
chenos 2024-01-13 09:47:35 +08:00
parent f466e6ec95
commit c44f459756
2 changed files with 13 additions and 9 deletions

View File

@ -12,15 +12,17 @@ export default class AddUsersPhoneMigration extends Migration {
{ {
type: 'string', type: 'string',
name: 'phone', name: 'phone',
unique: true,
}, },
], ],
}); });
const tableNameWithSchema = collection.getTableNameWithSchema(); const tableNameWithSchema = collection.getTableNameWithSchema();
const field = collection.getField('username'); const field = collection.getField('phone');
await this.db.sequelize.getQueryInterface().addColumn(tableNameWithSchema, field.columnName(), { const exists = await field.existsInDb();
type: DataTypes.STRING, if (!exists) {
}); await this.db.sequelize.getQueryInterface().addColumn(tableNameWithSchema, field.columnName(), {
type: DataTypes.STRING,
});
}
await this.db.sequelize.getQueryInterface().addConstraint(tableNameWithSchema, { await this.db.sequelize.getQueryInterface().addConstraint(tableNameWithSchema, {
type: 'unique', type: 'unique',
fields: [field.columnName()], fields: [field.columnName()],

View File

@ -12,15 +12,17 @@ export default class AddUserNameMigration extends Migration {
{ {
type: 'string', type: 'string',
name: 'username', name: 'username',
unique: true,
}, },
], ],
}); });
const tableNameWithSchema = collection.getTableNameWithSchema(); const tableNameWithSchema = collection.getTableNameWithSchema();
const field = collection.getField('username'); const field = collection.getField('username');
await this.db.sequelize.getQueryInterface().addColumn(tableNameWithSchema, field.columnName(), { const exists = await field.existsInDb();
type: DataTypes.STRING, if (!exists) {
}); await this.db.sequelize.getQueryInterface().addColumn(tableNameWithSchema, field.columnName(), {
type: DataTypes.STRING,
});
}
await this.db.sequelize.getQueryInterface().addConstraint(tableNameWithSchema, { await this.db.sequelize.getQueryInterface().addConstraint(tableNameWithSchema, {
type: 'unique', type: 'unique',
fields: [field.columnName()], fields: [field.columnName()],