Skip to content

Commit 2f9a34e

Browse files
committed
Enforce unique gh_id in the database
1 parent 0f90f99 commit 2f9a34e

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

src/bin/migrate.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -751,6 +751,19 @@ fn migrations() -> Vec<Migration> {
751751
DROP NOT NULL", &[]));
752752
Ok(())
753753
}),
754+
Migration::new(20160812094502, |tx| {
755+
// Enusre that gh_id is always unique (sure hope it is), but
756+
// only where the id is > 0. Historically we didn't track id, and we
757+
// had to fill it in at one point after-the-fact. User rows that
758+
// couldn't be resolved either have a github id of 0 or -1 so they
759+
// can't ever be logged into again.
760+
try!(tx.execute("CREATE UNIQUE INDEX users_gh_id \
761+
ON users (gh_id) WHERE gh_id > 0", &[]));
762+
Ok(())
763+
}, |tx| {
764+
try!(tx.execute("DROP INDEX users_gh_id", &[]));
765+
Ok(())
766+
}),
754767
];
755768
// NOTE: Generate a new id via `date +"%Y%m%d%H%M%S"`
756769

0 commit comments

Comments
 (0)