-
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.
BASIRA #275 - Converting value_lists.authorized_vocabulary and people…
….authorized_vocabulary fields to value lists
- Loading branch information
1 parent
0484a18
commit fa9379c
Showing
14 changed files
with
166 additions
and
127 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
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,7 +1,7 @@ | ||
class ValueListsSerializer < BaseSerializer | ||
index_attributes :id, :object, :group, :human_name, :authorized_vocabulary, :authorized_vocabulary_url, | ||
:database_value, :comment, :qualifications_count | ||
index_attributes :id, :object, :group, :human_name, :authorized_vocabulary_url, :database_value, :comment, | ||
:qualifications_count, qualifications: QualificationsSerializer | ||
|
||
show_attributes :id, :object, :group, :human_name, :authorized_vocabulary, :authorized_vocabulary_url, | ||
:database_value, :comment, :qualifications_count | ||
show_attributes :id, :object, :group, :human_name, :authorized_vocabulary_url, :database_value, :comment, | ||
:qualifications_count, qualifications: QualificationsSerializer | ||
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
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
41 changes: 41 additions & 0 deletions
41
db/data/20241211163139_create_authorized_vocabulary_value_lists.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,41 @@ | ||
# frozen_string_literal: true | ||
|
||
class CreateAuthorizedVocabularyValueLists < ActiveRecord::Migration[7.0] | ||
def up | ||
execute <<-SQL.squish | ||
INSERT INTO value_lists (object, "group", human_name, created_at, updated_at) | ||
SELECT DISTINCT 'General', 'Authorized Vocabulary', authorized_vocabulary, current_timestamp, current_timestamp | ||
FROM value_lists | ||
WHERE authorized_vocabulary IS NOT NULL | ||
UNION | ||
SELECT DISTINCT 'General', 'Authorized Vocabulary', authorized_vocabulary, current_timestamp, current_timestamp | ||
FROM people | ||
WHERE authorized_vocabulary IS NOT NULL | ||
ORDER BY authorized_vocabulary | ||
SQL | ||
|
||
execute <<-SQL.squish | ||
INSERT INTO qualifications (qualifiable_id, qualifiable_type, value_list_id) | ||
SELECT value_lists.id, 'ValueList', v.id | ||
FROM value_lists | ||
JOIN value_lists v ON v.human_name = value_lists.authorized_vocabulary | ||
AND v.object = 'General' | ||
AND v.group = 'Authorized Vocabulary' | ||
WHERE value_lists.authorized_vocabulary IS NOT NULL | ||
SQL | ||
|
||
execute <<-SQL.squish | ||
INSERT INTO qualifications (qualifiable_id, qualifiable_type, value_list_id) | ||
SELECT people.id, 'Person', value_lists.id | ||
FROM people | ||
JOIN value_lists ON value_lists.human_name = people.authorized_vocabulary | ||
AND value_lists.object = 'General' | ||
AND value_lists.group = 'Authorized Vocabulary' | ||
WHERE people.authorized_vocabulary IS NOT NULL | ||
SQL | ||
end | ||
|
||
def down | ||
raise ActiveRecord::IrreversibleMigration | ||
end | ||
end |
21 changes: 21 additions & 0 deletions
21
db/data/20241211173335_reset_value_list_qualifications_count.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,21 @@ | ||
# frozen_string_literal: true | ||
|
||
class ResetValueListQualificationsCount < ActiveRecord::Migration[7.0] | ||
def up | ||
execute <<-SQL.squish | ||
WITH qualification_counts AS ( | ||
SELECT qualifications.value_list_id, COUNT(*) AS qualifications_count | ||
FROM qualifications | ||
GROUP BY qualifications.value_list_id | ||
) | ||
UPDATE value_lists | ||
SET qualifications_count = qualification_counts.qualifications_count | ||
FROM qualification_counts | ||
WHERE qualification_counts.value_list_id = value_lists.id | ||
SQL | ||
end | ||
|
||
def down | ||
raise ActiveRecord::IrreversibleMigration | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
DataMigrate::Data.define(version: 20241127155125) | ||
DataMigrate::Data.define(version: 20241211173335) |
5 changes: 5 additions & 0 deletions
5
db/migrate/20241211200500_remove_value_lists_authorized_vocabulary.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,5 @@ | ||
class RemoveValueListsAuthorizedVocabulary < ActiveRecord::Migration[7.0] | ||
def change | ||
remove_column :value_lists, :authorized_vocabulary | ||
end | ||
end |
5 changes: 5 additions & 0 deletions
5
db/migrate/20241211201922_remove_people_authorized_vocabulary.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,5 @@ | ||
class RemovePeopleAuthorizedVocabulary < ActiveRecord::Migration[7.0] | ||
def change | ||
remove_column :people, :authorized_vocabulary | ||
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