Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use current queryRunner rather than a free-floating data source when checking if a migration can rely on PostgreSQL v13 or later [MRXN23-273] #1412

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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