Class: ColdStorage::Configuration
- Inherits:
-
Object
- Object
- ColdStorage::Configuration
- 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
-
#archive_database ⇒ Object
Name of the database.yml entry holding the archive database.
-
#archived_at_column ⇒ Object
Extra column added to every archive table, holding the archiving time.
-
#batch_size ⇒ Object
Rows copied (and deleted) per round trip.
-
#delete_after_archive ⇒ Object
Delete rows from the primary database once they are safely copied.
-
#delete_method ⇒ Object
:delete_all (fast, no callbacks) or :destroy_all (slow, runs callbacks).
-
#deleted_column ⇒ Object
Default column used by
deleted: true. -
#drop_removed_columns ⇒ Object
Drop archive columns that no longer exist in the primary database.
-
#dry_run ⇒ Object
Log every statement/plan the gem produces without touching any data.
-
#enabled ⇒ Object
Master switch.
-
#job_parent_class ⇒ Object
Parent class of the bundled jobs, as a string.
-
#job_queue ⇒ Object
ActiveJob queue used by the bundled jobs.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#mirror_defaults ⇒ Object
Copy column defaults.
-
#mirror_indexes ⇒ Object
Copy indexes to the archive tables.
-
#mirror_null_constraints ⇒ Object
Copy NOT NULL constraints.
-
#on_destroy_error ⇒ Object
What to do when
on_destroy:cannot reach the archive database: :raise (block the delete, keep the data) or :log (let the delete through). -
#on_type_mismatch ⇒ Object
What to do when a column type differs: :warn, :raise, :change or :ignore.
-
#sync_schema_after_migrate ⇒ Object
Run the schema mirror automatically after db:migrate / db:schema:load.
-
#throttle ⇒ Object
Seconds to sleep between batches, to keep long runs off the hot path.
-
#timestamp_column ⇒ Object
Default column used to decide how old a record is.
Instance Method Summary collapse
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
Constructor Details
#initialize ⇒ Configuration
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_database ⇒ Object
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_column ⇒ Object
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_size ⇒ Object
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_archive ⇒ Object
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_method ⇒ Object
: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_column ⇒ Object
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_columns ⇒ Object
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_run ⇒ Object
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 |
#enabled ⇒ Object
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_class ⇒ Object
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_queue ⇒ Object
ActiveJob queue used by the bundled jobs.
49 50 51 |
# File 'lib/cold_storage/configuration.rb', line 49 def job_queue @job_queue end |
#logger ⇒ Object
Returns the value of attribute logger.
54 55 56 |
# File 'lib/cold_storage/configuration.rb', line 54 def logger @logger end |
#mirror_defaults ⇒ Object
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_indexes ⇒ Object
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_constraints ⇒ Object
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_error ⇒ Object
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_mismatch ⇒ Object
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_migrate ⇒ Object
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 |
#throttle ⇒ Object
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_column ⇒ Object
Default column used to decide how old a record is.
19 20 21 |
# File 'lib/cold_storage/configuration.rb', line 19 def @timestamp_column end |