Module: Woods::Db::Migrations::RenameTables

Defined in:
lib/woods/db/migrations/006_rename_tables.rb

Overview

Renames codebase_* tables to woods_* as part of the gem rename.

Constant Summary collapse

VERSION =
6

Class Method Summary collapse

Class Method Details

.up(connection) ⇒ void

This method returns an undefined value.

Parameters:

  • connection (Object)

    Database connection



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/woods/db/migrations/006_rename_tables.rb', line 12

def self.up(connection)
  renames = {
    'codebase_units' => 'woods_units',
    'codebase_edges' => 'woods_edges',
    'codebase_embeddings' => 'woods_embeddings',
    'codebase_snapshots' => 'woods_snapshots',
    'codebase_snapshot_units' => 'woods_snapshot_units'
  }

  renames.each do |old_name, new_name|
    # Only rename if the old table exists (fresh installs won't have it)
    result = connection.execute(
      "SELECT name FROM sqlite_master WHERE type='table' AND name='#{old_name}'"
    )
    next if result.empty?

    connection.execute("ALTER TABLE #{old_name} RENAME TO #{new_name}")
  end
end