sequel-rails 0.1.8 → 0.4.0.pre

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. data/.gitignore +1 -0
  2. data/.rspec +3 -0
  3. data/.travis.yml +12 -0
  4. data/Gemfile +13 -16
  5. data/History.md +142 -0
  6. data/README.md +124 -0
  7. data/Rakefile +6 -30
  8. data/config.ru +7 -0
  9. data/lib/generators/sequel.rb +11 -8
  10. data/lib/generators/sequel/migration/migration_generator.rb +36 -11
  11. data/lib/generators/sequel/migration/templates/migration.rb.erb +48 -0
  12. data/lib/generators/sequel/model/model_generator.rb +8 -2
  13. data/lib/generators/sequel/model/templates/migration.rb.erb +16 -0
  14. data/lib/generators/sequel/model/templates/{model.rb → model.rb.erb} +4 -1
  15. data/lib/generators/sequel/observer/observer_generator.rb +2 -2
  16. data/lib/generators/sequel/observer/templates/{observer.rb → observer.rb.erb} +0 -0
  17. data/lib/sequel-rails.rb +1 -1
  18. data/lib/sequel_rails.rb +2 -0
  19. data/lib/sequel_rails/configuration.rb +64 -0
  20. data/lib/sequel_rails/migrations.rb +22 -0
  21. data/lib/sequel_rails/railtie.rb +94 -0
  22. data/lib/sequel_rails/railties/controller_runtime.rb +40 -0
  23. data/lib/sequel_rails/railties/database.rake +175 -0
  24. data/lib/sequel_rails/railties/i18n_support.rb +10 -0
  25. data/lib/sequel_rails/railties/log_subscriber.rb +56 -0
  26. data/lib/sequel_rails/sequel/database/active_support_notification.rb +28 -0
  27. data/lib/sequel_rails/sequel/plugins/rails_extensions.rb +35 -0
  28. data/lib/sequel_rails/session_store.rb +80 -0
  29. data/lib/sequel_rails/storage.rb +58 -0
  30. data/lib/sequel_rails/storage/abstract.rb +52 -0
  31. data/lib/sequel_rails/storage/jdbc.rb +45 -0
  32. data/lib/sequel_rails/storage/mysql.rb +31 -0
  33. data/lib/sequel_rails/storage/mysql2.rb +6 -0
  34. data/lib/sequel_rails/storage/postgres.rb +22 -0
  35. data/lib/sequel_rails/storage/sqlite.rb +26 -0
  36. data/lib/sequel_rails/version.rb +3 -0
  37. data/sequel-rails.gemspec +22 -86
  38. data/spec/internal/app/models/user.rb +2 -0
  39. data/spec/internal/config/database.yml +7 -0
  40. data/spec/internal/config/routes.rb +3 -0
  41. data/spec/internal/db/schema.rb +8 -0
  42. data/spec/internal/public/favicon.ico +0 -0
  43. data/spec/lib/generators/sequel/migration_spec.rb +256 -0
  44. data/spec/lib/sequel_rails/railtie_spec.rb +85 -0
  45. data/spec/lib/sequel_rails/railties/log_subscriber_spec.rb +29 -0
  46. data/spec/lib/sequel_rails/storage_spec.rb +108 -0
  47. data/spec/spec_helper.rb +30 -16
  48. data/tasks/spec.rake +63 -29
  49. metadata +194 -142
  50. data/CHANGELOG +0 -15
  51. data/README.rdoc +0 -86
  52. data/VERSION +0 -1
  53. data/autotest/discover.rb +0 -1
  54. data/lib/generators/sequel/migration/templates/migration.rb +0 -16
  55. data/lib/sequel-rails/configuration.rb +0 -61
  56. data/lib/sequel-rails/migrations.rb +0 -30
  57. data/lib/sequel-rails/railtie.rb +0 -90
  58. data/lib/sequel-rails/railties/benchmarking_mixin.rb +0 -23
  59. data/lib/sequel-rails/railties/controller_runtime.rb +0 -43
  60. data/lib/sequel-rails/railties/database.rake +0 -148
  61. data/lib/sequel-rails/railties/i18n_support.rb +0 -12
  62. data/lib/sequel-rails/railties/log_subscriber.rb +0 -31
  63. data/lib/sequel-rails/runtime.rb +0 -14
  64. data/lib/sequel-rails/session_store.rb +0 -82
  65. data/lib/sequel-rails/setup.rb +0 -19
  66. data/lib/sequel-rails/storage.rb +0 -210
  67. data/spec/rcov.opts +0 -6
  68. data/spec/setup_spec.rb +0 -7
  69. data/spec/spec.opts +0 -4
  70. data/tasks/ci.rake +0 -1
  71. data/tasks/clean.rake +0 -6
  72. data/tasks/metrics.rake +0 -37
  73. data/tasks/yard.rake +0 -9
  74. data/tasks/yardstick.rake +0 -20
data/.gitignore CHANGED
@@ -27,3 +27,4 @@ vendor
27
27
  .bundle
28
28
  .rvmrc
29
29
  *.gem
30
+ Gemfile.lock
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --format progress
3
+ --backtrace
data/.travis.yml ADDED
@@ -0,0 +1,12 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ env:
5
+ - "TEST_ADAPTER=postgresql TEST_OWNER=postgres TEST_USERNAME=postgres"
6
+ - "TEST_ADAPTER=mysql TEST_USERNAME=root TEST_ENCODING=utf8"
7
+ - "TEST_ADAPTER=mysql2 TEST_USERNAME=root TEST_ENCODING=utf8"
8
+ - "TEST_ADAPTER=sqlite3 TEST_DATABASE=':memory:'"
9
+ script: "rake spec"
10
+ notifications:
11
+ email:
12
+ - jonathan.tron@metrilio.com
data/Gemfile CHANGED
@@ -1,21 +1,18 @@
1
- source 'http://rubygems.org'
1
+ source "http://rubygems.org"
2
2
 
3
- gem 'rake', '~> 0.8.7'
4
- gem 'jeweler', '~> 1.4'
5
- gem 'yard', '~> 0.5'
6
-
7
- git 'git://github.com/rails/rails.git' do
8
-
9
- gem 'activesupport', '~> 3.0.0.beta3', :require => 'active_support'
10
- gem 'actionpack', '~> 3.0.0.beta3', :require => 'action_pack'
11
- gem 'railties', '~> 3.0.0.beta3', :require => 'rails'
3
+ gemspec
12
4
 
5
+ # MRI/Rubinius Adapter Dependencies
6
+ platform :ruby do
7
+ gem "pg"
8
+ gem "mysql"
9
+ gem "mysql2"
10
+ gem "sqlite3"
13
11
  end
14
12
 
15
- gem 'sequel', '~> 3.11.0'
16
-
17
- group :test do
18
- gem 'rspec'
19
- gem 'autotest'
20
- gem 'rcov'
13
+ # JRuby Adapter Dependencies
14
+ platform :jruby do
15
+ gem "jdbc-sqlite3"
16
+ gem "jdbc-mysql"
17
+ gem "jdbc-postgres"
21
18
  end
data/History.md ADDED
@@ -0,0 +1,142 @@
1
+ 0.4.0.pre
2
+ ==========
3
+
4
+ * Add [Travis-CI](http://travis-ci.org) configuration
5
+ * Ensure file name for migration are valid
6
+ * **BIG CHANGE** rename `Rails::Sequel` module as `SequelRails`, this becomes
7
+ the namespace for all sequel-rails related classes.
8
+ * Split `Rails::Sequel::Storage` class in multiple adapter for each db
9
+ * Only log queries if logger level is set to :debug (matching ActiveRecord
10
+ default).
11
+ * Correctly display time spent in models in controller logs.
12
+ * Add simple `ActiveSupport::Notification` support to Sequel using logger
13
+ facility. This is done by monkey patching `Sequel::Database#log_yield`, so
14
+ it does not yield directly if no loggers configured and instrument the yield
15
+ call. Note that this does not allow to know from which class the query comes
16
+ from. So it still does not display the `Sequel::Model` subclass like
17
+ `ActiveRecord` does (eg: User load).
18
+ * Add spec for Sequel::Railties::LogSubscriber
19
+ * Add initial specs for railtie setup
20
+
21
+ 0.3.10
22
+ ======
23
+
24
+ * Add post_install_message to notify users to switch to sequel-rails gem
25
+
26
+ 0.3.9
27
+ =====
28
+
29
+ * Correctly pass option to MySQL CLI and correctly escape them (Arron Washington)
30
+
31
+ 0.3.8
32
+ =====
33
+
34
+ * Fix bug in `db:force_close_open_connections` and make it work with
35
+ PostgreSQL 9.2.
36
+ * Ensure `db:test:prepare` use `execute` instead of `invoke` so that tasks
37
+ already invoked are executed again. This make the following work as expected:
38
+ `rake db:create db:migrate db:test:prepare`
39
+
40
+ 0.3.7
41
+ =====
42
+
43
+ * Check migration directory exists before checking if migration are pending
44
+
45
+ 0.3.6
46
+ =====
47
+
48
+ * Ensure some tasks use the right db after setting `Rails.env`:
49
+ - `db:schema:load`
50
+ - `db:schema:dump`
51
+ - `db:force_close_open_connections`
52
+ * Add check for pending migrations before running task depending on schema:
53
+ - `db:schema:load`
54
+ - `db:test:prepare`
55
+ * Make database task more like what rails is doing:
56
+ - `db:load` do not create the db anymore
57
+ - `db:create` don't create the test db automatically
58
+ - `db:drop` don't drop the test db automatically
59
+ - `db:test:prepare` don't depend on `db:reset` which was loading `db:seed` (Sean Kirby)
60
+ * Make `rake db:setup` load schema instead of running migrations (Markus Fenske)
61
+ * Depends on `railties` instead of `rails` to not pull `active_record`
62
+ as dependency (Markus Fenske)
63
+
64
+ 0.3.5
65
+ =====
66
+
67
+ * Fix `rake db:schema:load` (Markus Fenske)
68
+
69
+ 0.3.4
70
+ =====
71
+
72
+ * Make `rake db:schema:dump` generate a schema file which contains foreign_keys
73
+ and uses db types instead of ruby equivalents. This ensure loading the schema
74
+ file will result in a correct db
75
+
76
+ * Map some Sequel specific exceptions to `ActiveRecord` equivalents, in
77
+ `config.action_dispatch.rescue_responses`. This allows controllers to behave
78
+ more like `ActiveRecord` when Sequel raises exceptions. (Joshua Hansen)
79
+
80
+ * New Sequel plugin added to all `Sequel::Model` which allows to use
81
+ `Sequel::Model#find!` which will raise an exception if record does not exists.
82
+ This method is an alias to `Sequel::Model#[]` method. (Joshua Hansen)
83
+
84
+ 0.3.3
85
+ =====
86
+
87
+ * Fix generators and use better model and migration template (Joshua Hansen)
88
+
89
+ 0.3.2
90
+ =====
91
+ * Ignore environments without `database` key (like ActiveRecord do it), to allow
92
+ shared configurations in `database.yml`.
93
+ * Fix db creation commands to let the `system` method escape the arguments
94
+ * Fix error when using `mysql2` gem
95
+
96
+ 0.3.1
97
+ =====
98
+ * Make `db:schema:dump` Rake task depends on Rails `environment` task (Gabor Ratky)
99
+
100
+ 0.3.0
101
+ =====
102
+ * Update dependency to Rails (~> 3.2.0)
103
+
104
+ 0.2.3
105
+ =====
106
+ * Set `PGPASSWORD` environment variable before trying to create DB using `createdb`
107
+
108
+ 0.2.2
109
+ =====
110
+ * Ensure Sequel is disconnected before trying to drop a db
111
+
112
+ 0.2.1
113
+ =====
114
+ * Make dependency on Sequel more open (~> 3.28)
115
+
116
+ 0.2.0
117
+ =====
118
+ * Fix deprecation warning for config.generators
119
+ * Update dependency to Rails 3.1.1
120
+ * Update dependency to Sequel 3.28.0
121
+ * Update dependency to RSpec 2.7.0
122
+
123
+ 0.1.4
124
+ =====
125
+ * Merged in changes to rake tasks and timestamp migrations
126
+
127
+ 0.1.3
128
+ =====
129
+ * update sequel dependency, configuration change
130
+
131
+ 0.1.2
132
+ =====
133
+ * fixed log_subscriber bug that 0.1.1 was -supposed- to fix.
134
+ * fixed controller_runtime bug
135
+
136
+ 0.1.1
137
+ =====
138
+ * bug fixes, no additional functionality
139
+
140
+ 0.1.0
141
+ =====
142
+ * initial release
data/README.md ADDED
@@ -0,0 +1,124 @@
1
+ sequel-rails
2
+ ============
3
+
4
+ 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/talentbox/sequel-rails) uses the railtie API to hook into rails. The two are actually hooked into rails almost identically.
5
+
6
+ The code for this gem was initially taken from the excellent [dm-rails](http://github.com/datamapper/dm-rails) project.
7
+
8
+ This was originally a fork of [brasten](https://github.com/brasten)'s [sequel-rails](https://github.com/brasten/sequel-rails) that has been updated to support newer versions of rails.
9
+
10
+ Since January 2013, we've became the official maintainers of the gem after [brasten](https://github.com/brasten) proposed us.
11
+
12
+ Using sequel-rails
13
+ ==================
14
+
15
+ Using sequel with rails3 requires a couple minor changes.
16
+
17
+ First, add the following to your Gemfile (after the `Rails` lines):
18
+
19
+ ```ruby
20
+ # depending on you database
21
+ gem "pg" # for PostgreSQL
22
+ gem "mysql2" # for MySQL
23
+ gem "sqlite3" # for Sqlite
24
+
25
+ gem "sequel-rails"
26
+ ```
27
+
28
+ ... be sure to run "bundle install" if needed!
29
+
30
+ Secondly, you'll need to require the different Rails components separately in your `config/application.rb` file, and not require `ActiveRecord`. The top of your `config/application.rb` will probably look something like:
31
+
32
+ ```ruby
33
+ # require 'rails/all'
34
+
35
+ # Instead of 'rails/all', require these:
36
+ require "action_controller/railtie"
37
+ # require "active_record/railtie"
38
+ require "action_mailer/railtie"
39
+ require "sprockets/railtie"
40
+ ```
41
+
42
+ After those changes, you should be good to go!
43
+
44
+ Available sequel specific rake tasks
45
+ ====================================
46
+
47
+ To get a list of all available rake tasks in your rails3 app, issue the usual in you app's root directory:
48
+
49
+ ```bash
50
+ rake -T
51
+ ```
52
+
53
+ or if you don't have hooks in place to run commands with bundle by default:
54
+
55
+ ```bash
56
+ bundle exec rake -T
57
+ ```
58
+
59
+ Once you do that, you will see the following rake tasks among others. These are the ones that sequel-rails added or replaced:
60
+
61
+ ```bash
62
+ rake db:create[env] # Create the database defined in config/database.yml for the current Rails.env
63
+ rake db:create:all # Create all the local databases defined in config/database.yml
64
+ rake db:drop[env] # Create the database defined in config/database.yml for the current Rails.env
65
+ rake db:drop:all # Drops all the local databases defined in config/database.yml
66
+ rake db:force_close_open_connections # Forcibly close any open connections to the test database
67
+ rake db:forward # Pushes the schema to the next version. Specify the number of steps with STEP=n
68
+ rake db:migrate # Migrate the database to the latest version
69
+ rake db:migrate:down # Runs the "down" for a given migration VERSION.
70
+ rake db:migrate:redo # Rollbacks the database one migration and re migrate up.
71
+ rake db:migrate:reset # Resets your database using your migrations for the current environment
72
+ rake db:migrate:up # Runs the "up" for a given migration VERSION.
73
+ rake db:reset # Drops and recreates the database from db/schema.rb for the current environment and loads the seeds.
74
+ rake db:rollback # 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.
75
+ rake db:schema:dump # Create a db/schema.rb file that can be portably used against any DB supported by Sequel
76
+ rake db:schema:load # Load a schema.rb file into the database
77
+ rake db:seed # Load the seed data from db/seeds.rb
78
+ rake db:setup # Create the database, load the schema, and initialize with the seed data
79
+ rake db:test:prepare # Prepare test database (ensure all migrations ran, drop and re-create database then load schema). This task can be run in the same invocation as other task (eg: rake db:migrate db:test:prepare).
80
+ ```
81
+
82
+ Note on Patches/Pull Requests
83
+ =============================
84
+
85
+ * Fork the project.
86
+ * Make your feature addition or bug fix.
87
+ * Add specs for it. This is important so I don't break it in a
88
+ future version unintentionally.
89
+ * Commit, do not mess with rakefile, version, or history.
90
+ (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)
91
+ * Send me a pull request. Bonus points for topic branches.
92
+
93
+ The sequel-rails team
94
+ =====================
95
+
96
+ * Jonathan Tron (JonathanTron) - Current maintainer
97
+ * Joseph Halter (JosephHalter) - Current maintainer
98
+
99
+ Previous maintainer
100
+ ===================
101
+
102
+ [Original project](https://github.com/brasten/sequel-rails):
103
+
104
+ * Brasten Sager (brasten) - Project creator
105
+
106
+ Contributors
107
+ ============
108
+
109
+ Improvements has been made by those awesome contributors:
110
+
111
+ * Benjamin Atkin (benatkin)
112
+ * Gabor Ratky (rgabo)
113
+ * Joshua Hansen (binarypaladin)
114
+ * Arron Washington (radicaled)
115
+
116
+ Credits
117
+ =======
118
+
119
+ The [dm-rails](http://github.com/datamapper/dm-rails) team wrote most of the original code, I just sequel-ized it, but since then most of it as been either adapter or rewritten.
120
+
121
+ Copyright
122
+ =========
123
+
124
+ Copyright (c) 2010-2013 The sequel-rails team. See [LICENSE](http://github.com/brasten/sequel-rails/blob/master/LICENSE) for details.
data/Rakefile CHANGED
@@ -1,33 +1,9 @@
1
- require 'rubygems'
2
- require 'rake'
3
-
4
1
  begin
5
-
6
- require 'jeweler'
7
-
8
- Jeweler::Tasks.new do |gem|
9
-
10
- gem.name = 'sequel-rails'
11
- gem.summary = 'Use Sequel with Rails 3'
12
- gem.description = 'Integrate Sequel with Rails 3'
13
- gem.email = 'brasten@gmail.com'
14
- gem.homepage = 'http://github.com/brasten/sequel-rails'
15
- gem.authors = [ 'Brasten Sager (brasten)' ]
16
-
17
- gem.add_dependency 'sequel', '~> 3.13'
18
-
19
- gem.add_dependency 'activesupport', '~> 3.0.0'
20
- gem.add_dependency 'actionpack', '~> 3.0.0'
21
- gem.add_dependency 'railties', '~> 3.0.0'
22
-
23
- # gem.add_development_dependency 'yard', '~> 0.5'
24
-
25
- end
26
-
27
- Jeweler::GemcutterTasks.new
28
-
29
- FileList['tasks/**/*.rake'].each { |task| import task }
30
-
2
+ require 'bundler/setup'
31
3
  rescue LoadError
32
- puts 'Jeweler (or a dependency) not available. Install it with: gem install jeweler'
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
33
5
  end
6
+
7
+ Bundler::GemHelper.install_tasks
8
+
9
+ FileList['tasks/**/*.rake'].each { |task| import task }
data/config.ru ADDED
@@ -0,0 +1,7 @@
1
+ require 'rubygems'
2
+ require 'bundler'
3
+
4
+ Bundler.require :default, :development
5
+
6
+ Combustion.initialize! "sequel_rails"
7
+ run Combustion::Application
@@ -1,6 +1,6 @@
1
- require 'rails/generators/named_base'
2
- require 'rails/generators/migration'
3
- require 'rails/generators/active_model'
1
+ require "rails/generators/named_base"
2
+ require "rails/generators/migration"
3
+ require "rails/generators/active_model"
4
4
 
5
5
  module Sequel
6
6
  module Generators
@@ -9,9 +9,14 @@ module Sequel
9
9
 
10
10
  include ::Rails::Generators::Migration
11
11
 
12
+ def self.base_name
13
+ @_sequel_base_name ||= "sequel"
14
+ end
15
+
12
16
  def self.source_root
13
- @_sequel_source_root ||=
14
- File.expand_path("../#{base_name}/#{generator_name}/templates", __FILE__)
17
+ @_sequel_source_root ||= File.expand_path(
18
+ "../#{base_name}/#{generator_name}/templates", __FILE__
19
+ )
15
20
  end
16
21
 
17
22
  protected
@@ -38,7 +43,7 @@ module Sequel
38
43
  end
39
44
 
40
45
  def self.find(klass, params=nil)
41
- "#{klass}.get(#{params})"
46
+ "#{klass}.find!(#{params})"
42
47
  end
43
48
 
44
49
  def self.build(klass, params=nil)
@@ -70,7 +75,6 @@ module Sequel
70
75
  end
71
76
 
72
77
  module Rails
73
-
74
78
  module Generators
75
79
  class GeneratedAttribute #:nodoc:
76
80
  def type_class
@@ -79,5 +83,4 @@ module Rails
79
83
  end
80
84
  end
81
85
  end
82
-
83
86
  end
@@ -1,30 +1,55 @@
1
- require 'generators/sequel'
1
+ require "generators/sequel"
2
2
 
3
3
  module Sequel
4
- module Generators
4
+ class IllegalMigrationNameError < StandardError
5
+ def initialize(name)
6
+ super("Illegal name for migration file: #{name}\n\t(only lower case letters, numbers, and '_' allowed)")
7
+ end
8
+ end
5
9
 
6
- class MigrationGenerator < Base
10
+ module Generators
11
+ class MigrationGenerator < Base #:nodoc:
7
12
 
8
13
  argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
9
- class_option :id, :type => :numeric, :desc => "The id to be used in this migration"
10
14
 
11
15
  def create_migration_file
12
16
  set_local_assigns!
13
- migration_template "migration.rb", "db/migrate/#{file_name}.rb"
17
+ validate_file_name!
18
+ migration_template "migration.rb.erb", "db/migrate/#{file_name}.rb"
14
19
  end
15
20
 
16
- protected
21
+ attr_reader :migration_action, :table_action, :column_action, :use_change
17
22
 
18
- attr_reader :migration_action
23
+ protected
19
24
 
20
25
  def set_local_assigns!
21
- if file_name =~ /^(add|remove|drop)_.*_(?:to|from)_(.*)/
22
- @migration_action = $1 == 'add' ? 'add' : 'drop'
23
- @table_name = $2.pluralize
26
+ if file_name =~ /^(add|drop|remove)_.*_(?:to|from)_(.*)/
27
+ @table_action = 'alter'
28
+ @table_name = $2.pluralize
29
+ @column_action = $1 == 'add' ? 'add' : 'drop'
30
+ @use_change = @column_action == 'add' ? true : false
31
+ elsif file_name =~ /^(create|drop)_(.*)$/
32
+ @table_action = $1
33
+ @table_name = $2.pluralize
34
+ @column_action = 'add'
35
+ @use_change = @table_action == 'create' ? true : false
36
+ else
37
+ @table_action = 'alter'
38
+ if file_name =~ /^(alter)_(.*)/
39
+ @table_name = $2.pluralize
40
+ else
41
+ @table_name = file_name.pluralize
42
+ end
43
+ @use_change = false
44
+ @column_action = 'add'
24
45
  end
25
46
  end
26
47
 
48
+ def validate_file_name!
49
+ unless file_name =~ /^[_a-z0-9]+$/
50
+ raise IllegalMigrationNameError.new(file_name)
51
+ end
52
+ end
27
53
  end
28
-
29
54
  end
30
55
  end