Permalink
Browse files

Generate ActiveRecord 5.0 style migrations

Test that ActiveRecord::Migration responds to .[] before using
.current_version, as .current_version is used in previous versions
but for different purposes.
  • Loading branch information...
adam12 authored and ujifgc committed Aug 6, 2017
1 parent 8c9c6b3 commit f45566335f0b676d9dc2a8e7de68babc2274ff44
Showing with 13 additions and 0 deletions.
  1. +13 −0 padrino-gen/lib/padrino-gen/generators/components/orms/activerecord.rb
@@ -152,7 +152,19 @@ def create_model_file(name, options={})
create_file(model_path, model_contents,:skip => true)
end
if defined?(ActiveRecord::Migration) && ActiveRecord::Migration.respond_to?(:[])
AR_MIGRATION = (<<-MIGRATION) unless defined?(AR_MIGRATION)
class !FILECLASS! < ActiveRecord::Migration[#{ActiveRecord::Migration.current_version}]
def self.up
!UP!
end
def self.down
!DOWN!
end
end
MIGRATION
else
AR_MIGRATION = (<<-MIGRATION) unless defined?(AR_MIGRATION)
class !FILECLASS! < ActiveRecord::Migration
def self.up
@@ -164,6 +176,7 @@ def self.down
end
end
MIGRATION
end
AR_MODEL_UP_MG = (<<-MIGRATION).gsub(/^/,' ') unless defined?(AR_MODEL_UP_MG)
create_table :!TABLE! do |t|

0 comments on commit f455663

Please sign in to comment.