Skip to content

Commit

Permalink
feat: add datalayer url config
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaelTaylor3D committed Dec 7, 2022
1 parent e3fc443 commit aceb436
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 66 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "climate-warehouse",
"version": "1.2.18",
"version": "1.2.19",
"private": true,
"bin": "build/server.js",
"type": "module",
Expand Down
126 changes: 64 additions & 62 deletions src/database/migrations/20220816155101-reset-db-for-new-singletons.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,58 +2,59 @@

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,
},
);
}),
);
if (queryInterface.sequelize.getDialect() === 'sqlite') {
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(`
await queryInterface.dropTable('units_fts');
await queryInterface.sequelize.query(`
CREATE VIRTUAL TABLE units_fts USING fts5(
warehouseUnitId,
issuanceId,
Expand All @@ -80,8 +81,8 @@ export default {
timeStaged
);
`);
await queryInterface.sequelize.query(
`INSERT INTO units_fts SELECT
await queryInterface.sequelize.query(
`INSERT INTO units_fts SELECT
warehouseUnitId,
issuanceId,
projectLocationId,
Expand All @@ -106,9 +107,9 @@ export default {
unitCount,
timeStaged
FROM units`,
);
);

await queryInterface.sequelize.query(`
await queryInterface.sequelize.query(`
CREATE TRIGGER unit_insert_fts AFTER INSERT ON units BEGIN
INSERT INTO units_fts(
warehouseUnitId,
Expand Down Expand Up @@ -159,13 +160,13 @@ export default {
);
END;`);

await queryInterface.sequelize.query(`
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(`
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(
Expand Down Expand Up @@ -218,8 +219,8 @@ export default {
END;
`);

await queryInterface.dropTable('projects_fts');
await queryInterface.sequelize.query(`
await queryInterface.dropTable('projects_fts');
await queryInterface.sequelize.query(`
CREATE VIRTUAL TABLE projects_fts USING fts5(
warehouseProjectId,
orgUid,
Expand Down Expand Up @@ -248,7 +249,7 @@ export default {
);
`);

await queryInterface.sequelize.query(`
await queryInterface.sequelize.query(`
CREATE TRIGGER project_insert_fts AFTER INSERT ON projects BEGIN
INSERT INTO projects_fts(
warehouseProjectId,
Expand Down Expand Up @@ -303,13 +304,13 @@ export default {
);
END;`);

await queryInterface.sequelize.query(`
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(`
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(
Expand Down Expand Up @@ -365,6 +366,7 @@ export default {
);
END;
`);
}
},

async down() {
Expand Down
5 changes: 3 additions & 2 deletions src/datalayer/writeService.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { publicIpv4 } from '../utils/ip-tools';

logger.info('climate-warehouse:datalayer:writeService');

const { USE_SIMULATOR } = getConfig().APP;
const { USE_SIMULATOR, DATALAYER_FILE_SERVER_URL } = getConfig().APP;

const createDataLayerStore = async () => {
await wallet.waitForAllTransactionsToConfirm();
Expand All @@ -33,7 +33,8 @@ const createDataLayerStore = async () => {

await dataLayer.addMirror(
storeId,
`http://${await publicIpv4()}:${chiaConfig.data_layer.host_port}`,
DATALAYER_FILE_SERVER_URL ||
`http://${await publicIpv4()}:${chiaConfig.data_layer.host_port}`,
true,
);
}
Expand Down
3 changes: 2 additions & 1 deletion src/utils/defaultConfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
"CHIA_NETWORK": "mainnet",
"IS_GOVERNANCE_BODY": false,
"DEFAULT_FEE": 300000000,
"DEFAULT_COIN_AMOUNT": 300000000
"DEFAULT_COIN_AMOUNT": 300000000,
"DATALAYER_FILE_SERVER_URL": null
},
"GOVERNANCE": {
"GOVERNANCE_BODY_ID": "23f6498e015ebcd7190c97df30c032de8deb5c8934fc1caa928bc310e2b8a57e"
Expand Down

0 comments on commit aceb436

Please sign in to comment.