From f2f31a5f49a55081334025b9e8d7f70a143a4498 Mon Sep 17 00:00:00 2001 From: Washington Botelho Date: Tue, 27 Mar 2018 18:00:56 -0300 Subject: [PATCH] up: makes polymorphic column type smaller --- .../rating/templates/db/migrate/create_rate_table.rb | 6 +++++- .../rating/templates/db/migrate/create_rating_table.rb | 3 +++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/generators/rating/templates/db/migrate/create_rate_table.rb b/lib/generators/rating/templates/db/migrate/create_rate_table.rb index ae8336f..7d5dcc8 100644 --- a/lib/generators/rating/templates/db/migrate/create_rate_table.rb +++ b/lib/generators/rating/templates/db/migrate/create_rate_table.rb @@ -7,11 +7,15 @@ class CreateRateTable < ActiveRecord::Migration[5.0] 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.references :scopeable, index: true, null: true, polymorphic: true t.timestamps null: false end + change_column :rating_rates, :author_type, :string, limit: 10 + change_column :rating_rates, :resource_type, :string, limit: 10 + change_column :rating_rates, :scopeable_type, :string, limit: 10 + add_index :rating_rates, %i[author_type author_id resource_type resource_id scopeable_type scopeable_id], name: :index_rating_rates_on_author_and_resource_and_scopeable, unique: true diff --git a/lib/generators/rating/templates/db/migrate/create_rating_table.rb b/lib/generators/rating/templates/db/migrate/create_rating_table.rb index d927dd4..9afe1b0 100644 --- a/lib/generators/rating/templates/db/migrate/create_rating_table.rb +++ b/lib/generators/rating/templates/db/migrate/create_rating_table.rb @@ -14,6 +14,9 @@ class CreateRatingTable < ActiveRecord::Migration[5.0] t.timestamps null: false end + change_column :rating_ratings, :resource_type, :string, limit: 10 + change_column :rating_ratings, :scopeable_type, :string, limit: 10 + add_index :rating_ratings, %i[resource_type resource_id scopeable_type scopeable_id], name: :index_rating_rating_on_resource_and_scopeable, unique: true