Commit 09c9f3a4d23c5aba5b96cf7a4647ecde50bf77f9
1 parent
746a07c5
Exists in
gov-user-refactoring
gov-user: move institution relation from organization_ratings
Signed-off-by: Tallys Martins <tallysmartins@yahoo.com.br>
Showing
3 changed files
with
31 additions
and
0 deletions
Show diff stats
src/noosfero-spb/gov_user/db/migrate/20151105174601_create_institutions_organization_ratings_table.rb
0 → 100644
... | ... | @@ -0,0 +1,12 @@ |
1 | +class CreateInstitutionsOrganizationRatingsTable < ActiveRecord::Migration | |
2 | + def up | |
3 | + create_table :gov_user_plugin_institutions_organization_ratings, {:id => false, :force => true} do |t| | |
4 | + t.references :institution | |
5 | + t.references :organization_rating | |
6 | + end | |
7 | + end | |
8 | + | |
9 | + def down | |
10 | + drop_table :gov_user_plugin_institutions_organization_ratings | |
11 | + end | |
12 | +end | ... | ... |
src/noosfero-spb/gov_user/db/migrate/20151105175611_move_institutions_relation_with_organization_ratings.rb
0 → 100644
... | ... | @@ -0,0 +1,9 @@ |
1 | +class MoveInstitutionsRelationWithOrganizationRatings < ActiveRecord::Migration | |
2 | + def up | |
3 | + execute('INSERT INTO gov_user_plugin_institutions_organization_ratings (institution_id,organization_rating_id) SELECT institution_id, id from organization_ratings where institution_id IS NOT NULL;') | |
4 | + end | |
5 | + | |
6 | + def down | |
7 | + execute('DELETE FROM gov_user_plugin_institutions_organization_ratings;') | |
8 | + end | |
9 | +end | ... | ... |
src/noosfero-spb/gov_user/db/migrate/20151105175646_remove_old_institution_relation_from_organization_ratings.rb
0 → 100644
... | ... | @@ -0,0 +1,10 @@ |
1 | +class RemoveOldInstitutionRelationFromOrganizationRatings < ActiveRecord::Migration | |
2 | + def up | |
3 | + remove_column :organization_ratings, :institution_id | |
4 | + end | |
5 | + | |
6 | + def down | |
7 | + add_column :organization_ratings, :institution_id, :integer | |
8 | + execute('UPDATE organization_ratings AS oratings SET institution_id = (SELECT institution_id FROM gov_user_plugin_institutions_organization_ratings AS g WHERE g.organization_rating_id = oratings.id);') | |
9 | + end | |
10 | +end | ... | ... |