Class: Chicago::RakeTasks

Inherits:
Rake::TaskLib
  • Object
show all
Defined in:
lib/chicago/rake_tasks.rb

Overview

Rake tasks for a Chicago project.

To use, simply include:

Chicago::RakeTasks.new(db, schema)

in your project’s Rakefile.

Provides the following tasks:

db:create_null_records

creates all the null dimension records in db

db:create_etl_tables

defines the tables used for ETL batches and the like

db:write_migrations

writes the auto migrations to a “migrations” directory.

Instance Method Summary collapse

Constructor Details

#initialize(db, schema) ⇒ RakeTasks

Returns a new instance of RakeTasks.



23
24
25
26
27
28
# File 'lib/chicago/rake_tasks.rb', line 23

def initialize(db, schema)
  @migration_dir = "migrations"
  @db = db
  @schema = schema
  define
end

Instance Method Details

#defineObject

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.

Defines the rake tasks.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# File 'lib/chicago/rake_tasks.rb', line 33

def define
  namespace :db do
    desc "Write Null dimension records"
    task :create_null_records do
      # TODO: replace this with proper logging.
      warn "Loading NULL records."
      @schema.dimensions.each {|dimension| dimension.create_null_records(@db) }
    end

    desc "Writes a migration file to change the database based on defined Facts & Dimensions"
    task :write_migrations do
      Database::MigrationFileWriter.new(@db, @migration_dir).
        write_migration_file(@schema)
    end
  end
end