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/rdbms_sampler/sample.rb', line 18
def compute!
quoted_schema_names = @schemas.collect do |name|
@connection.quote_table_name(name)
end
warn "Discovering tables in databases: #{quoted_schema_names.to_sentence}..."
tables_without_views.each do |schema_name, table_name|
table_sample = TableSample.new(@connection, schema_name, table_name, @rows_per_table)
@table_samples[table_sample.identifier] = table_sample
end
return warn 'No tables found!' unless @table_samples.count > 0
warn "Sampling #{@table_samples.count} tables..."
@table_samples.values.map &:sample!
warn 'Ensuring referential integrity...'
begin
new_dependencies = 0
@table_samples.values.each do |table_sample|
newly_added = table_sample.ensure_referential_integrity(self)
if newly_added > 0
new_dependencies += newly_added
warn " Expanded sample with #{newly_added} new rows referenced from table #{table_sample.quoted_name}"
end
end
warn " Discovered #{new_dependencies} new dependencies" if new_dependencies > 0
end while new_dependencies > 0
warn 'Referential integrity obtained'
warn 'Final sample contains:'
@table_samples.values.each do |table_sample|
warn " #{table_sample.size} row(s) from `#{table_sample.identifier}`"
end
@computed = true
end
|