Class: Sequel::Postgres::AlterTableGenerator

Inherits:
Schema::AlterTableGenerator
  • Object
show all
Defined in:
lib/sequel/adapters/shared/postgres.rb

Instance Method Summary collapse

Instance Method Details

#add_exclusion_constraint(elements, opts = OPTS) ⇒ Object

Adds an exclusion constraint to an existing table, see CreateTableGenerator#exclude.



153
154
155
# File 'lib/sequel/adapters/shared/postgres.rb', line 153

def add_exclusion_constraint(elements, opts=OPTS)
  @operations << {:op => :add_constraint, :type => :exclude, :elements => elements}.merge!(opts)
end

#alter_constraint(name, opts = OPTS) ⇒ Object

Alter an existing constraint. Options: :deferrable :: Modify deferrable setting for constraint (PostgreSQL 9.4+):

           true :: DEFERRABLE INITIALLY DEFERRED
           false :: NOT DEFERRABLE
           :immediate :: DEFERRABLE INITIALLY IMMEDIATE

:enforced :: Set true to use ENFORCED, or false to use NOT ENFORCED (PostgreSQL 18+) :inherit :: Set true to use INHERIT, or false to use NO INHERIT (PostgreSQL 18+)



164
165
166
# File 'lib/sequel/adapters/shared/postgres.rb', line 164

def alter_constraint(name, opts=OPTS)
  @operations << {:op => :alter_constraint, :name => name}.merge!(opts)
end

#attach_partition(name, &block) ⇒ Object

Attach an existing table as a partition of the altered table. This is preferable to using create_table with :partition_of for a number of reasons. Accepts the same block that you would pass to create_table with the :partition_of option.



172
173
174
# File 'lib/sequel/adapters/shared/postgres.rb', line 172

def attach_partition(name, &block)
  @operations << {:op => :attach_partition, :name => name, :generator => CreatePartitionOfTableGenerator.new(&block)}
end

#detach_partition(name, concurrently: false, finalize: false) ⇒ Object

Detach a partition from a partitioned table. The detached partition becomes a separate table. Arguments: name: Name of partitioned table concurrently: Use CONCURRENTLY when detaching, which reduces the locking required. finalize: Use FINALIZE when detaching, to complete a case where CONCURRENTLY was used but could not complete the detach.



182
183
184
# File 'lib/sequel/adapters/shared/postgres.rb', line 182

def detach_partition(name, concurrently: false, finalize: false)
  @operations << {:op => :detach_partition, :name => name, :concurrently => concurrently, :finalize => finalize}
end

#rename_constraint(name, new_name) ⇒ Object

Rename an constraint.



187
188
189
# File 'lib/sequel/adapters/shared/postgres.rb', line 187

def rename_constraint(name, new_name)
  @operations << {:op => :rename_constraint, :name => name, :new_name => new_name}
end

#validate_constraint(name) ⇒ Object

Validate the constraint with the given name, which should have been added previously with NOT VALID.



193
194
195
# File 'lib/sequel/adapters/shared/postgres.rb', line 193

def validate_constraint(name)
  @operations << {:op => :validate_constraint, :name => name}
end