1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
//! Provides migration capabilities using SQL content provided directly as strings.
//!
//! This module is activated by the `content` feature. It allows applying migrations
//! where the SQL script is loaded or generated dynamically within the application,
//! rather than read from files. Each migration needs a unique ID.
//!
//! # Usage
//!
//! ```no_run
//! # #[cfg(feature = "content")]
//! # async fn run() -> Result<(), Box<dyn std::error::Error>> {
//! use libsql_migration::{content::migrate, errors::LibsqlContentMigratorError, util::MigrationResult};
//! use libsql::Builder;
//!
//! // Ensure the `content` feature is enabled and default features disabled in Cargo.toml
//! // [dependencies]
//! // libsql_migration = { version = "...", default-features = false, features = ["content"] }
//!
//! let db = Builder::new_local("my_database.db").build().await.unwrap();
//! let conn = db.connect().unwrap();
//!
//! let migration_id = "0001_create_users_content".to_string();
//! let migration_sql = "CREATE TABLE IF NOT EXISTS users_from_content (id INTEGER PRIMARY KEY);".to_string();
//!
//! match migrate(&conn, migration_id.clone(), migration_sql).await {
//! Ok(MigrationResult::Executed) => println!("Content migration '{}' applied successfully.", migration_id),
//! Ok(MigrationResult::AlreadyExecuted) => println!("Content migration '{}' was already applied.", migration_id),
//! Err(e) => eprintln!("Content migration '{}' failed: {}", migration_id, e),
//! }
//! # Ok(())
//! # }
//! ```
use crateLibsqlContentMigratorError;
use crate;
use Connection;
pub async