module PgSaurus::Migration::SetRoleMethod
Wrap original ‘exec_migration` to run migration with set postgresql role. If config.ensure_role_set=true but no role is set for the migration, then an exception is raised.
Attributes
role[R]
Public Class Methods
keep_default_role()
click to toggle source
Prevents raising exception when ensure_role_set=true and no role is set.
# File lib/pg_saurus/migration/set_role_method.rb, line 44 def keep_default_role if const_defined?("SeedMigrator") && !self.ancestors.include?(SeedMigrator) msg = <<~MSG Use set_role instead of keep_default_role for structure migration #{self} Example: class CreateExamples < ActiveRecord::Migration set_role "superhero" def up ... end def down ... end end MSG raise PgSaurus::UseSetRoleError, msg end @keep_default_role = true end
keep_default_role?()
click to toggle source
Was keep_default_role
called for the migration?
@return [Boolean]
# File lib/pg_saurus/migration/set_role_method.rb, line 73 def keep_default_role? @keep_default_role end
set_role(role)
click to toggle source
Set role
@param role [String]
# File lib/pg_saurus/migration/set_role_method.rb, line 15 def set_role(role) if const_defined?("SeedMigrator") && self.ancestors.include?(SeedMigrator) msg = <<~MSG Use keep_default_role instead of set_role for data change migration #{self} Example: class PopulateExample < ActiveRecord::Migration include #{self.ancestors[1]} keep_default_role def up apply_update "populate_example_data_update" end def down revert_update "populate_example_data_update" end end MSG raise PgSaurus::UseKeepDefaultRoleError, msg end @role = role end
Public Instance Methods
role()
click to toggle source
Get role
# File lib/pg_saurus/migration/set_role_method.rb, line 80 def role self.class.role end