Class: RubyCms::MigrationReconciler

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_cms/migration_reconciler.rb

Overview

Stamps pending framework migrations when their schema is already present. Covers partial installs where tables were created under an older timestamp and a re-run added duplicate migration files.

Constant Summary collapse

NOTICED_PATTERNS =
[
  "*create_noticed_tables*.rb",
  "*add_notifications_count_to_noticed*.rb"
].freeze

Instance Method Summary collapse

Constructor Details

#initialize(app_root:) ⇒ MigrationReconciler

Returns a new instance of MigrationReconciler.



15
16
17
# File 'lib/ruby_cms/migration_reconciler.rb', line 15

def initialize(app_root:)
  @migrate_dir = Pathname(app_root).join("db/migrate")
end

Instance Method Details

#reconcile!Object



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/ruby_cms/migration_reconciler.rb', line 19

def reconcile!
  return unless defined?(ActiveRecord::Base)

  conn = ActiveRecord::Base.connection
  return unless conn.table_exists?(:noticed_events)

  stamp_pending!(conn, @migrate_dir.glob(NOTICED_PATTERNS[0]))
  return unless conn.column_exists?(:noticed_events, :notifications_count)

  stamp_pending!(conn, @migrate_dir.glob(NOTICED_PATTERNS[1]))
end