Skip to content
Browse files

Created a generator to add a migration for bdrb_job_queues table.

  • Loading branch information...
1 parent 98435f5 commit 3c04fbca950d2b7e0f2a82732f142c660e9c23ae Seth Morabito committed
View
12 generators/bdrb_migration/USAGE
@@ -0,0 +1,12 @@
+Description:
+ Creates a migration to add the job queue table used by BackgrounDRb.
+ Pass the migration name, either CamelCased or under_scored, as an argument.
+
+Example:
+ ./script/generate bdrb_migration CreateBackgroundrbQueue
+
+ Assuming this is run at 09:00:15h on 12 September, 2008, this will create the
+ CreateBackgroundrbQueue migration in:
+
+ db/migrate/20080912090015_create_backgroundrb_queue.rb
+
View
19 generators/bdrb_migration/bdrb_migration_generator.rb
@@ -0,0 +1,19 @@
+class BdrbMigrationGenerator < Rails::Generator::NamedBase
+ def initialize(runtime_args, runtime_options = {})
+ runtime_args << 'add_bdrb_job_queue_table' if runtime_args.empty?
+ super
+ end
+
+ def manifest
+ record do |m|
+ m.migration_template 'migration.rb', 'db/migrate',
+ :assigns => { :bdrb_table_name => default_bdrb_table_name }
+ end
+ end
+
+ protected
+
+ def default_bdrb_table_name
+ ActiveRecord::Base.pluralize_table_names ? 'bdrb_job_queue'.pluralize : 'bdrb_job_queue'
+ end
+end
View
26 generators/bdrb_migration/templates/migration.rb
@@ -0,0 +1,26 @@
+class <%= class_name %> < ActiveRecord::Migration
+ def self.up
+ create_table :<%= bdrb_table_name %> do |t|
+ t.column :args, :binary
+ t.column :worker_name, :string
+ t.column :worker_method, :string
+ t.column :job_key, :string
+ t.column :taken, :int
+ t.column :finished, :int
+ t.column :timeout, :int
+ t.column :priority, :int
+ t.column :submitted_at, :datetime
+ t.column :started_at, :datetime
+ t.column :finished_at, :datetime
+ t.column :archived_at, :datetime
+ t.column :tag, :string
+ t.column :submitter_info, :string
+ t.column :runner_info, :string
+ t.column :worker_key, :string
+ end
+ end
+
+ def self.down
+ drop_table :<%= bdrb_table_name %>
+ end
+end

0 comments on commit 3c04fbc

Please sign in to comment.
Something went wrong with that request. Please try again.