use rullst_orm::Orm;
use rullst_orm::schema::{Blueprint, ColumnDefault, Schema};
#[tokio::main]
async fn main() -> Result<(), rullst_orm::Error> {
let _ = std::fs::remove_file("migrations_test.db");
std::fs::File::create("migrations_test.db").unwrap();
Orm::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(ColumnDefault::Integer(18));
table
.boolean("is_active")
.default(ColumnDefault::Integer(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 = Orm::pool();
let tables: Vec<(String, String)> = rullst_orm::_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(())
}