Class: Arfi::SqlFunctionLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/arfi/sql_function_loader.rb

Overview

Arfi::SqlFunctionLoader is a class which loads user defined SQL functions into database.

Class Method Summary collapse

Class Method Details

.load!Object



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

def load!
  return unless sql_files&.any?

  puts '[ARFI] Loading SQL functions BEFORE schema load transaction...'
  db_config = Rails.configuration.database_configuration[Rails.env]
  conn = conn(db_config)

  sql_files&.each do |file|
    sql = File.read(file).strip
    conn.exec(sql)
    puts "[ARFI] Loaded: #{File.basename(file)}"
  end

  conn.close
end