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