Class: ActiveRecord::Snapshot::MySQL

Inherits:
Object
  • Object
show all
Defined in:
lib/active_record/snapshot/commands/mysql.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.dump(*args) ⇒ Object



6
7
8
# File 'lib/active_record/snapshot/commands/mysql.rb', line 6

def self.dump(*args)
  new.dump(*args)
end

.import(*args) ⇒ Object



17
18
19
# File 'lib/active_record/snapshot/commands/mysql.rb', line 17

def self.import(*args)
  new.import(*args)
end

Instance Method Details

#dump(tables:, output:) ⇒ Object



10
11
12
13
14
15
# File 'lib/active_record/snapshot/commands/mysql.rb', line 10

def dump(tables:, output:)
  # the --no-tablespaces and --single-transaction flags are necessary to dump a db
  # containing SQL view queries and tablespace metadata
  dump_command("--no-data --single-transaction --no-tablespaces --set-gtid-purged=OFF #{database} > #{output}") &&
    dump_command("--quick --single-transaction --no-tablespaces --set-gtid-purged=OFF #{database} #{tables.join(" ")} >> #{output}")
end

#import(input:) ⇒ Object



21
22
23
24
25
26
27
28
29
# File 'lib/active_record/snapshot/commands/mysql.rb', line 21

def import(input:)
  system(<<~SH)
    nice mysql \\
      --user=#{username} \\
      #{password_string} \\
      --host=#{host} \\
      #{database} < #{input}
  SH
end