use rust_eloquent::Eloquent;
use rust_eloquent::schema::{Schema, Blueprint};
#[tokio::main]
async fn main() -> Result<(), rust_eloquent::sqlx::Error> {
let _ = std::fs::remove_file("migrations_test.db");
std::fs::File::create("migrations_test.db").unwrap();
Eloquent::init("sqlite://migrations_test.db").await?;
println!("Creating tables using Fluent Schema Builder...\n");
Schema::create("users", |table: &mut Blueprint| {
table.id(); table.string("name").not_null();
table.string("email").nullable();
table.integer("age").default("18");
table.boolean("is_active").default("1");
table.timestamps(); table.soft_deletes(); }).await?;
println!("Users table created successfully!");
Schema::create("posts", |table: &mut Blueprint| {
table.id();
table.integer("user_id").not_null();
table.string("title").not_null();
table.string("body").nullable();
table.timestamps();
}).await?;
println!("Posts table created successfully!");
let pool = Eloquent::pool();
let tables: Vec<(String, String)> = rust_eloquent::sqlx::query_as(
"SELECT name, sql FROM sqlite_schema WHERE type='table' AND name IN ('users', 'posts')"
)
.fetch_all(pool)
.await?;
println!("\n--- Generated SQL Schemas ---");
for (name, sql) in tables {
println!("Table: {}\n{}\n", name, sql);
}
Ok(())
}