-
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.
Merge pull request #33 from JuzerShakir/pg-enums
Pg Enums
- Loading branch information
Showing
34 changed files
with
191 additions
and
70 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module ArrayExtensions | ||
refine Array do | ||
def to_h_titleize_value = to_h { [_1, _1.to_s.titleize] } | ||
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,18 +1,17 @@ | ||
class Role < ApplicationRecord | ||
# * Constants | ||
NAMES = %w[admin member viewer] | ||
|
||
# rubocop:disable Rails/HasAndBelongsToMany | ||
has_and_belongs_to_many :users, join_table: :users_roles | ||
# rubocop:enable Rails/HasAndBelongsToMany | ||
|
||
belongs_to :resource, | ||
polymorphic: true, | ||
optional: true | ||
belongs_to :resource, polymorphic: true, optional: true | ||
|
||
validates :resource_type, | ||
inclusion: {in: Rolify.resource_types}, | ||
allow_nil: true | ||
validates :resource_type, inclusion: {in: Rolify.resource_types}, allow_nil: true | ||
|
||
validates :name, presence: true | ||
validates :name, inclusion: {in: ROLES} | ||
validates :name, inclusion: {in: NAMES} | ||
|
||
scopify | ||
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
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 |
---|---|---|
@@ -1,7 +1,2 @@ | ||
# ! Add new apartments, sizes & modes to the END of the list | ||
APARTMENTS = %i[mohammedi taiyebi burhani maimoon_a maimoon_b] | ||
SIZES = %i[small medium large] | ||
MODES = %i[cash cheque bank] | ||
ROLES = %w[admin member viewer] | ||
CURR_YR = 2022 | ||
PREV_YR = CURR_YR - 1 |
29 changes: 29 additions & 0 deletions
29
db/migrate/20231230113604_replace_apartment_integer_with_apartment_enum_type_in_sabeel.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 ReplaceApartmentIntegerWithApartmentEnumTypeInSabeel < ActiveRecord::Migration[7.1] | ||
def change | ||
apartments = ["Mohammedi", "Taiyebi", "Burhani", "Maimoon A", "Maimoon B"] | ||
create_enum :apartments, apartments | ||
|
||
add_column :sabeels, :apartment_enum, :enum, enum_type: :apartments, default: "Mohammedi", null: false | ||
|
||
reversible do |direction| | ||
# rubocop:disable Rails/SkipsModelValidations | ||
direction.up do | ||
apartments.each_with_index do |apartment, i| | ||
Sabeel.where(apartment: i).update_all(apartment_enum: apartment) | ||
end | ||
end | ||
|
||
direction.down do | ||
apartments.each_with_index do |apartment, i| | ||
Sabeel.where(apartment_enum: apartment).update_all(apartment: i) | ||
end | ||
# to access `#apartment` data, update the enum value of it in `app/models/sabeels` file: | ||
# enum apartment: APARTMENTS | ||
end | ||
# rubocop:enable Rails/SkipsModelValidations | ||
end | ||
|
||
remove_column :sabeels, :apartment, :integer | ||
rename_column :sabeels, :apartment_enum, :apartment | ||
end | ||
end |
29 changes: 29 additions & 0 deletions
29
db/migrate/20231230135852_replace_size_integer_with_size_enum_type_in_thaali.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 ReplaceSizeIntegerWithSizeEnumTypeInThaali < ActiveRecord::Migration[7.1] | ||
def change | ||
sizes = %w[Small Medium Large] | ||
create_enum :sizes, sizes | ||
|
||
add_column :thaalis, :size_enum, :enum, enum_type: :sizes, default: "Small", null: false | ||
|
||
reversible do |direction| | ||
# rubocop:disable Rails/SkipsModelValidations | ||
direction.up do | ||
sizes.each_with_index do |size, i| | ||
Thaali.where(size: i).update_all(size_enum: size) | ||
end | ||
end | ||
|
||
direction.down do | ||
sizes.each_with_index do |size, i| | ||
Thaali.where(size_enum: size).update_all(size: i) | ||
end | ||
# to access `#size` data, update the enum value of it in `app/models/thaalis` file: | ||
# enum size: SIZES | ||
end | ||
# rubocop:enable Rails/SkipsModelValidations | ||
end | ||
|
||
remove_column :thaalis, :size, :integer | ||
rename_column :thaalis, :size_enum, :size | ||
end | ||
end |
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 | ||
# to access `#mode` data, update the enum value of it in `app/models/transactions` file: | ||
# enum mode: MODES | ||
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.
Oops, something went wrong.