-
-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from wbotelhos/extracting-migrations
Extracted tables migration to multi-files
- Loading branch information
Showing
4 changed files
with
32 additions
and
20 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
19 changes: 19 additions & 0 deletions
19
lib/generators/rating/templates/db/migrate/create_rate_table.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,19 @@ | ||
# frozen_string_literal: true | ||
|
||
class CreateRateTable < ActiveRecord::Migration[5.0] | ||
def change | ||
create_table :rating_rates do |t| | ||
t.decimal :value, default: 0, precision: 25, scale: 16 | ||
|
||
t.references :author, index: true, null: false, polymorphic: true | ||
t.references :resource, index: true, null: false, polymorphic: true | ||
t.references :scopeable, index: true, null: true, polymorphic: true | ||
|
||
t.timestamps null: false | ||
end | ||
|
||
add_index :rating_rates, %i[author_id author_type resource_id resource_type scopeable_id scopeable_type], | ||
name: :index_rating_rates_on_author_and_resource_and_scopeable, | ||
unique: true | ||
end | ||
end |
16 changes: 1 addition & 15 deletions
16
...plates/db/migrate/create_rating_tables.rb → ...mplates/db/migrate/create_rating_table.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
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 |
---|---|---|
@@ -1,11 +1,13 @@ | ||
# frozen_string_literal: true | ||
|
||
require File.expand_path('../../lib/generators/rating/templates/db/migrate/create_rating_tables.rb', __dir__) | ||
require File.expand_path('../../lib/generators/rating/templates/db/migrate/create_rating_table.rb', __dir__) | ||
require File.expand_path('../../lib/generators/rating/templates/db/migrate/create_rate_table.rb', __dir__) | ||
|
||
Dir[File.expand_path('db/migrate/*.rb', __dir__)].each { |file| require file } | ||
|
||
CreateArticlesTable.new.change | ||
CreateAuthorsTable.new.change | ||
CreateCategoriesTable.new.change | ||
CreateRatingTables.new.change | ||
CreateRateTable.new.change | ||
CreateRatingTable.new.change | ||
AddCommentOnRatingRatesTable.new.change |