lenso_postgres_kit/lib.rs
1//! `PostgreSQL` lifecycle support for storage owned by one Lenso Module.
2//!
3//! This crate deliberately is not a shared State Module, SQL Capability, or
4//! repository abstraction. A Module keeps ownership of its data model,
5//! migrations, queries, and transaction boundaries. The kit only makes the
6//! repetitive `PostgreSQL` schema lifecycle explicit and fail-closed.
7
8mod error;
9mod lifecycle;
10mod plan;
11
12pub use error::{PostgresKitError, SetupOutcome, UpgradeOutcome};
13pub use lifecycle::{OwnedPostgres, SchemaOperator};
14pub use plan::{Migration, PlanError, SchemaPlan};
15
16/// Declares immutable migrations whose SQL bodies live in dedicated files.
17///
18/// Paths are resolved from the owning crate's `CARGO_MANIFEST_DIR`. Keeping the
19/// ordered version and stable name explicit makes review and checksum drift
20/// behavior unchanged.
21///
22/// ```ignore
23/// use lenso_postgres_kit::{Migration, sql_migrations};
24///
25/// const MIGRATIONS: &[Migration] = sql_migrations![
26/// (1, "create-orders", "migrations/001_create_orders.sql"),
27/// (2, "add-order-status", "migrations/002_add_order_status.sql"),
28/// ];
29/// ```
30#[macro_export]
31macro_rules! sql_migrations {
32 (
33 $(
34 ($version:literal, $name:literal, $path:literal $(,)?)
35 ),+ $(,)?
36 ) => {
37 &[
38 $(
39 $crate::Migration::new(
40 $version,
41 $name,
42 include_str!(concat!(env!("CARGO_MANIFEST_DIR"), "/", $path)),
43 ),
44 )+
45 ]
46 };
47}