forked from celsodantas/protokoll
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add scope_by generator and update README
- Loading branch information
Showing
7 changed files
with
59 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
require 'rails/generators' | ||
|
||
module Protokoll | ||
module Generators | ||
module Migration | ||
class ScopeByGenerator < ::Rails::Generators::Base | ||
|
||
include Rails::Generators::Migration | ||
|
||
desc "Generate protokoll's scope_by migration" | ||
def create_migration_file | ||
migration_name = "add_scope_by_to_custom_auto_increments.rb" | ||
migration_template migration_name, File.join('db', 'migrate', migration_name) | ||
end | ||
|
||
def self.source_root | ||
@source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'templates')) | ||
end | ||
|
||
def self.next_migration_number(path) | ||
Time.now.utc.strftime("%Y%m%d%H%M%S") | ||
end | ||
end | ||
end | ||
end | ||
end |
12 changes: 12 additions & 0 deletions
12
lib/generators/protokoll/migration/templates/add_scope_by_to_custom_auto_increments.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class AddScopeByToCustomAutoIncrements < ActiveRecord::Migration | ||
def up | ||
add_column :custom_auto_increments, :counter_model_scope, :string | ||
add_index :custom_auto_increments, [:counter_model_name, :counter_model_scope], | ||
:unique => true, :name => :counter_model_name_scope | ||
end | ||
|
||
def down | ||
remove_index :custom_auto_increments, name: :counter_model_name_scope | ||
remove_column :custom_auto_increments, :counter_model_scope, :string | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
test/dummy/db/migrate/20160310030821_add_scope_by_to_custom_auto_increments.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class AddScopeByToCustomAutoIncrements < ActiveRecord::Migration | ||
def up | ||
add_column :custom_auto_increments, :counter_model_scope, :string | ||
add_index :custom_auto_increments, [:counter_model_name, :counter_model_scope], | ||
:unique => true, :name => :counter_model_name_scope | ||
end | ||
|
||
def down | ||
remove_index :custom_auto_increments, name: :counter_model_name_scope | ||
remove_column :custom_auto_increments, :counter_model_scope, :string | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters