ariga / atlas

Manage your database schema as code
https://atlasgo.io
Apache License 2.0
6.02k stars 269 forks source link

File level transaction mode does not work when creating replication slots for Postgres #2057

Closed mjwwit closed 1 year ago

mjwwit commented 1 year ago

I'm having trouble applying the following migration:

-- atlas:txmode none

SELECT * FROM pg_create_logical_replication_slot('test_slot_decoderbufs', 'decoderbufs');

As you can see I am using file level transaction mode. This feature was seemingly introduced specifically to fix this exact issue (#1414). However, if this migration is applied using migrate apply, the following error is thrown: cannot create logical replication slot in transaction that has performed writes. This error appears to indicate that the statement is still being executed inside of a transaction.

I can only get this migration to run by explicitly setting --tx-mode "none" for all pending migrations, which I'd really like to avoid.

I am not sure if this is a regression or if it was never truly fixed to begin with.

a8m commented 1 year ago

Thanks for reporting this issue, @mjwwit. Unfortunately, I wasn't able to reproduce this as you can see below:

image

(I've tried on pg_create_logical_replication_slot as well).

Can you please share an example that reproduces this? A simple migration directory + a few pending files that one of them is tagged with txmode: none. Note, file directives must be detached from statements with double new lines.

mjwwit commented 1 year ago

How odd, might it have something to do with my use of the golang-migrate format migrations? Because your simple example does not work for me:

image

I am using atlas version v0.14.1-662f6d9-canary by the way.

a8m commented 1 year ago

Users that use golang-migrate format use the golang-migrate for migration execution. If you're using Atlas for executing the migration files, you should use its default format. The other migration tools/formats are not aware of these directives.

Sorry for the confusion, and I'm pretty sure this will solve your issue 😃

mjwwit commented 1 year ago

It does solve the issue, thanks for the clarification.