sequel-rails 0.1.8 → 0.4.0.pre
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +1 -0
- data/.rspec +3 -0
- data/.travis.yml +12 -0
- data/Gemfile +13 -16
- data/History.md +142 -0
- data/README.md +124 -0
- data/Rakefile +6 -30
- data/config.ru +7 -0
- data/lib/generators/sequel.rb +11 -8
- data/lib/generators/sequel/migration/migration_generator.rb +36 -11
- data/lib/generators/sequel/migration/templates/migration.rb.erb +48 -0
- data/lib/generators/sequel/model/model_generator.rb +8 -2
- data/lib/generators/sequel/model/templates/migration.rb.erb +16 -0
- data/lib/generators/sequel/model/templates/{model.rb → model.rb.erb} +4 -1
- data/lib/generators/sequel/observer/observer_generator.rb +2 -2
- data/lib/generators/sequel/observer/templates/{observer.rb → observer.rb.erb} +0 -0
- data/lib/sequel-rails.rb +1 -1
- data/lib/sequel_rails.rb +2 -0
- data/lib/sequel_rails/configuration.rb +64 -0
- data/lib/sequel_rails/migrations.rb +22 -0
- data/lib/sequel_rails/railtie.rb +94 -0
- data/lib/sequel_rails/railties/controller_runtime.rb +40 -0
- data/lib/sequel_rails/railties/database.rake +175 -0
- data/lib/sequel_rails/railties/i18n_support.rb +10 -0
- data/lib/sequel_rails/railties/log_subscriber.rb +56 -0
- data/lib/sequel_rails/sequel/database/active_support_notification.rb +28 -0
- data/lib/sequel_rails/sequel/plugins/rails_extensions.rb +35 -0
- data/lib/sequel_rails/session_store.rb +80 -0
- data/lib/sequel_rails/storage.rb +58 -0
- data/lib/sequel_rails/storage/abstract.rb +52 -0
- data/lib/sequel_rails/storage/jdbc.rb +45 -0
- data/lib/sequel_rails/storage/mysql.rb +31 -0
- data/lib/sequel_rails/storage/mysql2.rb +6 -0
- data/lib/sequel_rails/storage/postgres.rb +22 -0
- data/lib/sequel_rails/storage/sqlite.rb +26 -0
- data/lib/sequel_rails/version.rb +3 -0
- data/sequel-rails.gemspec +22 -86
- data/spec/internal/app/models/user.rb +2 -0
- data/spec/internal/config/database.yml +7 -0
- data/spec/internal/config/routes.rb +3 -0
- data/spec/internal/db/schema.rb +8 -0
- data/spec/internal/public/favicon.ico +0 -0
- data/spec/lib/generators/sequel/migration_spec.rb +256 -0
- data/spec/lib/sequel_rails/railtie_spec.rb +85 -0
- data/spec/lib/sequel_rails/railties/log_subscriber_spec.rb +29 -0
- data/spec/lib/sequel_rails/storage_spec.rb +108 -0
- data/spec/spec_helper.rb +30 -16
- data/tasks/spec.rake +63 -29
- metadata +194 -142
- data/CHANGELOG +0 -15
- data/README.rdoc +0 -86
- data/VERSION +0 -1
- data/autotest/discover.rb +0 -1
- data/lib/generators/sequel/migration/templates/migration.rb +0 -16
- data/lib/sequel-rails/configuration.rb +0 -61
- data/lib/sequel-rails/migrations.rb +0 -30
- data/lib/sequel-rails/railtie.rb +0 -90
- data/lib/sequel-rails/railties/benchmarking_mixin.rb +0 -23
- data/lib/sequel-rails/railties/controller_runtime.rb +0 -43
- data/lib/sequel-rails/railties/database.rake +0 -148
- data/lib/sequel-rails/railties/i18n_support.rb +0 -12
- data/lib/sequel-rails/railties/log_subscriber.rb +0 -31
- data/lib/sequel-rails/runtime.rb +0 -14
- data/lib/sequel-rails/session_store.rb +0 -82
- data/lib/sequel-rails/setup.rb +0 -19
- data/lib/sequel-rails/storage.rb +0 -210
- data/spec/rcov.opts +0 -6
- data/spec/setup_spec.rb +0 -7
- data/spec/spec.opts +0 -4
- data/tasks/ci.rake +0 -1
- data/tasks/clean.rake +0 -6
- data/tasks/metrics.rake +0 -37
- data/tasks/yard.rake +0 -9
- data/tasks/yardstick.rake +0 -20
data/CHANGELOG
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
== 0.1.4
|
2
|
-
* Merged in changes to rake tasks and timestamp migrations
|
3
|
-
|
4
|
-
== 0.1.3
|
5
|
-
* update sequel dependency, configuration change
|
6
|
-
|
7
|
-
== 0.1.2
|
8
|
-
* fixed log_subscriber bug that 0.1.1 was -supposed- to fix.
|
9
|
-
* fixed controller_runtime bug
|
10
|
-
|
11
|
-
== 0.1.1
|
12
|
-
* bug fixes, no additional functionality
|
13
|
-
|
14
|
-
== 0.1.0
|
15
|
-
* initial release
|
data/README.rdoc
DELETED
@@ -1,86 +0,0 @@
|
|
1
|
-
= sequel-rails
|
2
|
-
|
3
|
-
This gem provides the railtie that allows {sequel}[http://github.com/jeremyevans/sequel] to hook into {rails3}[http://github.com/rails/rails] and thus behave like a rails framework component. Just like activerecord does in rails, {sequel-rails}[http://github.com/brasten/sequel-rails] uses the railtie API to hook into rails. The two are actually hooked into rails almost identically.
|
4
|
-
|
5
|
-
The code for this gem was initially taken from the excellent {dm-rails}[http://github.com/datamapper/dm-rails] project.
|
6
|
-
|
7
|
-
== Using sequel-rails
|
8
|
-
|
9
|
-
Using sequel with rails3 requires a couple minor changes.
|
10
|
-
|
11
|
-
First, add the following to your Gemfile:
|
12
|
-
|
13
|
-
gem 'sequel-rails'
|
14
|
-
|
15
|
-
... be sure to run "bundle install" if needed!
|
16
|
-
|
17
|
-
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:
|
18
|
-
|
19
|
-
# require 'rails/all'
|
20
|
-
|
21
|
-
# Instead of 'rails/all', require these:
|
22
|
-
require "action_controller/railtie"
|
23
|
-
require "sequel-rails/railtie"
|
24
|
-
require "action_mailer/railtie"
|
25
|
-
|
26
|
-
|
27
|
-
After those changes, you should be good to go!
|
28
|
-
|
29
|
-
|
30
|
-
== Available sequel specific rake tasks
|
31
|
-
|
32
|
-
To get a list of all available rake tasks in your rails3 app, issue the usual
|
33
|
-
|
34
|
-
vendor/bin/rake -T
|
35
|
-
|
36
|
-
Once you do that, you will see the following rake tasks among others. These are the ones that sequel-rails added for us.
|
37
|
-
|
38
|
-
...
|
39
|
-
vendor/bin/rake db:create # Create the database(s) defined in config/database.yml for the current Rails.env - also creates the test database(s) if Rails.env.development?
|
40
|
-
vendor/bin/rake db:create:all # Create all the local databases defined in config/database.yml
|
41
|
-
vendor/bin/rake db:drop # Drops the database(s) for the current Rails.env - also drops the test database(s) if Rails.env.development?
|
42
|
-
vendor/bin/rake db:drop:all # Drop all the local databases defined in config/database.yml
|
43
|
-
vendor/bin/rake db:migrate # Migrate the database to the latest version
|
44
|
-
vendor/bin/rake db:migrate:down[version] # Migrate down using migrations
|
45
|
-
vendor/bin/rake db:migrate:up[version] # Migrate up using migrations
|
46
|
-
vendor/bin/rake db:seed # Load the seed data from db/seeds.rb
|
47
|
-
vendor/bin/rake db:sessions:clear # Clear the sessions table for SequelStore
|
48
|
-
vendor/bin/rake db:sessions:create # Creates the sessions table for SequelStore
|
49
|
-
vendor/bin/rake db:setup # Create the database, load the schema, and initialize with the seed data
|
50
|
-
...
|
51
|
-
|
52
|
-
|
53
|
-
== Current Issues
|
54
|
-
|
55
|
-
* There are bound to be a lot, but I'm not yet sure what they are
|
56
|
-
|
57
|
-
== TODO (not necessarily in that order)
|
58
|
-
|
59
|
-
* SPECS
|
60
|
-
* README changes
|
61
|
-
* Publish SQL issued by sequel to rails subscribers
|
62
|
-
|
63
|
-
== Credits
|
64
|
-
|
65
|
-
The {dm-rails}[http://github.com/datamapper/dm-rails] team wrote most of this code, I just sequel-ized it.
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
== Note on Patches/Pull Requests
|
70
|
-
|
71
|
-
* Fork the project.
|
72
|
-
* Make your feature addition or bug fix.
|
73
|
-
* Add tests for it. This is important so I don't break it in a
|
74
|
-
future version unintentionally.
|
75
|
-
* Commit, do not mess with rakefile, version, or history.
|
76
|
-
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
77
|
-
* Send me a pull request. Bonus points for topic branches.
|
78
|
-
|
79
|
-
|
80
|
-
== The sequel-rails team
|
81
|
-
|
82
|
-
* Brasten Sager (brasten)
|
83
|
-
|
84
|
-
== Copyright
|
85
|
-
|
86
|
-
Copyright (c) 2010 The sequel-rails team. See {LICENSE}[http://github.com/brasten/sequel-rails/blob/master/LICENSE] for details.
|
data/VERSION
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
0.1.8
|
data/autotest/discover.rb
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
Autotest.add_discovery { "rspec" }
|
@@ -1,16 +0,0 @@
|
|
1
|
-
class <%= migration_file_name.camelize %>Migration < Sequel::Migration
|
2
|
-
|
3
|
-
def up
|
4
|
-
create_table :<%= table_name %> do
|
5
|
-
primary_key :id
|
6
|
-
<% attributes.each do |attribute| -%>
|
7
|
-
<%= attribute.type_class %> :<%= attribute.name %>
|
8
|
-
<% end -%>
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
def down
|
13
|
-
drop_table :<%= table_name %>
|
14
|
-
end
|
15
|
-
|
16
|
-
end
|
@@ -1,61 +0,0 @@
|
|
1
|
-
require 'active_support/core_ext/hash/except'
|
2
|
-
require 'active_support/core_ext/class/attribute_accessors'
|
3
|
-
|
4
|
-
module Rails
|
5
|
-
module Sequel
|
6
|
-
|
7
|
-
mattr_accessor :configuration
|
8
|
-
|
9
|
-
class Configuration
|
10
|
-
|
11
|
-
def self.for(root, database_yml_hash)
|
12
|
-
Rails::Sequel.configuration ||= new(root, database_yml_hash)
|
13
|
-
end
|
14
|
-
|
15
|
-
attr_reader :root, :raw
|
16
|
-
attr_accessor :logger
|
17
|
-
attr_accessor :migration_dir
|
18
|
-
|
19
|
-
def environment_for(name)
|
20
|
-
environments[name.to_s] || environments[name.to_sym]
|
21
|
-
end
|
22
|
-
|
23
|
-
def environments
|
24
|
-
@environments ||= @raw.inject({}) do |normalized, environment|
|
25
|
-
name, config = environment.first, environment.last
|
26
|
-
normalized[name] = normalize_repository_config(config)
|
27
|
-
normalized
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
private
|
32
|
-
|
33
|
-
def initialize(root, database_yml_hash)
|
34
|
-
@root, @raw = root, database_yml_hash
|
35
|
-
end
|
36
|
-
|
37
|
-
def normalize_repository_config(hash)
|
38
|
-
config = {}
|
39
|
-
hash.each do |key, value|
|
40
|
-
config[key.to_s] =
|
41
|
-
if key.to_s == 'port'
|
42
|
-
value.to_i
|
43
|
-
elsif key.to_s == 'adapter' && value == 'sqlite3'
|
44
|
-
'sqlite'
|
45
|
-
elsif key.to_s == 'database' && (hash['adapter'] == 'sqlite3' ||
|
46
|
-
hash['adapter'] == 'sqlite' ||
|
47
|
-
hash[:adapter] == 'sqlite3' ||
|
48
|
-
hash[:adapter] == 'sqlite')
|
49
|
-
value == ':memory:' ? value : File.expand_path((hash['database'] || hash[:database]), root)
|
50
|
-
else
|
51
|
-
value
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
config
|
56
|
-
end
|
57
|
-
|
58
|
-
end
|
59
|
-
|
60
|
-
end
|
61
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
require 'sequel/extensions/migration'
|
2
|
-
|
3
|
-
module Rails
|
4
|
-
module Sequel
|
5
|
-
class Migrations
|
6
|
-
|
7
|
-
class << self
|
8
|
-
|
9
|
-
def migrate_up!(version=nil)
|
10
|
-
opts = {}
|
11
|
-
opts[:target] = version.to_i if version
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
::Sequel::Migrator.run(::Sequel::Model.db, "db/migrate", opts)
|
16
|
-
end
|
17
|
-
|
18
|
-
def migrate_down!(version=nil)
|
19
|
-
opts = {}
|
20
|
-
opts[:target] = version.to_i if version
|
21
|
-
|
22
|
-
::Sequel::Migrator.run(::Sequel::Model.db, "db/migrate", opts)
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|
26
|
-
|
27
|
-
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
data/lib/sequel-rails/railtie.rb
DELETED
@@ -1,90 +0,0 @@
|
|
1
|
-
require 'sequel'
|
2
|
-
|
3
|
-
require 'rails'
|
4
|
-
require 'active_model/railtie'
|
5
|
-
|
6
|
-
# Comment taken from active_record/railtie.rb
|
7
|
-
#
|
8
|
-
# For now, action_controller must always be present with
|
9
|
-
# rails, so let's make sure that it gets required before
|
10
|
-
# here. This is needed for correctly setting up the middleware.
|
11
|
-
# In the future, this might become an optional require.
|
12
|
-
require 'action_controller/railtie'
|
13
|
-
|
14
|
-
require 'sequel-rails/setup'
|
15
|
-
require "sequel-rails/railties/log_subscriber"
|
16
|
-
require "sequel-rails/railties/i18n_support"
|
17
|
-
|
18
|
-
|
19
|
-
module Rails
|
20
|
-
module Sequel
|
21
|
-
|
22
|
-
class Railtie < Rails::Railtie
|
23
|
-
|
24
|
-
::Sequel::Railties::LogSubscriber.attach_to :sequel
|
25
|
-
|
26
|
-
config.generators.orm :sequel, :migration => true
|
27
|
-
config.rails_fancy_pants_logging = true
|
28
|
-
|
29
|
-
rake_tasks do
|
30
|
-
load 'sequel-rails/railties/database.rake'
|
31
|
-
end
|
32
|
-
|
33
|
-
initializer 'sequel.configuration' do |app|
|
34
|
-
configure_sequel(app)
|
35
|
-
end
|
36
|
-
|
37
|
-
initializer 'sequel.logger' do |app|
|
38
|
-
setup_logger(app, Rails.logger)
|
39
|
-
end
|
40
|
-
|
41
|
-
initializer 'sequel.i18n_support' do |app|
|
42
|
-
setup_i18n_support(app)
|
43
|
-
end
|
44
|
-
|
45
|
-
# Expose database runtime to controller for logging.
|
46
|
-
initializer "sequel.log_runtime" do |app|
|
47
|
-
setup_controller_runtime(app)
|
48
|
-
end
|
49
|
-
|
50
|
-
initializer "sequel.connect" do |app|
|
51
|
-
Rails::Sequel.setup(Rails.env)
|
52
|
-
end
|
53
|
-
|
54
|
-
# Run setup code after_initialize to make sure all config/initializers
|
55
|
-
# are in effect once we setup the connection. This is especially necessary
|
56
|
-
# for the cascaded adapter wrappers that need to be declared before setup.
|
57
|
-
|
58
|
-
config.after_initialize do |app|
|
59
|
-
::Sequel::Model.plugin :active_model
|
60
|
-
::Sequel::Model.plugin :validation_helpers
|
61
|
-
|
62
|
-
::Sequel::Model.raise_on_save_failure = false
|
63
|
-
end
|
64
|
-
|
65
|
-
|
66
|
-
# Support overwriting crucial steps in subclasses
|
67
|
-
|
68
|
-
def configure_sequel(app)
|
69
|
-
app.config.sequel = Rails::Sequel::Configuration.for(
|
70
|
-
Rails.root, app.config.database_configuration
|
71
|
-
)
|
72
|
-
end
|
73
|
-
|
74
|
-
def setup_i18n_support(app)
|
75
|
-
::Sequel::Model.send :include, Rails::Sequel::I18nSupport
|
76
|
-
end
|
77
|
-
|
78
|
-
def setup_controller_runtime(app)
|
79
|
-
require "sequel-rails/railties/controller_runtime"
|
80
|
-
ActionController::Base.send :include, Rails::Sequel::Railties::ControllerRuntime
|
81
|
-
end
|
82
|
-
|
83
|
-
def setup_logger(app, logger)
|
84
|
-
app.config.sequel.logger=logger
|
85
|
-
end
|
86
|
-
|
87
|
-
end
|
88
|
-
|
89
|
-
end
|
90
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
module Sequel
|
2
|
-
module Adapters
|
3
|
-
module Benchmarking
|
4
|
-
|
5
|
-
%w[ create read update delete ].each do |method|
|
6
|
-
class_eval <<-RUBY, __FILE__, __LINE__
|
7
|
-
def #{method}(*args, &block)
|
8
|
-
result = nil
|
9
|
-
@runtime ||= 0
|
10
|
-
@runtime += Benchmark.ms { result = super(*args, &block) }
|
11
|
-
result
|
12
|
-
end
|
13
|
-
RUBY
|
14
|
-
end
|
15
|
-
|
16
|
-
def reset_runtime
|
17
|
-
rt, @runtime = @runtime, 0
|
18
|
-
rt.to_f
|
19
|
-
end
|
20
|
-
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
@@ -1,43 +0,0 @@
|
|
1
|
-
require 'active_support/core_ext/module/attr_internal'
|
2
|
-
|
3
|
-
module Rails
|
4
|
-
module Sequel
|
5
|
-
module Railties
|
6
|
-
|
7
|
-
module ControllerRuntime
|
8
|
-
|
9
|
-
extend ActiveSupport::Concern
|
10
|
-
|
11
|
-
protected
|
12
|
-
|
13
|
-
attr_internal :db_runtime
|
14
|
-
|
15
|
-
def cleanup_view_runtime
|
16
|
-
db_rt_before_render = ::Rails::Sequel.reset_runtime
|
17
|
-
runtime = super
|
18
|
-
db_rt_after_render = ::Rails::Sequel.reset_runtime
|
19
|
-
self.db_runtime = db_rt_before_render + db_rt_after_render
|
20
|
-
runtime - db_rt_after_render
|
21
|
-
end
|
22
|
-
|
23
|
-
def append_info_to_payload(payload)
|
24
|
-
super
|
25
|
-
payload[:db_runtime] = db_runtime
|
26
|
-
end
|
27
|
-
|
28
|
-
|
29
|
-
module ClassMethods
|
30
|
-
|
31
|
-
def log_process_action(payload)
|
32
|
-
messages, db_runtime = super, payload[:db_runtime]
|
33
|
-
messages << ("Models: %.1fms" % db_runtime.to_f) if db_runtime
|
34
|
-
messages
|
35
|
-
end
|
36
|
-
|
37
|
-
end
|
38
|
-
|
39
|
-
end
|
40
|
-
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
@@ -1,148 +0,0 @@
|
|
1
|
-
# TODO: DRY these up
|
2
|
-
namespace :db do
|
3
|
-
namespace :schema do
|
4
|
-
desc "Create a db/schema.rb file that can be portably used against any DB supported by Sequel"
|
5
|
-
task :dump do
|
6
|
-
Sequel.extension :schema_dumper
|
7
|
-
db = Sequel.connect(Rails.configuration.database_configuration[Rails.env])
|
8
|
-
File.open(ENV['SCHEMA'] || "#{Rails.root}/db/schema.rb", "w") do |file|
|
9
|
-
file.write(db.dump_schema_migration)
|
10
|
-
end
|
11
|
-
Rake::Task["db:schema:dump"].reenable
|
12
|
-
end
|
13
|
-
|
14
|
-
desc "Load a schema.rb file into the database"
|
15
|
-
task :load, :needs => :environment do
|
16
|
-
require 'sequel-rails/storage'
|
17
|
-
Rails::Sequel::Storage.new(Rails.env).create
|
18
|
-
|
19
|
-
file = ENV['SCHEMA'] || "#{Rails.root}/db/schema.rb"
|
20
|
-
if File.exists?(file)
|
21
|
-
load(file)
|
22
|
-
else
|
23
|
-
abort %{#{file} doesn't exist yet. Run "rake db:migrate" to create it then try again. If you do not intend to use a database, you should instead alter #{Rails.root}/config/boot.rb to limit the frameworks that will be loaded}
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
namespace :create do
|
29
|
-
desc 'Create all the local databases defined in config/database.yml'
|
30
|
-
task :all, :needs => :environment do
|
31
|
-
require 'sequel-rails/storage'
|
32
|
-
Rails::Sequel::Storage.create_all
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
desc "Create the database defined in config/database.yml for the current Rails.env - also creates the test database if Rails.env.development?"
|
37
|
-
task :create, :env, :needs => :environment do |t, args|
|
38
|
-
args.with_defaults(:env => Rails.env)
|
39
|
-
|
40
|
-
require 'sequel-rails/storage'
|
41
|
-
Rails::Sequel::Storage.new(args.env).create
|
42
|
-
|
43
|
-
if Rails.env.development? && Rails.configuration.database_configuration['test']
|
44
|
-
Rails::Sequel::Storage.new('test').create
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
namespace :drop do
|
49
|
-
desc 'Drops all the local databases defined in config/database.yml'
|
50
|
-
task :all, :needs => :environment do
|
51
|
-
require 'sequel-rails/storage'
|
52
|
-
Rails::Sequel::Storage.drop_all
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
desc "Create the database defined in config/database.yml for the current Rails.env - also creates the test database if Rails.env.development?"
|
57
|
-
task :drop, :env, :needs => :environment do |t, args|
|
58
|
-
args.with_defaults(:env => Rails.env)
|
59
|
-
|
60
|
-
require 'sequel-rails/storage'
|
61
|
-
Rails::Sequel::Storage.new(args.env).drop
|
62
|
-
|
63
|
-
if Rails.env.development? && Rails.configuration.database_configuration['test']
|
64
|
-
Rails::Sequel::Storage.new('test').drop
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
namespace :migrate do
|
69
|
-
task :load => :environment do
|
70
|
-
require 'sequel-rails/migrations'
|
71
|
-
end
|
72
|
-
|
73
|
-
desc 'Rollbacks the database one migration and re migrate up. If you want to rollback more than one step, define STEP=x. Target specific version with VERSION=x.'
|
74
|
-
task :redo => :load do
|
75
|
-
if ENV["VERSION"]
|
76
|
-
Rake::Task["db:migrate:down"].invoke
|
77
|
-
Rake::Task["db:migrate:up"].invoke
|
78
|
-
else
|
79
|
-
Rake::Task["db:rollback"].invoke
|
80
|
-
Rake::Task["db:migrate"].invoke
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
|
85
|
-
desc 'Resets your database using your migrations for the current environment'
|
86
|
-
task :reset => ["db:drop", "db:create", "db:migrate"]
|
87
|
-
|
88
|
-
desc 'Runs the "up" for a given migration VERSION.'
|
89
|
-
task :up => :load do
|
90
|
-
version = ENV["VERSION"] ? ENV["VERSION"].to_i : nil
|
91
|
-
raise "VERSION is required" unless version
|
92
|
-
Rails::Sequel::Migrations.migrate_up!(version)
|
93
|
-
Rake::Task["db:schema:dump"].invoke if Rails.env != 'test'
|
94
|
-
end
|
95
|
-
|
96
|
-
desc 'Runs the "down" for a given migration VERSION.'
|
97
|
-
task :down => :load do
|
98
|
-
version = ENV["VERSION"] ? ENV["VERSION"].to_i : nil
|
99
|
-
raise "VERSION is required" unless version
|
100
|
-
Rails::Sequel::Migrations.migrate_down!(version)
|
101
|
-
Rake::Task["db:schema:dump"].invoke if Rails.env != 'test'
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
desc 'Migrate the database to the latest version'
|
106
|
-
task :migrate => :'migrate:load' do
|
107
|
-
Rails::Sequel::Migrations.migrate_up!(ENV["VERSION"] ? ENV["VERSION"].to_i : nil)
|
108
|
-
Rake::Task["db:schema:dump"].invoke if Rails.env != 'test'
|
109
|
-
end
|
110
|
-
|
111
|
-
desc 'Rolls the schema back to the previous version. Specify the number of steps with STEP=n'
|
112
|
-
task :rollback => :'migrate:load' do
|
113
|
-
step = ENV['STEP'] ? ENV['STEP'].to_i : 1
|
114
|
-
Sequel::Migrator.rollback('db/migrate/', step)
|
115
|
-
Rake::Task["db:schema:dump"].invoke if Rails.env != 'test'
|
116
|
-
end
|
117
|
-
|
118
|
-
desc 'Pushes the schema to the next version. Specify the number of steps with STEP=n'
|
119
|
-
task :forward => :'migrate:load' do
|
120
|
-
step = ENV['STEP'] ? ENV['STEP'].to_i : 1
|
121
|
-
Sequel::Migrator.forward('db/migrate/', step)
|
122
|
-
Rake::Task["db:schema:dump"].invoke if Rails.env != 'test'
|
123
|
-
end
|
124
|
-
|
125
|
-
desc 'Load the seed data from db/seeds.rb'
|
126
|
-
task :seed => :environment do
|
127
|
-
seed_file = File.join(Rails.root, 'db', 'seeds.rb')
|
128
|
-
load(seed_file) if File.exist?(seed_file)
|
129
|
-
end
|
130
|
-
|
131
|
-
desc 'Create the database, load the schema, and initialize with the seed data'
|
132
|
-
task :setup => [ 'db:create', 'db:migrate', 'db:seed' ]
|
133
|
-
|
134
|
-
desc 'Drops and recreates the database from db/schema.rb for the current environment and loads the seeds.'
|
135
|
-
task :reset => [ 'db:drop', 'db:setup' ]
|
136
|
-
|
137
|
-
namespace :test do
|
138
|
-
task :prepare do
|
139
|
-
Rails.env = 'test'
|
140
|
-
Rake::Task['db:reset'].invoke()
|
141
|
-
Sequel::DATABASES.each do |db|
|
142
|
-
db.disconnect
|
143
|
-
end
|
144
|
-
end
|
145
|
-
end
|
146
|
-
end
|
147
|
-
|
148
|
-
task 'test:prepare' => 'db:test:prepare'
|