Class: CSGOLytics::SchemaManager

Inherits:
Object
  • Object
show all
Defined in:
lib/csgolytics/schema_manager.rb

Instance Method Summary collapse

Constructor Details

#initialize(db, schema_path) ⇒ SchemaManager

Returns a new instance of SchemaManager.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/csgolytics/schema_manager.rb', line 7

def initialize(db, schema_path)
  @db = db
  @schema_path = schema_path

  @tables = []
  Dir.entries(schema_path).each do |tbl|
    next if tbl.start_with?(".")

    if tbl =~ /(\w+)\.sql/
      @tables << $1
    else
      $stderr.puts "ERROR: invalid table schema file #{tbl}"
      exit 1
    end
  end
end

Instance Method Details

#migrate!Object



24
25
26
27
28
29
30
31
32
33
# File 'lib/csgolytics/schema_manager.rb', line 24

def migrate!
  $stderr.puts "Migrating database schemas, this may take a second"
  list_tables_qry = @db.query("show tables;")
  list_tables_res = list_tables_qry.execute!

  actual_tables = list_tables_res[0]["rows"].map(&:first)
  (@tables - actual_tables).each do |tbl|
    create_table!(tbl)
  end
end