Class: Glib::Generators::SnapshotV2Generator
- Inherits:
-
Rails::Generators::Base
- Object
- Rails::Generators::Base
- Glib::Generators::SnapshotV2Generator
- Includes:
- Rails::Generators::Migration
- Defined in:
- lib/generators/glib/snapshot_v2_generator.rb
Overview
Installs the Glib::SnapshotV2 database prerequisites. Two opt-in pieces, each produced only when the corresponding flag is passed:
`rails g glib:snapshot_v2` # adds V2 columns only (required for V2)
`rails g glib:snapshot_v2 --with-blob-references` # also creates the blob-reference table
Deliberately separate from glib:install: that generator overwrites config/database.yml
and writes dynamic-text migrations to the non-standard db/dynamic_text_migrate/ path,
neither of which a snapshot adopter wants re-run on their app. Snapshot tables live in the
primary DB and use the standard db/migrate/ path.
The V2 columns migration adds action / version / diff (jsonb) / source plus the
two composite indexes Glib::SnapshotV2's queries rely on. It does NOT backfill — adopters
who need to migrate legacy V1 snapshots (stored under metadata) own that one-way data
conversion themselves. See issue #960.
Class Method Summary collapse
Instance Method Summary collapse
Class Method Details
.next_migration_number(_dirname) ⇒ Object
46 47 48 49 50 51 |
# File 'lib/generators/glib/snapshot_v2_generator.rb', line 46 def self.next_migration_number(_dirname) @@migration_mutex.synchronize do @last_snapshot_v2_number ||= (Time.now.utc - 1.second).strftime('%Y%m%d%H%M%S') @last_snapshot_v2_number = (@last_snapshot_v2_number.to_i + 1).to_s end end |
Instance Method Details
#copy_blob_references_migration ⇒ Object
31 32 33 34 35 36 |
# File 'lib/generators/glib/snapshot_v2_generator.rb', line 31 def copy_blob_references_migration return unless [:with_blob_references] migration_template 'create_snapshot_blob_references.rb', 'db/migrate/create_snapshot_blob_references.rb' end |
#copy_v2_columns_migration ⇒ Object
26 27 28 29 |
# File 'lib/generators/glib/snapshot_v2_generator.rb', line 26 def copy_v2_columns_migration migration_template 'add_snapshot_v2_columns.rb', 'db/migrate/add_snapshot_v2_columns.rb' end |