diff --git a/src/cigogne.gleam b/src/cigogne.gleam index c9fa22a..4d7718f 100644 --- a/src/cigogne.gleam +++ b/src/cigogne.gleam @@ -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:)) @@ -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"), ) }) @@ -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"), ) }) diff --git a/src/cigogne/migration.gleam b/src/cigogne/migration.gleam index a3a7e3f..1daa399 100644 --- a/src/cigogne/migration.gleam +++ b/src/cigogne/migration.gleam @@ -170,8 +170,9 @@ 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) @@ -179,7 +180,7 @@ pub fn match_migrations( ) Ok(match) } - False -> Error(FileHashChanged(migration |> to_fullname())) + False, False -> Error(FileHashChanged(migration |> to_fullname())) } } Error(_) -> Error(MigrationNotFound(migration |> to_fullname())) diff --git a/test_libs/my_app/priv/migs/20250913102045-remove_lib.sql b/test_libs/my_app/priv/migs/20250913102045-remove_lib.sql index 7a10559..038fe23 100644 --- a/test_libs/my_app/priv/migs/20250913102045-remove_lib.sql +++ b/test_libs/my_app/priv/migs/20250913102045-remove_lib.sql @@ -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 \ No newline at end of file +--- migration:end