Class: Flydata::SourcePostgresql::GenerateSourceDump
- Inherits:
-
Flydata::Source::GenerateSourceDump
- Object
- Flydata::Source::Component
- Flydata::Source::GenerateSourceDump
- Flydata::SourcePostgresql::GenerateSourceDump
- Includes:
- PostgresqlComponent
- Defined in:
- lib/flydata/source_postgresql/generate_source_dump.rb
Constant Summary collapse
- DUMP_SIZE_QUERY =
<<EOS SELECT sum(pg_total_relation_size(c.oid)) AS "total_size" FROM pg_class c LEFT JOIN pg_namespace n ON n.oid = c.relnamespace WHERE nspname = $1 AND relname in (%s) EOS
- TABLE_PLACEHOLDER_START_NUM =
because $1 is used by table_schema
2
Instance Attribute Summary
Attributes inherited from Flydata::Source::GenerateSourceDump
Instance Method Summary collapse
- #confirmation_items ⇒ Object
- #dump(tables, file_path = nil, &src_pos_callback) ⇒ Object
- #dump_size(tables) ⇒ Object
- #run_compatibility_check(dump_dir, backup_dir) ⇒ Object
Methods included from PostgresqlComponent
Methods inherited from Flydata::Source::GenerateSourceDump
Methods inherited from Flydata::Source::Component
Constructor Details
This class inherits a constructor from Flydata::Source::GenerateSourceDump
Instance Method Details
#confirmation_items ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/flydata/source_postgresql/generate_source_dump.rb', line 23 def confirmation_items items = { "host" => de_prefs['host'], "port" => de_prefs['port'], "username" => de_prefs['username'], "database" => de_prefs['database'], "schema" => de_prefs['schema'], } items end |
#dump(tables, file_path = nil, &src_pos_callback) ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/flydata/source_postgresql/generate_source_dump.rb', line 51 def dump(tables, file_path = nil, &src_pos_callback) if file_path io = File.open(file_path, "w") else raise "dump via pipe has not been implemented yet" end cli = PGClient.new(de_prefs) source_pos = get_source_pos(cli, &src_pos_callback) context = source.sync_generate_table_ddl(dp, nil) missing_tables = context.each_source_tabledef(tables, de_prefs) do |tabledef, error| dump_table(tabledef, source_pos, io, cli) if tabledef end nil end |
#dump_size(tables) ⇒ Object
43 44 45 46 47 48 49 |
# File 'lib/flydata/source_postgresql/generate_source_dump.rb', line 43 def dump_size(tables) cli = PGClient.new(de_prefs) res = cli.query(DUMP_SIZE_QUERY, [de_prefs['schema']] + tables, placeholder_size: tables.size, placeholder_start_num: TABLE_PLACEHOLDER_START_NUM) res.first['total_size'].to_i end |
#run_compatibility_check(dump_dir, backup_dir) ⇒ Object
14 15 16 17 18 19 20 21 |
# File 'lib/flydata/source_postgresql/generate_source_dump.rb', line 14 def run_compatibility_check(dump_dir, backup_dir) %w(host username database schema).each do |k| if de_prefs[k].to_s.empty? raise "'#{k}' is required. Set the value in the conf file " + "-> #{Flydata::Preference::DataEntryPreference.conf_path(de)}" end end end |