libsql_migration/lib.rs
1//! # LibSQL Migration Crate
2//!
3//! `libsql_migration` is a Rust crate designed to manage database migrations
4//! for LibSQL (and SQLite). It provides a simple and flexible way to apply
5//! SQL migration scripts to your database, ensuring that schema changes are
6//! tracked and applied consistently.
7//!
8//! ## Key Features
9//!
10//! * **Multiple Migration Sources:** Supports migrations from local directories (`dir` feature),
11//! embedded SQL content (`content` feature), or remote HTTP endpoints (`remote` feature).
12//! * **Automatic Tracking:** Creates and manages a `libsql_migrations` table to keep
13//! track of which migrations have already been applied.
14//! * **Simple API:** Offers straightforward functions (`migrate`) within each feature module
15//! to apply migrations.
16//! * **Async Support:** Built with `async/await` for non-blocking database operations.
17//! * **Feature-Gated:** Use only the features you need to keep dependencies minimal.
18//!
19//! ## Getting Started
20//!
21//! Add `libsql_migration` to your `Cargo.toml`. By default, the `dir` feature is enabled.
22//!
23//! ```toml
24//! [dependencies]
25//! libsql_migration = "0.1.0" # Replace with the latest version
26//! libsql = { version = "...", features = ["local"] } # Or other libsql features
27//! tokio = { version = "1", features = ["full"] } # For the async runtime
28//! ```
29//!
30//! If you want to use other features like `content` or `remote`, you might need to
31//! disable default features and enable the specific ones you need. See the "Features"
32//! section below.
33//!
34//! ## Migration Tracking
35//!
36//! The migrator automatically creates a `libsql_migrations` table in your database
37//! (if it doesn't exist) upon the first migration attempt. This table stores the
38//! unique identifiers (e.g., filenames for `dir`, provided IDs for `content`/`remote`)
39//! of the migrations that have been successfully applied. Before applying any
40//! migration, the crate checks this table to prevent reapplying already executed scripts.
41//!
42//! ## Features
43//!
44//! This crate provides different ways to source migrations, controlled by Cargo features:
45//!
46//! * **`dir`** (enabled by default): Migrates using SQL files from a local directory.
47//! See the [`dir`] module documentation for details and usage examples.
48//! * **`content`**: Migrates using SQL content embedded directly in your code or loaded
49//! dynamically. See the [`content`] module documentation for details and usage examples.
50//! Requires disabling default features.
51//! * **`remote`**: Migrates using SQL files fetched from a remote location (e.g., HTTP).
52//! See the [`remote`] module documentation for details and usage examples.
53//! Requires disabling default features and adding `reqwest` and `serde` as dependencies.
54//!
55//! Enable features in your `Cargo.toml`:
56//!
57//! ```toml
58//! [dependencies]
59//! # Only enable the 'content' feature
60//! libsql_migration = { version = "...", default-features = false, features = ["content"] }
61//!
62//! # Enable 'remote' feature (requires reqwest and serde)
63//! # libsql_migration = { version = "...", default-features = false, features = ["remote"] }
64//! # reqwest = { version = "...", features = ["json"] }
65//! # serde = { version = "...", features = ["derive"] }
66//!
67//! # Enable 'dir' and 'remote' features (dir is default, so just adding remote works too if default is kept)
68//! # libsql_migration = { version = "...", features = ["remote"] } # If default-features = true (default)
69//! # libsql_migration = { version = "...", default-features = false, features = ["dir", "remote"] } # Explicit
70//! ```
71//!
72//! ## Example Usage (using default `dir` feature)
73//!
74//! For detailed examples of each feature, please refer to the respective module documentation
75//! ([`dir`], [`content`], [`remote`]). A basic example using the default `dir` feature is shown
76//! in the [`dir`] module documentation.
77//!
78//! [GitHub Repository](https://github.com/prashant1k99/libsql_migration)
79
80pub mod errors;
81pub mod util;
82
83#[cfg(feature = "content")]
84pub mod content;
85
86#[cfg(feature = "remote")]
87pub mod remote;
88
89#[cfg(feature = "dir")]
90pub mod dir;