Module: Sequel::Redshift::SchemaDumper

Includes:
SchemaDumper
Defined in:
lib/sequel/extensions/redshift_schema_dumper.rb

Constant Summary collapse

DISTSTYLE =

0=>:even, which is the default

{ 1 => :key, 8 => :all }.freeze

Instance Method Summary collapse

Methods included from SchemaDumper

#column_schema_to_ruby_type, #column_schema_to_ruby_type_without_uuid, #dump_schema_migration, #dump_schema_migration_original, #dump_table_schema_without_force

Instance Method Details

#dump_table_schema(table, options = OPTS) ⇒ Object



9
10
11
12
13
14
# File 'lib/sequel/extensions/redshift_schema_dumper.rb', line 9

def dump_table_schema(table, options=OPTS)
  gen = dump_table_generator(table, options)
  commands = [gen.dump_columns, gen.dump_constraints, gen.dump_indexes].reject { |x| x == '' }.join("\n\n")

  "create_table!(#{table.inspect}#{table_options(table, gen, options)}) do\n#{commands.gsub(/^/o, '  ')}\nend"
end

#table_options(table, gen, options) ⇒ Object



16
17
18
19
20
21
22
23
24
25
# File 'lib/sequel/extensions/redshift_schema_dumper.rb', line 16

def table_options(table, gen, options)
  s = {distkey: table_distkey(table),
   diststyle: table_diststyle(table),
   sortkeys: table_sortkeys(table),
   sortstyle: table_sortstyle(table),
   ignore_index_errors: (!options[:same_db] && options[:indexes] != false && !gen.indexes.empty?)
  }.select { |_,v| v }.inspect[1...-1]

  s.empty? ? s : ", #{s}"
end