Skip to content

Commit 31b44cc

Browse files
committed
Make the max_version migration reversible
This version of the down function won't necessariliy 100% replicate the data that was dropped, but it'll get pretty darn close and probably close enough for our purposes if we end up actually having to roll this back.
1 parent eedadbe commit 31b44cc

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

src/bin/migrate.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -871,8 +871,15 @@ fn migrations() -> Vec<Migration> {
871871
Migration::new(20170305123234, |tx| {
872872
tx.execute("ALTER TABLE crates DROP COLUMN max_version", &[])?;
873873
Ok(())
874-
}, |_| {
875-
panic!("Unreversible migration")
874+
}, |tx| {
875+
tx.execute("ALTER TABLE crates ADD COLUMN max_version VARCHAR NOT NULL DEFAULT '0.0.0'", &[])?;
876+
tx.execute("UPDATE crates SET max_version = COALESCE((
877+
SELECT num FROM VERSIONS
878+
WHERE num SIMILAR TO '[0-9]+\\.[0-9]+\\.[0-9]+'
879+
ORDER BY split_part(num, '.', 1)::int, split_part(num, '.', 2)::int, split_part(num, '.', 3)::int
880+
LIMIT 1
881+
), '0.0.0')", &[])?;
882+
Ok(())
876883
}),
877884
];
878885
// NOTE: Generate a new id via `date +"%Y%m%d%H%M%S"`

0 commit comments

Comments
 (0)