diff --git a/src/avram/tasks/gen/migration.cr b/src/avram/tasks/gen/migration.cr index 815d4ccfc..1c257ea66 100644 --- a/src/avram/tasks/gen/migration.cr +++ b/src/avram/tasks/gen/migration.cr @@ -3,19 +3,18 @@ require "./migration_generator" class Gen::Migration < LuckyTask::Task summary "Generate a new migration" help_message <<-TEXT - Generate a new migration using the passed in migration name. + Generate a new migration using the passed in migration file name. - The migration name must be CamelCase. No other options are available. + The migration file name can be underscore or CamelCase. No other options are available. Examples: - lucky gen.migration CreateUsers + lucky gen.migration create_users lucky gen.migration AddAgeToUsers - lucky gen.migration MakeUserNameOptional TEXT - positional_arg :migration_name, "The migration class name", format: /^[A-Z]/ + positional_arg :migration_file_name, "The migration file name" Habitat.create do setting io : IO = STDOUT @@ -29,7 +28,7 @@ class Gen::Migration < LuckyTask::Task def call Avram::Migrator.run do - Avram::Migrator::MigrationGenerator.new(name: migration_name, io: output).generate + Avram::Migrator::MigrationGenerator.new(name: migration_file_name, io: output).generate end end end diff --git a/src/avram/tasks/gen/migration_generator.cr b/src/avram/tasks/gen/migration_generator.cr index 2b3771a58..d5cdfe096 100644 --- a/src/avram/tasks/gen/migration_generator.cr +++ b/src/avram/tasks/gen/migration_generator.cr @@ -18,7 +18,7 @@ class Avram::Migrator::MigrationGenerator end def generate(@_version = @_version) - ensure_camelcase_name + @name = name.camelcase make_migrations_folder_if_missing ensure_unique File.write(file_path, contents) @@ -51,16 +51,6 @@ class Avram::Migrator::MigrationGenerator end.chomp end - private def ensure_camelcase_name - if name.camelcase != name - raise <<-ERROR - Migration must be in camel case. - - #{green_arrow} Try this instead: #{"lucky gen.migration #{name.camelcase}".colorize(:green)} - ERROR - end - end - private def ensure_unique d = Dir.new(Dir.current + "/db/migrations") d.each_child { |x|