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

[DRAFT] Bump auction id on staging #2913

Closed
wants to merge 2 commits into from
Closed
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
8 changes: 7 additions & 1 deletion crates/autopilot/src/database/auction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,13 @@ impl Postgres {
let data = serde_json::to_value(auction)?;
let mut ex = self.pool.begin().await?;
database::auction::delete_all_auctions(&mut ex).await?;
let id = database::auction::save(&mut ex, &data).await?;
let mut id = database::auction::save(&mut ex, &data).await?;
if id < i64::MAX / 2 {
// update the auction id in the `auctions` table
database::auction::update_current_auction_id(&mut ex, i64::MAX / 2).await?;
// return the updated value
id = i64::MAX / 2;
}
ex.commit().await?;
Ok(id)
}
Expand Down
17 changes: 17 additions & 0 deletions crates/database/src/auction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ RETURNING id
Ok(id)
}

pub async fn update_current_auction_id(
ex: &mut PgConnection,
id: AuctionId,
) -> Result<(), sqlx::Error> {
let query = format!("ALTER SEQUENCE auctions_id_seq RESTART WITH {};", id);
sqlx::query(&query).execute(ex).await.map(|_| ())
}

pub async fn load_most_recent(
ex: &mut PgConnection,
) -> Result<Option<(AuctionId, JsonValue)>, sqlx::Error> {
Expand Down Expand Up @@ -64,5 +72,14 @@ mod tests {
let (id, value_) = load_most_recent(&mut db).await.unwrap().unwrap();
assert_eq!(value, value_);
assert_eq!(id_, id);

// update works
update_current_auction_id(&mut db, 100).await.unwrap();

let id_ = save(&mut db, &value).await.unwrap();
assert_eq!(100, id_);

let id_ = save(&mut db, &value).await.unwrap();
assert_eq!(101, id_);
}
}
Loading