lucky icon indicating copy to clipboard operation
lucky copied to clipboard

Task gen.model doesn't honor default_columns of BaseModel

Open richarddewit opened this issue 5 years ago • 1 comments

Following the docs, I've changed the default_columns of the BaseModel, mainly to change the ID column type from Int64 to UUID:

abstract class BaseModel < Avram::Model
  macro default_columns
    # Sets the type for `id` to `UUID`
    primary_key id : UUID
    # adds the `created_at` and `updated_at` columns
    timestamps
  end

  def self.database
    AppDatabase
  end
end

Now after running lucky gen.model Todo, this happens:

Expected migration

  def migrate
    create table_for(Todo) do
      primary_key id : UUID
      add_timestamps
    end
  end

Actual migration

  def migrate
    create table_for(Todo) do
      primary_key id : Int64       # <-- the default type
      add_timestamps
    end
  end

richarddewit avatar Sep 26 '19 12:09 richarddewit

This may be tricky to do without a lot of changes. For now you'll have to manually change it to UUID in the migrations.

Maybe what we could do is add a setting to the migration generator that tells it to default to UUID, but that will require reworking some things in CLI. I'll see what we can do to improve this but it might be a bit. Thanks for reporting!

paulcsmith avatar Sep 26 '19 14:09 paulcsmith