Skip to content

Commit

Permalink
use current queryRunner rather than a free-floating data source
Browse files Browse the repository at this point in the history
  • Loading branch information
hotzevzl committed Aug 2, 2023
1 parent 0e93c69 commit 970f9e5
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export class AddSupportForAuthentication1610395720000
implements MigrationInterface {
async up(queryRunner: QueryRunner): Promise<any> {
// 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;
`);
Expand Down Expand Up @@ -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;
`);
Expand Down
7 changes: 3 additions & 4 deletions api/apps/api/src/utils/postgresql.utils.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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<boolean> {
// 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<boolean> {
const postgresqlMajorVersion = await queryRunner
.query('show server_version')
.then((result: [{ server_version: string }]) => {
return result[0].server_version.split('.')[0];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { MigrationInterface, QueryRunner } from 'typeorm';
export class InitialGeoDBSetup1611221157285 implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
// 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;
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export class AddFeatureScenarioOutputEntity1611828857842
implements MigrationInterface {
public async up(queryRunner: QueryRunner): Promise<void> {
// 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,
Expand All @@ -21,7 +21,7 @@ export class AddFeatureScenarioOutputEntity1611828857842
}

public async down(queryRunner: QueryRunner): Promise<void> {
if (await PostgreSQLUtils.version13Plus()) {
if (await PostgreSQLUtils.version13Plus(queryRunner)) {
await queryRunner.query(`
ALTER TABLE scenario_features_data
DROP COLUMN target_met,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { PostgreSQLUtils } from '@marxan-geoprocessing/utils/postgresql.utils';

export class FixUniquenessOfPuGeoms1641582332000 implements MigrationInterface {
async up(queryRunner: QueryRunner): Promise<void> {
if (await PostgreSQLUtils.version13Plus()) {
if (await PostgreSQLUtils.version13Plus(queryRunner)) {
await queryRunner.query(`
CREATE EXTENSION IF NOT EXISTS pgcrypto;
`);
Expand Down Expand Up @@ -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;
`);
Expand Down
7 changes: 3 additions & 4 deletions api/apps/geoprocessing/src/utils/postgresql.utils.ts
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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<boolean> {
// 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<boolean> {
const postgresqlMajorVersion = await queryRunner
.query('show server_version')
.then((result: [{ server_version: string }]) => {
return result[0].server_version.split('.')[0];
Expand Down

0 comments on commit 970f9e5

Please sign in to comment.