Migration not keeping varchar size information

Not sure if I found a bug or not. But if I have this attribute in my migration:
attribute :blibs, :string
attribute :blibs, :string
and then, after generating the first migration, add this:
migration_types blibs: {:varchar, 255}
migration_types blibs: {:varchar, 255}
Ash will generate this migration:
def up do
alter table(:users) do
modify :blibs, :varchar
end
end

def down do
alter table(:users) do
modify :blibs, :text
end
end
def up do
alter table(:users) do
modify :blibs, :varchar
end
end

def down do
alter table(:users) do
modify :blibs, :text
end
end
This migration doesn't contain any information about the varchar size in it. Now, if I actually have both the attribute and the migration_types in the resource before the first migration being generated, I will get the correct migration:
def up do
alter table(:users) do
add :blibs, :varchar, size: 255
end
end

def down do
alter table(:users) do
remove :blibs
end
end

def up do
alter table(:users) do
add :blibs, :varchar, size: 255
end
end

def down do
alter table(:users) do
remove :blibs
end
end

4 Replies
ZachDaniel
ZachDaniel2y ago
I think similar to the other issue you want to ignore this field on one of the resources.
Blibs
BlibsOP2y ago
There is only one resource in this case
ZachDaniel
ZachDaniel2y ago
Oh…interesting Can you make an issue on ash_postgres for this? And ideally a test in the migration generator test illustrating this behavior
Blibs
BlibsOP2y ago
GitHub
varchar size info for a column that already exists is missing from ...
Describe the bug Adding a specific size for a string/varchar field will not show in the migration file if the column already exists from another migration. To Reproduce First create the following r...

Did you find this page helpful?