Class: TestData::WarnsIfDumpIsNewerThanDatabase

Inherits:
Object
  • Object
show all
Defined in:
lib/test_data/warns_if_dump_is_newer_than_database.rb

Instance Method Summary collapse

Constructor Details

#initializeWarnsIfDumpIsNewerThanDatabase

Returns a new instance of WarnsIfDumpIsNewerThanDatabase.



3
4
5
6
7
# File 'lib/test_data/warns_if_dump_is_newer_than_database.rb', line 3

def initialize
  @config = TestData.config
  @determines_when_sql_dump_was_made = DeterminesWhenSqlDumpWasMade.new
  @determines_databases_associated_dump_time = DeterminesDatabasesAssociatedDumpTime.new
end

Instance Method Details

#callObject



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/test_data/warns_if_dump_is_newer_than_database.rb', line 9

def call
  return unless Rails.env.test_data?
  sql_dumped_at = @determines_when_sql_dump_was_made.call
  database_dumped_at = @determines_databases_associated_dump_time.call

  if sql_dumped_at.present? &&
      database_dumped_at.present? &&
      sql_dumped_at > database_dumped_at
    TestData.log.warn <<~MSG
      The SQL dumps in '#{File.dirname(@config.data_dump_path)}' were created
      after your local test_data database '#{@config.database_name}' was last dumped.

        SQL Dump: #{sql_dumped_at.localtime}
        Database: #{database_dumped_at.localtime}

      To avoid potential data loss, you may want to consider dropping '#{@config.database_name}'
      and loading the SQL dumps before making changes to the test data in this database
      or performing another dump.

      To do this, kill any processes with RAILS_ENV=test_data and then run:

        $ bin/rake test_data:reinitialize

    MSG
  end
end