Class: RubyLLM::Generators::OnlineCopyMigration

Inherits:
UpgradeMigration show all
Defined in:
lib/generators/ruby_llm/upgrade/online_copy_migration.rb,
lib/generators/ruby_llm/upgrade/online_copy_migration/data.rb,
lib/generators/ruby_llm/upgrade/online_copy_migration/journal.rb,
lib/generators/ruby_llm/upgrade/online_copy_migration/verification.rb

Overview

:nodoc: all

Defined Under Namespace

Classes: Data, Journal, Verification

Constant Summary

Constants inherited from UpgradeMigration

UpgradeMigration::TABLE, UpgradeMigration::VERSION_COLUMN

Instance Method Summary collapse

Methods inherited from UpgradeMigration

#activate, for, #initialize, #verify_cleanup

Constructor Details

This class inherits a constructor from RubyLLM::Generators::UpgradeMigration

Instance Method Details

#backfillObject



36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/generators/ruby_llm/upgrade/online_copy_migration.rb', line 36

def backfill
  with_migration_lock do
    state = states.first!
    unless state.active_version == 1 && %w[preparing active].include?(state.status)
      raise 'Online copy backfill requires RubyLLM 1.16 to be active'
    end
    raise 'Use resume after rolling back a finished upgrade' if data.finished?

    data.backfill
    data.catch_up(passes: 2)
    state.update!(needs_reconcile: false)
  end
end

#cleanupObject



105
106
107
108
109
110
111
112
113
# File 'lib/generators/ruby_llm/upgrade/online_copy_migration.rb', line 105

def cleanup
  with_migration_lock do
    verify_cleanup
    journal.remove
    yield if block_given?
    data.cleanup
    super
  end
end

#copy_model_referencesObject



32
33
34
# File 'lib/generators/ruby_llm/upgrade/online_copy_migration.rb', line 32

def copy_model_references
  nil
end

#copy_table(source, target) ⇒ Object



28
29
30
# File 'lib/generators/ruby_llm/upgrade/online_copy_migration.rb', line 28

def copy_table(source, target)
  create_copy_table(source, target) unless @connection.table_exists?(target)
end

#finalizeObject



101
102
103
# File 'lib/generators/ruby_llm/upgrade/online_copy_migration.rb', line 101

def finalize
  with_migration_lock { super }
end

#finish(discard_incomplete_tool_calls: false) ⇒ Object



50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/generators/ruby_llm/upgrade/online_copy_migration.rb', line 50

def finish(discard_incomplete_tool_calls: false)
  with_migration_lock do
    state = states.first!
    return if state.active_version == 2 && state.status == 'active' && data.finished?

    raise 'Run the copy backfill before finish' unless data.completed?

    pause(state, from: 1, statuses: %w[preparing active finishing])
    if discard_incomplete_tool_calls
      discarded = data.discard_incomplete_tool_calls
      ::ActiveRecord::Migration.say "Discarded #{discarded} incomplete legacy tool calls"
    end
    data.catch_up
    data.verify
    verify_completed_work
    yield
    journal.install
    state.update!(active_version: 2, status: 'active', needs_reconcile: false)
  end
end

#online?Boolean

Returns:

  • (Boolean)


10
# File 'lib/generators/ruby_llm/upgrade/online_copy_migration.rb', line 10

def online? = true

#prepare(settings) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/generators/ruby_llm/upgrade/online_copy_migration.rb', line 12

def prepare(settings)
  with_migration_lock do
    super(settings.merge(online: true), &nil)
    unless @connection.column_exists?(TABLE, :epoch)
      @connection.add_column(TABLE, :epoch, :bigint, null: false, default: 0)
    end
    yield if block_given?
    data.prepare
    journal.install
  end
end

#resumeObject



88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/generators/ruby_llm/upgrade/online_copy_migration.rb', line 88

def resume
  with_migration_lock do
    raise 'Finish the initial copy migrations before resuming 2.0' unless data.finished?

    state = states.first!
    pause(state, from: 1, statuses: %w[active finishing])
    data.catch_up
    data.verify
    verify_completed_work
    state.update!(active_version: 2, status: 'active', needs_reconcile: false)
  end
end

#rollbackObject



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/generators/ruby_llm/upgrade/online_copy_migration.rb', line 71

def rollback
  with_migration_lock do
    state = states.first!
    unless data.finished?
      raise 'The unfinished upgrade is not running on 1.16' unless state.active_version == 1

      state.update!(status: 'preparing', needs_reconcile: true)
      return
    end
    state.with_lock do
      require_active_version(state, 2)
      verify_completed_work
      state.update!(active_version: 1, epoch: state.epoch + 1)
    end
  end
end

#verify_settings(settings) ⇒ Object



24
25
26
# File 'lib/generators/ruby_llm/upgrade/online_copy_migration.rb', line 24

def verify_settings(settings)
  super(settings.merge(online: true))
end