Sha256: f615d1b5ae2874ea75507e61a2f7c3c50ccae234737eaa6e875dbf8a9e2682d2

Contents?: true

Size: 1.43 KB

Versions: 13

Compression:

Stored size: 1.43 KB

Contents

# :nocov:
# rubocop:todo Metrics/BlockLength
Hanami.app.register_provider :persistence, namespace: true do
  prepare do
    require "rom-changeset"
    require "rom/core"
    require "rom/sql"

    Sequel::Database.extension :constant_sql_override, :pg_enum
    Sequel.database_timezone = :utc
    Sequel.application_timezone = :local

    configuration = ROM::Configuration.new :sql, target["settings"].database_url

    configuration.plugin :sql, relations: :instrumentation do |plugin_config|
      plugin_config.notifications = target["notifications"]
    end

    configuration.plugin :sql, relations: :auto_restrictions

    database = configuration.gateways[:default].connection
    database.set_constant_sql Sequel::CURRENT_TIMESTAMP, "(CURRENT_TIMESTAMP AT TIME ZONE 'UTC')"

    register "config", configuration
    register "db", database

    Sequel::Migrator.is_current? database, Hanami.app.root.join("db/migrate")
  rescue NoMethodError, Sequel::Migrator::Error => error
    message = error.message
    Hanami.logger.error message unless error.is_a?(NoMethodError) && message.include?("migration")
  end

  start do
    configuration = target["persistence.config"]

    configuration.auto_registration(
      target.root.join("lib/<%= settings.project_path %>/persistence"),
      namespace: "<%= settings.project_namespaced_class %>::Persistence"
    )

    register "rom", ROM.container(configuration)
  end
end
# rubocop:enable Metrics/BlockLength

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
hanamismith-0.50.0 lib/hanamismith/templates/%project_name%/config/providers/persistence.rb.erb
hanamismith-0.49.1 lib/hanamismith/templates/%project_name%/config/providers/persistence.rb.erb
hanamismith-0.49.0 lib/hanamismith/templates/%project_name%/config/providers/persistence.rb.erb
hanamismith-0.48.0 lib/hanamismith/templates/%project_name%/config/providers/persistence.rb.erb
hanamismith-0.47.0 lib/hanamismith/templates/%project_name%/config/providers/persistence.rb.erb
hanamismith-0.46.0 lib/hanamismith/templates/%project_name%/config/providers/persistence.rb.erb
hanamismith-0.45.0 lib/hanamismith/templates/%project_name%/config/providers/persistence.rb.erb
hanamismith-0.44.0 lib/hanamismith/templates/%project_name%/config/providers/persistence.rb.erb
hanamismith-0.43.0 lib/hanamismith/templates/%project_name%/config/providers/persistence.rb.erb
hanamismith-0.42.0 lib/hanamismith/templates/%project_name%/config/providers/persistence.rb.erb
hanamismith-0.41.0 lib/hanamismith/templates/%project_name%/config/providers/persistence.rb.erb
hanamismith-0.40.0 lib/hanamismith/templates/%project_name%/config/providers/persistence.rb.erb
hanamismith-0.39.0 lib/hanamismith/templates/%project_name%/config/providers/persistence.rb.erb