Skip to content

Commit

Permalink
Inline various migration queries (#10231)
Browse files Browse the repository at this point in the history
There was no value in saving them off to temporary variables.

Signed-off-by: Tristan Partin <[email protected]>

Signed-off-by: Tristan Partin <[email protected]>
  • Loading branch information
tristan957 authored Jan 2, 2025
1 parent cd10c71 commit eefad27
Showing 1 changed file with 14 additions and 17 deletions.
31 changes: 14 additions & 17 deletions compute_tools/src/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,6 @@ impl<'m> MigrationRunner<'m> {
/// used if you would like to fail the application of a series of migrations
/// at some point.
fn update_migration_id(&mut self, migration_id: i64) -> Result<()> {
let setval = format!("UPDATE neon_migration.migration_id SET id={}", migration_id);

// We use this fail point in order to check that failing in the
// middle of applying a series of migrations fails in an expected
// manner
Expand All @@ -58,28 +56,27 @@ impl<'m> MigrationRunner<'m> {
}

self.client
.simple_query(&setval)
.query(
"UPDATE neon_migration.migration_id SET id = $1",
&[&migration_id],
)
.context("run_migrations update id")?;

Ok(())
}

/// Prepare the migrations the target database for handling migrations
fn prepare_database(&mut self) -> Result<()> {
let query = "CREATE SCHEMA IF NOT EXISTS neon_migration";
self.client.simple_query(query)?;

let query = "CREATE TABLE IF NOT EXISTS neon_migration.migration_id (key INT NOT NULL PRIMARY KEY, id bigint NOT NULL DEFAULT 0)";
self.client.simple_query(query)?;

let query = "INSERT INTO neon_migration.migration_id VALUES (0, 0) ON CONFLICT DO NOTHING";
self.client.simple_query(query)?;

let query = "ALTER SCHEMA neon_migration OWNER TO cloud_admin";
self.client.simple_query(query)?;

let query = "REVOKE ALL ON SCHEMA neon_migration FROM PUBLIC";
self.client.simple_query(query)?;
self.client
.simple_query("CREATE SCHEMA IF NOT EXISTS neon_migration")?;
self.client.simple_query("CREATE TABLE IF NOT EXISTS neon_migration.migration_id (key INT NOT NULL PRIMARY KEY, id bigint NOT NULL DEFAULT 0)")?;
self.client.simple_query(
"INSERT INTO neon_migration.migration_id VALUES (0, 0) ON CONFLICT DO NOTHING",
)?;
self.client
.simple_query("ALTER SCHEMA neon_migration OWNER TO cloud_admin")?;
self.client
.simple_query("REVOKE ALL ON SCHEMA neon_migration FROM PUBLIC")?;

Ok(())
}
Expand Down

1 comment on commit eefad27

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

7366 tests run: 7003 passed, 1 failed, 362 skipped (full report)


Failures on Postgres 16

  • test_storage_controller_many_tenants[github-actions-selfhosted]: release-x86-64
# Run all failed tests locally:
scripts/pytest -vv -n $(nproc) -k "test_storage_controller_many_tenants[release-pg16-github-actions-selfhosted]"
Flaky tests (1)

Postgres 15

  • test_physical_replication_config_mismatch_max_locks_per_transaction: release-arm64

Code coverage* (full report)

  • functions: 31.2% (8406 of 26937 functions)
  • lines: 47.9% (66704 of 139128 lines)

* collected from Rust tests only


The comment gets automatically updated with the latest test results
eefad27 at 2025-01-03T00:24:13.933Z :recycle:

Please sign in to comment.