Skip to content
Open
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
4 changes: 3 additions & 1 deletion .github/workflows/build-and-deploy-rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v3

- name: Check formatting on Rust ${{ matrix.toolchain }}
if: matrix.check-fmt
run: rustup component add rustfmt && cd rust && cargo fmt --all -- --check
- name: Build and Deploy VSS Server
run: |
cd rust
Expand Down
21 changes: 10 additions & 11 deletions rust/impls/src/postgres_store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,7 @@ async fn drop_database(postgres_endpoint: &str, db_name: &str) -> Result<(), Err

let drop_database_statement = format!("{} {};", DROP_DB_CMD, db_name);
let num_rows = client.execute(&drop_database_statement, &[]).await.map_err(|e| {
Error::new(
ErrorKind::Other,
format!("Failed to drop database {}: {}", db_name, e),
)
Error::new(ErrorKind::Other, format!("Failed to drop database {}: {}", db_name, e))
})?;
assert_eq!(num_rows, 0);

Expand Down Expand Up @@ -134,10 +131,7 @@ impl PostgresBackendImpl {

async fn migrate_vss_database(&self, migrations: &[&str]) -> Result<(usize, usize), Error> {
let mut conn = self.pool.get().await.map_err(|e| {
Error::new(
ErrorKind::Other,
format!("Failed to fetch a connection from Pool: {}", e),
)
Error::new(ErrorKind::Other, format!("Failed to fetch a connection from Pool: {}", e))
})?;

// Get the next migration to be applied.
Expand Down Expand Up @@ -230,7 +224,9 @@ impl PostgresBackendImpl {
async fn get_upgrades_list(&self) -> Vec<usize> {
let conn = self.pool.get().await.unwrap();
let rows = conn.query(GET_MIGRATION_LOG_STMT, &[]).await.unwrap();
rows.iter().map(|row| usize::try_from(row.get::<&str, i32>(MIGRATION_LOG_COLUMN)).unwrap()).collect()
rows.iter()
.map(|row| usize::try_from(row.get::<&str, i32>(MIGRATION_LOG_COLUMN)).unwrap())
.collect()
}

fn build_vss_record(&self, user_token: String, store_id: String, kv: KeyValue) -> VssDbRecord {
Expand Down Expand Up @@ -581,10 +577,10 @@ impl KvStore for PostgresBackendImpl {

#[cfg(test)]
mod tests {
use super::{drop_database, DUMMY_MIGRATION, MIGRATIONS};
use crate::postgres_store::PostgresBackendImpl;
use api::define_kv_store_tests;
use tokio::sync::OnceCell;
use super::{MIGRATIONS, DUMMY_MIGRATION, drop_database};

const POSTGRES_ENDPOINT: &str = "postgresql://postgres:postgres@localhost:5432";
const MIGRATIONS_START: usize = 0;
Expand Down Expand Up @@ -670,7 +666,10 @@ mod tests {
let (start, end) = store.migrate_vss_database(&migrations).await.unwrap();
assert_eq!(start, MIGRATIONS_END + 1);
assert_eq!(end, MIGRATIONS_END + 3);
assert_eq!(store.get_upgrades_list().await, [MIGRATIONS_START, MIGRATIONS_END, MIGRATIONS_END + 1]);
assert_eq!(
store.get_upgrades_list().await,
[MIGRATIONS_START, MIGRATIONS_END, MIGRATIONS_END + 1]
);
assert_eq!(store.get_schema_version().await, MIGRATIONS_END + 3);
};

Expand Down