-
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.
switch
transaction#mode
from integer
type to enum
type
- Loading branch information
1 parent
daf6152
commit 86040c1
Showing
9 changed files
with
52 additions
and
14 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
29 changes: 29 additions & 0 deletions
29
db/migrate/20231230171413_replace_mode_integer_with_mode_enum_type_in_transaction.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,29 @@ | ||
class ReplaceModeIntegerWithModeEnumTypeInTransaction < ActiveRecord::Migration[7.1] | ||
def change | ||
modes = %w[Cash Cheque Bank] | ||
create_enum :modes, modes | ||
|
||
add_column :transactions, :mode_enum, :enum, enum_type: :modes, default: "Cash", null: false | ||
|
||
reversible do |direction| | ||
# rubocop:disable Rails/SkipsModelValidations | ||
direction.up do | ||
modes.each_with_index do |mode, i| | ||
Transaction.where(mode: i).update_all(mode_enum: mode) | ||
end | ||
end | ||
|
||
direction.down do | ||
modes.each_with_index do |mode, i| | ||
Transaction.where(mode_enum: mode).update_all(mode: i) | ||
end | ||
# make sure to update the MODES constant value in order to access the 'mode' data | ||
# MODES = %i[cash cheque bank] | ||
end | ||
# rubocop:enable Rails/SkipsModelValidations | ||
end | ||
|
||
remove_column :transactions, :mode, :integer | ||
rename_column :transactions, :mode_enum, :mode | ||
end | ||
end |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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