-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #740 from RailsEventStore/multiple-databases-repos…
…itory Multiple databases repository
- Loading branch information
Showing
121 changed files
with
2,987 additions
and
0 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
contrib/multiple_databases_repository_sample_app/.gitignore
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,20 @@ | ||
!/log/.keep | ||
!/storage/.keep | ||
!/tmp/.keep | ||
.byebug_history | ||
.yarn-integrity | ||
/.bundle | ||
/config/master.key | ||
/db/*.sqlite3 | ||
/db/*.sqlite3-journal | ||
/elm-stuff | ||
/log/* | ||
/node_modules | ||
/public/assets | ||
/public/packs | ||
/public/packs-test | ||
/storage/* | ||
/tmp/* | ||
/yarn-error.log | ||
coverage | ||
yarn-debug.log* |
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 @@ | ||
--require spec_helper |
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,38 @@ | ||
source 'https://rubygems.org' | ||
git_source(:github) { |repo| "https://github.com/#{repo}.git" } | ||
|
||
ruby '2.6.6' | ||
|
||
# Bundle edge Rails instead: gem 'rails', github: 'rails/rails' | ||
gem 'rails', '~> 6.0.3', '>= 6.0.3.1' | ||
# Use sqlite3 as the database for Active Record | ||
gem 'sqlite3', '~> 1.4' | ||
# Use Puma as the app server | ||
gem 'puma', '~> 4.1' | ||
# Build JSON APIs with ease. Read more: https://github.com/rails/jbuilder | ||
gem 'jbuilder', '~> 2.7' | ||
# Use Active Model has_secure_password | ||
# gem 'bcrypt', '~> 3.1.7' | ||
|
||
group :development, :test do | ||
# Call 'byebug' anywhere in the code to stop execution and get a debugger console | ||
gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] | ||
gem 'rspec-rails' | ||
gem 'database_cleaner' | ||
gem 'rails_event_store-rspec' | ||
end | ||
|
||
group :development do | ||
# Access an interactive console on exception pages or by calling 'console' anywhere in the code. | ||
gem 'web-console', '>= 3.3.0' | ||
end | ||
|
||
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem | ||
gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby] | ||
|
||
gem 'dry-struct' | ||
gem 'dry-types' | ||
|
||
gem 'ruby_event_store', path: '../../ruby_event_store' | ||
gem 'rails_event_store_active_record', path: '../../rails_event_store_active_record' | ||
gem 'rails_event_store', path: '../../rails_event_store' |
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,5 @@ | ||
# Domain description | ||
|
||
TDB | ||
|
||
[Event storming board](https://miro.com/app/embed/o9J_krLAGIQ=/?) |
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,6 @@ | ||
# Add your own tasks in files placed in lib/tasks ending in .rake, | ||
# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. | ||
|
||
require_relative 'config/application' | ||
|
||
Rails.application.load_tasks |
2 changes: 2 additions & 0 deletions
2
contrib/multiple_databases_repository_sample_app/app/assets/config/manifest.js
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,2 @@ | ||
//= link_tree ../images | ||
//= link_directory ../stylesheets .css |
15 changes: 15 additions & 0 deletions
15
contrib/multiple_databases_repository_sample_app/app/assets/stylesheets/application.css
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 @@ | ||
/* | ||
* This is a manifest file that'll be compiled into application.css, which will include all the files | ||
* listed below. | ||
* | ||
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, or any plugin's | ||
* vendor/assets/stylesheets directory can be referenced here using a relative path. | ||
* | ||
* You're free to add application-wide styles to this file and they'll appear at the bottom of the | ||
* compiled file so the styles you add here take precedence over styles defined in any other CSS/SCSS | ||
* files in this directory. Styles in this file should be added after the last require_* statement. | ||
* It is generally better to create a new file per style scope. | ||
* | ||
*= require_tree . | ||
*= require_self | ||
*/ |
2 changes: 2 additions & 0 deletions
2
contrib/multiple_databases_repository_sample_app/app/controllers/application_controller.rb
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,2 @@ | ||
class ApplicationController < ActionController::Base | ||
end |
2 changes: 2 additions & 0 deletions
2
contrib/multiple_databases_repository_sample_app/app/helpers/application_helper.rb
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,2 @@ | ||
module ApplicationHelper | ||
end |
7 changes: 7 additions & 0 deletions
7
contrib/multiple_databases_repository_sample_app/app/jobs/application_job.rb
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,7 @@ | ||
class ApplicationJob < ActiveJob::Base | ||
# Automatically retry jobs that encountered a deadlock | ||
# retry_on ActiveRecord::Deadlocked | ||
|
||
# Most jobs are safe to ignore if the underlying records are no longer available | ||
# discard_on ActiveJob::DeserializationError | ||
end |
3 changes: 3 additions & 0 deletions
3
contrib/multiple_databases_repository_sample_app/app/models/application_record.rb
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,3 @@ | ||
class ApplicationRecord < ActiveRecord::Base | ||
self.abstract_class = true | ||
end |
14 changes: 14 additions & 0 deletions
14
contrib/multiple_databases_repository_sample_app/app/views/layouts/application.html.erb
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,14 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>Sample</title> | ||
<%= csrf_meta_tags %> | ||
<%= csp_meta_tag %> | ||
|
||
<%= stylesheet_link_tag 'application', media: 'all' %> | ||
</head> | ||
|
||
<body> | ||
<%= yield %> | ||
</body> | ||
</html> |
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,5 @@ | ||
# This file is used by Rack-based servers to start the application. | ||
|
||
require_relative 'config/environment' | ||
|
||
run Rails.application |
38 changes: 38 additions & 0 deletions
38
contrib/multiple_databases_repository_sample_app/config/application.rb
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,38 @@ | ||
require_relative 'boot' | ||
|
||
require "rails" | ||
# Pick the frameworks you want: | ||
require "active_model/railtie" | ||
require "active_job/railtie" | ||
require "active_record/railtie" | ||
# require "active_storage/engine" | ||
require "action_controller/railtie" | ||
# require "action_mailer/railtie" | ||
# require "action_mailbox/engine" | ||
# require "action_text/engine" | ||
require "action_view/railtie" | ||
# require "action_cable/engine" | ||
# require "sprockets/railtie" | ||
# require "rails/test_unit/railtie" | ||
|
||
# Require the gems listed in Gemfile, including any gems | ||
# you've limited to :test, :development, or :production. | ||
Bundler.require(*Rails.groups) | ||
|
||
module Sample | ||
class Application < Rails::Application | ||
# Initialize configuration defaults for originally generated Rails version. | ||
config.load_defaults 6.0 | ||
|
||
# Settings in config/environments/* take precedence over those specified here. | ||
# Application configuration can go into files in config/initializers | ||
# -- all .rb files in that directory are automatically loaded after loading | ||
# the framework and any gems in your application. | ||
config.paths.add 'orders/lib', eager_load: true | ||
config.paths.add 'payments/lib', eager_load: true | ||
config.paths.add 'shipping/lib', eager_load: true | ||
|
||
# Don't generate system test files. | ||
config.generators.system_tests = nil | ||
end | ||
end |
3 changes: 3 additions & 0 deletions
3
contrib/multiple_databases_repository_sample_app/config/boot.rb
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,3 @@ | ||
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) | ||
|
||
require 'bundler/setup' # Set up gems listed in the Gemfile. |
1 change: 1 addition & 0 deletions
1
contrib/multiple_databases_repository_sample_app/config/credentials.yml.enc
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 @@ | ||
d1WzgYIe3R/fpHfTZfMP5wrp9uDbDMQc2SBiBqg5sqbHZKnTNktELx1YrV9xCcJqUa/V7RBEvsfXBAuu/5luTXkK/sKKL81mlcNuy57i09y7LjQ+ojRB6aWpTcquXM8RSDimSmjKQd9QKDNLxRKGK4wHhBWDa4+4urG2n72+6iVH4JvycVFv5Wgzkhe+su22rraZOKg7LLE9Nvrwrwf1Is1mDHJdxTZqnS4JzWljGbCGFO5AXhyEPp/zHJ/B1zooCcEeO/TUVpxU9OB1bjhIslKY0S+JFPsheY56eYv6WOEpt9EZAPNe4ZEj71H131kVZyD9SZajq+bUCJePJuKjMRjL2w/pkrKXXi9yz4W4bDsKvM2Oz4CNOtXePYe9G+YauExNYEO79oghgxz1UFUQEy1WGZfi/pj6I2mj--BY9vm19PlrY42f7d--DMlEvIHGiG+9KuB6ArAYkA== |
64 changes: 64 additions & 0 deletions
64
contrib/multiple_databases_repository_sample_app/config/database.yml
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,64 @@ | ||
# SQLite. Versions 3.8.0 and up are supported. | ||
# gem install sqlite3 | ||
# | ||
# Ensure the SQLite 3 gem is defined in your Gemfile | ||
# gem 'sqlite3' | ||
# | ||
default: &default | ||
adapter: sqlite3 | ||
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %> | ||
timeout: 5000 | ||
|
||
development: | ||
primary: | ||
<<: *default | ||
database: db/development.sqlite3 | ||
orders: | ||
<<: *default | ||
database: db/orders_development.sqlite3 | ||
migrations_paths: db/orders | ||
payments: | ||
<<: *default | ||
database: db/payments_development.sqlite3 | ||
migrations_paths: db/payments | ||
shipping: | ||
<<: *default | ||
database: db/shipping_development.sqlite3 | ||
migrations_paths: db/shipping | ||
|
||
# Warning: The database defined as "test" will be erased and | ||
# re-generated from your development database when you run "rake". | ||
# Do not set this db to the same as development or production. | ||
test: | ||
primary: | ||
<<: *default | ||
database: db/test.sqlite3 | ||
orders: | ||
<<: *default | ||
database: db/orders_test.sqlite3 | ||
migrations_paths: db/orders | ||
payments: | ||
<<: *default | ||
database: db/payments_test.sqlite3 | ||
migrations_paths: db/payments | ||
shipping: | ||
<<: *default | ||
database: db/shipping_test.sqlite3 | ||
migrations_paths: db/shipping | ||
|
||
production: | ||
primary: | ||
<<: *default | ||
database: db/production.sqlite3 | ||
orders: | ||
<<: *default | ||
database: db/orders_production.sqlite3 | ||
migrations_paths: db/orders | ||
payments: | ||
<<: *default | ||
database: db/payments_production.sqlite3 | ||
migrations_paths: db/payments | ||
shipping: | ||
<<: *default | ||
database: db/shipping_production.sqlite3 | ||
migrations_paths: db/shipping |
5 changes: 5 additions & 0 deletions
5
contrib/multiple_databases_repository_sample_app/config/environment.rb
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,5 @@ | ||
# Load the Rails application. | ||
require_relative 'application' | ||
|
||
# Initialize the Rails application. | ||
Rails.application.initialize! |
49 changes: 49 additions & 0 deletions
49
contrib/multiple_databases_repository_sample_app/config/environments/development.rb
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,49 @@ | ||
Rails.application.configure do | ||
# Settings specified here will take precedence over those in config/application.rb. | ||
|
||
# In the development environment your application's code is reloaded on | ||
# every request. This slows down response time but is perfect for development | ||
# since you don't have to restart the web server when you make code changes. | ||
config.cache_classes = false | ||
|
||
# Do not eager load code on boot. | ||
config.eager_load = false | ||
|
||
# Show full error reports. | ||
config.consider_all_requests_local = true | ||
|
||
# Enable/disable caching. By default caching is disabled. | ||
# Run rails dev:cache to toggle caching. | ||
if Rails.root.join('tmp', 'caching-dev.txt').exist? | ||
config.action_controller.perform_caching = true | ||
config.action_controller.enable_fragment_cache_logging = true | ||
|
||
config.cache_store = :memory_store | ||
config.public_file_server.headers = { | ||
'Cache-Control' => "public, max-age=#{2.days.to_i}" | ||
} | ||
else | ||
config.action_controller.perform_caching = false | ||
|
||
config.cache_store = :null_store | ||
end | ||
|
||
# Print deprecation notices to the Rails logger. | ||
config.active_support.deprecation = :log | ||
|
||
# Raise an error on page load if there are pending migrations. | ||
config.active_record.migration_error = :page_load | ||
|
||
# Highlight code that triggered database queries in logs. | ||
config.active_record.verbose_query_logs = true | ||
|
||
|
||
# Raises error for missing translations. | ||
# config.action_view.raise_on_missing_translations = true | ||
|
||
# Use an evented file watcher to asynchronously detect changes in source code, | ||
# routes, locales, etc. This feature depends on the listen gem. | ||
# config.file_watcher = ActiveSupport::EventedFileUpdateChecker | ||
|
||
config.number_generator_factory = ->{ Orders::NumberGenerator.new } | ||
end |
94 changes: 94 additions & 0 deletions
94
contrib/multiple_databases_repository_sample_app/config/environments/production.rb
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,94 @@ | ||
Rails.application.configure do | ||
# Settings specified here will take precedence over those in config/application.rb. | ||
|
||
# Code is not reloaded between requests. | ||
config.cache_classes = true | ||
|
||
# Eager load code on boot. This eager loads most of Rails and | ||
# your application in memory, allowing both threaded web servers | ||
# and those relying on copy on write to perform better. | ||
# Rake tasks automatically ignore this option for performance. | ||
config.eager_load = true | ||
|
||
# Full error reports are disabled and caching is turned on. | ||
config.consider_all_requests_local = false | ||
config.action_controller.perform_caching = true | ||
|
||
# Ensures that a master key has been made available in either ENV["RAILS_MASTER_KEY"] | ||
# or in config/master.key. This key is used to decrypt credentials (and other encrypted files). | ||
# config.require_master_key = true | ||
|
||
# Disable serving static files from the `/public` folder by default since | ||
# Apache or NGINX already handles this. | ||
config.public_file_server.enabled = ENV['RAILS_SERVE_STATIC_FILES'].present? | ||
|
||
# Enable serving of images, stylesheets, and JavaScripts from an asset server. | ||
# config.action_controller.asset_host = 'http://assets.example.com' | ||
|
||
# Specifies the header that your server uses for sending files. | ||
# config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache | ||
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX | ||
|
||
# Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. | ||
# config.force_ssl = true | ||
|
||
# Use the lowest log level to ensure availability of diagnostic information | ||
# when problems arise. | ||
config.log_level = :debug | ||
|
||
# Prepend all log lines with the following tags. | ||
config.log_tags = [ :request_id ] | ||
|
||
# Use a different cache store in production. | ||
# config.cache_store = :mem_cache_store | ||
|
||
# Use a real queuing backend for Active Job (and separate queues per environment). | ||
# config.active_job.queue_adapter = :resque | ||
# config.active_job.queue_name_prefix = "sample_production" | ||
|
||
# Enable locale fallbacks for I18n (makes lookups for any locale fall back to | ||
# the I18n.default_locale when a translation cannot be found). | ||
config.i18n.fallbacks = true | ||
|
||
# Send deprecation notices to registered listeners. | ||
config.active_support.deprecation = :notify | ||
|
||
# Use default logging formatter so that PID and timestamp are not suppressed. | ||
config.log_formatter = ::Logger::Formatter.new | ||
|
||
# Use a different logger for distributed setups. | ||
# require 'syslog/logger' | ||
# config.logger = ActiveSupport::TaggedLogging.new(Syslog::Logger.new 'app-name') | ||
|
||
if ENV["RAILS_LOG_TO_STDOUT"].present? | ||
logger = ActiveSupport::Logger.new(STDOUT) | ||
logger.formatter = config.log_formatter | ||
config.logger = ActiveSupport::TaggedLogging.new(logger) | ||
end | ||
|
||
# Do not dump schema after migrations. | ||
config.active_record.dump_schema_after_migration = false | ||
|
||
# Inserts middleware to perform automatic connection switching. | ||
# The `database_selector` hash is used to pass options to the DatabaseSelector | ||
# middleware. The `delay` is used to determine how long to wait after a write | ||
# to send a subsequent read to the primary. | ||
# | ||
# The `database_resolver` class is used by the middleware to determine which | ||
# database is appropriate to use based on the time delay. | ||
# | ||
# The `database_resolver_context` class is used by the middleware to set | ||
# timestamps for the last write to the primary. The resolver uses the context | ||
# class timestamps to determine how long to wait before reading from the | ||
# replica. | ||
# | ||
# By default Rails will store a last write timestamp in the session. The | ||
# DatabaseSelector middleware is designed as such you can define your own | ||
# strategy for connection switching and pass that into the middleware through | ||
# these configuration options. | ||
# config.active_record.database_selector = { delay: 2.seconds } | ||
# config.active_record.database_resolver = ActiveRecord::Middleware::DatabaseSelector::Resolver | ||
# config.active_record.database_resolver_context = ActiveRecord::Middleware::DatabaseSelector::Resolver::Session | ||
|
||
config.number_generator_factory = -> { Orders::NumberGenerator.new } | ||
end |
Oops, something went wrong.