Use env variable DATABASE_URL for sqlite
This commit is contained in:
parent
4b364b0419
commit
488fa685d3
|
@ -44,7 +44,7 @@
|
|||
sqlite
|
||||
];
|
||||
env = {
|
||||
DATABASE_URL = "sqlite://sqlite.db";
|
||||
DATABASE_URL = "/tmp/sqlite.db";
|
||||
RUST_BACKTRACE = 1;
|
||||
};
|
||||
};
|
||||
|
|
|
@ -153,15 +153,16 @@ impl SqliteDb {
|
|||
.idle_timeout(None)
|
||||
.max_connections(max_size);
|
||||
|
||||
let db_url = "sqlite://sqlite.db";
|
||||
if !Sqlite::database_exists(db_url).await.unwrap_or(false) {
|
||||
log::info!("Creating database {}", db_url);
|
||||
match Sqlite::create_database(db_url).await {
|
||||
Ok(_) => log::info!("Db {} created", db_url),
|
||||
Err(_) => panic!("Failed to create database {}", db_url),
|
||||
let env_db_path = std::env::var("DATABASE_URL").unwrap_or("/tmp/sqlite.db".to_string());
|
||||
|
||||
if !Sqlite::database_exists(&env_db_path).await.unwrap_or(false) {
|
||||
log::info!("Creating database {}", &env_db_path);
|
||||
match Sqlite::create_database(&env_db_path).await {
|
||||
Ok(_) => log::info!("Db {} created", &env_db_path),
|
||||
Err(_) => panic!("Failed to create database {}", &env_db_path),
|
||||
}
|
||||
}
|
||||
if let Ok(pool) = pool_options.connect(db_url).await {
|
||||
if let Ok(pool) = pool_options.connect(&env_db_path).await {
|
||||
log::info!("Connected to sqlite pool {}", name);
|
||||
|
||||
pool
|
||||
|
|
Loading…
Reference in a new issue