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

BugFix: Fix migration to drop missed instance of wldtaxonomic_units_id column #1314

Merged
merged 2 commits into from
Jun 25, 2024
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
1 change: 1 addition & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ on:
pull_request:
types: [opened, reopened, synchronize, ready_for_review]
branches-ignore:
- test
- prod

concurrency:
Expand Down
23 changes: 0 additions & 23 deletions database/src/migrations/20240624000000_attachment_type_fix.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
import { Knex } from 'knex';

/**
* Drop deprecated study_species.wldtaxonomic_units_id column.
* Drop deprecated survey.field_method_id column.
*
* Migrate outdated project_attachment.file_type and survey_attachment.file_type values:
* - Deprecated values 'Spatial Data' and 'Data File' are now 'Other'.
*
Expand All @@ -13,34 +10,14 @@ import { Knex } from 'knex';
*/
export async function up(knex: Knex): Promise<void> {
await knex.raw(`--sql
----------------------------------------------------------------------------------------
-- Drop views
----------------------------------------------------------------------------------------
SET SEARCH_PATH=biohub_dapi_v1;

DROP VIEW IF EXISTS study_species;
DROP VIEW IF EXISTS survey;

----------------------------------------------------------------------------------------
-- Alter tables/data
----------------------------------------------------------------------------------------
SET SEARCH_PATH=biohub;

-- Drop deprecated columns
ALTER TABLE study_species DROP COLUMN wldtaxonomic_units_id;
ALTER TABLE survey DROP COLUMN field_method_id;

-- Migrate deprecated file_type values
UPDATE project_attachment SET file_type = 'Other' WHERE file_type NOT IN ('Other', 'KeyX', 'Report');
UPDATE survey_attachment SET file_type = 'Other' WHERE file_type NOT IN ('Other', 'KeyX', 'Report');

----------------------------------------------------------------------------------------
-- Update views
----------------------------------------------------------------------------------------
SET SEARCH_PATH=biohub_dapi_v1;

CREATE OR REPLACE VIEW study_species as SELECT * FROM biohub.study_species;
CREATE OR REPLACE VIEW survey as SELECT * FROM biohub.survey;
`);
}

Expand Down
50 changes: 50 additions & 0 deletions database/src/migrations/20240625000000_deprecated_columns.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { Knex } from 'knex';

/**
* Drop deprecated study_species.wldtaxonomic_units_id column.
* Drop deprecated survey_observation.wldtaxonomic_units_id column.
* Drop deprecated survey.field_method_id column.
*
* @export
* @param {Knex} knex
* @return {*} {Promise<void>}
*/
export async function up(knex: Knex): Promise<void> {
await knex.raw(`--sql
----------------------------------------------------------------------------------------
-- Drop views
----------------------------------------------------------------------------------------
SET SEARCH_PATH=biohub_dapi_v1;

DROP VIEW IF EXISTS study_species;
DROP VIEW IF EXISTS survey_observation;

DROP VIEW IF EXISTS survey;

----------------------------------------------------------------------------------------
-- Alter tables/data
----------------------------------------------------------------------------------------
SET SEARCH_PATH=biohub;

-- Drop deprecated wldtaxonomic_units_id column
ALTER TABLE study_species DROP COLUMN IF EXISTS wldtaxonomic_units_id;
ALTER TABLE survey_observation DROP COLUMN IF EXISTS wldtaxonomic_units_id;

-- Drop deprecated field_method_id column
ALTER TABLE survey DROP COLUMN IF EXISTS field_method_id;

----------------------------------------------------------------------------------------
-- Update views
----------------------------------------------------------------------------------------
SET SEARCH_PATH=biohub_dapi_v1;

CREATE OR REPLACE VIEW study_species as SELECT * FROM biohub.study_species;
CREATE OR REPLACE VIEW survey_observation as SELECT * FROM biohub.survey_observation;

CREATE OR REPLACE VIEW survey as SELECT * FROM biohub.survey;
`);
}

export async function down(knex: Knex): Promise<void> {
await knex.raw(``);
}