Skip to content

Commit 7551ea0

Browse files
jyn514Joshua Nelson
authored and
Joshua Nelson
committed
Remove unused date_added columns from the database
This fixes the following panic that only appeared in production: ``` Error: Failed to run database migrations Caused by: Error running migration migrate timestamp to be timezone aware, error: db error: ERROR: column "date_added" does not exist ``` This is probably because the original schema in the migrations file didn't match the schema in the production database (the schema for migrations was written later). Fortunately, the `date_added` column is completely unused, so it can simply be deleted locally. This should not impact the production database, except for allowing the TIMESTAMP migration to go through.
1 parent 279752c commit 7551ea0

File tree

1 file changed

+21
-18
lines changed

1 file changed

+21
-18
lines changed

src/db/migrate.rs

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ pub fn migrate(version: Option<Version>, conn: &mut Client) -> CratesfyiResult<(
472472
// downgrade query
473473
"
474474
ALTER TABLE releases DROP COLUMN features;
475-
DROP TYPE feature;
475+
DROP TYPE feature;
476476
"
477477
),
478478
migration!(
@@ -559,43 +559,46 @@ pub fn migrate(version: Option<Version>, conn: &mut Client) -> CratesfyiResult<(
559559
migration!(
560560
context,
561561
24,
562+
"drop unused `date_added` columns",
563+
// upgrade
564+
"ALTER TABLE queue DROP COLUMN IF EXISTS date_added;
565+
ALTER TABLE files DROP COLUMN IF EXISTS date_added;",
566+
// downgrade
567+
"ALTER TABLE queue ADD COLUMN date_added TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP;
568+
ALTER TABLE files ADD COLUMN date_added TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP;",
569+
),
570+
migration!(
571+
context,
572+
25,
562573
"migrate timestamp to be timezone aware",
563574
// upgrade
564575
"
565-
ALTER TABLE builds
576+
ALTER TABLE builds
566577
ALTER build_time TYPE timestamptz USING build_time AT TIME ZONE 'UTC';
567578
568579
ALTER TABLE files
569-
ALTER date_added TYPE timestamptz USING date_added AT TIME ZONE 'UTC',
570580
ALTER date_updated TYPE timestamptz USING date_updated AT TIME ZONE 'UTC';
571581
572-
ALTER TABLE github_repos
573-
ALTER updated_at TYPE timestamptz USING updated_at AT TIME ZONE 'UTC',
582+
ALTER TABLE github_repos
583+
ALTER updated_at TYPE timestamptz USING updated_at AT TIME ZONE 'UTC',
574584
ALTER last_commit TYPE timestamptz USING last_commit AT TIME ZONE 'UTC';
575585
576-
ALTER TABLE queue
577-
ALTER date_added TYPE timestamptz USING date_added AT TIME ZONE 'UTC';
578-
579-
ALTER TABLE releases
586+
ALTER TABLE releases
580587
ALTER release_time TYPE timestamptz USING release_time AT TIME ZONE 'UTC';
581588
",
582-
// downgrade
589+
// downgrade
583590
"
584-
ALTER TABLE builds
591+
ALTER TABLE builds
585592
ALTER build_time TYPE timestamp USING build_time AT TIME ZONE 'UTC';
586593
587594
ALTER TABLE files
588-
ALTER date_added TYPE timestamp USING date_added AT TIME ZONE 'UTC',
589595
ALTER date_updated TYPE timestamp USING date_updated AT TIME ZONE 'UTC';
590596
591-
ALTER TABLE github_repos
592-
ALTER updated_at TYPE timestamp USING updated_at AT TIME ZONE 'UTC',
597+
ALTER TABLE github_repos
598+
ALTER updated_at TYPE timestamp USING updated_at AT TIME ZONE 'UTC',
593599
ALTER last_commit TYPE timestamp USING last_commit AT TIME ZONE 'UTC';
594600
595-
ALTER TABLE queue
596-
ALTER date_added TYPE timestamp USING date_added AT TIME ZONE 'UTC';
597-
598-
ALTER TABLE releases
601+
ALTER TABLE releases
599602
ALTER release_time TYPE timestamp USING release_time AT TIME ZONE 'UTC';
600603
",
601604
),

0 commit comments

Comments
 (0)