lib/fulmar/infrastructure/service/database/database_service.rb in fulmar-1.8.3 vs lib/fulmar/infrastructure/service/database/database_service.rb in fulmar-1.8.4

- old
+ new

@@ -15,11 +15,12 @@ maria: { host: '127.0.0.1', port: 3306, user: 'root', password: '', - encoding: 'utf8' + encoding: 'utf8', + ignore_tables: [] } } def initialize(config) @config = config @@ -73,14 +74,12 @@ end def dump(filename = backup_filename) filename = "#{@config[:remote_path]}/#{filename}" unless filename[0, 1] == '/' - diffable = @config[:maria][:diffable_dump] ? '--skip-comments --skip-extended-insert ' : '' - @shell.run "mysqldump -h #{@config[:maria][:host]} -u #{@config[:maria][:user]} --password='#{@config[:maria][:password]}' " \ - "#{@config[:maria][:database]} --single-transaction #{diffable}-r \"#{filename}\"" + "#{@config[:maria][:database]} --single-transaction #{diffable} #{ignore_tables} -r \"#{filename}\"" filename end def load_dump(dump_file, database = @config[:maria][:database]) @@ -124,9 +123,22 @@ def try_connect(options, i) @client = Mysql2::Client.new options rescue Mysql2::Error => e sleep 1 if i < 3 raise e.message if i == 3 + end + + # Return mysql command line options to ignore specific tables + def ignore_tables + @config[:maria][:ignore_tables] = [*@config[:maria][:ignore_tables]] + @config[:maria][:ignore_tables].map do |table| + "--ignore-table=#{@config[:maria][:database]}.#{table}" + end.join(' ') + end + + # Return the mysql configuration options to make a dump diffable + def diffable + @config[:maria][:diffable_dump] ? '--skip-comments --skip-extended-insert ' : '' end # Test configuration def config_test fail 'Configuration option "database" missing.' unless @config[:maria][:database]