-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: upgrade to new file based subscriptions
- Loading branch information
1 parent
4a7f754
commit 3c430d2
Showing
13 changed files
with
1,143 additions
and
90 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
373 changes: 373 additions & 0 deletions
373
src/database/migrations/20220816155101-reset-db-for-new-singletons.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,373 @@ | ||
'use strict'; | ||
|
||
export default { | ||
async up(queryInterface) { | ||
await queryInterface.sequelize.query( | ||
`DROP TRIGGER IF EXISTS project_delete_fts`, | ||
); | ||
await queryInterface.sequelize.query( | ||
`DROP TRIGGER IF EXISTS project_insert_fts`, | ||
); | ||
await queryInterface.sequelize.query( | ||
`DROP TRIGGER IF EXISTS project_update_fts`, | ||
); | ||
await queryInterface.sequelize.query( | ||
`DROP TRIGGER IF EXISTS unit_delete_fts`, | ||
); | ||
await queryInterface.sequelize.query( | ||
`DROP TRIGGER IF EXISTS unit_insert_fts`, | ||
); | ||
await queryInterface.sequelize.query( | ||
`DROP TRIGGER IF EXISTS unit_update_fts`, | ||
); | ||
await Promise.all( | ||
[ | ||
'audit', | ||
'coBenefits', | ||
'estimations', | ||
'fileStore', | ||
'governance', | ||
'issuances', | ||
'label_unit', | ||
'labels', | ||
'meta', | ||
'organizations', | ||
'projectLocations', | ||
'projectRatings', | ||
'projects', | ||
'relatedProjects', | ||
'simulator', | ||
'staging', | ||
'units', | ||
].map((table) => { | ||
queryInterface.bulkDelete( | ||
table, | ||
{}, | ||
{ | ||
truncate: true, | ||
cascade: true, | ||
restartIdentity: true, | ||
}, | ||
); | ||
}), | ||
); | ||
|
||
await queryInterface.dropTable('units_fts'); | ||
await queryInterface.sequelize.query(` | ||
CREATE VIRTUAL TABLE units_fts USING fts5( | ||
warehouseUnitId, | ||
issuanceId, | ||
projectLocationId, | ||
orgUid, | ||
unitOwner, | ||
countryJurisdictionOfOwner, | ||
inCountryJurisdictionOfOwner, | ||
serialNumberBlock, | ||
vintageYear, | ||
unitType, | ||
marketplace, | ||
marketplaceLink, | ||
marketplaceIdentifier, | ||
unitTags, | ||
unitStatus, | ||
unitStatusReason, | ||
unitRegistryLink, | ||
correspondingAdjustmentDeclaration, | ||
correspondingAdjustmentStatus, | ||
unitBlockStart, | ||
unitBlockEnd, | ||
unitCount, | ||
timeStaged | ||
); | ||
`); | ||
await queryInterface.sequelize.query( | ||
`INSERT INTO units_fts SELECT | ||
warehouseUnitId, | ||
issuanceId, | ||
projectLocationId, | ||
orgUid, | ||
unitOwner, | ||
countryJurisdictionOfOwner, | ||
inCountryJurisdictionOfOwner, | ||
serialNumberBlock, | ||
vintageYear, | ||
unitType, | ||
marketplace, | ||
marketplaceLink, | ||
marketplaceIdentifier, | ||
unitTags, | ||
unitStatus, | ||
unitStatusReason, | ||
unitRegistryLink, | ||
correspondingAdjustmentDeclaration, | ||
correspondingAdjustmentStatus, | ||
unitBlockStart, | ||
unitBlockEnd, | ||
unitCount, | ||
timeStaged | ||
FROM units`, | ||
); | ||
|
||
await queryInterface.sequelize.query(` | ||
CREATE TRIGGER unit_insert_fts AFTER INSERT ON units BEGIN | ||
INSERT INTO units_fts( | ||
warehouseUnitId, | ||
issuanceId, | ||
projectLocationId, | ||
orgUid, | ||
unitOwner, | ||
countryJurisdictionOfOwner, | ||
inCountryJurisdictionOfOwner, | ||
serialNumberBlock, | ||
vintageYear, | ||
unitType, | ||
marketplace, | ||
marketplaceLink, | ||
marketplaceIdentifier, | ||
unitTags, | ||
unitStatus, | ||
unitStatusReason, | ||
unitRegistryLink, | ||
correspondingAdjustmentDeclaration, | ||
correspondingAdjustmentStatus, | ||
unitBlockStart, | ||
unitBlockEnd, | ||
unitCount | ||
) VALUES ( | ||
new.warehouseUnitId, | ||
new.issuanceId, | ||
new.projectLocationId, | ||
new.orgUid, | ||
new.unitOwner, | ||
new.countryJurisdictionOfOwner, | ||
new.inCountryJurisdictionOfOwner, | ||
new.serialNumberBlock, | ||
new.vintageYear, | ||
new.unitType, | ||
new.marketplace, | ||
new.marketplaceLink, | ||
new.marketplaceIdentifier, | ||
new.unitTags, | ||
new.unitStatus, | ||
new.unitStatusReason, | ||
new.unitRegistryLink, | ||
new.correspondingAdjustmentDeclaration, | ||
new.correspondingAdjustmentStatus, | ||
new.unitBlockStart, | ||
new.unitBlockEnd, | ||
new.unitCount | ||
); | ||
END;`); | ||
|
||
await queryInterface.sequelize.query(` | ||
CREATE TRIGGER unit_delete_fts AFTER DELETE ON units BEGIN | ||
DELETE FROM units_fts WHERE warehouseUnitId = old.warehouseUnitId; | ||
END; | ||
`); | ||
|
||
await queryInterface.sequelize.query(` | ||
CREATE TRIGGER unit_update_fts AFTER UPDATE ON units BEGIN | ||
DELETE FROM units_fts WHERE warehouseUnitId = old.warehouseUnitId; | ||
INSERT INTO units_fts( | ||
warehouseUnitId, | ||
issuanceId, | ||
projectLocationId, | ||
orgUid, | ||
unitOwner, | ||
countryJurisdictionOfOwner, | ||
inCountryJurisdictionOfOwner, | ||
serialNumberBlock, | ||
vintageYear, | ||
unitType, | ||
marketplace, | ||
marketplaceLink, | ||
marketplaceIdentifier, | ||
unitTags, | ||
unitStatus, | ||
unitStatusReason, | ||
unitRegistryLink, | ||
correspondingAdjustmentDeclaration, | ||
correspondingAdjustmentStatus, | ||
unitBlockStart, | ||
unitBlockEnd, | ||
unitCount | ||
) VALUES ( | ||
new.warehouseUnitId, | ||
new.issuanceId, | ||
new.projectLocationId, | ||
new.orgUid, | ||
new.unitOwner, | ||
new.countryJurisdictionOfOwner, | ||
new.inCountryJurisdictionOfOwner, | ||
new.serialNumberBlock, | ||
new.vintageYear, | ||
new.unitType, | ||
new.marketplace, | ||
new.marketplaceLink, | ||
new.marketplaceIdentifier, | ||
new.unitTags, | ||
new.unitStatus, | ||
new.unitStatusReason, | ||
new.unitRegistryLink, | ||
new.correspondingAdjustmentDeclaration, | ||
new.correspondingAdjustmentStatus, | ||
new.unitBlockStart, | ||
new.unitBlockEnd, | ||
new.unitCount | ||
); | ||
END; | ||
`); | ||
|
||
await queryInterface.dropTable('projects_fts'); | ||
await queryInterface.sequelize.query(` | ||
CREATE VIRTUAL TABLE projects_fts USING fts5( | ||
warehouseProjectId, | ||
orgUid, | ||
currentRegistry, | ||
projectId, | ||
registryOfOrigin, | ||
originProjectId, | ||
program, | ||
projectName, | ||
projectLink, | ||
projectDeveloper, | ||
sector, | ||
coveredByNDC, | ||
projectType, | ||
projectTags, | ||
ndcInformation, | ||
projectStatus, | ||
projectStatusDate, | ||
unitMetric, | ||
methodology, | ||
methodology2, | ||
validationBody, | ||
validationDate, | ||
timeStaged | ||
); | ||
`); | ||
|
||
await queryInterface.sequelize.query(` | ||
CREATE TRIGGER project_insert_fts AFTER INSERT ON projects BEGIN | ||
INSERT INTO projects_fts( | ||
warehouseProjectId, | ||
orgUid, | ||
currentRegistry, | ||
projectId, | ||
registryOfOrigin, | ||
originProjectId, | ||
program, | ||
projectName, | ||
projectLink, | ||
projectDeveloper, | ||
sector, | ||
coveredByNDC, | ||
projectType, | ||
projectTags, | ||
ndcInformation, | ||
projectStatus, | ||
projectStatusDate, | ||
unitMetric, | ||
methodology, | ||
methodology2, | ||
validationBody, | ||
validationDate, | ||
timeStaged | ||
) VALUES ( | ||
new.warehouseProjectId, | ||
new.orgUid, | ||
new.currentRegistry, | ||
new.projectId, | ||
new.registryOfOrigin, | ||
new.originProjectId, | ||
new.program, | ||
new.projectName, | ||
new.projectLink, | ||
new.projectDeveloper, | ||
new.sector, | ||
new.coveredByNDC, | ||
new.projectType, | ||
new.projectTags, | ||
new.ndcInformation, | ||
new.projectStatus, | ||
new.projectStatusDate, | ||
new.unitMetric, | ||
new.methodology, | ||
new.methodology2, | ||
new.validationBody, | ||
new.validationDate, | ||
new.timeStaged | ||
); | ||
END;`); | ||
|
||
await queryInterface.sequelize.query(` | ||
CREATE TRIGGER project_delete_fts AFTER DELETE ON projects BEGIN | ||
DELETE FROM projects_fts WHERE warehouseProjectId = old.warehouseProjectId; | ||
END; | ||
`); | ||
|
||
await queryInterface.sequelize.query(` | ||
CREATE TRIGGER project_update_fts AFTER UPDATE ON projects BEGIN | ||
DELETE FROM projects_fts WHERE warehouseProjectId = old.warehouseProjectId; | ||
INSERT INTO projects_fts( | ||
warehouseProjectId, | ||
orgUid, | ||
currentRegistry, | ||
projectId, | ||
registryOfOrigin, | ||
originProjectId, | ||
program, | ||
projectName, | ||
projectLink, | ||
projectDeveloper, | ||
sector, | ||
coveredByNDC, | ||
projectType, | ||
projectTags, | ||
ndcInformation, | ||
projectStatus, | ||
projectStatusDate, | ||
unitMetric, | ||
methodology, | ||
methodology2, | ||
validationBody, | ||
validationDate, | ||
timeStaged | ||
) VALUES ( | ||
new.warehouseProjectId, | ||
new.orgUid, | ||
new.currentRegistry, | ||
new.projectId, | ||
new.registryOfOrigin, | ||
new.originProjectId, | ||
new.program, | ||
new.projectName, | ||
new.projectLink, | ||
new.projectDeveloper, | ||
new.sector, | ||
new.coveredByNDC, | ||
new.projectType, | ||
new.projectTags, | ||
new.ndcInformation, | ||
new.projectStatus, | ||
new.projectStatusDate, | ||
new.unitMetric, | ||
new.methodology, | ||
new.methodology2, | ||
new.validationBody, | ||
new.validationDate, | ||
new.timeStaged | ||
); | ||
END; | ||
`); | ||
}, | ||
|
||
async down() { | ||
/** | ||
* Add reverting commands here. | ||
* | ||
* Example: | ||
* await queryInterface.dropTable('users'); | ||
*/ | ||
}, | ||
}; |
Oops, something went wrong.