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',
name: 'phone',
unique: true,
},
],
});
const tableNameWithSchema = collection.getTableNameWithSchema();
const field = collection.getField('username');
await this.db.sequelize.getQueryInterface().addColumn(tableNameWithSchema, field.columnName(), {
type: DataTypes.STRING,
});
const field = collection.getField('phone');
const exists = await field.existsInDb();
if (!exists) {
await this.db.sequelize.getQueryInterface().addColumn(tableNameWithSchema, field.columnName(), {
type: DataTypes.STRING,
});
}
await this.db.sequelize.getQueryInterface().addConstraint(tableNameWithSchema, {
type: 'unique',
fields: [field.columnName()],

View File

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