Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/1476 create parent approvals for old parent accounts #6305

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
'use strict';
const models = require('../server/models/index');

const dateAccountsCreatedInService = new Date('2019-08-30T00:00:00Z');

module.exports = {
up: async (queryInterface, Sequelize) => {
return queryInterface.sequelize.transaction(async (transaction) => {
const parentEstablishmentsWithoutApprovalRecord = await queryInterface.sequelize.query(
`
SELECT e."EstablishmentID", u."RegistrationID"
FROM cqc."Establishment" e
LEFT JOIN cqc."Approvals" a ON e."EstablishmentID" = a."EstablishmentID"
JOIN cqc."User" u ON e."EstablishmentID" = u."EstablishmentID"
WHERE a."EstablishmentID" IS NULL AND e."IsParent" = true
AND e."Archived" = false
AND u."IsPrimary" = true
AND u."Archived" = false;
`,
{ type: Sequelize.QueryTypes.SELECT, transaction },
);

for (const establishment of parentEstablishmentsWithoutApprovalRecord) {
await models.Approvals.create(
{
EstablishmentID: establishment.EstablishmentID,
ApprovalType: 'BecomeAParent',
UserID: establishment.RegistrationID,
Status: 'Approved',
createdAt: dateAccountsCreatedInService,
updatedAt: dateAccountsCreatedInService,
},
{
transaction,
silent: true, // prevents updatedAt being overridden
},
);
}
});
},

down: async (queryInterface) => {
return queryInterface.sequelize.transaction(async (transaction) => {
await models.Approvals.destroy(
{
where: {
createdAt: dateAccountsCreatedInService,
},
},
{ transaction },
);
});
},
};
Loading