Class: ColdStorage::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/cold_storage/configuration.rb

Overview

Global defaults. Every model can override most of these through its own archivable options.

Constant Summary collapse

TYPE_MISMATCH_STRATEGIES =
%i[warn raise change ignore].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/cold_storage/configuration.rb', line 56

def initialize
  @enabled                   = true
  @archive_database          = :archive
  @batch_size                = 1_000
  @timestamp_column          = :created_at
  @deleted_column            = :deleted_at
  @archived_at_column        = :archived_at
  @delete_after_archive      = true
  @delete_method             = :delete_all
  @mirror_indexes            = true
  @mirror_null_constraints   = false
  @mirror_defaults           = false
  @drop_removed_columns      = false
  @on_type_mismatch          = :warn
  @on_destroy_error          = :raise
  @sync_schema_after_migrate = true
  @throttle                  = 0
  @job_queue                 = :default
  @job_parent_class          = 'ActiveJob::Base'
  @dry_run                   = false
  @logger                    = nil
end

Instance Attribute Details

#archive_databaseObject

Name of the database.yml entry holding the archive database.



15
16
17
# File 'lib/cold_storage/configuration.rb', line 15

def archive_database
  @archive_database
end

#archived_at_columnObject

Extra column added to every archive table, holding the archiving time. Set to nil to disable.



24
25
26
# File 'lib/cold_storage/configuration.rb', line 24

def archived_at_column
  @archived_at_column
end

#batch_sizeObject

Rows copied (and deleted) per round trip.



17
18
19
# File 'lib/cold_storage/configuration.rb', line 17

def batch_size
  @batch_size
end

#delete_after_archiveObject

Delete rows from the primary database once they are safely copied.



26
27
28
# File 'lib/cold_storage/configuration.rb', line 26

def delete_after_archive
  @delete_after_archive
end

#delete_methodObject

:delete_all (fast, no callbacks) or :destroy_all (slow, runs callbacks).



28
29
30
# File 'lib/cold_storage/configuration.rb', line 28

def delete_method
  @delete_method
end

#deleted_columnObject

Default column used by deleted: true.



21
22
23
# File 'lib/cold_storage/configuration.rb', line 21

def deleted_column
  @deleted_column
end

#drop_removed_columnsObject

Drop archive columns that no longer exist in the primary database. Off by default so that already archived data keeps its columns.



38
39
40
# File 'lib/cold_storage/configuration.rb', line 38

def drop_removed_columns
  @drop_removed_columns
end

#dry_runObject

Log every statement/plan the gem produces without touching any data.



53
54
55
# File 'lib/cold_storage/configuration.rb', line 53

def dry_run
  @dry_run
end

#enabledObject

Master switch. When false, nothing is copied or deleted: scheduled runs report themselves as skipped and the on_destroy hook stands down. Handy for the test environment, which has no archive database. Schema tasks keep working, so schema:check can still run in CI.



13
14
15
# File 'lib/cold_storage/configuration.rb', line 13

def enabled
  @enabled
end

#job_parent_classObject

Parent class of the bundled jobs, as a string.



51
52
53
# File 'lib/cold_storage/configuration.rb', line 51

def job_parent_class
  @job_parent_class
end

#job_queueObject

ActiveJob queue used by the bundled jobs.



49
50
51
# File 'lib/cold_storage/configuration.rb', line 49

def job_queue
  @job_queue
end

#loggerObject

Returns the value of attribute logger.



54
55
56
# File 'lib/cold_storage/configuration.rb', line 54

def logger
  @logger
end

#mirror_defaultsObject

Copy column defaults. Off by default, rows are always inserted complete.



35
36
37
# File 'lib/cold_storage/configuration.rb', line 35

def mirror_defaults
  @mirror_defaults
end

#mirror_indexesObject

Copy indexes to the archive tables.



30
31
32
# File 'lib/cold_storage/configuration.rb', line 30

def mirror_indexes
  @mirror_indexes
end

#mirror_null_constraintsObject

Copy NOT NULL constraints. Off by default: an archive table should never reject historical rows because the primary schema grew stricter later.



33
34
35
# File 'lib/cold_storage/configuration.rb', line 33

def mirror_null_constraints
  @mirror_null_constraints
end

#on_destroy_errorObject

What to do when on_destroy: cannot reach the archive database: :raise (block the delete, keep the data) or :log (let the delete through).



43
44
45
# File 'lib/cold_storage/configuration.rb', line 43

def on_destroy_error
  @on_destroy_error
end

#on_type_mismatchObject

What to do when a column type differs: :warn, :raise, :change or :ignore.



40
41
42
# File 'lib/cold_storage/configuration.rb', line 40

def on_type_mismatch
  @on_type_mismatch
end

#sync_schema_after_migrateObject

Run the schema mirror automatically after db:migrate / db:schema:load.



45
46
47
# File 'lib/cold_storage/configuration.rb', line 45

def sync_schema_after_migrate
  @sync_schema_after_migrate
end

#throttleObject

Seconds to sleep between batches, to keep long runs off the hot path.



47
48
49
# File 'lib/cold_storage/configuration.rb', line 47

def throttle
  @throttle
end

#timestamp_columnObject

Default column used to decide how old a record is.



19
20
21
# File 'lib/cold_storage/configuration.rb', line 19

def timestamp_column
  @timestamp_column
end