-
-
Notifications
You must be signed in to change notification settings - Fork 31
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enum backfill data migration (#3936)
Follows #3925 > This PR is the first of few to migrate the few enums (backed by integers) to ones backed by strings > > 1. add new columns, with temp_ in the name and prefix: true to avoid method namespace collision with existing enums > 2. backfill data migration to populate new column with the string equivalent of the integer column (0 => draft, etc) This PR does 1 and 2 from #3925
- Loading branch information
1 parent
63fc5d4
commit db23795
Showing
8 changed files
with
132 additions
and
57 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
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 |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# rubocop:disable Metrics/MethodLength | ||
class DataMigrate | ||
class << self | ||
def run | ||
# locales | ||
Locale.find_each do |locale| | ||
locale.update! temp_language_direction: locale.language_direction | ||
end | ||
|
||
# users | ||
User.find_each do |user| | ||
user.update! temp_role: user.role | ||
end | ||
|
||
# "publishable" tables | ||
Article.find_each do |article| | ||
article.update! temp_publication_status: article.publication_status | ||
end | ||
|
||
Book.find_each do |book| | ||
book.update! temp_publication_status: book.publication_status | ||
end | ||
|
||
Definition.find_each do |definition| | ||
definition.update! temp_publication_status: definition.publication_status | ||
end | ||
|
||
Episode.find_each do |episode| | ||
episode.update! temp_publication_status: episode.publication_status | ||
end | ||
|
||
Issue.find_each do |issue| | ||
issue.update! temp_publication_status: issue.publication_status | ||
end | ||
|
||
Journal.find_each do |journal| | ||
journal.update! temp_publication_status: journal.publication_status | ||
end | ||
|
||
Logo.find_each do |logo| | ||
logo.update! temp_publication_status: logo.publication_status | ||
end | ||
|
||
Page.find_each do |page| | ||
page.update! temp_publication_status: page.publication_status | ||
end | ||
|
||
Poster.find_each do |poster| | ||
poster.update! temp_publication_status: poster.publication_status | ||
end | ||
|
||
Sticker.find_each do |sticker| | ||
sticker.update! temp_publication_status: sticker.publication_status | ||
end | ||
|
||
Video.find_each do |video| | ||
video.update! temp_publication_status: video.publication_status | ||
end | ||
|
||
Zine.find_each do |zine| | ||
zine.update! temp_publication_status: zine.publication_status | ||
end | ||
end | ||
end | ||
end | ||
# rubocop:enable Metrics/MethodLength |
5 changes: 5 additions & 0 deletions
5
db/migrate/20240909064134_rename_column_temp_roles_on_users.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 RenameColumnTempRolesOnUsers < ActiveRecord::Migration[7.2] | ||
def change | ||
rename_column :users, :temp_roles, :temp_role | ||
end | ||
end |
Oops, something went wrong.