Class: Nando::Migration

Inherits:
Object
  • Object
show all
Defined in:
lib/nando/migration.rb

Direct Known Subclasses

MigrationWithoutTransaction

Instance Method Summary collapse

Constructor Details

#initialize(conn, version) ⇒ Migration

Returns a new instance of Migration.



4
5
6
7
8
9
# File 'lib/nando/migration.rb', line 4

def initialize (conn, version)
  @conn = conn
  @version = version
  @migration_table = NandoMigrator.instance.migration_table
  @migration_field = NandoMigrator.instance.migration_field
end

Instance Method Details

#execute(sql) ⇒ Object



11
12
13
# File 'lib/nando/migration.rb', line 11

def execute (sql)
  @conn.exec(sql)
end

#execute_migration(method) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/nando/migration.rb', line 20

def execute_migration (method)
  # TODO: review this is the best way of creating a transaction (don't know if re-assigning connections has weird behaviours)
  old_connection = @conn
  @conn.transaction do |conn|
    @conn = conn
    self.send(method)
  end
  @conn = old_connection
end

#invalidate_postgresql_redis_cache!Object



30
31
32
33
34
# File 'lib/nando/migration.rb', line 30

def invalidate_postgresql_redis_cache!
  # TODO: how to do this?
  Rake::Task['cloudware:toconline:system:redis:postgresql_cache_invalidate'].invoke
  Rake::Task['cloudware:toconline:system:redis:redis_current_company_invalidate'].invoke
end

#update_function(sql) ⇒ Object



15
16
17
18
# File 'lib/nando/migration.rb', line 15

def update_function (sql)
  # TODO: add validations here
  @conn.exec(sql)
end