Class: ProjectUnification::SpecialHandlers::CachedTablesHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/project_unification/special_handlers.rb

Overview

Handler for cached_* tables - no validation needed, just bulk update.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(source_project_id:, target_project_id:, klass:) ⇒ CachedTablesHandler

Returns a new instance of CachedTablesHandler.



12
13
14
15
16
# File 'lib/project_unification/special_handlers.rb', line 12

def initialize(source_project_id:, target_project_id:, klass:)
  @source_project_id = source_project_id
  @target_project_id = target_project_id
  @klass = klass
end

Instance Attribute Details

#klassObject (readonly)

Returns the value of attribute klass.



10
11
12
# File 'lib/project_unification/special_handlers.rb', line 10

def klass
  @klass
end

#source_project_idObject (readonly)

Returns the value of attribute source_project_id.



10
11
12
# File 'lib/project_unification/special_handlers.rb', line 10

def source_project_id
  @source_project_id
end

#target_project_idObject (readonly)

Returns the value of attribute target_project_id.



10
11
12
# File 'lib/project_unification/special_handlers.rb', line 10

def target_project_id
  @target_project_id
end

Instance Method Details

#migrateObject



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/project_unification/special_handlers.rb', line 18

def migrate
  migrated = klass.where(project_id: source_project_id)
                  .update_all(project_id: target_project_id)

  {
    track: :cached,
    migrated: migrated,
    method: :direct_sql,
    errors: []
  }
rescue => e
  {
    track: :cached,
    migrated: 0,
    method: :direct_sql,
    errors: [{ error: e.message, backtrace: e.backtrace.first(3) }]
  }
end