-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
440 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
src/lib/migration/migrations/20250104060831_update_dosage_bounds.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
-- Step 1: Create a new table with NULLABLE lower_bound_amount and upper_bound_amount | ||
CREATE TABLE `substance_route_of_administration_dosage_new` | ||
( | ||
`id` TEXT NOT NULL PRIMARY KEY, | ||
`intensity` TEXT NOT NULL, | ||
`lower_bound_amount` REAL NULL, | ||
`upper_bound_amount` REAL NULL, | ||
`unit` TEXT NOT NULL, | ||
`routeOfAdministrationId` TEXT NULL, | ||
CONSTRAINT `route_of_administration_dosage_routeOfAdministrationId_fkey` | ||
FOREIGN KEY (`routeOfAdministrationId`) REFERENCES `substance_route_of_administration` (`id`) | ||
ON UPDATE CASCADE | ||
ON DELETE SET NULL | ||
); | ||
|
||
-- Step 2: Copy data from the old table to the new table, skipping rows with `0.0` bounds | ||
INSERT INTO `substance_route_of_administration_dosage_new` (`id`, `intensity`, `lower_bound_amount`, | ||
`upper_bound_amount`, `unit`, `routeOfAdministrationId`) | ||
SELECT `id`, | ||
`intensity`, | ||
`lower_bound_amount`, | ||
`upper_bound_amount`, | ||
`unit`, | ||
`routeOfAdministrationId` | ||
FROM `substance_route_of_administration_dosage`; | ||
|
||
-- Step 3: Drop the old table | ||
DROP TABLE `substance_route_of_administration_dosage`; | ||
|
||
-- Step 4: Rename the new table to the original name | ||
ALTER TABLE `substance_route_of_administration_dosage_new` | ||
RENAME TO `substance_route_of_administration_dosage`; | ||
|
||
UPDATE substance_route_of_administration_dosage | ||
SET lower_bound_amount = NULL | ||
WHERE intensity = 'threshold'; | ||
|
||
UPDATE substance_route_of_administration_dosage | ||
SET upper_bound_amount = NULL | ||
WHERE intensity = 'heavy'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
h1:puu37dd6GHWGaEV8fpiar5Uldvijkr3D8lMxIDXewZ4= | ||
h1:4iQajbNu+KzPnAT79k0i5bqMCd5XO4N2ZW6B5ATmpbg= | ||
20250101000001_add_ingestion_table.sql h1:9u7Hg7oMQAqDIHfGFYwZC3xmcHixHOrmiwL3VZbufWQ= | ||
20250101000002_import_substance.sql h1:XJuYaltpeWe1LJOMArORZIhVo9U0ulXk7ObAPlpZNYs= | ||
20250101235153_drop_unrelated_data.sql h1:PhD/D6b9tbrjusjmDG8x+Z2oFqLwELhnYSDBWOgqcJw= | ||
20250104060831_update_dosage_bounds.sql h1:sd10cfw6uuXSgtkCyI28s4GrVerQpjMFbbHS0JAIhkU= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.