Module: AR::Sequence::SchemaDumper

Defined in:
lib/ar/sequence/schema_dumper.rb

Instance Method Summary collapse

Instance Method Details

#header(stream) ⇒ Object



6
7
8
9
# File 'lib/ar/sequence/schema_dumper.rb', line 6

def header(stream)
  super
  sequences(stream)
end

#sequences(stream) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/ar/sequence/schema_dumper.rb', line 11

def sequences(stream)
  sequences = @connection.check_sequences
  return if sequences.empty?

  sequences.each do |seq|
    start_value = seq["start_value"]
    increment = seq["increment"]

    options = []
    options << "start: #{start_value}" if start_value && Integer(start_value) != 1
    options << "increment: #{increment}" if increment && Integer(increment) != 1

    statement = ["create_sequence", seq["sequence_name"].inspect].join(" ")
    statement << (options.any? ? ", #{options.join(', ')}" : "") if options.any?

    stream.puts "  #{statement}"
  end

  stream.puts
end