glimr/db/gen/migrate/snapshot

Migration Snapshot

Handles schema snapshots for migration diffing. Snapshots capture the current state of table schemas and are stored as JSON between migration runs to detect changes.

Types

Snapshot of a single column’s properties including name, type, nullability, and whether it has a default value.

pub type ColumnSnapshot {
  ColumnSnapshot(
    name: String,
    column_type: String,
    nullable: Bool,
    has_default: Bool,
  )
}

Constructors

  • ColumnSnapshot(
      name: String,
      column_type: String,
      nullable: Bool,
      has_default: Bool,
    )

Snapshot of all table schemas, stored as JSON between runs. Used to detect what has changed since the last migration.

pub type Snapshot {
  Snapshot(tables: dict.Dict(String, TableSnapshot))
}

Constructors

Snapshot of a single table’s column definitions.

pub type TableSnapshot {
  TableSnapshot(columns: List(ColumnSnapshot))
}

Constructors

Values

pub fn build(tables: List(schema_parser.Table)) -> Snapshot

Build a new snapshot from a list of parsed Table schemas.

pub fn column_type_to_string(
  col_type: schema_parser.ColumnType,
) -> String

Convert a ColumnType to its string representation for snapshots.

pub fn load(path: String) -> Snapshot

Load the schema snapshot from a JSON file. Returns an empty snapshot if the file doesn’t exist or can’t be parsed.

pub fn merge(old: Snapshot, new: Snapshot) -> Snapshot

Merge new snapshot into old snapshot (used when filtering by model). Tables in the new snapshot will overwrite those in the old snapshot, but tables only in the old snapshot are preserved.

pub fn save(path: String, snapshot: Snapshot) -> Result(Nil, Nil)

Save a snapshot to a JSON file.

Search Document