Skip to content

Fixing the varchar size migration bug (Issue #150)#694

Open
Jatanasio wants to merge 1 commit intoash-project:mainfrom
Jatanasio:main
Open

Fixing the varchar size migration bug (Issue #150)#694
Jatanasio wants to merge 1 commit intoash-project:mainfrom
Jatanasio:main

Conversation

@Jatanasio
Copy link

Contributor checklist

Leave anything that you believe does not apply unchecked.

  • [x ] I accept the AI Policy, or AI was not used in the creation of this PR.
  • [ x] Bug fixes include regression tests
  • Chores
  • Documentation changes
  • Features include unit/acceptance tests
  • Refactoring
  • Update dependencies

So the bug as far as I was able to find was due to the migration size emission logic being nested in an if statement that does a snapshot comparison of the difference of the :size in the old and new migrations. The size emission logic relied on there being a difference detected within the two snapshots, so instances with attributes mapped to :text without a size such as with the :string in the bug example provided transitioning to a sized-type such as varchar would not process it properly. So it would simply skip that portion of the alter_opts function altogether.

The new logic checks if the new migration snapshot has a size attribute, then checks if it is different from the old snapshot size. If it does not have a difference in size values, or if the old migration snapshot does not have a size attribute to compare, it then checks if the current migration contains an attribute that should have a size connected to it and if it does then it updates the size column.

I also added various tests for the new logic; such as, updating existing string columns, changing sizes from a varchar that already has a size, if you're trying to update only specific strings among many they don't all get the update, etc.

@Jatanasio Jatanasio changed the title Fixing the varchar size migration bug (Issue #150 in ash_postgres) Fixing the varchar size migration bug (Issue #150) Feb 13, 2026
describe "varchar migration_types on modify" do
setup do
on_exit(fn ->
File.rm_rf!("test_snapshots_path")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated the testing patterns in this file, please take a look and adopt them to this test 🙇

@zachdaniel
Copy link
Contributor

I don't think the approach here is quite right. I believe what we need to do is add the size option if one of the following is true:

  • the size is changing
  • the type is changing

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.

2 participants