Skip to content

Commit

Permalink
feat: don't run Tokenserver migrations on startup
Browse files Browse the repository at this point in the history
  • Loading branch information
Ethan Donowitz committed Apr 21, 2022
1 parent 37d2251 commit 3cfcbdb
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 24 deletions.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,13 @@ python:
venv/bin/python -m pip install -r requirements.txt

run: python
PATH=./venv/bin:$(PATH) RUST_LOG=debug RUST_BACKTRACE=full cargo run -- --config config/local.toml
PATH="./venv/bin:$(PATH)" RUST_LOG=debug RUST_BACKTRACE=full cargo run -- --config config/local.toml

run_spanner:
GOOGLE_APPLICATION_CREDENTIALS=$(PATH_TO_SYNC_SPANNER_KEYS) GRPC_DEFAULT_SSL_ROOTS_FILE_PATH=$(PATH_TO_GRPC_CERT) make run

test:
SYNC_DATABASE_URL=$(SYNC_DATABASE_URL) SYNC_TOKENSERVER__DATABASE_URL=$(SYNC_TOKENSERVER__DATABASE_URL) RUST_TEST_THREADS=1 cargo test

tokenserver_migrate:
diesel --database-url $(SYNC_TOKENSERVER__DATABASE_URL) migration --migration-dir src/tokenserver/migrations run
2 changes: 1 addition & 1 deletion src/tokenserver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ cargo install diesel_cli
```
Then, run the migrations:
```
diesel --database-url mysql://sample_user:sample_password@localhost/tokenserver_rs migration --migration-dir src/tokenserver/migrations run
make tokenserver_migrate
```
You should replace the above database Data Source Name (DSN) with the DSN of the database you are using.

Expand Down
22 changes: 0 additions & 22 deletions src/tokenserver/db/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ use async_trait::async_trait;
use diesel::{
mysql::MysqlConnection,
r2d2::{ConnectionManager, Pool},
Connection,
};
#[cfg(test)]
use diesel_logger::LoggingConnection;
use std::time::Duration;

use super::models::{Db, DbResult, TokenserverDb};
Expand All @@ -17,23 +14,6 @@ use crate::tokenserver::settings::Settings;
#[cfg(test)]
use crate::db::mysql::TestTransactionCustomizer;

embed_migrations!("src/tokenserver/migrations");

/// Run the diesel embedded migrations
///
/// Mysql DDL statements implicitly commit which could disrupt MysqlPool's
/// begin_test_transaction during tests. So this runs on its own separate conn.
pub fn run_embedded_migrations(database_url: &str) -> DbResult<()> {
let conn = MysqlConnection::establish(database_url)?;

#[cfg(test)]
embedded_migrations::run(&LoggingConnection::new(conn))?;
#[cfg(not(test))]
embedded_migrations::run(&conn)?;

Ok(())
}

#[derive(Clone)]
pub struct TokenserverPool {
/// Pool of db connections
Expand All @@ -47,8 +27,6 @@ impl TokenserverPool {
metrics: &Metrics,
_use_test_transactions: bool,
) -> DbResult<Self> {
run_embedded_migrations(&settings.database_url)?;

let manager = ConnectionManager::<MysqlConnection>::new(settings.database_url.clone());
let builder = Pool::builder()
.max_size(settings.database_pool_max_size.unwrap_or(10))
Expand Down

0 comments on commit 3cfcbdb

Please sign in to comment.