diff --git a/db/db-migrations/sqlx-data.json b/db/db-migrations/sqlx-data.json new file mode 100644 index 00000000..95c8c858 --- /dev/null +++ b/db/db-migrations/sqlx-data.json @@ -0,0 +1,3 @@ +{ + "db": "PostgreSQL" +} \ No newline at end of file diff --git a/db/db-migrations/src/main.rs b/db/db-migrations/src/main.rs index 461174aa..7f777e12 100644 --- a/db/db-migrations/src/main.rs +++ b/db/db-migrations/src/main.rs @@ -14,3 +14,27 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ +use std::env; + +use sqlx::postgres::PgPoolOptions; + +#[cfg(not(tarpaulin_include))] +#[actix_rt::main] +async fn main() { + //TODO featuregate sqlite and postgres + postgres_migrate().await; +} + +async fn postgres_migrate() { + let db_url = env::var("POSTGRES_DATABASE_URL").expect("set POSTGRES_DATABASE_URL env var"); + let db = PgPoolOptions::new() + .max_connections(2) + .connect(&db_url) + .await + .expect("Unable to form database pool"); + + sqlx::migrate!("../db-sqlx-postgres/migrations/") + .run(&db) + .await + .unwrap(); +}