Skip to content

Commit

Permalink
fix initial migration that should not include old database_versions
Browse files Browse the repository at this point in the history
… table
  • Loading branch information
syphar committed Jan 24, 2024
1 parent 7667f34 commit a6ec84f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 16 deletions.
1 change: 0 additions & 1 deletion migrations/20231021111635_initial.down.sql
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ DROP TABLE compression_rels CASCADE;
DROP TABLE config CASCADE;
DROP TABLE crate_priorities CASCADE;
DROP TABLE crates CASCADE;
DROP TABLE database_versions CASCADE;
DROP TABLE doc_coverage CASCADE;
DROP TABLE files CASCADE;
DROP TABLE keyword_rels CASCADE;
Expand Down
10 changes: 0 additions & 10 deletions migrations/20231021111635_initial.up.sql
Original file line number Diff line number Diff line change
Expand Up @@ -130,11 +130,6 @@ ALTER SEQUENCE crates_id_seq OWNED BY crates.id;



CREATE TABLE database_versions (
version bigint NOT NULL
);



CREATE TABLE doc_coverage (
release_id integer NOT NULL,
Expand Down Expand Up @@ -388,11 +383,6 @@ ALTER TABLE ONLY crates



ALTER TABLE ONLY database_versions
ADD CONSTRAINT database_versions_pkey PRIMARY KEY (version);



ALTER TABLE ONLY doc_coverage
ADD CONSTRAINT doc_coverage_release_id_key UNIQUE (release_id);

Expand Down
14 changes: 9 additions & 5 deletions src/db/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,16 @@ pub async fn migrate(conn: &mut sqlx::PgConnection, target: Option<i64>) -> Resu
.await?
.is_some()
{
let max_version: i64 = sqlx::query_scalar("SELECT max(version) FROM database_versions")
.fetch_one(&mut *conn)
.await?;
let max_version: Option<i64> =
sqlx::query_scalar("SELECT max(version) FROM database_versions")
.fetch_one(&mut *conn)
.await?;

if max_version != 39 {
anyhow::bail!("database_versions table has unexpected version");
if max_version != Some(39) {
anyhow::bail!(
"database_versions table has unexpected version: {:?}",
max_version
);
}

sqlx::query(
Expand Down

0 comments on commit a6ec84f

Please sign in to comment.