Class: DynamicMigrations::Postgres::Server::Database::Schema::Table::Index
- Inherits:
-
DynamicMigrations::Postgres::Server::Database::Source
- Object
- DynamicMigrations::Postgres::Server::Database::Source
- DynamicMigrations::Postgres::Server::Database::Schema::Table::Index
- Defined in:
- lib/dynamic_migrations/postgres/server/database/schema/table/index.rb
Overview
This class represents a postgres table index
Defined Under Namespace
Classes: DuplicateColumnError, ExpectedArrayOfColumnsError, ExpectedTableError, InvalidNameError, UnexpectedIndexTypeError, UnexpectedNullsPositionError, UnexpectedOrderError
Constant Summary collapse
- INDEX_TYPES =
[:btree, :hash, :gist, :gin, :bring, :spgist]
- ORDERS =
[:asc, :desc]
- NULL_POSITIONS =
[:first, :last]
Instance Attribute Summary collapse
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#nulls_position ⇒ Object
readonly
Returns the value of attribute nulls_position.
-
#order ⇒ Object
readonly
Returns the value of attribute order.
-
#table ⇒ Object
readonly
Returns the value of attribute table.
-
#type ⇒ Object
readonly
Returns the value of attribute type.
-
#unique ⇒ Object
readonly
Returns the value of attribute unique.
-
#where ⇒ Object
readonly
Returns the value of attribute where.
Attributes inherited from DynamicMigrations::Postgres::Server::Database::Source
Instance Method Summary collapse
- #column_names ⇒ Object
-
#columns ⇒ Object
return an array of this indexes columns.
- #differences_descriptions(other_index) ⇒ Object
-
#has_description? ⇒ Boolean
return true if this has a description, otherwise false.
- #include_column_names ⇒ Object
-
#include_columns ⇒ Object
return an array of this indexes include_columns.
-
#initialize(source, table, columns, name, description: nil, unique: false, where: nil, type: :btree, include_columns: [], order: :asc, nulls_position: :last) ⇒ Index
constructor
initialize a new object to represent a index 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, unique: false, where: nil, type: :btree, include_columns: [], order: :asc, nulls_position: :last) ⇒ Index
initialize a new object to represent a index in a postgres table
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/dynamic_migrations/postgres/server/database/schema/table/index.rb', line 46 def initialize source, table, columns, name, description: nil, unique: false, where: nil, type: :btree, include_columns: [], order: :asc, nulls_position: :last super source raise ExpectedTableError, table unless table.is_a? Table @table = table @columns = {} @include_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, unique unless [true, false].include?(unique) @unique = unique unless where.nil? raise ExpectedStringError, where unless where.is_a? String @where = where.freeze end raise UnexpectedIndexTypeError, type unless INDEX_TYPES.include?(type) @type = type # assert that the include_columns is an array (it's optional, so can be an empty array) unless include_columns.is_a?(Array) raise ExpectedArrayOfColumnsError end include_columns.each do |include_column| add_column include_column, is_include_column: true end raise UnexpectedOrderError, order unless ORDERS.include?(order) @order = order raise UnexpectedNullsPositionError, nulls_position unless NULL_POSITIONS.include?(nulls_position) @nulls_position = nulls_position end |
Instance Attribute Details
#description ⇒ Object (readonly)
Returns the value of attribute description.
43 44 45 |
# File 'lib/dynamic_migrations/postgres/server/database/schema/table/index.rb', line 43 def description @description end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
37 38 39 |
# File 'lib/dynamic_migrations/postgres/server/database/schema/table/index.rb', line 37 def name @name end |
#nulls_position ⇒ Object (readonly)
Returns the value of attribute nulls_position.
42 43 44 |
# File 'lib/dynamic_migrations/postgres/server/database/schema/table/index.rb', line 42 def nulls_position @nulls_position end |
#order ⇒ Object (readonly)
Returns the value of attribute order.
41 42 43 |
# File 'lib/dynamic_migrations/postgres/server/database/schema/table/index.rb', line 41 def order @order end |
#table ⇒ Object (readonly)
Returns the value of attribute table.
36 37 38 |
# File 'lib/dynamic_migrations/postgres/server/database/schema/table/index.rb', line 36 def table @table end |
#type ⇒ Object (readonly)
Returns the value of attribute type.
40 41 42 |
# File 'lib/dynamic_migrations/postgres/server/database/schema/table/index.rb', line 40 def type @type end |
#unique ⇒ Object (readonly)
Returns the value of attribute unique.
38 39 40 |
# File 'lib/dynamic_migrations/postgres/server/database/schema/table/index.rb', line 38 def unique @unique end |
#where ⇒ Object (readonly)
Returns the value of attribute where.
39 40 41 |
# File 'lib/dynamic_migrations/postgres/server/database/schema/table/index.rb', line 39 def where @where end |
Instance Method Details
#column_names ⇒ Object
109 110 111 |
# File 'lib/dynamic_migrations/postgres/server/database/schema/table/index.rb', line 109 def column_names @columns.keys end |
#columns ⇒ Object
return an array of this indexes columns
105 106 107 |
# File 'lib/dynamic_migrations/postgres/server/database/schema/table/index.rb', line 105 def columns @columns.values end |
#differences_descriptions(other_index) ⇒ Object
122 123 124 125 126 127 128 129 130 131 |
# File 'lib/dynamic_migrations/postgres/server/database/schema/table/index.rb', line 122 def differences_descriptions other_index method_differences_descriptions other_index, [ :column_names, :unique, :where, :type, :order, :nulls_position ] end |
#has_description? ⇒ Boolean
return true if this has a description, otherwise false
100 101 102 |
# File 'lib/dynamic_migrations/postgres/server/database/schema/table/index.rb', line 100 def has_description? !@description.nil? end |
#include_column_names ⇒ Object
118 119 120 |
# File 'lib/dynamic_migrations/postgres/server/database/schema/table/index.rb', line 118 def include_column_names @include_columns.keys end |
#include_columns ⇒ Object
return an array of this indexes include_columns
114 115 116 |
# File 'lib/dynamic_migrations/postgres/server/database/schema/table/index.rb', line 114 def include_columns @include_columns.values end |