Skip to content

Commit

Permalink
feat: upgrade to new file based subscriptions
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelTaylor3D committed Aug 16, 2022
1 parent 4a7f754 commit 3c430d2
Show file tree
Hide file tree
Showing 13 changed files with 1,143 additions and 90 deletions.
708 changes: 690 additions & 18 deletions package-lock.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"mysql2": "^2.3.3",
"mysql2-promise": "^0.1.4",
"node-xlsx": "^0.21.0",
"public-ip": "^6.0.1",
"random-hash": "^4.0.1",
"regenerator-runtime": "^0.13.9",
"request-promise": "^4.2.6",
Expand Down
4 changes: 2 additions & 2 deletions src/controllers/organization.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,14 @@ export const importOrg = async (req, res) => {
await assertIfReadOnlyMode();
await assertWalletIsSynced();

const { orgUid, ip, port } = req.body;
const { orgUid } = req.body;

res.json({
message:
'Importing and subscribing organization this can take a few mins.',
});

return Organization.importOrganization(orgUid, ip, port);
return Organization.importOrganization(orgUid);
} catch (error) {
console.trace(error);
res.status(400).json({
Expand Down
373 changes: 373 additions & 0 deletions src/database/migrations/20220816155101-reset-db-for-new-singletons.js
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');
*/
},
};
Loading

0 comments on commit 3c430d2

Please sign in to comment.