diff options
Diffstat (limited to 'db/migrations')
| -rw-r--r-- | db/migrations/20260924000000_official_climb_sample.sql | 7 | ||||
| -rw-r--r-- | db/migrations/20260925000000_official_climb_sample_not_null.sql | 38 |
2 files changed, 45 insertions, 0 deletions
diff --git a/db/migrations/20260924000000_official_climb_sample.sql b/db/migrations/20260924000000_official_climb_sample.sql new file mode 100644 index 0000000..6a3990f --- /dev/null +++ b/db/migrations/20260924000000_official_climb_sample.sql @@ -0,0 +1,7 @@ +-- migrate:up +ALTER TABLE official_climbs ADD COLUMN sample_distance_m real; +ALTER TABLE official_climbs ADD COLUMN sample_elevation_gain_m real; + +-- migrate:down +ALTER TABLE official_climbs DROP COLUMN sample_distance_m; +ALTER TABLE official_climbs DROP COLUMN sample_elevation_gain_m; diff --git a/db/migrations/20260925000000_official_climb_sample_not_null.sql b/db/migrations/20260925000000_official_climb_sample_not_null.sql new file mode 100644 index 0000000..a3f80c2 --- /dev/null +++ b/db/migrations/20260925000000_official_climb_sample_not_null.sql @@ -0,0 +1,38 @@ +-- Every climb carries its segment sample, so the columns stop being optional; SQLite cannot alter nullability, hence the rebuild (it fails loudly on a missing sample). +-- migrate:up transaction:false +PRAGMA foreign_keys=OFF; +CREATE TABLE official_climbs_rebuild ( + id integer primary key, + name text not null, + start_latitude real not null, + start_longitude real not null, + end_latitude real not null, + end_longitude real not null, + created_at text not null default (strftime('%Y-%m-%dT%H:%M:%SZ', 'now')), + updated_at text not null default (strftime('%Y-%m-%dT%H:%M:%SZ', 'now')), + sample_distance_m real not null, + sample_elevation_gain_m real not null +); +INSERT INTO official_climbs_rebuild (id, name, start_latitude, start_longitude, end_latitude, end_longitude, created_at, updated_at, sample_distance_m, sample_elevation_gain_m) +SELECT id, name, start_latitude, start_longitude, end_latitude, end_longitude, created_at, updated_at, sample_distance_m, sample_elevation_gain_m FROM official_climbs; +DROP TABLE official_climbs; +ALTER TABLE official_climbs_rebuild RENAME TO official_climbs; + +-- migrate:down transaction:false +PRAGMA foreign_keys=OFF; +CREATE TABLE official_climbs_rebuild ( + id integer primary key, + name text not null, + start_latitude real not null, + start_longitude real not null, + end_latitude real not null, + end_longitude real not null, + created_at text not null default (strftime('%Y-%m-%dT%H:%M:%SZ', 'now')), + updated_at text not null default (strftime('%Y-%m-%dT%H:%M:%SZ', 'now')), + sample_distance_m real, + sample_elevation_gain_m real +); +INSERT INTO official_climbs_rebuild (id, name, start_latitude, start_longitude, end_latitude, end_longitude, created_at, updated_at, sample_distance_m, sample_elevation_gain_m) +SELECT id, name, start_latitude, start_longitude, end_latitude, end_longitude, created_at, updated_at, sample_distance_m, sample_elevation_gain_m FROM official_climbs; +DROP TABLE official_climbs; +ALTER TABLE official_climbs_rebuild RENAME TO official_climbs; |
