-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ROM boilerplate for database connections
We will need to reconcile the common notion of separate dev/test databases with our earlier setup scripts, but this sets up the new Hanami app to connect to "the database" via ROM and mysql2. We can refer to the relations that are still under the top level lib directory as we begin building out the API and need these tables mapped.
- Loading branch information
Showing
10 changed files
with
106 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
DATABASE_URL=mysql2://lauth:lauth@db.lauth.local:3306/lauth |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
DATABASE_URL=mysql2://lauth:lauth@db.lauth.local:3306/lauth_test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,16 @@ | ||
# frozen_string_literal: true | ||
|
||
require "hanami/rake_tasks" | ||
require "rom/sql/rake_task" | ||
|
||
task :environment do | ||
require_relative "config/app" | ||
require "hanami/prepare" | ||
end | ||
|
||
namespace :db do | ||
task setup: :environment do | ||
Hanami.app.prepare(:persistence) | ||
ROM::SQL::RakeSupport.env = Hanami.app["persistence.config"] | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
Hanami.app.register_provider :persistence, namespace: true do | ||
prepare do | ||
require "rom" | ||
|
||
config = ROM::Configuration.new(:sql, target["settings"].database_url) | ||
|
||
register "config", config | ||
register "db", config.gateways[:default].connection | ||
end | ||
|
||
start do | ||
config = target["persistence.config"] | ||
|
||
config.auto_registration( | ||
target.root.join("lib/lauth/persistence"), | ||
namespace: "Lauth::Persistence" | ||
) | ||
|
||
register "rom", ROM.container(config) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ | |
|
||
require_relative "support/rspec" | ||
require_relative "support/requests" | ||
require_relative "support/database_cleaner" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
Hanami.app.prepare(:persistence) | ||
DatabaseCleaner[:sequel, db: Hanami.app["persistence.db"]] | ||
|
||
RSpec.configure do |config| | ||
config.before(:suite) do | ||
DatabaseCleaner.strategy = :transaction | ||
DatabaseCleaner.clean_with(:truncation) | ||
end | ||
|
||
config.around(:each, type: :database) do |example| | ||
DatabaseCleaner.cleaning do | ||
example.run | ||
end | ||
end | ||
end |