gloo/migration

DDL migration DSL. Each migration has a version (integer timestamp), a name, an up SQL string, and an optional down SQL string.

Build columns using the DB-specific modules (gloo/pg, gloo/sqlite) then pass them to create_table, add_column, etc. gloo/migration itself carries no column-type knowledge.

Types

pub type Column {
  Column(
    name: String,
    type_sql: String,
    nullable: Bool,
    default: option.Option(String),
    primary_key: Bool,
    unique: Bool,
  )
}

Constructors

  • Column(
      name: String,
      type_sql: String,
      nullable: Bool,
      default: option.Option(String),
      primary_key: Bool,
      unique: Bool,
    )
pub type Migration {
  Migration(
    version: Int,
    name: String,
    up: String,
    down: option.Option(String),
  )
}

Constructors

  • Migration(
      version: Int,
      name: String,
      up: String,
      down: option.Option(String),
    )

Values

pub fn add_column(
  version v: Int,
  name n: String,
  table table: String,
  column col: Column,
) -> Migration
pub fn add_constraint(
  version v: Int,
  name n: String,
  table table: String,
  constraint constraint: String,
  definition definition: String,
) -> Migration
pub fn change_column(
  version v: Int,
  name n: String,
  table table: String,
  column_name col: String,
  new_type new_type: String,
) -> Migration
pub fn column(name: String, type_sql: String) -> Column

Low-level constructor that takes a raw SQL type string. Prefer gloo/pg.column or gloo/sqlite.column for type-safe construction.

pub fn create_index(
  version v: Int,
  name n: String,
  index index: String,
  table table: String,
  columns cols: List(String),
) -> Migration
pub fn create_table(
  version v: Int,
  name n: String,
  table table: String,
  columns cols: List(Column),
) -> Migration
pub fn default(col: Column, expr: String) -> Column
pub fn drop_column(
  version v: Int,
  name n: String,
  table table: String,
  column_name col: String,
) -> Migration
pub fn drop_constraint(
  version v: Int,
  name n: String,
  table table: String,
  constraint constraint: String,
) -> Migration
pub fn drop_index(
  version v: Int,
  name n: String,
  index index: String,
) -> Migration
pub fn drop_table(
  version v: Int,
  name n: String,
  table table: String,
) -> Migration
pub fn execute_sql(
  version v: Int,
  name n: String,
  up up: String,
  down down: String,
) -> Migration
pub fn new(
  version v: Int,
  name n: String,
  up u: String,
) -> Migration
pub fn not_null(col: Column) -> Column
pub fn primary_key(col: Column) -> Column
pub fn rename_column(
  version v: Int,
  name n: String,
  table table: String,
  from from: String,
  to to: String,
) -> Migration
pub fn rename_table(
  version v: Int,
  name n: String,
  from from: String,
  to to: String,
) -> Migration
pub fn unique(col: Column) -> Column
pub fn with_down(m: Migration, down: String) -> Migration
Search Document