不要怂,就是干,撸起袖子干!

Commit 8d9e58b4 by Sushant Committed by GitHub

fix(sync): pass options to all query methods (#12208)

1 parent 4c674e29
Showing with 14 additions and 19 deletions
......@@ -1284,23 +1284,25 @@ class Model {
if (options.force) {
await this.drop(options);
}
await this.QueryInterface.createTable(this.getTableName(options), attributes, options, this);
const tableName = this.getTableName(options);
await this.QueryInterface.createTable(tableName, attributes, options, this);
if (options.alter) {
const tableInfos = await Promise.all([
this.QueryInterface.describeTable(this.getTableName(options)),
this.QueryInterface.getForeignKeyReferencesForTable(this.getTableName(options))
this.QueryInterface.describeTable(tableName, options),
this.QueryInterface.getForeignKeyReferencesForTable(tableName, options)
]);
const columns = tableInfos[0];
// Use for alter foreign keys
const foreignKeyReferences = tableInfos[1];
const removedConstraints = {};
for (const columnName in attributes) {
if (!Object.prototype.hasOwnProperty.call(attributes, columnName)) continue;
if (!columns[columnName] && !columns[attributes[columnName].field]) {
await this.QueryInterface.addColumn(this.getTableName(options), attributes[columnName].field || columnName, attributes[columnName]);
await this.QueryInterface.addColumn(tableName, attributes[columnName].field || columnName, attributes[columnName], options);
}
}
......@@ -1309,7 +1311,7 @@ class Model {
if (!Object.prototype.hasOwnProperty.call(columns, columnName)) continue;
const currentAttribute = rawAttributes[columnName];
if (!currentAttribute) {
await this.QueryInterface.removeColumn(this.getTableName(options), columnName, options);
await this.QueryInterface.removeColumn(tableName, columnName, options);
continue;
}
if (currentAttribute.primaryKey) continue;
......@@ -1329,16 +1331,16 @@ class Model {
&& (schema ? foreignKeyReference.referencedTableSchema === schema : true)
&& !removedConstraints[constraintName]) {
// Remove constraint on foreign keys.
await this.QueryInterface.removeConstraint(this.getTableName(options), constraintName, options);
await this.QueryInterface.removeConstraint(tableName, constraintName, options);
removedConstraints[constraintName] = true;
}
}
}
await this.QueryInterface.changeColumn(this.getTableName(options), columnName, currentAttribute);
await this.QueryInterface.changeColumn(tableName, columnName, currentAttribute, options);
}
}
}
let indexes = await this.QueryInterface.showIndex(this.getTableName(options), options);
let indexes = await this.QueryInterface.showIndex(tableName, options);
indexes = this._indexes.filter(item1 =>
!indexes.some(item2 => item1.name === item2.name)
).sort((index1, index2) => {
......@@ -1352,20 +1354,13 @@ class Model {
});
for (const index of indexes) {
await this.QueryInterface.addIndex(
this.getTableName(options),
Object.assign({
logging: options.logging,
benchmark: options.benchmark,
transaction: options.transaction,
schema: options.schema
}, index),
this.tableName
);
await this.QueryInterface.addIndex(tableName, Object.assign({}, options, index));
}
if (options.hooks) {
await this.runHooks('afterSync', options);
}
return this;
}
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!