diff --git a/indexer-js-queue-handler/__snapshots__/hasura-client.test.js.snap b/indexer-js-queue-handler/__snapshots__/hasura-client.test.js.snap index 803dab568..21beb1116 100644 --- a/indexer-js-queue-handler/__snapshots__/hasura-client.test.js.snap +++ b/indexer-js-queue-handler/__snapshots__/hasura-client.test.js.snap @@ -397,7 +397,7 @@ exports[`HasuraClient untracks the specified tables 1`] = ` [ "mock-hasura-endpoint/v1/metadata", { - "body": "{"type":"pg_untrack_tables","args":{"tables":[{"table":{"schema":"schema","name":"height"},"source":"default","cascade":true},{"table":{"schema":"schema","name":"width"},"source":"default","cascade":true}]}}", + "body": "{"type":"bulk","args":[{"type":"pg_untrack_table","args":{"table":{"schema":"schema","name":"height"},"source":"default","cascade":true}},{"type":"pg_untrack_table","args":{"table":{"schema":"schema","name":"width"},"source":"default","cascade":true}}]}", "headers": { "X-Hasura-Admin-Secret": "mock-hasura-admin-secret", }, diff --git a/indexer-js-queue-handler/hasura-client.js b/indexer-js-queue-handler/hasura-client.js index 9d7bba456..0e5f0cbc1 100644 --- a/indexer-js-queue-handler/hasura-client.js +++ b/indexer-js-queue-handler/hasura-client.js @@ -130,16 +130,19 @@ export default class HasuraClient { } async untrackTables(source, schema, tableNames, cascade = true) { - return this.executeMetadataRequest('pg_untrack_tables', { - tables: tableNames.map((name) => ({ - table: { - schema, - name, - }, - source, - cascade, + return this.executeBulkMetadataRequest( + tableNames.map((name) => ({ + type: 'pg_untrack_table', + args: { + table: { + schema, + name, + }, + source, + cascade, + } })) - }); + ); } async getForeignKeys(schemaName, source) { diff --git a/indexer-js-queue-handler/scripts/migrate-schema-to-db.js b/indexer-js-queue-handler/scripts/migrate-schema-to-db.js index 50e32e9f8..3ad255676 100644 --- a/indexer-js-queue-handler/scripts/migrate-schema-to-db.js +++ b/indexer-js-queue-handler/scripts/migrate-schema-to-db.js @@ -1,14 +1,12 @@ -process.env.HASURA_ENDPOINT = 'http://localhost:8080' -process.env.HASURA_ADMIN_SECRET = 'myadminsecretkey' - -process.env.PG_ADMIN_USER = 'postgres' -process.env.PG_ADMIN_PASSWORD = 'postgrespassword' -process.env.PG_ADMIN_DATABASE = 'postgres' -process.env.PG_HOST = 'localhost' -process.env.PG_PORT = 5432 - -process.env.CHAIN_ID = 'mainnet' -process.env.ENV = 'dev' +// export HASURA_ENDPOINT='https://queryapi-hasura-graphql-vcqilefdcq-ew.a.run.app' +// export HASURA_ADMIN_SECRET='' +// export PG_ADMIN_USER='hasura' +// export PG_ADMIN_PASSWORD='' +// export PG_ADMIN_DATABASE='postgres' +// export PG_HOST='' +// export PG_PORT=5432 +// export CHAIN_ID='mainnet' +// export ENV='dev' import { execSync } from 'child_process' import { providers } from 'near-api-js' @@ -59,8 +57,8 @@ const schemaName = sanitizedFunctionName; const existingSchemaName = `${sanitizedAccountId}_${sanitizedFunctionName}`; +const password = provisioner.generatePassword() if (!await provisioner.hasuraClient.doesSourceExist(databaseName)) { - const password = provisioner.generatePassword() console.log(`Creating user: ${userName} and database: ${databaseName} with password: ${password}`); await provisioner.createUserDb(userName, password, databaseName); console.log('Adding datasource to Hasura') @@ -77,13 +75,19 @@ await provisioner.createSchema(databaseName, existingSchemaName); await provisioner.runMigrations(databaseName, existingSchemaName, databaseSchema); console.log('Dumping existing data'); -execSync(`pg_dump --data-only --schema=${existingSchemaName} --file="${existingSchemaName}.sql"`); +execSync( + `pg_dump ${`postgres://${process.env.PG_ADMIN_USER}:${process.env.PG_ADMIN_PASSWORD}@${process.env.PG_HOST}:${process.env.PG_PORT}/${process.env.PG_ADMIN_DATABASE}`} --data-only --schema=${existingSchemaName} --file="${existingSchemaName}.sql"` +); console.log(`Restoring data to schema ${existingSchemaName} in DB ${databaseName}`); -execSync(`psql --dbname=${databaseName} < "${existingSchemaName}.sql"`); +execSync( + `psql ${`postgres://${userName}:${password}@${process.env.PG_HOST}:${process.env.PG_PORT}/${databaseName}`} < "${existingSchemaName}.sql"` +); console.log(`Renaming schema ${existingSchemaName} to ${schemaName}`); -execSync(`psql --dbname=${databaseName} --command="ALTER SCHEMA \"${existingSchemaName}\" RENAME TO \"${schemaName}\";"`) +execSync( + `psql ${`postgres://${userName}:${password}@${process.env.PG_HOST}:${process.env.PG_PORT}/${databaseName}`} --command="ALTER SCHEMA \"${existingSchemaName}\" RENAME TO \"${schemaName}\";"` +) console.log('Tracking tables'); await provisioner.trackTables(schemaName, tableNames, databaseName);