Skip to content

Commit

Permalink
Resolve type before using it in migrations (#700)
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewmcgarvey authored Jul 9, 2021
1 parent d43f036 commit e4d8d20
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 8 deletions.
8 changes: 4 additions & 4 deletions src/avram/migrator/alter_table_statement.cr
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,16 @@ class Avram::Migrator::AlterTableStatement
end

macro add(type_declaration, index = false, using = :btree, unique = false, default = nil, fill_existing_with = nil, **type_options)
{% type = type_declaration.type %}
{% type = type_declaration.type.resolve %}
{% nilable = false %}
{% array = false %}
{% should_fill_existing = (!(fill_existing_with == nil)) && (fill_existing_with != :nothing) %}

{% if type.is_a?(Union) %}
{% type = type.types.first %}
{% if type.nilable? %}
{% type = type.union_types.reject(&.==(Nil)).first %}
{% nilable = true %}
{% end %}
{% if type.is_a?(Generic) %}
{% if type < Array %}
{% type = type.type_vars.first %}
{% array = true %}
{% end %}
Expand Down
8 changes: 4 additions & 4 deletions src/avram/migrator/create_table_statement.cr
Original file line number Diff line number Diff line change
Expand Up @@ -87,14 +87,14 @@ class Avram::Migrator::CreateTableStatement
end

macro add(type_declaration, default = nil, index = false, unique = false, using = :btree, **type_options)
{% type = type_declaration.type %}
{% type = type_declaration.type.resolve %}
{% nilable = false %}
{% array = false %}
{% if type.is_a?(Union) %}
{% type = type.types.first %}
{% if type.nilable? %}
{% type = type.union_types.reject(&.==(Nil)).first %}
{% nilable = true %}
{% end %}
{% if type.is_a?(Generic) %}
{% if type < Array %}
{% type = type.type_vars.first %}
{% array = true %}
{% end %}
Expand Down

0 comments on commit e4d8d20

Please sign in to comment.