diff --git a/packages/account-postgres-sink-service/index_config_example.json b/packages/account-postgres-sink-service/index_config_example.json deleted file mode 100644 index 3c56832d7..000000000 --- a/packages/account-postgres-sink-service/index_config_example.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "configs": [ - "CREATE UNIQUE INDEX IF NOT EXISTS key_to_asset_asset_index ON key_to_assets(asset);", - "CREATE UNIQUE INDEX IF NOT EXISTS iot_hotspot_infos_asset_index ON iot_hotspot_infos(asset);", - "CREATE UNIQUE INDEX IF NOT EXISTS mobile_hotspot_infos_asset_index ON mobile_hotspot_infos(asset);" - ] -} \ No newline at end of file diff --git a/packages/account-postgres-sink-service/program_account_configs_example.json b/packages/account-postgres-sink-service/program_account_configs_example.json index f84671ad4..0d540d950 100644 --- a/packages/account-postgres-sink-service/program_account_configs_example.json +++ b/packages/account-postgres-sink-service/program_account_configs_example.json @@ -117,5 +117,10 @@ { "type": "RecipientV0", "table": "recipients", "schema": "public" } ] } + ], + "indexConfigs": [ + "CREATE UNIQUE INDEX IF NOT EXISTS key_to_asset_asset_index ON key_to_assets(asset);", + "CREATE UNIQUE INDEX IF NOT EXISTS iot_hotspot_infos_asset_index ON iot_hotspot_infos(asset);", + "CREATE UNIQUE INDEX IF NOT EXISTS mobile_hotspot_infos_asset_index ON mobile_hotspot_infos(asset);" ] } diff --git a/packages/account-postgres-sink-service/src/env.ts b/packages/account-postgres-sink-service/src/env.ts index 760dbc849..ec0c96df4 100644 --- a/packages/account-postgres-sink-service/src/env.ts +++ b/packages/account-postgres-sink-service/src/env.ts @@ -9,8 +9,6 @@ export const PROGRAM_ACCOUNT_CONFIGS = process.env.PROGRAM_ACCOUNT_CONFIGS || `${__dirname}/../program_account_configs_example.json`; -export const INDEX_CONFIGS = process.env.INDEX_CONFIGS; - export const HELIUS_AUTH_SECRET = process.env.HELIUS_AUTH_SECRET; export const RUN_JOBS_AT_STARTUP = process.env.RUN_JOBS_AT_STARTUP === 'true'; diff --git a/packages/account-postgres-sink-service/src/server.ts b/packages/account-postgres-sink-service/src/server.ts index 8815da6ee..6a8956d58 100644 --- a/packages/account-postgres-sink-service/src/server.ts +++ b/packages/account-postgres-sink-service/src/server.ts @@ -7,7 +7,6 @@ import { PublicKey } from "@solana/web3.js"; import { HELIUS_AUTH_SECRET, PROGRAM_ACCOUNT_CONFIGS, - INDEX_CONFIGS, RUN_JOBS_AT_STARTUP, } from "./env"; import database from "./utils/database"; @@ -26,22 +25,16 @@ if (!HELIUS_AUTH_SECRET) { } (async () => { - const configs = (() => { - const accountConfigs: null | { + const { configs, indexConfigs } = (() => { + const dbConfigs: null | { configs: IConfig[]; + indexConfigs?: string[] } = JSON.parse(fs.readFileSync(PROGRAM_ACCOUNT_CONFIGS, "utf8")); - return accountConfigs ? accountConfigs.configs : []; - })(); - - const indexConfigs = (() => { - let configs: null | { configs: string[] } = null; - - if (INDEX_CONFIGS) { - configs = JSON.parse(fs.readFileSync(INDEX_CONFIGS, "utf8")); + return { + configs: dbConfigs && dbConfigs.configs ? dbConfigs.configs : [], + indexConfigs: dbConfigs && dbConfigs.indexConfigs ? dbConfigs.indexConfigs : [], } - - return configs ? configs.configs : []; })(); const customJobs = configs diff --git a/packages/account-postgres-sink-service/src/utils/createPgIndexes.ts b/packages/account-postgres-sink-service/src/utils/createPgIndexes.ts index 368a5c5d7..28efaeea5 100644 --- a/packages/account-postgres-sink-service/src/utils/createPgIndexes.ts +++ b/packages/account-postgres-sink-service/src/utils/createPgIndexes.ts @@ -8,6 +8,11 @@ export const createPgIndexes = async ({ sequelize: Sequelize; }) => { try { + if (indexConfigs.length === 0) { + console.log("createPgIndexes: No indexes created!"); + return; + } + const indexPromises = indexConfigs.map((config) => { return sequelize.query(config); });