cigogne/migration

Types

Migrations are often generated by reading migration files. However, we allow you to create your own Migrations.

pub type Migration {
  Migration(
    path: String,
    timestamp: timestamp.Timestamp,
    name: String,
    queries_up: List(String),
    queries_down: List(String),
    options: MigrationOptions,
    sha256: String,
  )
}

Constructors

Errors that can happen when manipulating migrations.

pub type MigrationError {
  NameTooLongError(name: String)
  NothingToMergeError
  MigrationNotFound(fullname: String)
  FileHashChanged(fullname: String)
  CompoundError(errors: List(MigrationError))
}

Constructors

  • NameTooLongError(name: String)
  • NothingToMergeError
  • MigrationNotFound(fullname: String)
  • FileHashChanged(fullname: String)
  • CompoundError(errors: List(MigrationError))

Options for a migration. Options are activated by adding flags after “— migration:up”

pub type MigrationOptions {
  MigrationOptions(disable_transaction: Bool)
}

Constructors

  • MigrationOptions(disable_transaction: Bool)

Values

pub fn check_name(name: String) -> Result(String, MigrationError)

Check that the provided name is a valid migration name.

pub fn chunk_by_transaction_option(
  migrations: List(Migration),
) -> List(#(Bool, List(Migration)))

Chunk a list of migrations into multiple lists depending on their disable_transaction option

pub fn compare(
  migration_a: Migration,
  migration_b: Migration,
) -> order.Order

Compare two migrations.

pub fn create_zero_migration(
  name: String,
  queries_up: List(String),
  queries_down: List(String),
) -> Migration

Create a “zero” migration that should be applied before the user’s migrations.

pub const default_migration_options: MigrationOptions
pub fn find_unapplied(
  migrations: List(Migration),
  applied: List(Migration),
) -> List(Migration)

Find migrations that are in migrations but not in applied.

pub fn get_error_message(error: MigrationError) -> String
pub fn is_zero_migration(migration: Migration) -> Bool

Checks if a migration is a zero migration (has been created with create_zero_migration).

pub fn match_migrations(
  elements: List(Migration),
  matches: List(Migration),
  no_hash_check: Bool,
) -> Result(List(Migration), MigrationError)

Match a list of migrations usually from the database with a list of migration usually from the filesystem and ensure their hashes match. This returns migrations from the second list as they are usually more detailed. This fails it a migration is not found or if a hash does not match.

pub fn merge(
  migrations: List(Migration),
) -> Result(
  List(#(List(String), List(String), MigrationOptions)),
  MigrationError,
)

Merge multiple migrations into a list of queries up, queries down and disable_transaction.

pub fn new(
  folder: String,
  name: String,
  timestamp: timestamp.Timestamp,
) -> Result(Migration, MigrationError)

Create a new migration with the given folder, name and timestamp. The migration will have empty up and down queries and an empty sha256 hash.

pub fn set_folder(
  migration: Migration,
  folder: String,
) -> Migration

Set the folder of a migration, updating its path accordingly.

pub fn to_fullname(migration: Migration) -> String

Get the full name of a migration, which is its timestamp followed by its name.

Search Document