multi-database-9000 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (128) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +19 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +59 -0
  6. data/Rakefile +2 -0
  7. data/features/creating_databases.feature +75 -0
  8. data/features/development_migrations.feature +94 -0
  9. data/features/production_migrations.feature +32 -0
  10. data/features/step_definitions/development_migrations_steps.rb +244 -0
  11. data/features/step_definitions/production_migration_steps.rb +28 -0
  12. data/features/step_definitions/sqlite_database_steps.rb +41 -0
  13. data/features/step_definitions/test_migration_steps.rb +84 -0
  14. data/features/support/env.rb +2 -0
  15. data/features/test_app.feature +6 -0
  16. data/features/test_migrations.feature +24 -0
  17. data/lib/multi-database-9000/multi-database-9000.rb +12 -0
  18. data/lib/multi-database-9000/tasks/multi-database-9000_tasks.rake +143 -0
  19. data/lib/multi-database-9000/version.rb +3 -0
  20. data/lib/multi-database-9000.rb +10 -0
  21. data/multi-database-9000.gemspec +29 -0
  22. data/multi-db-dummy/Gemfile +15 -0
  23. data/multi-db-dummy/Gemfile.lock +115 -0
  24. data/multi-db-dummy/README.rdoc +28 -0
  25. data/multi-db-dummy/Rakefile +6 -0
  26. data/multi-db-dummy/app/assets/images/.keep +0 -0
  27. data/multi-db-dummy/app/assets/stylesheets/application.css +15 -0
  28. data/multi-db-dummy/app/controllers/application_controller.rb +5 -0
  29. data/multi-db-dummy/app/controllers/concerns/.keep +0 -0
  30. data/multi-db-dummy/app/helpers/application_helper.rb +2 -0
  31. data/multi-db-dummy/app/mailers/.keep +0 -0
  32. data/multi-db-dummy/app/models/.keep +0 -0
  33. data/multi-db-dummy/app/models/concerns/.keep +0 -0
  34. data/multi-db-dummy/app/models/gadget.rb +3 -0
  35. data/multi-db-dummy/app/views/layouts/application.html.erb +13 -0
  36. data/multi-db-dummy/bin/bundle +3 -0
  37. data/multi-db-dummy/bin/rails +4 -0
  38. data/multi-db-dummy/bin/rake +4 -0
  39. data/multi-db-dummy/bin/setup +29 -0
  40. data/multi-db-dummy/config/application.rb +35 -0
  41. data/multi-db-dummy/config/boot.rb +3 -0
  42. data/multi-db-dummy/config/database.yml +49 -0
  43. data/multi-db-dummy/config/environment.rb +5 -0
  44. data/multi-db-dummy/config/environments/development.rb +28 -0
  45. data/multi-db-dummy/config/environments/production.rb +67 -0
  46. data/multi-db-dummy/config/environments/test.rb +42 -0
  47. data/multi-db-dummy/config/initializers/backtrace_silencers.rb +7 -0
  48. data/multi-db-dummy/config/initializers/cookies_serializer.rb +3 -0
  49. data/multi-db-dummy/config/initializers/filter_parameter_logging.rb +4 -0
  50. data/multi-db-dummy/config/initializers/inflections.rb +16 -0
  51. data/multi-db-dummy/config/initializers/mime_types.rb +4 -0
  52. data/multi-db-dummy/config/initializers/session_store.rb +3 -0
  53. data/multi-db-dummy/config/initializers/wrap_parameters.rb +14 -0
  54. data/multi-db-dummy/config/locales/en.yml +23 -0
  55. data/multi-db-dummy/config/routes.rb +56 -0
  56. data/multi-db-dummy/config/secrets.yml +22 -0
  57. data/multi-db-dummy/config.ru +4 -0
  58. data/multi-db-dummy/lib/assets/.keep +0 -0
  59. data/multi-db-dummy/lib/tasks/.keep +0 -0
  60. data/multi-db-dummy/log/.keep +0 -0
  61. data/multi-db-dummy/public/404.html +67 -0
  62. data/multi-db-dummy/public/422.html +67 -0
  63. data/multi-db-dummy/public/500.html +66 -0
  64. data/multi-db-dummy/public/favicon.ico +0 -0
  65. data/multi-db-dummy/public/robots.txt +5 -0
  66. data/multi-db-dummy/test/controllers/.keep +0 -0
  67. data/multi-db-dummy/test/fixtures/.keep +0 -0
  68. data/multi-db-dummy/test/helpers/.keep +0 -0
  69. data/multi-db-dummy/test/integration/.keep +0 -0
  70. data/multi-db-dummy/test/mailers/.keep +0 -0
  71. data/multi-db-dummy/test/models/.keep +0 -0
  72. data/multi-db-dummy/test/models/gadget_test.rb +8 -0
  73. data/multi-db-dummy/test/test_helper.rb +12 -0
  74. data/multi-db-dummy/vendor/assets/stylesheets/.keep +0 -0
  75. data/single-db-dummy/Gemfile +16 -0
  76. data/single-db-dummy/Gemfile.lock +115 -0
  77. data/single-db-dummy/README.rdoc +28 -0
  78. data/single-db-dummy/Rakefile +6 -0
  79. data/single-db-dummy/app/assets/images/.keep +0 -0
  80. data/single-db-dummy/app/assets/stylesheets/application.css +15 -0
  81. data/single-db-dummy/app/controllers/application_controller.rb +5 -0
  82. data/single-db-dummy/app/controllers/concerns/.keep +0 -0
  83. data/single-db-dummy/app/helpers/application_helper.rb +2 -0
  84. data/single-db-dummy/app/mailers/.keep +0 -0
  85. data/single-db-dummy/app/models/.keep +0 -0
  86. data/single-db-dummy/app/models/concerns/.keep +0 -0
  87. data/single-db-dummy/app/models/user.rb +3 -0
  88. data/single-db-dummy/app/views/layouts/application.html.erb +13 -0
  89. data/single-db-dummy/bin/bundle +3 -0
  90. data/single-db-dummy/bin/rails +4 -0
  91. data/single-db-dummy/bin/rake +4 -0
  92. data/single-db-dummy/bin/setup +29 -0
  93. data/single-db-dummy/config/application.rb +35 -0
  94. data/single-db-dummy/config/boot.rb +3 -0
  95. data/single-db-dummy/config/database.yml +25 -0
  96. data/single-db-dummy/config/environment.rb +5 -0
  97. data/single-db-dummy/config/environments/development.rb +28 -0
  98. data/single-db-dummy/config/environments/production.rb +67 -0
  99. data/single-db-dummy/config/environments/test.rb +42 -0
  100. data/single-db-dummy/config/initializers/backtrace_silencers.rb +7 -0
  101. data/single-db-dummy/config/initializers/cookies_serializer.rb +3 -0
  102. data/single-db-dummy/config/initializers/filter_parameter_logging.rb +4 -0
  103. data/single-db-dummy/config/initializers/inflections.rb +16 -0
  104. data/single-db-dummy/config/initializers/mime_types.rb +4 -0
  105. data/single-db-dummy/config/initializers/session_store.rb +3 -0
  106. data/single-db-dummy/config/initializers/wrap_parameters.rb +14 -0
  107. data/single-db-dummy/config/locales/en.yml +23 -0
  108. data/single-db-dummy/config/routes.rb +56 -0
  109. data/single-db-dummy/config/secrets.yml +22 -0
  110. data/single-db-dummy/config.ru +4 -0
  111. data/single-db-dummy/lib/assets/.keep +0 -0
  112. data/single-db-dummy/lib/tasks/.keep +0 -0
  113. data/single-db-dummy/log/.keep +0 -0
  114. data/single-db-dummy/public/404.html +67 -0
  115. data/single-db-dummy/public/422.html +67 -0
  116. data/single-db-dummy/public/500.html +66 -0
  117. data/single-db-dummy/public/favicon.ico +0 -0
  118. data/single-db-dummy/public/robots.txt +5 -0
  119. data/single-db-dummy/test/controllers/.keep +0 -0
  120. data/single-db-dummy/test/fixtures/.keep +0 -0
  121. data/single-db-dummy/test/helpers/.keep +0 -0
  122. data/single-db-dummy/test/integration/.keep +0 -0
  123. data/single-db-dummy/test/mailers/.keep +0 -0
  124. data/single-db-dummy/test/models/.keep +0 -0
  125. data/single-db-dummy/test/models/user_test.rb +8 -0
  126. data/single-db-dummy/test/test_helper.rb +10 -0
  127. data/single-db-dummy/vendor/assets/stylesheets/.keep +0 -0
  128. metadata +295 -0
@@ -0,0 +1,84 @@
1
+ Given(/^A development database with a "([^"]*)" table with columns "([^"]*)", "([^"]*)" and "([^"]*)"$/) do |table, column1, column2, column3|
2
+ write_single_db_migration
3
+ run_task_in_single_db_app "bundle exec rake db:migrate"
4
+ end
5
+
6
+ When(/^I run a model test$/) do
7
+ test_file = <<-TEST_FILE_END
8
+ require 'test_helper'
9
+
10
+ class UserTest < ActiveSupport::TestCase
11
+ test "should save" do
12
+ user = User.new
13
+ assert user.save
14
+ end
15
+ end
16
+ TEST_FILE_END
17
+
18
+ write_file "../../single-db-dummy/test/models/user_test.rb", test_file
19
+
20
+ run_task_in_single_db_app "bundle exec rake test"
21
+ end
22
+
23
+ Then(/^I should see the created users table in the default test database$/) do
24
+ table_exists? :app => "single-db-dummy", :database => "test.sqlite3", :table => "users"
25
+ end
26
+
27
+ Then(/^I should see the correct columns in the users table in the default test database$/) do
28
+ columns_exist? app: "single-db-dummy", :database => "test.sqlite3", :table => "users", :columns => ["name", "email", "age"]
29
+ end
30
+
31
+ Given(/^A "([^"]*)" development database with a "([^"]*)" table with columns "([^"]*)", "([^"]*)" and "([^"]*)"$/) do |database, table, column1, column2, column3|
32
+ write_migration_for_default_db
33
+ write_migration_for_users_db
34
+ write_migration_for_widgets_db
35
+ run_task_in_multi_db_app "bundle exec rake db:migrate"
36
+ end
37
+
38
+ When(/^I run a model test in the multi\-database app$/) do
39
+ test_file = <<-TEST_FILE_END
40
+ require 'test_helper'
41
+
42
+ class GadgetTest < ActiveSupport::TestCase
43
+ test "should save" do
44
+ gadget = Gadget.new
45
+ assert gadget.save
46
+ end
47
+ end
48
+ TEST_FILE_END
49
+
50
+ write_file "../../multi-db-dummy/test/models/gadget_test.rb", test_file
51
+
52
+ run_task_in_multi_db_app "bundle exec rake test"
53
+ end
54
+
55
+ Then(/^I should see the created "([^"]*)" table in the "([^"]*)" test database$/) do |table, database|
56
+ if database == "default"
57
+ database_file = "test"
58
+ else
59
+ database_file = "#{database}_test"
60
+ end
61
+ table_exists? :app => "multi-db-dummy", :database => "#{database_file}.sqlite3", :table => table
62
+ end
63
+
64
+
65
+ # helpers
66
+
67
+ def table_exists?(app:, database:, table:)
68
+ SQLite3::Database.new( "#{app}/db/#{database}" ) do |db|
69
+ table_query = db.execute( "SELECT name FROM sqlite_master WHERE type='table' AND name='#{table}'" )
70
+ expect(table_query[0][0]).to eq table
71
+ end
72
+ end
73
+
74
+ def columns_exist?(app:, database:, table:, columns:)
75
+ SQLite3::Database.new( "#{app}/db/#{database}" ) do |db|
76
+ users_columns = db.execute( "PRAGMA table_info(#{table})" )
77
+ column_names = users_columns.map do |column|
78
+ column[1]
79
+ end
80
+ columns.each do |test_column|
81
+ expect(column_names).to include test_column
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,2 @@
1
+ require 'aruba/cucumber'
2
+
@@ -0,0 +1,6 @@
1
+ Feature: Testing the test app
2
+ Scenario: running rake in the test app
3
+ When I cd to "../../multi-db-dummy"
4
+ And I run `rake -T`
5
+ Then the exit status should be 0
6
+ And the output should match /rake db:create/
@@ -0,0 +1,24 @@
1
+ Feature: Running migrations and test preparation for all database in the app
2
+
3
+ Background:
4
+ Given empty databases have been created for the app
5
+
6
+ Scenario: Test database is correctly set up in a single-database app
7
+ Given A development database with a "users" table with columns "name", "age" and "email"
8
+ When I run a model test
9
+ Then I should see the created users table in the default test database
10
+ And I should see the correct columns in the users table in the default test database
11
+
12
+ Scenario: Test database is correctly set up in a multi-database app
13
+ Given A "default" development database with a "posts" table with columns "title", "text" and "author"
14
+ And A "users" development database with a "accounts" table with columns "user_id", "expenses" and "total"
15
+ And A "widgets" development database with a "gadgets" table with columns "doobry", "wotsit" and "thingy"
16
+ When I run a model test in the multi-database app
17
+ Then I should see the created "posts" table in the "default" test database
18
+ Then I should see the created "accounts" table in the "users" test database
19
+ Then I should see the created "gadgets" table in the "widgets" test database
20
+ And I should see the "title", "text" and "author" columns in the "posts" table in the "default" database
21
+ And I should see the "expense", "user_id" and "total" columns in the "accounts" table in the "users" database
22
+ And I should see the "doobry", "wotsit" and "thingy" columns in the "gadgets" table in the "widgets" database
23
+
24
+
@@ -0,0 +1,12 @@
1
+ module MultiDatabase9000
2
+ def self.maintain_all_test_schemas! # :nodoc:
3
+ # Roundrip to Rake to allow plugins to hook into database initialization.
4
+ FileUtils.cd Rails.root do
5
+ current_config = ActiveRecord::Base.connection_config
6
+ ActiveRecord::Base.clear_all_connections!
7
+ system("bin/rake db:test:prepare")
8
+ # Establish a new connection, the old database may be gone (db:test:prepare uses purge)
9
+ ActiveRecord::Base.establish_connection(current_config)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,143 @@
1
+ require 'pry'
2
+
3
+ def database_connections(database: nil, rails_envs: nil)
4
+ connections = connections_for_environment(rails_envs)
5
+ if database.present?
6
+ connections.keep_if {|key, _| key.match Regexp.new(database)}
7
+ end
8
+ return connections
9
+ end
10
+
11
+ def connections_for_environment(rails_envs)
12
+ rails_envs = Array(rails_envs)
13
+ matcher = ->(key, value){rails_envs.any?{|env| key.match Regexp.new(env)}}
14
+ return ActiveRecord::Base.configurations.keep_if &matcher
15
+ end
16
+
17
+ def database_name(connection_key)
18
+ if connection_key.match /\w+_\w+/
19
+ return connection_key.split('_').first
20
+ else
21
+ return "default"
22
+ end
23
+ end
24
+
25
+ def migration_directory(connection_key)
26
+ if ['test','development','staging','cucumber','production'].include? connection_key
27
+ return "db/migrate/"
28
+ else
29
+ return "db/#{database_name(connection_key)}_migrate/"
30
+ end
31
+ end
32
+
33
+ def schema_file_name(connection_key)
34
+ if ['test','development','staging','cucumber','production'].include? connection_key
35
+ return "schema.rb"
36
+ else
37
+ return "#{database_name(connection_key)}_schema.rb"
38
+ end
39
+ end
40
+
41
+ Rake::Task['db:create'].clear
42
+ Rake::Task['db:migrate'].clear
43
+ Rake::Task['db:schema:dump'].clear
44
+ Rake::Task['db:migrate:status'].clear
45
+
46
+ Rake::Task["db:test:load_schema"].enhance do
47
+ begin
48
+ should_reconnect = ActiveRecord::Base.connection_pool.active_connection?
49
+ connections_for_environment("test").each do |connection_key, connection|
50
+ ActiveRecord::Tasks::DatabaseTasks.load_schema_for connection, :ruby, "db/#{schema_file_name(connection_key)}"
51
+ end
52
+ ensure
53
+ if should_reconnect
54
+ ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations[ActiveRecord::Tasks::DatabaseTasks.env])
55
+ end
56
+ end
57
+ end
58
+
59
+ Rake::Task["db:test:purge"].enhance do
60
+ connections_for_environment("test").values.each do |connection|
61
+ ActiveRecord::Tasks::DatabaseTasks.purge connection
62
+ end
63
+ end
64
+
65
+ db_namespace = namespace :db do
66
+ desc "Creates all databases from config/database.yml, or the database specified by DATABASE for the current RAILS_ENV"
67
+ task :create => [:load_config] do
68
+ if ENV["RAILS_ENV"] == "development" || ENV["RAILS_ENV"].nil?
69
+ rails_envs = ["development", "test"]
70
+ else
71
+ rails_envs = ENV["RAILS_ENV"]
72
+ end
73
+ database_connections(:database => ENV["DATABASE"], :rails_envs => rails_envs).values.each do |database_connection|
74
+ ActiveRecord::Tasks::DatabaseTasks.create database_connection
75
+ end
76
+ end
77
+
78
+ task :migrate => :environment do
79
+ rails_env = ENV["RAILS_ENV"] || "development"
80
+ database_connections(:database => ENV["DATABASE"], :rails_envs => rails_env).keys.each do |connection_key|
81
+ ActiveRecord::Base.establish_connection(connection_key)
82
+ ActiveRecord::Migrator.migrate(migration_directory(connection_key) , ENV["VERSION"] ? ENV["VERSION"].to_i : nil)
83
+ end
84
+ db_namespace['_dump'].invoke
85
+ end
86
+
87
+ namespace :migrate do
88
+ desc 'Display status of migrations'
89
+ task :status => [:environment] do
90
+ migrations_list = []
91
+
92
+ database_connections(:database => ENV["DATABASE"], :rails_envs => "development" || ENV["RAILS_ENV"]).keys.each do |connection_key|
93
+ ActiveRecord::Base.establish_connection(connection_key)
94
+
95
+ abort 'Schema migrations table does not exist yet.' unless ActiveRecord::SchemaMigration.table_exists?
96
+
97
+ db_list = ActiveRecord::SchemaMigration.normalized_versions
98
+
99
+ file_list =
100
+ Dir.foreach(migration_directory(connection_key)).grep(/^(\d{3,})_(.+)\.rb$/) do
101
+ version = ActiveRecord::SchemaMigration.normalize_migration_number($1)
102
+ status = db_list.delete(version) ? 'up' : 'down'
103
+ [status, version, database_name(connection_key), $2.humanize]
104
+ end
105
+
106
+ db_list.map! do |version|
107
+ ['up', version, database_name(connection_key), '********** NO FILE **********']
108
+ end
109
+
110
+ migrations_list += db_list + file_list
111
+ end
112
+
113
+ # output
114
+ puts "#{'Status'.center(8)} #{'Migration ID'.ljust(14)} #{'Database'.ljust(14)} Migration Name"
115
+ puts "-" * 50
116
+ (migrations_list).sort_by { |_, version, _, _| version }.each do |status, version, database, name|
117
+ puts "#{status.center(8)} #{version.ljust(14)} #{database.ljust(14)} #{name}"
118
+ end
119
+ puts
120
+ end
121
+ end
122
+
123
+ namespace :schema do
124
+ desc 'Create a db/schema.rb file for each database, that is portable against any DB supported by AR'
125
+ task :dump => [:environment] do
126
+ require 'active_record/schema_dumper'
127
+
128
+ if ENV["RAILS_ENV"] == "development" || ENV["RAILS_ENV"].nil?
129
+ rails_envs = ["development", "test"]
130
+ else
131
+ rails_envs = ENV["RAILS_ENV"]
132
+ end
133
+ database_connections(:database => ENV["DATABASE"], :rails_envs => rails_envs).keys.each do |connection_key|
134
+ ActiveRecord::Base.establish_connection(connection_key)
135
+ filename = ENV['SCHEMA'] || File.join(ActiveRecord::Tasks::DatabaseTasks.db_dir, schema_file_name(connection_key))
136
+ File.open(filename, "w:utf-8") do |file|
137
+ ActiveRecord::SchemaDumper.dump(ActiveRecord::Base.connection, file)
138
+ end
139
+ end
140
+ db_namespace['schema:dump'].reenable
141
+ end
142
+ end
143
+ end
@@ -0,0 +1,3 @@
1
+ module MultiDatabase9000
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,10 @@
1
+ require "multi-database-9000/version"
2
+ require "multi-database-9000/multi-database-9000"
3
+
4
+ module MultiDatabase9000
5
+ class Railtie < Rails::Railtie
6
+ rake_tasks do
7
+ load "multi-database-9000/tasks/multi-database-9000_tasks.rake"
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'multi-database-9000/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "multi-database-9000"
8
+ spec.version = MultiDatabase9000::VERSION
9
+ spec.authors = ["Mark Weston", "Stefania Cardenas", "Colin Frankish"]
10
+ spec.email = ["mark@markweston.me.uk"]
11
+ spec.summary = %q{Enables Rails apps with multiple databases to handle migrations and rake tasks transparently}
12
+ spec.description = %q{See README.md for details}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.7"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec", ">= 3.0"
24
+ spec.add_development_dependency "cucumber"
25
+ spec.add_development_dependency "aruba"
26
+ spec.add_development_dependency "sqlite3"
27
+ spec.add_development_dependency "pry"
28
+ spec.add_runtime_dependency "rails", ">= 4.0"
29
+ end
@@ -0,0 +1,15 @@
1
+ source 'https://rubygems.org'
2
+
3
+
4
+ # Bundle edge Rails instead: gem 'rails', github: 'rails/rails'
5
+ gem 'rails', '4.2.4'
6
+ # Use sqlite3 as the database for Active Record
7
+ gem 'sqlite3'
8
+
9
+ gem 'multi-database-9000', :path => ".."
10
+
11
+ group :development, :test do
12
+ gem 'pry'
13
+ end
14
+
15
+
@@ -0,0 +1,115 @@
1
+ PATH
2
+ remote: ..
3
+ specs:
4
+ multi-database-9000 (0.0.1)
5
+ rails (>= 4.0)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ actionmailer (4.2.4)
11
+ actionpack (= 4.2.4)
12
+ actionview (= 4.2.4)
13
+ activejob (= 4.2.4)
14
+ mail (~> 2.5, >= 2.5.4)
15
+ rails-dom-testing (~> 1.0, >= 1.0.5)
16
+ actionpack (4.2.4)
17
+ actionview (= 4.2.4)
18
+ activesupport (= 4.2.4)
19
+ rack (~> 1.6)
20
+ rack-test (~> 0.6.2)
21
+ rails-dom-testing (~> 1.0, >= 1.0.5)
22
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
23
+ actionview (4.2.4)
24
+ activesupport (= 4.2.4)
25
+ builder (~> 3.1)
26
+ erubis (~> 2.7.0)
27
+ rails-dom-testing (~> 1.0, >= 1.0.5)
28
+ rails-html-sanitizer (~> 1.0, >= 1.0.2)
29
+ activejob (4.2.4)
30
+ activesupport (= 4.2.4)
31
+ globalid (>= 0.3.0)
32
+ activemodel (4.2.4)
33
+ activesupport (= 4.2.4)
34
+ builder (~> 3.1)
35
+ activerecord (4.2.4)
36
+ activemodel (= 4.2.4)
37
+ activesupport (= 4.2.4)
38
+ arel (~> 6.0)
39
+ activesupport (4.2.4)
40
+ i18n (~> 0.7)
41
+ json (~> 1.7, >= 1.7.7)
42
+ minitest (~> 5.1)
43
+ thread_safe (~> 0.3, >= 0.3.4)
44
+ tzinfo (~> 1.1)
45
+ arel (6.0.3)
46
+ builder (3.2.2)
47
+ coderay (1.1.0)
48
+ erubis (2.7.0)
49
+ globalid (0.3.6)
50
+ activesupport (>= 4.1.0)
51
+ i18n (0.7.0)
52
+ json (1.8.3)
53
+ loofah (2.0.3)
54
+ nokogiri (>= 1.5.9)
55
+ mail (2.6.3)
56
+ mime-types (>= 1.16, < 3)
57
+ method_source (0.8.2)
58
+ mime-types (2.6.2)
59
+ mini_portile (0.6.2)
60
+ minitest (5.8.1)
61
+ nokogiri (1.6.6.2)
62
+ mini_portile (~> 0.6.0)
63
+ pry (0.10.1)
64
+ coderay (~> 1.1.0)
65
+ method_source (~> 0.8.1)
66
+ slop (~> 3.4)
67
+ rack (1.6.4)
68
+ rack-test (0.6.3)
69
+ rack (>= 1.0)
70
+ rails (4.2.4)
71
+ actionmailer (= 4.2.4)
72
+ actionpack (= 4.2.4)
73
+ actionview (= 4.2.4)
74
+ activejob (= 4.2.4)
75
+ activemodel (= 4.2.4)
76
+ activerecord (= 4.2.4)
77
+ activesupport (= 4.2.4)
78
+ bundler (>= 1.3.0, < 2.0)
79
+ railties (= 4.2.4)
80
+ sprockets-rails
81
+ rails-deprecated_sanitizer (1.0.3)
82
+ activesupport (>= 4.2.0.alpha)
83
+ rails-dom-testing (1.0.7)
84
+ activesupport (>= 4.2.0.beta, < 5.0)
85
+ nokogiri (~> 1.6.0)
86
+ rails-deprecated_sanitizer (>= 1.0.1)
87
+ rails-html-sanitizer (1.0.2)
88
+ loofah (~> 2.0)
89
+ railties (4.2.4)
90
+ actionpack (= 4.2.4)
91
+ activesupport (= 4.2.4)
92
+ rake (>= 0.8.7)
93
+ thor (>= 0.18.1, < 2.0)
94
+ rake (10.4.2)
95
+ slop (3.6.0)
96
+ sprockets (3.3.5)
97
+ rack (> 1, < 3)
98
+ sprockets-rails (2.3.3)
99
+ actionpack (>= 3.0)
100
+ activesupport (>= 3.0)
101
+ sprockets (>= 2.8, < 4.0)
102
+ sqlite3 (1.3.10)
103
+ thor (0.19.1)
104
+ thread_safe (0.3.5)
105
+ tzinfo (1.2.2)
106
+ thread_safe (~> 0.1)
107
+
108
+ PLATFORMS
109
+ ruby
110
+
111
+ DEPENDENCIES
112
+ multi-database-9000!
113
+ pry
114
+ rails (= 4.2.4)
115
+ sqlite3
@@ -0,0 +1,28 @@
1
+ == README
2
+
3
+ This README would normally document whatever steps are necessary to get the
4
+ application up and running.
5
+
6
+ Things you may want to cover:
7
+
8
+ * Ruby version
9
+
10
+ * System dependencies
11
+
12
+ * Configuration
13
+
14
+ * Database creation
15
+
16
+ * Database initialization
17
+
18
+ * How to run the test suite
19
+
20
+ * Services (job queues, cache servers, search engines, etc.)
21
+
22
+ * Deployment instructions
23
+
24
+ * ...
25
+
26
+
27
+ Please feel free to use a different markup language if you do not plan to run
28
+ <tt>rake doc:app</tt>.
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require File.expand_path('../config/application', __FILE__)
5
+
6
+ Rails.application.load_tasks
File without changes
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,5 @@
1
+ class ApplicationController < ActionController::Base
2
+ # Prevent CSRF attacks by raising an exception.
3
+ # For APIs, you may want to use :null_session instead.
4
+ protect_from_forgery with: :exception
5
+ end
File without changes
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
File without changes
File without changes
File without changes
@@ -0,0 +1,3 @@
1
+ class Gadget < ActiveRecord::Base
2
+ establish_connection "widgets_#{Rails.env}".to_sym
3
+ end
@@ -0,0 +1,13 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>MultiDbDummy</title>
5
+ <%= stylesheet_link_tag 'application', media: 'all' %>
6
+ <%= csrf_meta_tags %>
7
+ </head>
8
+ <body>
9
+
10
+ <%= yield %>
11
+
12
+ </body>
13
+ </html>
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env ruby
2
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3
+ load Gem.bin_path('bundler', 'bundle')
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
3
+ require_relative '../config/boot'
4
+ require 'rails/commands'
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require_relative '../config/boot'
3
+ require 'rake'
4
+ Rake.application.run
@@ -0,0 +1,29 @@
1
+ #!/usr/bin/env ruby
2
+ require 'pathname'
3
+
4
+ # path to your application root.
5
+ APP_ROOT = Pathname.new File.expand_path('../../', __FILE__)
6
+
7
+ Dir.chdir APP_ROOT do
8
+ # This script is a starting point to setup your application.
9
+ # Add necessary setup steps to this file:
10
+
11
+ puts "== Installing dependencies =="
12
+ system "gem install bundler --conservative"
13
+ system "bundle check || bundle install"
14
+
15
+ # puts "\n== Copying sample files =="
16
+ # unless File.exist?("config/database.yml")
17
+ # system "cp config/database.yml.sample config/database.yml"
18
+ # end
19
+
20
+ puts "\n== Preparing database =="
21
+ system "bin/rake db:setup"
22
+
23
+ puts "\n== Removing old logs and tempfiles =="
24
+ system "rm -f log/*"
25
+ system "rm -rf tmp/cache"
26
+
27
+ puts "\n== Restarting application server =="
28
+ system "touch tmp/restart.txt"
29
+ end
@@ -0,0 +1,35 @@
1
+ require File.expand_path('../boot', __FILE__)
2
+
3
+ require "rails"
4
+ # Pick the frameworks you want:
5
+ require "active_model/railtie"
6
+ require "active_job/railtie"
7
+ require "active_record/railtie"
8
+ require "action_controller/railtie"
9
+ require "action_mailer/railtie"
10
+ require "action_view/railtie"
11
+ # require "sprockets/railtie"
12
+ require "rails/test_unit/railtie"
13
+
14
+ # Require the gems listed in Gemfile, including any gems
15
+ # you've limited to :test, :development, or :production.
16
+ Bundler.require(*Rails.groups)
17
+
18
+ module MultiDbDummy
19
+ class Application < Rails::Application
20
+ # Settings in config/environments/* take precedence over those specified here.
21
+ # Application configuration should go into files in config/initializers
22
+ # -- all .rb files in that directory are automatically loaded.
23
+
24
+ # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
25
+ # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
26
+ # config.time_zone = 'Central Time (US & Canada)'
27
+
28
+ # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
29
+ # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
30
+ # config.i18n.default_locale = :de
31
+
32
+ # Do not swallow errors in after_commit/after_rollback callbacks.
33
+ config.active_record.raise_in_transactional_callbacks = true
34
+ end
35
+ end
@@ -0,0 +1,3 @@
1
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
2
+
3
+ require 'bundler/setup' # Set up gems listed in the Gemfile.