-
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.
Merge pull request #61 from Chia-Network/feat/triggers
feat: triggers for fts on units and projects in sqlite
- Loading branch information
Showing
3 changed files
with
232 additions
and
45 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
up: async (queryInterface, Sequelize) => { | ||
if (queryInterface.sequelize.getDialect() === 'sqlite') { | ||
await queryInterface.sequelize.query(` | ||
CREATE TRIGGER project_insert_fts AFTER INSERT ON projects BEGIN | ||
INSERT INTO projects_fts( | ||
id, | ||
warehouseProjectId, | ||
currentRegistry, | ||
registryOfOrigin, | ||
originProjectId, | ||
program, | ||
projectName, | ||
projectLink, | ||
projectDeveloper, | ||
sector, | ||
projectType, | ||
coveredByNDC, | ||
NDCLinkage, | ||
projectStatus, | ||
projectStatusDate, | ||
unitMetric, | ||
methodology, | ||
methodologyVersion, | ||
validationApproach, | ||
validationDate, | ||
projectTag | ||
) VALUES ( | ||
new.id, | ||
new.warehouseProjectId, | ||
new.currentRegistry, | ||
new.registryOfOrigin, | ||
new.originProjectId, | ||
new.program, | ||
new.projectName, | ||
new.projectLink, | ||
new.projectDeveloper, | ||
new.sector, | ||
new.projectType, | ||
new.coveredByNDC, | ||
new.NDCLinkage, | ||
new.projectStatus, | ||
new.projectStatusDate, | ||
new.unitMetric, | ||
new.methodology, | ||
new.methodologyVersion, | ||
new.validationApproach, | ||
new.validationDate, | ||
new.projectTag | ||
); | ||
END;`); | ||
|
||
await queryInterface.sequelize.query(` | ||
CREATE TRIGGER project_delete_fts AFTER DELETE ON projects BEGIN | ||
DELETE FROM projects_fts WHERE id = old.id; | ||
END; | ||
`); | ||
|
||
await queryInterface.sequelize.query(` | ||
CREATE TRIGGER project_update_fts AFTER UPDATE ON projects BEGIN | ||
DELETE FROM projects_fts WHERE id = old.id; | ||
INSERT INTO projects_fts( | ||
id, | ||
warehouseProjectId, | ||
currentRegistry, | ||
registryOfOrigin, | ||
originProjectId, | ||
program, | ||
projectName, | ||
projectLink, | ||
projectDeveloper, | ||
sector, | ||
projectType, | ||
coveredByNDC, | ||
NDCLinkage, | ||
projectStatus, | ||
projectStatusDate, | ||
unitMetric, | ||
methodology, | ||
methodologyVersion, | ||
validationApproach, | ||
validationDate, | ||
projectTag | ||
) VALUES ( | ||
new.id, | ||
new.warehouseProjectId, | ||
new.currentRegistry, | ||
new.registryOfOrigin, | ||
new.originProjectId, | ||
new.program, | ||
new.projectName, | ||
new.projectLink, | ||
new.projectDeveloper, | ||
new.sector, | ||
new.projectType, | ||
new.coveredByNDC, | ||
new.NDCLinkage, | ||
new.projectStatus, | ||
new.projectStatusDate, | ||
new.unitMetric, | ||
new.methodology, | ||
new.methodologyVersion, | ||
new.validationApproach, | ||
new.validationDate, | ||
new.projectTag | ||
); | ||
END; | ||
`); | ||
}}, | ||
|
||
down: async (queryInterface, Sequelize) => { | ||
if (queryInterface.sequelize.getDialect() === 'sqlite') { | ||
await queryInterface.sequelize.query("DROP TRIGGER project_insert_fts;"); | ||
await queryInterface.sequelize.query("DROP TRIGGER project_delete_fts;"); | ||
await queryInterface.sequelize.query("DROP TRIGGER project_update_fts;"); | ||
} | ||
} | ||
}; |
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,105 @@ | ||
'use strict'; | ||
|
||
module.exports = { | ||
up: async (queryInterface, Sequelize) => { | ||
if (queryInterface.sequelize.getDialect() === 'sqlite') { | ||
await queryInterface.sequelize.query(` | ||
CREATE TRIGGER unit_insert_fts AFTER INSERT ON units BEGIN | ||
INSERT INTO units_fts( | ||
id, | ||
projectId, | ||
buyer, | ||
registry, | ||
blockIdentifier, | ||
identifier, | ||
qualificationId, | ||
unitType, | ||
unitCount, | ||
unitStatus, | ||
unitStatusDate, | ||
transactionType, | ||
unitIssuanceLocation, | ||
unitLink, | ||
correspondingAdjustment, | ||
unitTag, | ||
vintageId | ||
) VALUES ( | ||
new.id, | ||
new.projectId, | ||
new.buyer, | ||
new.registry, | ||
new.blockIdentifier, | ||
new.identifier, | ||
new.qualificationId, | ||
new.unitType, | ||
new.unitCount, | ||
new.unitStatus, | ||
new.unitStatusDate, | ||
new.transactionType, | ||
new.unitIssuanceLocation, | ||
new.unitLink, | ||
new.correspondingAdjustment, | ||
new.unitTag, | ||
new.vintageId | ||
); | ||
END;`); | ||
|
||
await queryInterface.sequelize.query(` | ||
CREATE TRIGGER unit_delete_fts AFTER DELETE ON units BEGIN | ||
DELETE FROM unit_insert_fts WHERE id = old.id; | ||
END; | ||
`); | ||
|
||
await queryInterface.sequelize.query(` | ||
CREATE TRIGGER unit_update_fts AFTER UPDATE ON units BEGIN | ||
DELETE FROM units_fts WHERE id = old.id; | ||
INSERT INTO units_fts( | ||
id, | ||
projectId, | ||
buyer, | ||
registry, | ||
blockIdentifier, | ||
identifier, | ||
qualificationId, | ||
unitType, | ||
unitCount, | ||
unitStatus, | ||
unitStatusDate, | ||
transactionType, | ||
unitIssuanceLocation, | ||
unitLink, | ||
correspondingAdjustment, | ||
unitTag, | ||
vintageId | ||
) VALUES ( | ||
new.id, | ||
new.projectId, | ||
new.buyer, | ||
new.registry, | ||
new.blockIdentifier, | ||
new.identifier, | ||
new.qualificationId, | ||
new.unitType, | ||
new.unitCount, | ||
new.unitStatus, | ||
new.unitStatusDate, | ||
new.transactionType, | ||
new.unitIssuanceLocation, | ||
new.unitLink, | ||
new.correspondingAdjustment, | ||
new.unitTag, | ||
new.vintageId | ||
); | ||
END; | ||
`); | ||
} | ||
}, | ||
|
||
down: async (queryInterface, Sequelize) => { | ||
if (queryInterface.sequelize.getDialect() === 'sqlite') { | ||
await queryInterface.sequelize.query("DROP TRIGGER unit_insert_fts;"); | ||
await queryInterface.sequelize.query("DROP TRIGGER unit_delete_fts;"); | ||
await queryInterface.sequelize.query("DROP TRIGGER unit_update_fts;"); | ||
} | ||
} | ||
}; |