Skip to content

Commit

Permalink
fix: Ensure subsequent provision requests untrack existing tables
Browse files Browse the repository at this point in the history
  • Loading branch information
morgsmccauley committed Jul 26, 2023
1 parent 1ac747a commit 2268243
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
14 changes: 7 additions & 7 deletions indexer-js-queue-handler/provisioner.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,18 +147,18 @@ export default class Provisioner {

try {
if (!await this.hasuraClient.doesSourceExist(databaseName)) {
// Untrack tables from old schema to prevent conflicts with new DB
const oldSchemaName = `${sanitizedAccountId}_${sanitizedFunctionName}`;
if (await this.hasuraClient.doesSchemaExist(HasuraClient.DEFAULT_DATABASE, oldSchemaName)) {
const tableNames = await this.getTableNames(oldSchemaName, HasuraClient.DEFAULT_DATABASE);
await this.hasuraClient.untrackTables(HasuraClient.DEFAULT_DATABASE, oldSchemaName, tableNames);
}

const password = this.generatePassword()
await this.createUserDb(userName, password, databaseName);
await this.addDatasource(userName, password, databaseName);
}

// Untrack tables from old schema to prevent conflicts with new DB
const oldSchemaName = `${sanitizedAccountId}_${sanitizedFunctionName}`;
if (await this.hasuraClient.doesSchemaExist(HasuraClient.DEFAULT_DATABASE, oldSchemaName)) {
const tableNames = await this.getTableNames(oldSchemaName, HasuraClient.DEFAULT_DATABASE);
await this.hasuraClient.untrackTables(HasuraClient.DEFAULT_DATABASE, oldSchemaName, tableNames);
}

await this.createSchema(databaseName, schemaName);
await this.runMigrations(databaseName, schemaName, databaseSchema);

Expand Down
2 changes: 1 addition & 1 deletion indexer-js-queue-handler/provisioner.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ describe('Provisioner', () => {
);
});

it('untracks tables from the previous schema if it exists', async () => {
it('untracks tables from the previous schema if they exists', async () => {
hasuraClient.doesSchemaExist = jest.fn().mockReturnValueOnce(true);

const provisioner = new Provisioner(hasuraClient, pgClient, crypto);
Expand Down

0 comments on commit 2268243

Please sign in to comment.