6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
# File 'lib/ridgepole/dumper.rb', line 6
def dump
stream = StringIO.new
conn = ActiveRecord::Base.connection
target_tables = @options[:tables]
ignore_tables = @options[:ignore_tables]
if target_tables
conn.tables.each do |tbl|
next if target_tables.include?(tbl)
ActiveRecord::SchemaDumper.ignore_tables << tbl
end
end
if ignore_tables
conn.tables.each do |tbl|
if ignore_tables.any? {|i| i =~ tbl }
ActiveRecord::SchemaDumper.ignore_tables << tbl
end
end
end
ActiveRecord::SchemaDumper.dump(conn, stream)
if target_tables or ignore_tables
ActiveRecord::SchemaDumper.ignore_tables.clear
end
dsl = stream.string.lines.select {|line|
line !~ /\A#/ &&
line !~ /\AActiveRecord::Schema\.define/ &&
line !~ /\Aend/
}.join.undent.strip
definitions = []
each_table(dsl) do |name, definition|
if target?(name)
definitions << definition
yield(name, definition) if block_given?
end
end
definitions.join("\n\n")
end
|