Add migration to generator

This commit is contained in:
Dzmitry Plashchynski
2015-03-06 22:08:48 +02:00
parent 0f32f8a5a4
commit 20135b87ae
5 changed files with 35 additions and 3 deletions

View File

@@ -1,12 +1,26 @@
require 'rails/generators'
require 'rails/generators/migration'
require 'rails/generators/active_record'
module Crono
module Generators
class InstallGenerator < ::Rails::Generators::Base
include Rails::Generators::Migration
def self.next_migration_number(path)
ActiveRecord::Generators::Base.next_migration_number(path)
end
desc "Installs crono and generates the necessary configuration files"
source_root File.expand_path("../templates", __FILE__)
def copy_config
template 'cronotab.rb.erb', 'config/cronotab.rb'
end
def create_migrations
migration_template 'migrations/create_crono_jobs.rb', 'db/migrate/create_crono_jobs.rb'
end
end
end
end

View File

@@ -0,0 +1,15 @@
class CreateActiveAdminComments < ActiveRecord::Migration
def self.up
create_table :crono_jobs do |t|
t.string :job_id, null: false
t.text :log
t.datetime :last_performed_at
t.timestamps
end
add_index :crono_jobs, [:job_id]
end
def self.down
drop_table :crono_jobs
end
end