Running migrations.
This commit is contained in:
parent
6e08a0c8c3
commit
111d9026c5
@ -9,3 +9,4 @@ edition = "2021"
|
|||||||
walkdir = "2.3.2"
|
walkdir = "2.3.2"
|
||||||
sqlx = { version = "0.5", features = [ "runtime-tokio-rustls", "sqlite", "migrate" ] }
|
sqlx = { version = "0.5", features = [ "runtime-tokio-rustls", "sqlite", "migrate" ] }
|
||||||
tokio = { version = "1.16.1", features = ["full"] }
|
tokio = { version = "1.16.1", features = ["full"] }
|
||||||
|
dirs = "4.0.0"
|
||||||
|
13
migrations/00001_create_watched_table.sql
Normal file
13
migrations/00001_create_watched_table.sql
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
CREATE TABLE profile (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
name TEXT NOT NULL,
|
||||||
|
UNIQUE(name)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE watched (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
profile INTEGER NOT NULL,
|
||||||
|
path TEXT NOT NULL,
|
||||||
|
recorded_at DATE NOT NULL,
|
||||||
|
FOREIGN KEY(profile) REFERENCES profile(id)
|
||||||
|
);
|
22
src/main.rs
22
src/main.rs
@ -1,8 +1,12 @@
|
|||||||
use std::{env, fs::FileType};
|
use sqlx::sqlite::SqliteConnectOptions;
|
||||||
|
use sqlx::sqlite::SqlitePool;
|
||||||
|
use std::env;
|
||||||
|
use std::str::FromStr;
|
||||||
use walkdir::DirEntry;
|
use walkdir::DirEntry;
|
||||||
use walkdir::WalkDir;
|
use walkdir::WalkDir;
|
||||||
|
|
||||||
fn main() {
|
#[tokio::main]
|
||||||
|
async fn main() -> Result<(), sqlx::Error> {
|
||||||
let mut args = env::args();
|
let mut args = env::args();
|
||||||
let _program = args.next().expect("argv[0] should be this program?");
|
let _program = args.next().expect("argv[0] should be this program?");
|
||||||
let profile = args.next().expect("Must provide a profile");
|
let profile = args.next().expect("Must provide a profile");
|
||||||
@ -22,4 +26,18 @@ fn main() {
|
|||||||
for f in files {
|
for f in files {
|
||||||
println!("{}", f.path().display());
|
println!("{}", f.path().display());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let db_path = dirs::home_dir()
|
||||||
|
.map(|pb| pb.join(".record_watch.sqlite"))
|
||||||
|
.unwrap();
|
||||||
|
let url = format!("sqlite://{}", db_path.as_path().display());
|
||||||
|
|
||||||
|
println!("{}", &url);
|
||||||
|
|
||||||
|
let pool =
|
||||||
|
SqlitePool::connect_with(SqliteConnectOptions::from_str(&url)?.create_if_missing(true))
|
||||||
|
.await?;
|
||||||
|
sqlx::migrate!("./migrations").run(&pool).await?;
|
||||||
|
|
||||||
|
Ok(())
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user