Sha256: 593d3f63c3f6c87fca4ff10f8fde20d4f3ed9d42e0dff5e6f655aa9020e3e056

Contents?: true

Size: 1.17 KB

Versions: 19

Compression:

Stored size: 1.17 KB

Contents

module CoreExtensions
  module ActiveRecord
    module MigrationHelpers
      # Can be called from a migration to load in a function from a sql file
      # at e.g. db/functions/my_function_v01.sql
      #
      # Example usage:
      #  load_function("my_function_v01.sql")
      #
      def load_function(filename)
        load_sql_file(DatabaseObjectPaths.functions, filename)
      end

      # Can be called from a migration to load in a trigger from a sql file
      # at e.g. db/functions/my_trigger_v01.sql
      #
      # Example usage:
      #  load_trigger("my_trigger_v01.sql")
      #
      def load_trigger(filename)
        load_sql_file(DatabaseObjectPaths.triggers, filename)
      end

      def load_sql_file(path, filename)
        connection.execute(File.read(path.join(filename)))
      end

      class DatabaseObjectPaths
        class << self
          def triggers
            Renalware::Engine.root.join("db", "triggers")
          end

          def functions
            Renalware::Engine.root.join("db", "functions")
          end
        end
      end
    end
  end
end

ActiveRecord::Migration[5.1].send(:prepend, CoreExtensions::ActiveRecord::MigrationHelpers)

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
renalware-core-2.0.16 lib/core_extensions/active_record/migration_helpers.rb
renalware-core-2.0.15 lib/core_extensions/active_record/migration_helpers.rb
renalware-core-2.0.14 lib/core_extensions/active_record/migration_helpers.rb
renalware-core-2.0.13 lib/core_extensions/active_record/migration_helpers.rb
renalware-core-2.0.12 lib/core_extensions/active_record/migration_helpers.rb
renalware-core-2.0.11 lib/core_extensions/active_record/migration_helpers.rb
renalware-core-2.0.9 lib/core_extensions/active_record/migration_helpers.rb
renalware-core-2.0.8 lib/core_extensions/active_record/migration_helpers.rb
renalware-core-2.0.7 lib/core_extensions/active_record/migration_helpers.rb
renalware-core-2.0.5 lib/core_extensions/active_record/migration_helpers.rb
renalware-core-2.0.4 lib/core_extensions/active_record/migration_helpers.rb
renalware-core-2.0.3 lib/core_extensions/active_record/migration_helpers.rb
renalware-core-2.0.2 lib/core_extensions/active_record/migration_helpers.rb
renalware-core-2.0.1 lib/core_extensions/active_record/migration_helpers.rb
renalware-core-2.0.0 lib/core_extensions/active_record/migration_helpers.rb
renalware-core-2.0.0.pre.rc13 lib/core_extensions/active_record/migration_helpers.rb
renalware-core-2.0.0.pre.rc11 lib/core_extensions/active_record/migration_helpers.rb
renalware-core-2.0.0.pre.rc10 lib/core_extensions/active_record/migration_helpers.rb
renalware-core-2.0.0.pre.rc9 lib/core_extensions/active_record/migration_helpers.rb