Skip to content

Commit 1bd5ce2

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 27f8f00 commit 1bd5ce2

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
@@ -834,8 +834,15 @@ fn migrations() -> Vec<Migration> {
834834
Migration::new(20170305123234, |tx| {
835835
tx.execute("ALTER TABLE crates DROP COLUMN max_version", &[])?;
836836
Ok(())
837-
}, |_| {
838-
panic!("Unreversible migration")
837+
}, |tx| {
838+
tx.execute("ALTER TABLE crates ADD COLUMN max_version VARCHAR NOT NULL DEFAULT '0.0.0'", &[])?;
839+
tx.execute("UPDATE crates SET max_version = COALESCE((
840+
SELECT num FROM VERSIONS
841+
WHERE num SIMILAR TO '[0-9]+\\.[0-9]+\\.[0-9]+'
842+
ORDER BY split_part(num, '.', 1)::int, split_part(num, '.', 2)::int, split_part(num, '.', 3)::int
843+
LIMIT 1
844+
), '0.0.0')", &[])?;
845+
Ok(())
839846
}),
840847
];
841848
// NOTE: Generate a new id via `date +"%Y%m%d%H%M%S"`

0 commit comments

Comments
 (0)