我有一个15部分的承诺链,是Sequelize交易的一部分。链的前提是当用户采取删除其帐户的操作时删除所有表记录。在删除所有表记录之前,我将存储其对象的长度,以便能够记录要删除的帐户以及先前与每个表关联的记录数量。在我当前的设置中,我正在通过表格,但在.create
方法中遇到以下错误,以便为已删除的帐户创建记录。
Transaction Error
[SequelizeDatabaseError: could not serialize access due to concurrent update]
当我在postgres帐户中运行执行的SQL查询时,我没有问题,这表明Sequelize生成的SQL是正确的,但另一个问题是问题。
Executing (35807900-1fe0-4676-b132-877a32307385): INSERT INTO "test_account" ("test_account_id","account_id","document_quantity","document_report_quantity","category_quantity","user_quantity","updated_at","created_at") VALUES (DEFAULT,51,1,0,2,2,'2017-07-16 23:12:03.180 +00:00','2017-07-16 23:12:03.180 +00:00') RETURNING *;
有人可以告诉我这意味着什么以及为什么在触发这段代码时会发生这种情况?
test_account
与account
之间存在一种关联:
classMethods: {
associate: function(db) {
TestAccount.belongsTo(db.Account, { foreignKey: 'account_id' });
}
}
以下是链条:
return models.sequelize.transaction().then(function(t){
//STEP 1: Query Documents
return deleteAccount.queryAllDocuments(req.session.organizationId, t)
.then(function(_document){
documents = _document;
documentsArr = documents;
documentsLength = documents.length;
})
//STEP 2: Cancel Stripe Account
.then(() => deleteAccount.cancelStripeAccount(req.session.subscriptionId))
.then(function(_canceledStripeAccount){
canceledStripeAccount = _canceledStripeAccount;
canceledAt = canceledStripeAccount.canceled_at;
})
//STEP 3: Update Account Record
.then(() => deleteAccount.updateAccountCancelDate(canceledAt, canceledStripeAccount, t))
//STEP 4: Query Account Record
.then(() => deleteAccount.queryAccount(req.session.subscriptionId, t))
.then(function(_account){
accountId = _account.accountId;
})
//STEP 5: Create Delete Account Record
.then(() => deleteAccount.createDeletedAccountRecord(accountId, req.session.organizationId, canceledAt, t))
.then(function(_deletedAccount){
deletedAccount = _deletedAccount;
})
//STEP 6: Query All Document Records
.then(() => deleteAccount.queryAllDocumentReports(documentsArr, t))
.then(function(_documentsReports){
documentsReports = _documentsReports.length;
})
//STEP 7: Delete All Document File Records
.then(() => deleteAccount.deleteDocumentFiles(documentsArr, req.session.organizationId, documentsFiles, t))
//STEP 8: Delete All Document Records
.then(() => deleteAccount.deleteDocuments(documentsArr, t))
//STEP 9: Query All Category Records
.then(() => deleteAccount.queryAllCategories(req.session.organizationId, t))
.then(function(_categories){
categories = _categories.length;
})
//STEP 10: Delete All Category Records
.then(() => deleteAccount.deleteCategories(req.session.organizationId, t))
//STEP 11: Query All User Records
.then(() => deleteAccount.queryUsers(req.session.organizationId, t))
.then(function(_users){
users = _users.length;
usersArr = components.usersRecordId(_users);
})
//STEP 12: Query Account Record
.then(() => deleteAccount.queryAccount(req.session.subscriptionId, t))
.then(function(_account){
accountId = _account.accountId;
})
//STEP 13: Update Deleted Account Record ////////THIS IS WHERE THE ERROR TRANSACTION ERROR OCCURS
.then(() => deleteAccount.createTestAccount(accountId, documentsLength, documentsReports, categories, users, t))
//STEP 14: Deleted Organization Record
.then(() => deleteAccount.deleteOrganization(req.session.organizationId, t))
//STEP 15: Delete All User Records
.then(() => deleteAccount.deleteUsers(usersArr, t))
.then(function(){
console.log("Account Deleted Successfully");
t.commit();
});
}).then(function(){
req.session.destroy();
req.logout();
res.redirect('/');
}).catch(function(err){
console.log("Transaction Error");
console.log(err);
});