Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add skip_transaction support to single migrations #1021

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

pauldps
Copy link

@pauldps pauldps commented Apr 11, 2024

This adds support for calling skip_transaction true inside the migrate method in a single migration so that the statements are run outside the default transaction.

Motivation / real example (CockroachDB does not allow that ALTER TABLE inside a transaction):

class ChangeUsernameInUsers::V20240411185756 < Avram::Migrator::Migration::V1
  def migrate
    skip_transaction true

    # Sized strings require experimental flag
    # https://www.cockroachlabs.com/docs/stable/collate#details
    execute "SET enable_experimental_alter_column_type_general = true;"

    # Case-insensitive collation (CockroachDB does not support CITEXT)
    execute "ALTER TABLE users ALTER username TYPE STRING(30) COLLATE \"en-US-u-ks-level2\";"
  end

  def rollback
    # no-op since it alters existing column in backwards-compatible way
  end
end

▸ Error message unimplemented: ALTER COLUMN TYPE is not supported inside a transaction. Query ALTER TABLE users ALTER COLUMN username TYPE STRING(30) COLLATE "en-US-u-ks-level2";.

TODO:

  • tests - my local setup isn't ideal (I don't run Docker) so I'm not able to run tests locally atm
  • cleanup

@pauldps pauldps changed the title Add skip_migration support to single migrations Add skip_transaction support to single migrations Apr 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant