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 =
"SELECT sum(pg_total_relation_size(c.oid)) AS \"total_size\"\n FROM pg_class c\n LEFT JOIN pg_namespace n ON n.oid = c.relnamespace\n WHERE nspname = %{schema} AND relname in (%{tables})\n"
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
25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/flydata/source_postgresql/generate_source_dump.rb', line 25 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
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/flydata/source_postgresql/generate_source_dump.rb', line 62 def dump(tables, file_path = nil, &src_pos_callback) io = nil if file_path io = File.open(file_path, "w") else raise "dump via pipe has not been implemented yet" end = Flydata::SourcePostgresql::TableMeta.new(de_prefs, tables) cli = FlydataCore::Postgresql::PGClient.new(de_prefs) .reload(cli) context = source.sync_generate_table_ddl(dp, nil) source_pos = get_source_pos(.current_snapshot, &src_pos_callback) = de_prefs.merge(table_meta: ) missing_tables = context.each_source_tabledef(tables, ) do |tabledef, error| dump_table(tabledef, source_pos, io, cli) if tabledef end nil ensure cli.close if cli io.close if io end |
#dump_size(tables) ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/flydata/source_postgresql/generate_source_dump.rb', line 44 def dump_size(tables) cli = FlydataCore::Postgresql::PGClient.new(de_prefs) base_query = DUMP_SIZE_QUERY % { schema: FlydataCore::Postgresql::QueryHelper.schema_as_value(de_prefs['schema']), tables: '%s' # Use binding parameters for tables } query = FlydataCore::Postgresql::PGQuery.new(base_query, placeholder_size: tables.size, placeholder_start_num: 1) res = cli.query(query, tables) res.first['total_size'].to_i ensure cli.close if cli end |
#run_compatibility_check(dump_dir, backup_dir) ⇒ Object
16 17 18 19 20 21 22 23 |
# File 'lib/flydata/source_postgresql/generate_source_dump.rb', line 16 def run_compatibility_check(dump_dir, backup_dir) %w(host username database).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 |