mirror of
https://github.com/mCaptcha/mCaptcha.git
synced 2024-11-30 08:00:02 +03:00
feat: implement postgres migrations
This commit is contained in:
parent
95e7a74559
commit
af36961299
2 changed files with 27 additions and 0 deletions
3
db/db-migrations/sqlx-data.json
Normal file
3
db/db-migrations/sqlx-data.json
Normal file
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"db": "PostgreSQL"
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue