mirror of https://github.com/raftario/filite.git
Embed migrations in debug builds
This commit is contained in:
parent
dcd5200485
commit
799a583372
|
@ -517,6 +517,15 @@ dependencies = [
|
|||
"syn 0.15.44 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "diesel_migrations"
|
||||
version = "1.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"migrations_internals 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"migrations_macros 1.4.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "digest"
|
||||
version = "0.8.1"
|
||||
|
@ -625,6 +634,7 @@ dependencies = [
|
|||
"blake2 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"chrono 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"diesel 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"diesel_migrations 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"dirs 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"dotenv 0.14.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"env_logger 0.7.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
|
@ -879,6 +889,25 @@ name = "memchr"
|
|||
version = "2.2.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
|
||||
[[package]]
|
||||
name = "migrations_internals"
|
||||
version = "1.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"diesel 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "migrations_macros"
|
||||
version = "1.4.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
dependencies = [
|
||||
"migrations_internals 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"proc-macro2 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"quote 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
"syn 1.0.5 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "mime"
|
||||
version = "0.3.14"
|
||||
|
@ -1909,6 +1938,7 @@ dependencies = [
|
|||
"checksum derive_more 0.15.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7a141330240c921ec6d074a3e188a7c7ef95668bb95e7d44fa0e5778ec2a7afe"
|
||||
"checksum diesel 1.4.2 (registry+https://github.com/rust-lang/crates.io-index)" = "8d24935ba50c4a8dc375a0fd1f8a2ba6bdbdc4125713126a74b965d6a01a06d7"
|
||||
"checksum diesel_derives 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "62a27666098617d52c487a41f70de23d44a1dc1f3aa5877ceba2790fb1f1cab4"
|
||||
"checksum diesel_migrations 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "bf3cde8413353dc7f5d72fa8ce0b99a560a359d2c5ef1e5817ca731cd9008f4c"
|
||||
"checksum digest 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f3d0c8c8752312f9713efd397ff63acb9f85585afbf179282e720e7704954dd5"
|
||||
"checksum dirs 2.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "13aea89a5c93364a98e9b37b2fa237effbb694d5cfe01c5b70941f7eb087d5e3"
|
||||
"checksum dirs-sys 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "afa0b23de8fd801745c471deffa6e12d248f962c9fd4b4c33787b055599bde7b"
|
||||
|
@ -1952,6 +1982,8 @@ dependencies = [
|
|||
"checksum lru-cache 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "31e24f1ad8321ca0e8a1e0ac13f23cb668e6f5466c2c57319f6a5cf1cc8e3b1c"
|
||||
"checksum matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08"
|
||||
"checksum memchr 2.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "88579771288728879b57485cc7d6b07d648c9f0141eb955f8ab7f9d45394468e"
|
||||
"checksum migrations_internals 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "8089920229070f914b9ce9b07ef60e175b2b9bc2d35c3edd8bf4433604e863b9"
|
||||
"checksum migrations_macros 1.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "719ef0bc7f531428764c9b70661c14abd50a7f3d21f355752d9985aa21251c9e"
|
||||
"checksum mime 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)" = "dd1d63acd1b78403cc0c325605908475dd9b9a3acbf65ed8bcab97e27014afcf"
|
||||
"checksum mime_guess 2.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "1a0ed03949aef72dbdf3116a383d7b38b4768e6f960528cd6a6044aa9ed68599"
|
||||
"checksum miniz-sys 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "1e9e3ae51cea1576ceba0dde3d484d30e6e5b86dee0b2d412fe3a16a15c98202"
|
||||
|
|
|
@ -10,6 +10,7 @@ actix-web = "1.0.8"
|
|||
base64 = "0.10.1"
|
||||
blake2 = "0.8.1"
|
||||
chrono = "0.4.9"
|
||||
diesel_migrations = "1.4.0"
|
||||
dirs = "2.0.2"
|
||||
env_logger = "0.7.0"
|
||||
futures = "0.1.29"
|
||||
|
|
11
src/main.rs
11
src/main.rs
|
@ -3,6 +3,9 @@ extern crate diesel;
|
|||
#[macro_use]
|
||||
extern crate serde;
|
||||
|
||||
#[cfg_attr(not(debug_assertions), macro_use)]
|
||||
extern crate diesel_migrations;
|
||||
|
||||
use crate::setup::Config;
|
||||
|
||||
use actix_web::{web, App, FromRequest, HttpServer};
|
||||
|
@ -22,6 +25,9 @@ pub mod setup;
|
|||
/// SQLite database connection pool
|
||||
pub type Pool = r2d2::Pool<ConnectionManager<SqliteConnection>>;
|
||||
|
||||
#[cfg(not(debug_assertions))]
|
||||
embed_migrations!("./migrations");
|
||||
|
||||
/// Performs the initial setup
|
||||
#[cfg(not(debug_assertions))]
|
||||
fn init() -> Config {
|
||||
|
@ -62,6 +68,11 @@ fn main() {
|
|||
setup::init_logger();
|
||||
|
||||
let pool = setup::create_pool(&config.database_url, config.pool_size);
|
||||
#[cfg(not(debug_assertions))]
|
||||
embedded_migrations::run(&pool.get().unwrap()).unwrap_or_else(|e| {
|
||||
eprintln!("Can't prepare database: {}.", e);
|
||||
process::exit(1);
|
||||
});
|
||||
|
||||
let port = config.port;
|
||||
let max_filesize = (config.max_filesize as f64 * 1.37) as usize;
|
||||
|
|
Loading…
Reference in New Issue