Skip to content

Commit

Permalink
feat: add basic cli for migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
cmackenzie1 committed Feb 8, 2025
1 parent 2e34a5a commit 0fd6b21
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 11 deletions.
18 changes: 7 additions & 11 deletions torii/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,16 @@ torii-core = { path = "../torii-core", version = "0.1.0" }
torii-auth-email = { path = "../torii-auth-email", version = "0.1.0", optional = true }
torii-auth-oidc = { path = "../torii-auth-oidc", version = "0.1.0", optional = true }
torii-storage-sqlite = { path = "../torii-storage-sqlite", version = "0.1.0", optional = true }
sqlx = { workspace = true, optional = true }
tokio = { workspace = true, optional = true }
tracing = { workspace = true, optional = true }
sqlx = { workspace = true, features = ["runtime-tokio-rustls", "sqlite"] }
tokio = { workspace = true, features = ["full"] }
tracing = { workspace = true }
clap = { version = "4.5.28", features = ["derive"] }

[dev-dependencies]
tokio = { workspace = true }
tracing-subscriber = { workspace = true }

[features]
default = ["email-auth", "sqlite"]
# Authentication methods
email-auth = ["torii-auth-email"]
oidc-auth = ["torii-auth-oidc"]
# Database backends
sqlite = ["sqlx/sqlite", "torii-storage-sqlite"]
# Runtime
tokio-runtime = ["tokio"]
email-auth = ["dep:torii-auth-email"]
oidc-auth = ["dep:torii-auth-oidc"]
sqlite = ["dep:torii-storage-sqlite"]
47 changes: 47 additions & 0 deletions torii/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
use clap::Parser;
use sqlx::SqlitePool;
use torii_storage_sqlite::SqliteStorage;

#[derive(Parser)]
#[command(author, version, about, long_about = None)]
struct Cli {
/// Enable email authentication
#[arg(long)]
email_auth: bool,

/// Enable OpenID Connect authentication
#[arg(long)]
oidc_auth: bool,

/// Database connection string
#[arg(long)]
db_url: String,

#[command(subcommand)]
command: Commands,
}

#[derive(clap::Subcommand)]
enum Commands {
/// Run database migrations
Migrate,
/// Print version information
Version,
}

#[tokio::main]
async fn main() {
let cli = Cli::parse();

match cli.command {
Commands::Migrate => {
println!("Running migrations...");
let pool = SqlitePool::connect(&cli.db_url).await.unwrap();
let storage = SqliteStorage::new(pool);
storage.migrate().await.unwrap();
}
Commands::Version => {
println!("Torii v{}", env!("CARGO_PKG_VERSION"));
}
}
}

0 comments on commit 0fd6b21

Please sign in to comment.