Class: Chicago::ETL::TableBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/chicago/etl/table_builder.rb

Overview

Builds ETL tables.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(db) ⇒ TableBuilder

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of TableBuilder.



12
13
14
# File 'lib/chicago/etl/table_builder.rb', line 12

def initialize(db)
  @db = db
end

Class Method Details

.build(db) ⇒ Object

Creates the necessary tables for the ETL process in the given database.



7
8
9
# File 'lib/chicago/etl/table_builder.rb', line 7

def self.build(db)
  new(db).build
end

Instance Method Details

#buildObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/chicago/etl/table_builder.rb', line 17

def build
  create_table :etl_batches do
    primary_key :id, :type => :integer, :unsigned => true
    timestamp   :started_at, :null => false, :default => :current_timestamp.sql_function
    timestamp   :finished_at, :null => true, :default => nil
    timestamp   :extracted_to, :null => true, :default => nil
    enum        :state, :null => false, :elements => %w{Started Finished Error}, :default => "Started"
  end

  create_table :etl_task_invocations do
    primary_key :id, :type => :integer, :unsigned => true
    integer     :batch_id, :unsigned => true, :null => false
    enum        :stage, :null => false, :elements => %w{Extract Transform Load}
    varchar     :name, :null => false
    timestamp   :started_at, :null => false, :default => :current_timestamp.sql_function
    timestamp   :finished_at, :null => true, :default => nil
    enum        :state, :null => false, :elements => %w{Created Started Finished Error}, :default => "Created"
    smallint    :attempts, :null => false, :unsigned => true

    index [:batch_id, :stage, :name], :unique => true
  end
end