no migration will be added if model and column is exists
This commit is contained in:
parent
b93bd80c3c
commit
7443311fb4
|
@ -27,6 +27,7 @@ Gem::Specification.new do |s|
|
|||
# debugging
|
||||
# s.add_development_dependency 'debugger'
|
||||
s.add_development_dependency 'pry'
|
||||
s.add_development_dependency 'pry-nav'
|
||||
|
||||
s.files = `git ls-files`.split("\n")
|
||||
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
||||
|
|
|
@ -22,6 +22,12 @@ RUBY
|
|||
|
||||
private
|
||||
|
||||
def column_exists?
|
||||
table_name.singularize.humanize.constantize.column_names.include?(column_name.to_s)
|
||||
rescue NameError
|
||||
false
|
||||
end
|
||||
|
||||
def model_exists?
|
||||
File.exists?(File.join(destination_root, model_path))
|
||||
end
|
||||
|
|
|
@ -11,7 +11,9 @@ module ActiveRecord
|
|||
source_root File.expand_path("../templates", __FILE__)
|
||||
|
||||
def copy_aasm_migration
|
||||
if model_exists?
|
||||
if column_exists?
|
||||
puts "Both model and column exists"
|
||||
elsif model_exists?
|
||||
migration_template "migration_existing.rb", "db/migrate/add_#{column_name}_to_#{table_name}.rb"
|
||||
else
|
||||
migration_template "migration.rb", "db/migrate/aasm_create_#{table_name}.rb"
|
||||
|
|
|
@ -20,6 +20,10 @@ ActiveRecord::Migration.suppress_messages do
|
|||
t.string "right"
|
||||
end
|
||||
|
||||
ActiveRecord::Migration.create_table "jobs", :force => true do |t|
|
||||
t.string "state"
|
||||
end
|
||||
|
||||
%w(validators multiple_validators workers invalid_persistors multiple_invalid_persistors silent_persistors multiple_silent_persistors).each do |table_name|
|
||||
ActiveRecord::Migration.create_table table_name, :force => true do |t|
|
||||
t.string "name"
|
||||
|
|
|
@ -43,5 +43,11 @@ if defined?(ActiveRecord)
|
|||
assert_migration "db/migrate/add_state_to_jobs.rb"
|
||||
end
|
||||
|
||||
it "dont add column if column is already exists" do
|
||||
require 'models/active_record/job.rb'
|
||||
load_schema
|
||||
run_generator %w(job state)
|
||||
assert_no_migration "db/migrate/add_state_to_jobs.rb"
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
class Job < ActiveRecord::Base
|
||||
include AASM
|
||||
end
|
|
@ -13,6 +13,7 @@ SEQUEL_DB = defined?(JRUBY_VERSION) ? 'jdbc:sqlite::memory:' : 'sqlite:/'
|
|||
|
||||
def load_schema
|
||||
require 'logger'
|
||||
require 'yaml'
|
||||
config = YAML::load(IO.read(File.dirname(__FILE__) + '/database.yml'))
|
||||
ActiveRecord::Base.logger = Logger.new(File.dirname(__FILE__) + "/debug.log")
|
||||
ActiveRecord::Base.establish_connection(config['sqlite3'])
|
||||
|
|
Loading…
Reference in New Issue