commit 7e1e64f5db5593deaefdac146e4d91fb5d16d7d7 from: witcher date: Sun Nov 20 16:12:57 2022 UTC Add migrations to use with sqlx Migrations are embedded into the binary and run on startup with `sqlx::migrate!()`. commit - b78b84dda46392047c1c797891adff38999ecc86 commit + 7e1e64f5db5593deaefdac146e4d91fb5d16d7d7 blob - cd7812b38aa289f6da7899e9441b4b193006f3d0 blob + 2c2336a684b75dc631aafa03a7ed6bdfac663997 --- Cargo.lock +++ Cargo.lock @@ -356,6 +356,9 @@ name = "either" version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "90e5c1c8368803113bf0c9584fc495a58b86dc8a29edbf8fe877d21d9507e797" +dependencies = [ + "serde", +] [[package]] name = "email-encoding" @@ -1345,6 +1348,7 @@ dependencies = [ "percent-encoding", "rustls", "rustls-pemfile", + "serde", "sha2", "smallvec", "sqlformat", @@ -1365,9 +1369,12 @@ dependencies = [ "dotenvy", "either", "heck", + "hex", "once_cell", "proc-macro2", "quote", + "serde", + "serde_json", "sha2", "sqlx-core", "sqlx-rt", blob - b8cf0dcf0c580aefaf60cb416a914e8802453619 blob + ad126db75bc8b4c31f989c8956cc270e9947084a --- Cargo.toml +++ Cargo.toml @@ -20,4 +20,4 @@ directories = "4.0.1" log = "0.4.17" env_logger = "0.9.0" tokio = { version = "1.21.2", default-features = false, features = ["rt-multi-thread", "macros"] } -sqlx = { version = "0.6.2", features = ["runtime-tokio-rustls", "sqlite"] } +sqlx = { version = "0.6.2", features = ["runtime-tokio-rustls", "migrate", "sqlite", "offline"] } blob - a8c711c634784e7a1f3cf4b55c4be3f9ca0fc81b (mode 644) blob + /dev/null --- migrations/2022-02-22-214045_create_posts/down.sql +++ /dev/null @@ -1,2 +0,0 @@ --- This file should undo anything in `up.sql` -DROP TABLE posts blob - 87c7854151cf92a4ad352f7928fdd0ee37909e7b (mode 644) blob + /dev/null --- migrations/2022-02-22-214045_create_posts/up.sql +++ /dev/null @@ -1,11 +0,0 @@ --- Your SQL goes here -CREATE TABLE posts ( - guid TEXT PRIMARY KEY NOT NULL, - title TEXT, - author TEXT, - url TEXT, - feedurl TEXT, - pub_date BIGINT, - content TEXT, - sent BOOLEAN NOT NULL DEFAULT 0 -) blob - /dev/null blob + b1eab722bc189f77be4945956ba7ef9f34c6188d (mode 644) --- /dev/null +++ migrations/20221120130636_create_posts_table.down.sql @@ -0,0 +1 @@ +DROP TABLE posts blob - /dev/null blob + fa5e70c2498450231d92b8f201cf6ae42a1c9c65 (mode 644) --- /dev/null +++ migrations/20221120130636_create_posts_table.up.sql @@ -0,0 +1,10 @@ +CREATE TABLE posts ( + guid TEXT PRIMARY KEY NOT NULL, + title TEXT, + author TEXT, + url TEXT, + feedurl TEXT, + pub_date BIGINT, + content TEXT, + sent BOOLEAN NOT NULL DEFAULT 0 +) blob - 0ac9058280a7d2d1449e892283bd7bef9aa08a2a blob + 97d3e68e205c9872dd8f757d395bcfe9d7c53470 --- src/main.rs +++ src/main.rs @@ -23,8 +23,6 @@ use tokio::task::JoinSet; #[tokio::main] async fn main() -> anyhow::Result<()> { - // TODO: migrations - //diesel_migrations::embed_migrations!("migrations/"); env_logger::init(); let args = cli::Cli::build_app()?; @@ -46,9 +44,9 @@ async fn main() -> anyhow::Result<()> { .max_connections(5) .connect(db_path.to_str().unwrap()) .await?; - // TODO: migrations - //embedded_migrations::run(&conn)?; + sqlx::migrate!("./migrations").run(&pool).await?; + let mut set = JoinSet::new(); for u in urls { set.spawn(async move { rss::fetch_new(u).await });