Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/cigogne.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ pub fn create_engine(
)
|> result.map_error(MigrationError),
)
io.println("")
let unapplied = migration.find_unapplied(files, applied)

Ok(MigrationEngine(db_data:, applied:, unapplied:, files:, config:))
Expand Down Expand Up @@ -478,13 +479,13 @@ pub fn apply_migrations(
database.DatabaseData(..engine.db_data, connection: transaction)
use migration <- list.try_each(migrations)

io.println("\nApplying migration " <> migration.to_fullname(migration))
io.println("Applying migration " <> migration.to_fullname(migration))
database.apply_migration_no_transaction(db_data, migration)
}
|> result.map_error(DatabaseError)
|> result.map(fn(_) {
io.println(
"Migrations applied:\n\t"
"\nMigrations applied:\n\t"
<> list.map(migrations, migration.to_fullname) |> string.join("\n\t"),
)
})
Expand All @@ -506,13 +507,13 @@ pub fn rollback_migrations(
database.DatabaseData(..engine.db_data, connection: transaction)
use migration <- list.try_each(migrations)

io.println("\nRolling back migration " <> migration.to_fullname(migration))
io.println("Rolling back migration " <> migration.to_fullname(migration))
database.rollback_migration_no_transaction(db_data, migration)
}
|> result.map_error(DatabaseError)
|> result.map(fn(_) {
io.println(
"Migrations rolled back:\n\t"
"\nMigrations rolled back:\n\t"
<> list.map(migrations, migration.to_fullname) |> string.join("\n\t"),
)
})
Expand Down
7 changes: 4 additions & 3 deletions src/cigogne/migration.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -170,16 +170,17 @@ pub fn match_migrations(
use #(migration, match_res) <- list.map(matches)
case match_res {
Ok(match) -> {
case no_hash_check || migration.sha256 == match.sha256 {
True -> {
case migration.sha256 == match.sha256, no_hash_check {
True, _ -> Ok(match)
False, True -> {
io.println(
"Warning: Hash of file "
<> to_fullname(migration)
<> " has changed, but hash check is disabled.",
)
Ok(match)
}
False -> Error(FileHashChanged(migration |> to_fullname()))
False, False -> Error(FileHashChanged(migration |> to_fullname()))
}
}
Error(_) -> Error(MigrationNotFound(migration |> to_fullname()))
Expand Down
8 changes: 4 additions & 4 deletions test_libs/my_app/priv/migs/20250913102045-remove_lib.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ drop table books;
--- 20250913102033-lib
--- 20250913083538-Test1
create table if not exists books (
id: serial primary key,
title: text,
rating: int,
id serial primary key,
title text,
rating int
);
--- 20250913091039-Test2
alter table books
add price float;
update books
set price = 26.5;
--- migration:end
--- migration:end