ciallo-migrate

    Schema diff, SHA-256 drift detection, transactional migrations, and idempotent seeds for unmbt/ciallo-orm

    migrate
    sql
    schema
    sha256
    ciallo
    Download zip
    Author
    Version
    0.1.1
    License
    MIT
    Last updated
    13 hours ago
    Downloads
    11

    #unmbt/ciallo-migrate

    Schema diffing (up.sql / down.sql), pure-MoonBit SHA-256 checksum drift detection (_ciallo_migrations), transactional migration application, and idempotent seeding for unmbt/ciallo-orm.

    MigrateError

    pub(all) suberror MigrateError {
    ChecksumDrift(version~ : String, expected~ : String, actual~ : String)
    ApplyFailed(version~ : String, message~ : String)
    RollbackFailed(version~ : String, message~ : String)
    } derive(Eq,
    Debug
    )

    ColumnDef

    pub(all) struct ColumnDef {
    name : String
    sql_type : String
    nullable : Bool
    primary_key : Bool
    auto_increment : Bool
    unique : Bool
    default_expr : String?
    } derive(Eq,
    Debug
    ,
    FromJson
    ,
    ToJson
    )

    列定义快照(供 Schema Diff 与 DB-first 逆向建模共用)

    ColumnDef::ColumnDef

    fn ColumnDef::ColumnDef(name~ : String, sql_type~ : String, nullable? : Bool, primary_key? : Bool, auto_increment? : Bool, unique? : Bool, default_expr? : String) -> ColumnDef

    MigrationFile

    pub(all) struct MigrationFile {
    version : String
    name : String
    up_sql : String
    down_sql : String?
    } derive(Eq,
    Debug
    )

    MigrationFile::checksum

    fn MigrationFile::checksum(self : MigrationFile) -> String

    MigrationRecord

    pub(all) struct MigrationRecord {
    version : String
    name : String
    checksum_sha256 : String
    applied_at_ms : Int64
    } derive(Eq,
    Debug
    )

    MigrationStatusEntry

    pub(all) struct MigrationStatusEntry {
    version : String
    name : String
    applied : Bool
    checksum_matches : Bool
    } derive(Eq,
    Debug
    )

    SchemaDiffResult

    pub(all) struct SchemaDiffResult {
    up_sql : String
    down_sql : String
    has_changes : Bool
    } derive(Eq,
    Debug
    )

    SchemaSnapshot

    完整数据库 Schema 快照

    SchemaSnapshot::empty

    SchemaSnapshot::to_json

    automatically derived

    SeedFile

    pub(all) struct SeedFile {
    name : String
    sql : String
    } derive(Eq,
    Debug
    )

    TableDef

    表定义快照

    apply_migrations

    async fn apply_migrations(driver : &
    SqlDriver
    , migrations : Array[MigrationFile]) -> Array[MigrationRecord]

    事务化顺序执行未应用的迁移脚本(执行前先校验历史防漂移,失败自动回滚)

    diff_schemas

    比较新旧 SchemaSnapshot,按指定方言生成确定性 up.sql 与 down.sql 迁移脚本

    migration_status

    async fn migration_status(driver : &
    SqlDriver
    , migrations : Array[MigrationFile]) -> Array[MigrationStatusEntry]

    查询所有迁移脚本的当前状态(是否已执行及校验和是否一致)

    run_seeds

    async fn run_seeds(driver : &
    SqlDriver
    , seeds : Array[SeedFile]) -> Array[String]

    幂等种子执行器:按种子名记录 _ciallo_seeds,重复执行安全跳过已运行种子

    sha256_bytes_hex

    fn sha256_bytes_hex(data : Bytes) -> String

    纯 MoonBit FIPS 180-4 SHA-256(零第三方依赖,用于迁移脚本防漂移校验和)

    sha256_str_hex

    fn sha256_str_hex(input : StringView) -> String

    verify_migrations

    async fn verify_migrations(driver : &
    SqlDriver
    , migrations : Array[MigrationFile]) -> Unit

    校验目标库已执行迁移脚本的 SHA-256 校验和,精准拦截历史脚本漂移篡改