feat: implement postgres migrations

This commit is contained in:
realaravinth 2022-05-11 13:15:23 +05:30
parent 95e7a74559
commit af36961299
No known key found for this signature in database
GPG key ID: AD9F0F08E855ED88
2 changed files with 27 additions and 0 deletions

View file

@ -0,0 +1,3 @@
{
"db": "PostgreSQL"
}

View file

@ -14,3 +14,27 @@
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
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();
}