Method: DynamicMigrations::Postgres::Server::Database::Schema::Table::Index#initialize
- Defined in:
- lib/dynamic_migrations/postgres/server/database/schema/table/index.rb
#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 |