Skip to content

Commit 681b80e

Browse files
committed
fixup: Add comments to MIGRATIONS list
1 parent 9c74f8f commit 681b80e

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

rust/impls/src/postgres_store.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,18 @@ const LOG_MIGRATION_STMT: &str = "INSERT INTO vss_db_upgrades VALUES($1);";
4141
#[cfg(test)]
4242
const GET_MIGRATION_LOG_STMT: &str = "SELECT upgrade_from FROM vss_db_upgrades;";
4343

44+
// APPEND-ONLY list of migration statements
45+
//
46+
// Each statement MUST be applied in-order, and only once per database.
47+
//
48+
// We make an exception for the vss_db table creation statement, as users of VSS could have initialized the table
49+
// themselves.
4450
const MIGRATIONS: &[&str] = &[
4551
"CREATE TABLE vss_db_version (db_version INTEGER);",
4652
"INSERT INTO vss_db_version VALUES(1);",
53+
// A write-only log of all the migrations performed on this database, useful for debugging and testing
4754
"CREATE TABLE vss_db_upgrades (upgrade_from INTEGER);",
48-
// We do not complain if the table already exists, as a previous version of VSS could have already created
49-
// this table
55+
// We do not complain if the table already exists, as users of VSS could have already created this table
5056
"CREATE TABLE IF NOT EXISTS vss_db (
5157
user_token character varying(120) NOT NULL CHECK (user_token <> ''),
5258
store_id character varying(120) NOT NULL CHECK (store_id <> ''),
@@ -100,7 +106,7 @@ async fn initialize_vss_database(postgres_endpoint: &str, db_name: &str) -> Resu
100106
})?;
101107

102108
if num_rows == 0 {
103-
let stmt = format!("{} {}", INIT_DB_CMD, db_name);
109+
let stmt = format!("{} {};", INIT_DB_CMD, db_name);
104110
client.execute(&stmt, &[]).await.map_err(|e| {
105111
Error::new(ErrorKind::Other, format!("Failed to create database {}: {}", db_name, e))
106112
})?;

0 commit comments

Comments
 (0)