Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Supporting Multiple Databases #6

Open
wants to merge 11 commits into from

2 participants

@bhauff

Hello,

I added a few small changes and some documentation in the README to support multiple databases per environment in sequel-rails. There is a caching mechanism that makes sure you connect to a database when you first request it, and then for subsequent requests it is reused. I worked on this with Jeremy Evans a bit. In the future it would be good to support nesting multiple databases under each environment. For now I just implemented supporting multiple top level databases. Let me know what you think!

Thanks,

Brandon Hauff

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 4, 2010
  1. @bhauff
Commits on Nov 5, 2010
  1. @bhauff
  2. @bhauff

    Cleaning up README.rdoc.

    bhauff authored
Commits on Jan 28, 2011
  1. @brandonh
Commits on Mar 31, 2011
  1. @brandonh

    Ignore Rubymine files.

    brandonh authored
  2. @brandonh

    Version bump to 0.1.6

    brandonh authored
  3. @brandonh

    Version bump to 0.1.7

    brandonh authored
  4. @brandonh

    Version bump to 0.1.8

    brandonh authored
  5. @brandonh

    Version bump to 0.1.9

    brandonh authored
  6. @brandonh
  7. @brandonh

    Update sequel dependency.

    brandonh authored
This page is out of date. Refresh to see the latest.
View
3  .gitignore
@@ -27,3 +27,6 @@ vendor
.bundle
.rvmrc
*.gem
+
+## Rubymine
+.idea
View
8 Gemfile
@@ -6,13 +6,13 @@ gem 'yard', '~> 0.5'
git 'git://github.com/rails/rails.git' do
- gem 'activesupport', '~> 3.0.0.beta3', :require => 'active_support'
- gem 'actionpack', '~> 3.0.0.beta3', :require => 'action_pack'
- gem 'railties', '~> 3.0.0.beta3', :require => 'rails'
+ gem 'activesupport', '~> 3.0.0', :require => 'active_support'
+ gem 'actionpack', '~> 3.0.0', :require => 'action_pack'
+ gem 'railties', '~> 3.0.0', :require => 'rails'
end
-gem 'sequel', '~> 3.11.0'
+gem 'sequel', '~> 3.13'
group :test do
gem 'rspec'
View
52 README.rdoc
@@ -11,18 +11,18 @@ Using sequel with rails3 requires a couple minor changes.
First, add the following to your Gemfile:
gem 'sequel-rails'
-
+
... be sure to run "bundle install" if needed!
Secondly, you'll need to require "sequel-rails/railtie" in your config/application.rb file, and not require activerecord. The top of your config/application.rb will probably look something like:
-
+
# require 'rails/all'
-
+
# Instead of 'rails/all', require these:
require "action_controller/railtie"
- require "sequel-rails/railtie"
require "action_mailer/railtie"
-
+ require "rails/test_unit/railtie"
+ require "sequel-rails/railtie"
After those changes, you should be good to go!
@@ -49,6 +49,48 @@ Once you do that, you will see the following rake tasks among others. These are
vendor/bin/rake db:setup # Create the database, load the schema, and initialize with the seed data
...
+== Supporting Multiple Databases
+
+Sequel and sequel-rails support the use of more than one database per environment across your models.
+Currently, additional databases can be entered at the top level of your database.yml:
+
+ ...
+ development:
+ adapter: mysql
+ database: development
+ username: username
+ password: password
+ host: localhost
+
+ test:
+ adapter: mysql
+ database: test
+ username: username
+ password: password
+ host: localhost
+
+ production:
+ adapter: mysql
+ database: production
+ username: username
+ password: password
+ host: localhost
+
+ extra:
+ adapter: mysql
+ database: extra
+ username: username
+ password: password
+ host: localhost
+ ...
+
+You can then set an extra database for a model using the following syntax:
+
+ class Foo < Sequel::Model(Rails::Sequel.database(:extra))
+
+ end
+
+Databases are only connected to once they are defined for a Sequel::Model
== Current Issues
View
6 Rakefile
@@ -16,9 +16,9 @@ begin
gem.add_dependency 'sequel', '~> 3.13'
- gem.add_dependency 'activesupport', '~> 3.0.0.rc'
- gem.add_dependency 'actionpack', '~> 3.0.0.rc'
- gem.add_dependency 'railties', '~> 3.0.0.rc'
+ gem.add_dependency 'activesupport', '~> 3.0.0'
+ gem.add_dependency 'actionpack', '~> 3.0.0'
+ gem.add_dependency 'railties', '~> 3.0.0'
# gem.add_development_dependency 'yard', '~> 0.5'
View
2  VERSION
@@ -1 +1 @@
-0.1.5
+0.1.9
View
2  lib/sequel-rails/railtie.rb
@@ -48,7 +48,7 @@ class Railtie < Rails::Railtie
end
initializer "sequel.connect" do |app|
- Rails::Sequel.setup(Rails.env)
+ Rails::Sequel.database(Rails.env)
end
# Run setup code after_initialize to make sure all config/initializers
View
13 lib/sequel-rails/setup.rb
@@ -8,12 +8,15 @@
module Rails
module Sequel
-
+ @databases = {}
+
def self.setup(environment)
- puts "[sequel] Setting up the #{environment.inspect} environment:"
-
- ::Sequel.connect({:logger => configuration.logger}.merge(::Rails::Sequel.configuration.environment_for(environment.to_s)))
+ config = ::Rails::Sequel.configuration.environment_for(environment.to_s)
+ ::Sequel.connect({:logger => configuration.logger}.merge(config))
+ end
+
+ def self.database(name)
+ @databases[name] ||= setup(name)
end
-
end
end
View
133 sequel-rails.gemspec
@@ -1,93 +1,112 @@
# Generated by jeweler
# DO NOT EDIT THIS FILE DIRECTLY
-# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
+# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
# -*- encoding: utf-8 -*-
Gem::Specification.new do |s|
s.name = %q{sequel-rails}
- s.version = "0.1.7"
+ s.version = "0.1.9"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Brasten Sager (brasten)"]
- s.date = %q{2010-08-11}
+ s.date = %q{2011-03-31}
s.description = %q{Integrate Sequel with Rails 3}
s.email = %q{brasten@gmail.com}
s.extra_rdoc_files = [
+ "CHANGELOG",
"LICENSE",
- "README.rdoc"
+ "README.rdoc"
]
s.files = [
".document",
- ".gitignore",
- "CHANGELOG",
- "Gemfile",
- "LICENSE",
- "README.rdoc",
- "Rakefile",
- "VERSION",
- "autotest/discover.rb",
- "lib/generators/sequel.rb",
- "lib/generators/sequel/migration/migration_generator.rb",
- "lib/generators/sequel/migration/templates/migration.rb",
- "lib/generators/sequel/model/model_generator.rb",
- "lib/generators/sequel/model/templates/model.rb",
- "lib/generators/sequel/observer/observer_generator.rb",
- "lib/generators/sequel/observer/templates/observer.rb",
- "lib/sequel-rails.rb",
- "lib/sequel-rails/configuration.rb",
- "lib/sequel-rails/migrations.rb",
- "lib/sequel-rails/railtie.rb",
- "lib/sequel-rails/railties/benchmarking_mixin.rb",
- "lib/sequel-rails/railties/controller_runtime.rb",
- "lib/sequel-rails/railties/database.rake",
- "lib/sequel-rails/railties/i18n_support.rb",
- "lib/sequel-rails/railties/log_subscriber.rb",
- "lib/sequel-rails/runtime.rb",
- "lib/sequel-rails/session_store.rb",
- "lib/sequel-rails/setup.rb",
- "lib/sequel-rails/storage.rb",
- "sequel-rails.gemspec",
- "spec/rcov.opts",
- "spec/setup_spec.rb",
- "spec/spec.opts",
- "spec/spec_helper.rb",
- "tasks/ci.rake",
- "tasks/clean.rake",
- "tasks/metrics.rake",
- "tasks/spec.rake",
- "tasks/yard.rake",
- "tasks/yardstick.rake"
+ "CHANGELOG",
+ "Gemfile",
+ "LICENSE",
+ "README.rdoc",
+ "Rakefile",
+ "VERSION",
+ "autotest/discover.rb",
+ "lib/generators/sequel.rb",
+ "lib/generators/sequel/migration/migration_generator.rb",
+ "lib/generators/sequel/migration/templates/migration.rb",
+ "lib/generators/sequel/model/model_generator.rb",
+ "lib/generators/sequel/model/templates/model.rb",
+ "lib/generators/sequel/observer/observer_generator.rb",
+ "lib/generators/sequel/observer/templates/observer.rb",
+ "lib/sequel-rails.rb",
+ "lib/sequel-rails/configuration.rb",
+ "lib/sequel-rails/migrations.rb",
+ "lib/sequel-rails/railtie.rb",
+ "lib/sequel-rails/railties/benchmarking_mixin.rb",
+ "lib/sequel-rails/railties/controller_runtime.rb",
+ "lib/sequel-rails/railties/database.rake",
+ "lib/sequel-rails/railties/i18n_support.rb",
+ "lib/sequel-rails/railties/log_subscriber.rb",
+ "lib/sequel-rails/runtime.rb",
+ "lib/sequel-rails/session_store.rb",
+ "lib/sequel-rails/setup.rb",
+ "lib/sequel-rails/storage.rb",
+ "sequel-rails.gemspec",
+ "spec/rcov.opts",
+ "spec/setup_spec.rb",
+ "spec/spec.opts",
+ "spec/spec_helper.rb",
+ "tasks/ci.rake",
+ "tasks/clean.rake",
+ "tasks/metrics.rake",
+ "tasks/spec.rake",
+ "tasks/yard.rake",
+ "tasks/yardstick.rake"
]
s.homepage = %q{http://github.com/brasten/sequel-rails}
- s.rdoc_options = ["--charset=UTF-8"]
s.require_paths = ["lib"]
- s.rubygems_version = %q{1.3.6}
+ s.rubygems_version = %q{1.4.2}
s.summary = %q{Use Sequel with Rails 3}
s.test_files = [
"spec/setup_spec.rb",
- "spec/spec_helper.rb"
+ "spec/spec_helper.rb"
]
if s.respond_to? :specification_version then
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
s.specification_version = 3
- if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
+ s.add_runtime_dependency(%q<rake>, ["~> 0.8.7"])
+ s.add_runtime_dependency(%q<jeweler>, ["~> 1.4"])
+ s.add_runtime_dependency(%q<yard>, ["~> 0.5"])
+ s.add_runtime_dependency(%q<activesupport>, ["~> 3.0.0"])
+ s.add_runtime_dependency(%q<actionpack>, ["~> 3.0.0"])
+ s.add_runtime_dependency(%q<railties>, ["~> 3.0.0"])
+ s.add_runtime_dependency(%q<sequel>, ["~> 3.13"])
s.add_runtime_dependency(%q<sequel>, ["~> 3.13"])
- s.add_runtime_dependency(%q<activesupport>, ["~> 3.0.0.rc"])
- s.add_runtime_dependency(%q<actionpack>, ["~> 3.0.0.rc"])
- s.add_runtime_dependency(%q<railties>, ["~> 3.0.0.rc"])
+ s.add_runtime_dependency(%q<activesupport>, ["~> 3.0.0"])
+ s.add_runtime_dependency(%q<actionpack>, ["~> 3.0.0"])
+ s.add_runtime_dependency(%q<railties>, ["~> 3.0.0"])
else
+ s.add_dependency(%q<rake>, ["~> 0.8.7"])
+ s.add_dependency(%q<jeweler>, ["~> 1.4"])
+ s.add_dependency(%q<yard>, ["~> 0.5"])
+ s.add_dependency(%q<activesupport>, ["~> 3.0.0"])
+ s.add_dependency(%q<actionpack>, ["~> 3.0.0"])
+ s.add_dependency(%q<railties>, ["~> 3.0.0"])
s.add_dependency(%q<sequel>, ["~> 3.13"])
- s.add_dependency(%q<activesupport>, ["~> 3.0.0.rc"])
- s.add_dependency(%q<actionpack>, ["~> 3.0.0.rc"])
- s.add_dependency(%q<railties>, ["~> 3.0.0.rc"])
+ s.add_dependency(%q<sequel>, ["~> 3.13"])
+ s.add_dependency(%q<activesupport>, ["~> 3.0.0"])
+ s.add_dependency(%q<actionpack>, ["~> 3.0.0"])
+ s.add_dependency(%q<railties>, ["~> 3.0.0"])
end
else
+ s.add_dependency(%q<rake>, ["~> 0.8.7"])
+ s.add_dependency(%q<jeweler>, ["~> 1.4"])
+ s.add_dependency(%q<yard>, ["~> 0.5"])
+ s.add_dependency(%q<activesupport>, ["~> 3.0.0"])
+ s.add_dependency(%q<actionpack>, ["~> 3.0.0"])
+ s.add_dependency(%q<railties>, ["~> 3.0.0"])
+ s.add_dependency(%q<sequel>, ["~> 3.13"])
s.add_dependency(%q<sequel>, ["~> 3.13"])
- s.add_dependency(%q<activesupport>, ["~> 3.0.0.rc"])
- s.add_dependency(%q<actionpack>, ["~> 3.0.0.rc"])
- s.add_dependency(%q<railties>, ["~> 3.0.0.rc"])
+ s.add_dependency(%q<activesupport>, ["~> 3.0.0"])
+ s.add_dependency(%q<actionpack>, ["~> 3.0.0"])
+ s.add_dependency(%q<railties>, ["~> 3.0.0"])
end
end
Something went wrong with that request. Please try again.