Class: DynamicMigrations::Postgres::Server::Database::Schema::Table::UniqueConstraint
- Inherits:
-
DynamicMigrations::Postgres::Server::Database::Source
- Object
- DynamicMigrations::Postgres::Server::Database::Source
- DynamicMigrations::Postgres::Server::Database::Schema::Table::UniqueConstraint
- Defined in:
- lib/dynamic_migrations/postgres/server/database/schema/table/unique_constraint.rb
Overview
This class represents a postgres table unique_constraint
Defined Under Namespace
Classes: DuplicateColumnError, ExpectedArrayOfColumnsError, ExpectedTableError, InvalidNameError, UnexpectedNullsPositionError, UnexpectedOrderError
Instance Attribute Summary collapse
-
#deferrable ⇒ Object
readonly
Returns the value of attribute deferrable.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#initially_deferred ⇒ Object
readonly
Returns the value of attribute initially_deferred.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#table ⇒ Object
readonly
Returns the value of attribute table.
Attributes inherited from DynamicMigrations::Postgres::Server::Database::Source
Instance Method Summary collapse
- #column_names ⇒ Object
-
#columns ⇒ Object
return an array of this unique_constraints columns.
- #differences_descriptions(other_unique_constraint) ⇒ Object
-
#has_description? ⇒ Boolean
return true if this has a description, otherwise false.
-
#initialize(source, table, columns, name, description: nil, deferrable: false, initially_deferred: false) ⇒ UniqueConstraint
constructor
initialize a new object to represent a unique_constraint in a postgres table.
Methods inherited from DynamicMigrations::Postgres::Server::Database::Source
#assert_is_a_symbol!, #from_configuration?, #from_database?
Constructor Details
#initialize(source, table, columns, name, description: nil, deferrable: false, initially_deferred: false) ⇒ UniqueConstraint
initialize a new object to represent a unique_constraint in a postgres table
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/dynamic_migrations/postgres/server/database/schema/table/unique_constraint.rb', line 36 def initialize source, table, columns, name, description: nil, deferrable: false, initially_deferred: false super source raise ExpectedTableError, table unless table.is_a? Table @table = table @columns = {} # assert that the provided columns is an array unless columns.is_a?(Array) && columns.count > 0 raise ExpectedArrayOfColumnsError end columns.each do |column| add_column column end raise InvalidNameError, "Unexpected name `#{name}`. Name should be a Symbol" unless name.is_a? Symbol raise InvalidNameError, "The name `#{name}` is too long. Names must be less than 64 characters" unless name.length < 64 @name = name unless description.nil? raise ExpectedStringError, description unless description.is_a? String @description = description.strip.freeze @description = nil if description == "" end raise ExpectedBooleanError, deferrable unless [true, false].include?(deferrable) @deferrable = deferrable raise ExpectedBooleanError, initially_deferred unless [true, false].include?(initially_deferred) @initially_deferred = initially_deferred end |
Instance Attribute Details
#deferrable ⇒ Object (readonly)
Returns the value of attribute deferrable.
31 32 33 |
# File 'lib/dynamic_migrations/postgres/server/database/schema/table/unique_constraint.rb', line 31 def deferrable @deferrable end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
33 34 35 |
# File 'lib/dynamic_migrations/postgres/server/database/schema/table/unique_constraint.rb', line 33 def description @description end |
#initially_deferred ⇒ Object (readonly)
Returns the value of attribute initially_deferred.
32 33 34 |
# File 'lib/dynamic_migrations/postgres/server/database/schema/table/unique_constraint.rb', line 32 def initially_deferred @initially_deferred end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
30 31 32 |
# File 'lib/dynamic_migrations/postgres/server/database/schema/table/unique_constraint.rb', line 30 def name @name end |
#table ⇒ Object (readonly)
Returns the value of attribute table.
29 30 31 |
# File 'lib/dynamic_migrations/postgres/server/database/schema/table/unique_constraint.rb', line 29 def table @table end |
Instance Method Details
#column_names ⇒ Object
78 79 80 |
# File 'lib/dynamic_migrations/postgres/server/database/schema/table/unique_constraint.rb', line 78 def column_names @columns.keys end |
#columns ⇒ Object
return an array of this unique_constraints columns
74 75 76 |
# File 'lib/dynamic_migrations/postgres/server/database/schema/table/unique_constraint.rb', line 74 def columns @columns.values end |
#differences_descriptions(other_unique_constraint) ⇒ Object
82 83 84 85 86 87 88 |
# File 'lib/dynamic_migrations/postgres/server/database/schema/table/unique_constraint.rb', line 82 def differences_descriptions other_unique_constraint method_differences_descriptions other_unique_constraint, [ :column_names, :deferrable, :initially_deferred ] end |
#has_description? ⇒ Boolean
return true if this has a description, otherwise false
69 70 71 |
# File 'lib/dynamic_migrations/postgres/server/database/schema/table/unique_constraint.rb', line 69 def has_description? !@description.nil? end |