Merge pull request #1 from wbotelhos/extracting-migrations
Extracted tables migration to multi-filesmain
commit
754aaca0e8
|
@ -7,13 +7,18 @@ module Rating
|
|||
desc 'creates Rating migration'
|
||||
|
||||
def create_migration
|
||||
template 'db/migrate/create_rating_tables.rb', "db/migrate/#{timestamp}_create_rating_tables.rb"
|
||||
template 'db/migrate/create_rating_table.rb', "db/migrate/#{timestamp(0)}_create_rating_table.rb"
|
||||
template 'db/migrate/create_rate_table.rb', "db/migrate/#{timestamp(1)}_create_rate_table.rb"
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def timestamp
|
||||
Time.current.strftime '%Y%m%d%H%M%S'
|
||||
def time
|
||||
@time ||= Time.current
|
||||
end
|
||||
|
||||
def timestamp(seconds)
|
||||
(time + seconds.seconds).strftime '%Y%m%d%H%M%S'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -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
|
|
@ -1,21 +1,7 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
class CreateRatingTables < ActiveRecord::Migration[5.0]
|
||||
class CreateRatingTable < 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
|
||||
|
||||
create_table :rating_ratings do |t|
|
||||
t.decimal :average, default: 0, mull: false, precision: 25, scale: 16
|
||||
t.decimal :estimate, default: 0, mull: false, precision: 25, scale: 16
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue