chore: remove redundant migrations directory and migrate binary
All content from 003_add_device_codes.sql and 004_add_trigram_indexes.sql was already absorbed into db/schema.sql (the single source of truth). The migrations had additional problems: - Broken numbering (started at 003, missing 001/002) - 004 used CREATE INDEX CONCURRENTLY which fails inside sqlx transactions - No production flow ever invoked the migrate binary Removed: db/migrations/, src/bin/migrate.rs, migrations Cargo feature, [[bin]] migrate target, and doc/database-migrations.md.
This commit is contained in:
@@ -1,49 +0,0 @@
|
||||
use sqlx::postgres::PgPoolOptions;
|
||||
use std::env;
|
||||
use std::path::Path;
|
||||
use std::time::Duration;
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
// Configure logging
|
||||
tracing_subscriber::fmt::init();
|
||||
|
||||
// Load environment variables (.env.local first, then .env)
|
||||
if let Ok(path) = env::var("DOTENV_PATH") {
|
||||
dotenvy::from_path(Path::new(&path)).ok();
|
||||
} else {
|
||||
dotenvy::from_filename(".env.local").ok();
|
||||
dotenvy::dotenv().ok();
|
||||
}
|
||||
|
||||
// Get DATABASE_URL from environment variables
|
||||
let database_url = env::var("DATABASE_URL").expect("DATABASE_URL must be configured");
|
||||
|
||||
println!("Connecting to the database...");
|
||||
|
||||
// Create connection pool
|
||||
let pool = PgPoolOptions::new()
|
||||
.max_connections(5)
|
||||
.acquire_timeout(Duration::from_secs(10))
|
||||
.connect(&database_url)
|
||||
.await?;
|
||||
|
||||
// Run migrations
|
||||
println!("Running migrations...");
|
||||
|
||||
// Get the directory from an environment variable or use a default value
|
||||
let migrations_dir = env::var("MIGRATIONS_DIR").unwrap_or_else(|_| "./migrations".to_string());
|
||||
println!("Migrations directory: {}", migrations_dir);
|
||||
|
||||
// Create a migrator
|
||||
let migrator = sqlx::migrate::Migrator::new(Path::new(&migrations_dir))
|
||||
.await
|
||||
.expect("Could not create the migrator");
|
||||
|
||||
// Run all pending migrations
|
||||
migrator.run(&pool).await?;
|
||||
|
||||
println!("Migrations applied successfully");
|
||||
|
||||
Ok(())
|
||||
}
|
||||
Reference in New Issue
Block a user