diff --git a/api/apps/api/src/migrations/api/1610395720000-AddSupportForAuthentication.ts b/api/apps/api/src/migrations/api/1610395720000-AddSupportForAuthentication.ts index 76c8b67be1..5a6542e0fc 100644 --- a/api/apps/api/src/migrations/api/1610395720000-AddSupportForAuthentication.ts +++ b/api/apps/api/src/migrations/api/1610395720000-AddSupportForAuthentication.ts @@ -6,7 +6,7 @@ export class AddSupportForAuthentication1610395720000 implements MigrationInterface { async up(queryRunner: QueryRunner): Promise { // Only CREATEDB privilege required in 13+ rather than SUPERUSER (ht @agnessa) - if (await PostgreSQLUtils.version13Plus()) { + if (await PostgreSQLUtils.version13Plus(queryRunner)) { await queryRunner.query(` CREATE EXTENSION IF NOT EXISTS pgcrypto; `); @@ -42,7 +42,7 @@ DROP TABLE issued_authn_tokens; ALTER TABLE users DROP COLUMN password_hash; `); - if (await PostgreSQLUtils.version13Plus()) { + if (await PostgreSQLUtils.version13Plus(queryRunner)) { await queryRunner.query(` DROP EXTENSION IF EXISTS pgcrypto; `); diff --git a/api/apps/api/src/utils/postgresql.utils.ts b/api/apps/api/src/utils/postgresql.utils.ts index 385fa1f70c..151d0a1ae2 100644 --- a/api/apps/api/src/utils/postgresql.utils.ts +++ b/api/apps/api/src/utils/postgresql.utils.ts @@ -1,4 +1,4 @@ -import { apiMigrationDataSource } from '@marxan-api/ormconfig.migration'; +import { QueryRunner } from 'typeorm'; /** * Utility functions related to lower-level interaction with PostgreSQL servers. @@ -9,9 +9,8 @@ export class PostgreSQLUtils { /** * Check if the PostgreSQL server we are connected to is version 13 or higher. */ - static async version13Plus(): Promise { - // Here we do not need to initialize DataSource again, because it is happening internally when starting the migration process - const postgresqlMajorVersion = await apiMigrationDataSource + static async version13Plus(queryRunner: QueryRunner): Promise { + const postgresqlMajorVersion = await queryRunner .query('show server_version') .then((result: [{ server_version: string }]) => { return result[0].server_version.split('.')[0]; diff --git a/api/apps/geoprocessing/src/migrations/geoprocessing/1611221157285-InitialGeoDBSetup.ts b/api/apps/geoprocessing/src/migrations/geoprocessing/1611221157285-InitialGeoDBSetup.ts index 02a37bd7cc..98bc443eef 100644 --- a/api/apps/geoprocessing/src/migrations/geoprocessing/1611221157285-InitialGeoDBSetup.ts +++ b/api/apps/geoprocessing/src/migrations/geoprocessing/1611221157285-InitialGeoDBSetup.ts @@ -4,7 +4,7 @@ import { MigrationInterface, QueryRunner } from 'typeorm'; export class InitialGeoDBSetup1611221157285 implements MigrationInterface { public async up(queryRunner: QueryRunner): Promise { // Only CREATEDB privilege required in 13+ rather than SUPERUSER (ht @agnessa) - if (await PostgreSQLUtils.version13Plus()) { + if (await PostgreSQLUtils.version13Plus(queryRunner)) { await queryRunner.query(` CREATE EXTENSION IF NOT EXISTS plpgsql; CREATE EXTENSION IF NOT EXISTS postgis; @@ -194,7 +194,7 @@ export class InitialGeoDBSetup1611221157285 implements MigrationInterface { `); // Only CREATEDB privilege required in 13+ rather than SUPERUSER (ht @agnessa) - if (await PostgreSQLUtils.version13Plus()) { + if (await PostgreSQLUtils.version13Plus(queryRunner)) { await queryRunner.query(` DROP EXTENSION postgis_topology; -- OPTIONAL DROP EXTENSION postgis_raster; -- OPTIONAL diff --git a/api/apps/geoprocessing/src/migrations/geoprocessing/1611828857842-AddFeatureScenarioOutputEntity.ts b/api/apps/geoprocessing/src/migrations/geoprocessing/1611828857842-AddFeatureScenarioOutputEntity.ts index 71636012b9..8e1cbb57b2 100644 --- a/api/apps/geoprocessing/src/migrations/geoprocessing/1611828857842-AddFeatureScenarioOutputEntity.ts +++ b/api/apps/geoprocessing/src/migrations/geoprocessing/1611828857842-AddFeatureScenarioOutputEntity.ts @@ -6,7 +6,7 @@ export class AddFeatureScenarioOutputEntity1611828857842 implements MigrationInterface { public async up(queryRunner: QueryRunner): Promise { // Only CREATEDB privilege required in 13+ rather than SUPERUSER (ht @agnessa) - if (await PostgreSQLUtils.version13Plus()) { + if (await PostgreSQLUtils.version13Plus(queryRunner)) { await queryRunner.query(` ALTER TABLE scenario_features_data ADD COLUMN target_met float8, @@ -21,7 +21,7 @@ export class AddFeatureScenarioOutputEntity1611828857842 } public async down(queryRunner: QueryRunner): Promise { - if (await PostgreSQLUtils.version13Plus()) { + if (await PostgreSQLUtils.version13Plus(queryRunner)) { await queryRunner.query(` ALTER TABLE scenario_features_data DROP COLUMN target_met, diff --git a/api/apps/geoprocessing/src/migrations/geoprocessing/1641582332000-FixUniquenessOfPuGeoms.ts b/api/apps/geoprocessing/src/migrations/geoprocessing/1641582332000-FixUniquenessOfPuGeoms.ts index 1ae7ecac05..277c48b1b3 100644 --- a/api/apps/geoprocessing/src/migrations/geoprocessing/1641582332000-FixUniquenessOfPuGeoms.ts +++ b/api/apps/geoprocessing/src/migrations/geoprocessing/1641582332000-FixUniquenessOfPuGeoms.ts @@ -4,7 +4,7 @@ import { PostgreSQLUtils } from '@marxan-geoprocessing/utils/postgresql.utils'; export class FixUniquenessOfPuGeoms1641582332000 implements MigrationInterface { async up(queryRunner: QueryRunner): Promise { - if (await PostgreSQLUtils.version13Plus()) { + if (await PostgreSQLUtils.version13Plus(queryRunner)) { await queryRunner.query(` CREATE EXTENSION IF NOT EXISTS pgcrypto; `); @@ -54,7 +54,7 @@ export class FixUniquenessOfPuGeoms1641582332000 implements MigrationInterface { on planning_units_geom(the_geom, type, coalesce(project_id, '00000000-0000-0000-0000-000000000000')); `); - if (await PostgreSQLUtils.version13Plus()) { + if (await PostgreSQLUtils.version13Plus(queryRunner)) { await queryRunner.query(` DROP EXTENSION IF EXISTS pgcrypto; `); diff --git a/api/apps/geoprocessing/src/utils/postgresql.utils.ts b/api/apps/geoprocessing/src/utils/postgresql.utils.ts index 9d118d7e24..151d0a1ae2 100644 --- a/api/apps/geoprocessing/src/utils/postgresql.utils.ts +++ b/api/apps/geoprocessing/src/utils/postgresql.utils.ts @@ -1,4 +1,4 @@ -import { geoMigrationDataSource } from '@marxan-geoprocessing/ormconfig.migration'; +import { QueryRunner } from 'typeorm'; /** * Utility functions related to lower-level interaction with PostgreSQL servers. @@ -9,9 +9,8 @@ export class PostgreSQLUtils { /** * Check if the PostgreSQL server we are connected to is version 13 or higher. */ - static async version13Plus(): Promise { - // Here we do not need to initialize DataSource again, because it is happening internally when starting the migration process - const postgresqlMajorVersion = await geoMigrationDataSource + static async version13Plus(queryRunner: QueryRunner): Promise { + const postgresqlMajorVersion = await queryRunner .query('show server_version') .then((result: [{ server_version: string }]) => { return result[0].server_version.split('.')[0];