cigogne
Types
The MigrationEngine contains all the data required to apply and roll back migrations. Checks are run in order to make sure the database is in a correct state. When you have a MigrationEngine, you can be sure that your database is in a correct state to apply migrations.
pub opaque type MigrationEngine
Values
pub fn apply_migration(
engine: MigrationEngine,
migration: types.Migration,
) -> Result(Nil, types.MigrateError)
Apply a migration to the database.
pub fn apply_migration_if_not_applied(
engine: MigrationEngine,
migration: types.Migration,
) -> Result(Nil, types.MigrateError)
Apply a migration to the database if it hasn’t been applied.
pub fn apply_next_migration(
engine: MigrationEngine,
) -> Result(Nil, types.MigrateError)
Apply the next migration that wasn’t applied yet.
pub fn create_migration_engine(
config: types.Config,
) -> Result(MigrationEngine, types.MigrateError)
Creates a MigrationEngine from a configuration. This function will try to connect to the database, create the migrations table if it doesn’t exist. Then it will fetch the applied migrations and the existing migration files and check hashes do match.
pub fn create_zero_migration(
name: String,
queries_up: List(String),
queries_down: List(String),
) -> types.Migration
Create a “zero” migration that should be applied before the user’s migrations
pub const default_config: types.Config
The default configuration you can use to get a MigrationEngine. This configuration uses the DATABASE_URL envvar to connect to the database, uses the ‘default’ schema, keeps migration data in the ‘_migrations’ table looks for migrations in ‘priv/migrations/*.sql’ files and generates a schema file in the sql.schema file
pub fn execute_migrations_to_last(
engine: MigrationEngine,
) -> Result(Nil, types.MigrateError)
Apply migrations until we reach the last defined migration.
pub fn execute_n_migrations(
engine: MigrationEngine,
count: Int,
) -> Result(Nil, types.MigrateError)
Apply or roll back the next count
migrations.
pub fn get_migrations(
engine: MigrationEngine,
) -> Result(List(types.Migration), types.MigrateError)
Get all defined migrations in your project.
pub fn get_schema(
engine: MigrationEngine,
) -> Result(String, types.MigrateError)
Get details about the schema of the database.
pub fn is_zero_migration(migration: types.Migration) -> Bool
Checks if a migration is a zero migration (has been created with create_zero_migration)
pub fn new_migration(
migrations_folder: String,
name: String,
) -> Result(Nil, types.MigrateError)
Create a new migration file in the specified folder with the provided name.
pub fn print_error(error: types.MigrateError) -> Nil
Print a MigrateError to the standard error stream.
pub fn roll_back_migration(
engine: MigrationEngine,
migration: types.Migration,
) -> Result(Nil, types.MigrateError)
Roll back a migration from the database.
pub fn roll_back_previous_migration(
engine: MigrationEngine,
) -> Result(Nil, types.MigrateError)
Roll back the last applied migration.
pub fn update_schema(
engine: MigrationEngine,
) -> Result(Nil, types.MigrateError)
Create or update a schema file if the engine configuration permits it.