//! Migs - A SQL migration script collection library
//!
//! This library provides macros for registering SQL scripts at compile time
//! and collecting them into a registry.
//!
//! # Example
//!
//! ```
//! use migs::{migs, collect, Migs};
//!
//! // Register inline SQL (scope defaults to "init")
//! migs!(sql = "CREATE TABLE users (id INT)");
//!
//! // Register inline SQL with explicit scope
//! migs!(sql = "CREATE TABLE {{name}} (id INT)", scope = "create");
//!
//! // Register SQL with explicit scope and order
//! // Note: Duplicate orders within the same scope will cause a compile error
//! migs!(sql = "CREATE INDEX idx_users ON users(id)", scope = "create", order = 1);
//!
//! // Collect all registered scripts
//! let all_scripts: Vec<&Migs> = collect!();
//! ```
// Re-export inventory for use in macros
pub use inventory;
// Re-export the macros
pub use migs_macro::{collect, migs};
/// Represents a registered SQL migration script with metadata
#[derive(Debug, Clone)]
pub struct Migs {
/// The scope/category of this migration (e.g., "init", "create", "seed")
pub scope: &'static str,
/// The source of this migration (file path or "<inline>")
pub source: &'static str,
/// The SQL content with optional {{template}} placeholders
pub content: &'static str,
/// The execution order of this migration within its scope (None = auto-assigned)
pub order: Option<u32>,
}
// Register Migs with inventory for collection
inventory::collect!(Migs);
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_migs_struct_creation() {
let migs = Migs {
scope: "test",
source: "<inline>",
content: "SELECT 1",
order: Some(1),
};
assert_eq!(migs.scope, "test");
assert_eq!(migs.source, "<inline>");
assert_eq!(migs.content, "SELECT 1");
assert_eq!(migs.order, Some(1));
}
}