Commit c63eeed5 by ivan Lan

Add migrations generator

parent 1896df9a
class CreateMediaObjsAndMediaAttachments < ActiveRecord::Migration[5.1]
def change
create_table :media_objs do |t|
t.attachment :file
t.string :type
t.references :creator, polymorphic: true
t.timestamps
end
create_table :media_attachments do |t|
t.string :column_name
t.references :attached, polymorphic: true
t.references :obj
t.timestamps
end
end
end
require 'whaleback/generators/migrations_generator'
\ No newline at end of file
require "whaleback/version"
require 'paperclip'
module Whaleback
# Your code goes here...
......
require 'rails/generators/migration'
module Whaleback
module Generators
class MigrationsGenerator < Rails::Generators::Base
include Rails::Generators::Migration
desc 'Copy whaleback migrations to your application.'
def self.next_migration_number(dir)
sleep 1
Time.now.utc.strftime("%Y%m%d%H%M%S")
end
source_root File.expand_path("../../../../db/migrate", __FILE__)
def copy_migrations
# Use sort() to order the migrations by seq
# Use [2..-1] to delete the seq
Dir[ File.join(self.class.source_root, '*.rb') ].sort.each { |f|
copy_migration File.basename(f, '.rb')
}
end
protected
def copy_migration(filename)
if self.class.migration_exists?("db/migrate", "#{filename[2..-1]}")
say_status("skipped", "Migration #{filename[2..-1]} already exists")
else
migration_template "#{filename}.rb", "db/migrate/#{filename[2..-1]}.rb"
end
end
end
end
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment