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),
sha256: String,
)
}
Constructors
-
Migration( path: String, timestamp: timestamp.Timestamp, name: String, queries_up: List(String), queries_down: List(String), sha256: String, )
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))
Values
pub fn check_name(name: String) -> Result(String, MigrationError)
Check that the provided name is a valid migration name.
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 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),
timestamp: timestamp.Timestamp,
name: String,
) -> Result(Migration, MigrationError)
Merge multiple migrations into a single one, concatenating their up and down queries. The resulting migration will have an empty path and sha256 hash. The provided timestamp and name will be used for the resulting migration.
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.