Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix initial migration that should not include old database_versions table #2394

Merged
merged 1 commit into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading