ameingast / postgresql-simple-migration

PostgreSQL Schema Migrations for Haskell
Other
85 stars 48 forks source link

MigrationInitialization can be noisy #12

Closed expipiplus1 closed 7 years ago

expipiplus1 commented 7 years ago

When MigrationInitialization is run when schema_migrations already exists it prints out NOTICE: relation "schema_migrations" already exists, skipping.

Perhaps I've misunderstood how to use this library, but I've got a list of MigrationCommands which I'm sequencing over during program startup, the first of which is MigrationInitialization.

ameingast commented 7 years ago

Perhaps I've misunderstood how to use this library, but I've got a list of MigrationCommands which I'm sequencing over during program startup, the first of which is MigrationInitialization.

The idea is to run the initialisation only once when you bootstrap your application the first time.

Afterwards you can use MigrationValidation to validate the database state and apply your migrations.

expipiplus1 commented 7 years ago

The idea is to run the initialisation only once when you bootstrap your application the first time.

I was hoping that the absence of schema_migrations could be an indication that this is being run for the first time.

I suppose I could always do SET LOCAL client_min_messages TO warning; in the transaction.

At the moment I can't imagine a situation where I wouldn't want to apply any remaining migrations upon discovering (with MigrationValidation) that the database isn't at the latest version.

Reading the source it seems as though the correct way to test for schema_migrations would be to run MigrationValidation MigrationInitialization.

ameingast commented 7 years ago

Reading the source it seems as though the correct way to test for schema_migrations would be to run MigrationValidation MigrationInitialization.

Exactly.

paradoxix commented 7 years ago

Checking for the existence of schema_migrations via MigrationValidation MigrationInitialization doesn't work as existsTable function seems broken. The SQL-Query select count(relname) from pg_class where relname = ? always returns a row and therefor checking the lists length always indicates the tables existence, which is wrong. The queries result (always one row) should be numerically compared to 0 not if there is a row returned.

ameingast commented 7 years ago

Thanks for the bug report!

It's fixed in 0a1a1bba081618e9575123fd5f371d997e96f154 and release 0.1.11.0.

paradoxix commented 7 years ago

That was quick, thanks!