diff --git a/Makefile b/Makefile index a44b266428..baf0e07cce 100644 --- a/Makefile +++ b/Makefile @@ -44,7 +44,7 @@ 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 diff --git a/docker-compose.e2e.mysql.yaml b/docker-compose.e2e.mysql.yaml index 4391d4488f..2f256d933d 100644 --- a/docker-compose.e2e.mysql.yaml +++ b/docker-compose.e2e.mysql.yaml @@ -33,6 +33,7 @@ services: SYNC_TOKENSERVER__FXA_BROWSERID_ISSUER: "api-accounts.stage.mozaws.net" SYNC_TOKENSERVER__FXA_EMAIL_DOMAIN: api-accounts.stage.mozaws.net SYNC_TOKENSERVER__FXA_METRICS_HASH_SECRET: secret0 + SYNC_TOKENSERVER__RUN_MIGRATIONS: "true" TOKENSERVER_HOST: http://localhost:8000 entrypoint: > /bin/sh -c " diff --git a/docker-compose.e2e.spanner.yaml b/docker-compose.e2e.spanner.yaml index 45e15e5200..d7dca5e5ff 100644 --- a/docker-compose.e2e.spanner.yaml +++ b/docker-compose.e2e.spanner.yaml @@ -34,6 +34,7 @@ services: SYNC_TOKENSERVER__FXA_BROWSERID_ISSUER: "api-accounts.stage.mozaws.net" SYNC_TOKENSERVER__FXA_EMAIL_DOMAIN: api-accounts.stage.mozaws.net SYNC_TOKENSERVER__FXA_METRICS_HASH_SECRET: secret0 + SYNC_TOKENSERVER__RUN_MIGRATIONS: "true" TOKENSERVER_HOST: http://localhost:8000 entrypoint: > /bin/sh -c " diff --git a/docker-compose.mysql.yaml b/docker-compose.mysql.yaml index 8becc48cb7..3ea3d72e55 100644 --- a/docker-compose.mysql.yaml +++ b/docker-compose.mysql.yaml @@ -49,6 +49,7 @@ services: SYNC_MASTER_SECRET: secret0 SYNC_DATABASE_URL: mysql://test:test@sync-db:3306/syncstorage SYNC_TOKENSERVER__DATABASE_URL: mysql://test:test@tokenserver-db:3306/tokenserver + SYNC_TOKENSERVER__RUN_MIGRATIONS: "true" volumes: sync_db_data: diff --git a/docker-compose.spanner.yaml b/docker-compose.spanner.yaml index 5317d91138..3f510e697e 100644 --- a/docker-compose.spanner.yaml +++ b/docker-compose.spanner.yaml @@ -10,7 +10,7 @@ services: sync-db-setup: image: app:build depends_on: - - sync-db + - sync-db restart: "no" entrypoint: "/app/scripts/prepare-spanner.sh" environment: @@ -39,19 +39,20 @@ services: image: ${SYNCSTORAGE_RS_IMAGE:-syncstorage-rs:latest} restart: always ports: - - "8000:8000" + - "8000:8000" depends_on: - - sync-db-setup + - sync-db-setup environment: - SYNC_HOST: 0.0.0.0 - SYNC_MASTER_SECRET: secret0 - SYNC_DATABASE_URL: spanner://projects/test-project/instances/test-instance/databases/test-database - SYNC_SPANNER_EMULATOR_HOST: sync-db:9010 - SYNC_TOKENSERVER__DATABASE_URL: mysql://test:test@tokenserver-db:3306/tokenserver + SYNC_HOST: 0.0.0.0 + SYNC_MASTER_SECRET: secret0 + SYNC_DATABASE_URL: spanner://projects/test-project/instances/test-instance/databases/test-database + SYNC_SPANNER_EMULATOR_HOST: sync-db:9010 + SYNC_TOKENSERVER__DATABASE_URL: mysql://test:test@tokenserver-db:3306/tokenserver + SYNC_TOKENSERVER__RUN_MIGRATIONS: "true" volumes: tokenserver_db_data: -# Application runs off of port 8000. -# you can test if it's available with -# curl "http://localhost:8000/__heartbeat__" + # Application runs off of port 8000. + # you can test if it's available with + # curl "http://localhost:8000/__heartbeat__" diff --git a/src/settings.rs b/src/settings.rs index f106fdd56f..5566e4a517 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -215,6 +215,7 @@ impl Settings { s.set_default("tokenserver.fxa_oauth_request_timeout", 10)?; s.set_default("tokenserver.node_type", "spanner")?; s.set_default("tokenserver.statsd_label", "syncstorage.tokenserver")?; + s.set_default("tokenserver.run_migrations", cfg!(test))?; // Set Cors defaults s.set_default( diff --git a/src/tokenserver/db/pool.rs b/src/tokenserver/db/pool.rs index 50ca2aa76d..e9d0b6d081 100644 --- a/src/tokenserver/db/pool.rs +++ b/src/tokenserver/db/pool.rs @@ -3,14 +3,13 @@ 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}; use crate::db::{error::DbError, DbErrorKind}; +use crate::diesel::Connection; use crate::server::metrics::Metrics; use crate::tokenserver::settings::Settings; @@ -26,10 +25,7 @@ embed_migrations!("src/tokenserver/migrations"); 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(()) } @@ -47,7 +43,9 @@ impl TokenserverPool { metrics: &Metrics, _use_test_transactions: bool, ) -> DbResult { - run_embedded_migrations(&settings.database_url)?; + if settings.run_migrations { + run_embedded_migrations(&settings.database_url)?; + } let manager = ConnectionManager::::new(settings.database_url.clone()); let builder = Pool::builder() diff --git a/src/tokenserver/settings.rs b/src/tokenserver/settings.rs index 1538efad38..aa5459ac8f 100644 --- a/src/tokenserver/settings.rs +++ b/src/tokenserver/settings.rs @@ -46,6 +46,8 @@ pub struct Settings { pub node_type: NodeType, /// The label to be used when reporting Metrics. pub statsd_label: String, + /// Whether or not to run the Tokenserver migrations upon startup. + pub run_migrations: bool, } impl Default for Settings { @@ -68,6 +70,7 @@ impl Default for Settings { node_capacity_release_rate: None, node_type: NodeType::Spanner, statsd_label: "syncstorage.tokenserver".to_owned(), + run_migrations: cfg!(test), } } }