Class: Arfi::SqlFunctionLoader
- Inherits:
-
Object
- Object
- Arfi::SqlFunctionLoader
- Defined in:
- lib/arfi/sql_function_loader.rb
Overview
Loads user-defined SQL functions into the database by executing SQL files located under ‘db/functions`.
Supported directory layout (Option B: explicit public):
db/functions/public/*.sql (generic public)
db/functions/postgresql/public/*.sql (postgres public)
db/functions/postgresql/<schema>/*.sql (postgres schema)
db/functions/mysql/public/*.sql (mysql/trilogy public)
Backward-compatible legacy aliases:
db/functions/*.sql (generic public legacy)
db/functions/postgresql/*.sql (postgres public legacy)
db/functions/mysql/*.sql (mysql public legacy)
Rules:
-
underscore-prefixed files are ignored (_shared.sql)
-
adapter-specific overrides generic when schema+filename matches
Class Method Summary collapse
-
.load!(task_name: nil, connection: nil, clear_active_connections: true, verbose: true) ⇒ void
Load all SQL function files into the database.
Class Method Details
.load!(task_name: nil, connection: nil, clear_active_connections: true, verbose: true) ⇒ void
This method returns an undefined value.
Load all SQL function files into the database.
Handles both single-DB and multi-DB setups. Uses the given connection or infers it.
35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/arfi/sql_function_loader.rb', line 35 def load!(task_name: nil, connection: nil, clear_active_connections: true, verbose: true) task_short = task_name ? task_name[/([^:]+$)/] : nil conn = connection || default_connection raise_unless_supported_adapter(conn) if connection.nil? && multi_db? && task_name.nil? populate_multiple_db(verbose: verbose, task_name: task_short) else populate_db(conn, verbose: verbose, task_name: task_short) end ensure clear_active_connections_if_needed(clear_active_connections) end |