Expand description
Database migration system
Provides a flexible migration framework for evolving projection schemas.
§Example
use azoth::prelude::*;
use azoth::{Migration, MigrationManager};
use rusqlite::Connection;
// Define migrations
struct CreateAccountsTable;
impl Migration for CreateAccountsTable {
fn version(&self) -> u32 {
2
}
fn name(&self) -> &str {
"create_accounts_table"
}
fn up(&self, conn: &Connection) -> Result<()> {
conn.execute(
"CREATE TABLE accounts (
id INTEGER PRIMARY KEY,
balance INTEGER NOT NULL DEFAULT 0,
created_at TEXT NOT NULL DEFAULT (datetime('now'))
)",
[],
).map_err(|e| AzothError::Projection(e.to_string()))?;
Ok(())
}
fn down(&self, conn: &Connection) -> Result<()> {
conn.execute("DROP TABLE accounts", [])
.map_err(|e| AzothError::Projection(e.to_string()))?;
Ok(())
}
}
// Create manager and register migrations
let mut manager = MigrationManager::new();
manager.add(Box::new(CreateAccountsTable));
// Run migrations
let db = AzothDb::open("./data")?;
manager.run(db.projection())?;Structs§
- File
Migration - File-based migration
- Migration
History Entry - Migration history entry
- Migration
Info - Migration information
- Migration
Manager - Migration manager
Traits§
- Migration
- Migration trait