aspgems-redhillonrails_core 2.0.0.beta2 → 2.0.0.beta4

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.
Files changed (36) hide show
  1. data/.gitignore +8 -0
  2. data/.travis.yml +8 -0
  3. data/CHANGELOG +16 -0
  4. data/README.md +50 -10
  5. data/README_DEV.md +41 -0
  6. data/Rakefile +43 -13
  7. data/Thorfile +45 -0
  8. data/gemfiles/rails-3.0.7 +13 -0
  9. data/gemfiles/rails-3.0.7.lock +90 -0
  10. data/gemfiles/rails-3.0.8 +13 -0
  11. data/gemfiles/rails-3.0.8.lock +90 -0
  12. data/gemfiles/rails-3.0.9 +13 -0
  13. data/gemfiles/rails-3.0.9.lock +92 -0
  14. data/gemfiles/rails-3.1.0.rc5 +13 -0
  15. data/gemfiles/rails-3.1.0.rc5.lock +106 -0
  16. data/lib/redhillonrails_core.rb +12 -0
  17. data/lib/redhillonrails_core/active_record/base.rb +1 -1
  18. data/lib/redhillonrails_core/active_record/connection_adapters/abstract/foreign_key_definition.rb +13 -6
  19. data/lib/redhillonrails_core/active_record/connection_adapters/abstract/index_definition.rb +3 -0
  20. data/lib/redhillonrails_core/active_record/connection_adapters/abstract_adapter.rb +10 -6
  21. data/lib/redhillonrails_core/active_record/connection_adapters/mysql_adapter.rb +27 -53
  22. data/lib/redhillonrails_core/active_record/connection_adapters/postgresql_adapter.rb +82 -57
  23. data/lib/redhillonrails_core/active_record/migration/command_recorder.rb +30 -0
  24. data/lib/redhillonrails_core/active_record/schema_dumper.rb +18 -6
  25. data/lib/redhillonrails_core/version.rb +1 -1
  26. data/redhillonrails_core.gemspec +2 -1
  27. data/spec/command_recorder_spec.rb +39 -0
  28. data/spec/connections/mysql/connection.rb +4 -6
  29. data/spec/connections/mysql2/connection.rb +4 -6
  30. data/spec/connections/postgresql/connection.rb +4 -3
  31. data/spec/connections/sqlite3/connection.rb +4 -3
  32. data/spec/foreign_key_definition_spec.rb +31 -2
  33. data/spec/foreign_key_spec.rb +15 -2
  34. data/spec/migration_spec.rb +34 -0
  35. data/spec/table_definition_spec.rb +28 -0
  36. metadata +30 -11
data/.gitignore ADDED
@@ -0,0 +1,8 @@
1
+ pkg
2
+ debug.log
3
+ Gemfile.lock
4
+ gemfiles/bin/*
5
+ gemfiles/vendor/*
6
+ bin
7
+ .gemfile
8
+ *.db
data/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ script: "bundle exec rake create_databases spec"
2
+ bundler_args: "--without development"
3
+ rvm:
4
+ - 1.8.7
5
+ - 1.9.2
6
+ gemfile:
7
+ - gemfiles/rails-3.0.9
8
+ - gemfiles/rails-3.1.0.rc5
data/CHANGELOG CHANGED
@@ -1,3 +1,19 @@
1
+ 2.0.0.beta4
2
+ * To fix version number released
3
+
4
+ 2.0.0.beta3
5
+ * postgresql specs pass again
6
+ * compatibility with mysql 0.2.X line
7
+ * quoting fixes
8
+ * proper foreign keys ordering
9
+ * views support for mysql and sqlite
10
+ * sorting of indexes and foreign keys on schema dumpe
11
+
12
+ 2.0.0.beta2
13
+
14
+ 2.0.0.beta1
15
+ * build as a gem with bundler
16
+
1
17
  [REVISION 20110112]
2
18
 
3
19
  [REMOVE] Remove unused columns monkeypatch and avoid a query to get the indexes of a table that cost so much in tables with so many records
data/README.md CHANGED
@@ -1,10 +1,14 @@
1
- = Disclaimer
1
+ [![Build Status](https://secure.travis-ci.org/aspgems/redhillonrails_core.png)](http://travis-ci.org/aspgems/redhillonrails_core)
2
+
3
+ Disclaimer
4
+ ==========
2
5
 
3
6
  redhillonrails_core was originally created by http://github.com/harukizaemon but it was retired and is no longer supported.
4
7
 
5
8
  That fork is intended to make redhillonrails_core compatible with edge rails and introduce some new features.
6
9
 
7
- = RedHill on Rails Core
10
+ RedHill on Rails Core
11
+ =====================
8
12
 
9
13
  Goal of redhillonrails_core is to provided missing ActiveRecord support for database specific features:
10
14
 
@@ -12,19 +16,22 @@ Goal of redhillonrails_core is to provided missing ActiveRecord support for data
12
16
  * case-insensitive and partial indexes (pgsql only)
13
17
  * views
14
18
 
15
- == Installation
19
+ Installation
20
+ ------------
16
21
 
17
22
  As a gem
18
23
 
19
24
  gem install aspgems-redhillonrails_core
20
25
 
21
- == Compatibility
26
+ Compatibility
27
+ -------------
22
28
 
23
29
  * Ruby - 1.8, 1.9
24
30
  * ActiveRecord - 2.X, 3.X
25
31
  * Databases - PostgreSQL, MySQL, SQLite3 (most features should also run on others)
26
32
 
27
- === Foreign Key Support
33
+ Foreign Key Support
34
+ -------------------
28
35
 
29
36
  The plugin provides two mechanisms for adding foreign keys as well as
30
37
  preserving foreign keys when performing a schema dump. (Using SQL-92 syntax and
@@ -34,36 +41,48 @@ constraints.)
34
41
  The first mechanism for creating foreign-keys allows you to add a foreign key
35
42
  when defining a table. For example:
36
43
 
44
+ ```ruby
37
45
  create_table :orders do |t|
38
46
  ...
39
47
  t.foreign_key :customer_id, :customers, :id
40
48
  end
49
+ ```
41
50
 
42
51
  You also have the option of specifying what to do on delete/update using
43
52
  <code>:on_delete</code>/<code>:on_update</code>, respectively to one of: <code>:cascade</code>; <code>:restrict</code>; and <code>:set_null</code>:
44
53
 
54
+ ```ruby
45
55
  create_table :orders do |t|
46
56
  ...
47
57
  t.foreign_key :customer_id, :customers, :id, :on_delete => :set_null, :on_update => :cascade
48
58
  end
59
+ ```
49
60
 
50
61
  The second method allows you to create arbitrary foreign-keys at any time:
51
62
 
63
+ ```ruby
52
64
  add_foreign_key(:orders, :customer_id, :customers, :id, :on_delete => :set_null, :on_update => :cascade)
65
+ ```
53
66
 
54
67
  In either case, if your database supports deferred foreign keys (for example PostgreSQL) you can specify this as well:
55
68
 
69
+ ```ruby
56
70
  t.foreign_key :customer_id, :customers, :id, :deferrable => true
57
71
  add_foreign_key(:orders, :customer_id, :customers, :id, :deferrable => true)
72
+ ```
58
73
 
59
74
  By default, the foreign key will be assigned a name by the underlying database. However, if this doesn't suit
60
75
  your needs, you can override the default assignment using the <code>:name</code> option:
61
76
 
77
+ ```ruby
62
78
  add_foreign_key(:orders, :customer_id, :customers, :id, :on_delete => :set_null, :on_update => :cascade, <strong>:name => :orders_customer_id_foreign_key<strong>)
79
+ ```
63
80
 
64
81
  You can also query the foreign keys for a model yourself by calling <code>foreign_keys()</code>:
65
82
 
83
+ ```ruby
66
84
  Order.foreign_keys
85
+ ```
67
86
 
68
87
  Or for an arbitrary table by calling <code>foreign_keys(table_name)</code> on a database adapter.
69
88
 
@@ -77,7 +96,9 @@ Either method returns an array of the following meta-data:
77
96
 
78
97
  If you need to drop a foreign-key, use:
79
98
 
99
+ ```ruby
80
100
  remove_foreign_key :orders, :orders_ordered_by_id_fkey
101
+ ```
81
102
 
82
103
  The plugin also ensures that all foreign keys are output when performing a
83
104
  schema dump. This happens automatically when running <code>rake migrate</code> or
@@ -85,24 +106,32 @@ schema dump. This happens automatically when running <code>rake migrate</code> o
85
106
  unit tests that contain fixtures. To ensure the test data is correctly reset after
86
107
  each test, you should list your fixtures in order of parent->child. For example:
87
108
 
109
+ ```ruby
88
110
  fixtures :customers, :products, :orders, :order_lines
111
+ ```
89
112
 
90
113
  Rails will then set-up and tear-down the fixtures in the correct sequence.
91
114
 
92
115
  Some databases (PostgreSQL and MySQL for example) allow you to set a comment for a
93
116
  table. You can do this for existing tables by using:
94
117
 
118
+ ```ruby
95
119
  set_table_comment :orders, "All pending and processed orders"
120
+ ```
96
121
 
97
122
  or even at the time of creation:
98
123
 
124
+ ```ruby
99
125
  create_table :orders, :comment => "All pending and processed orders" do |t|
100
126
  ...
101
127
  end
128
+ ```
102
129
 
103
130
  You can clear table comments using:
104
131
 
132
+ ```ruby
105
133
  clear_table_comment :orders
134
+ ```
106
135
 
107
136
  There is also a rake tasks to show all database tables and their comments:
108
137
 
@@ -115,31 +144,39 @@ configuration properties:
115
144
  * <code>config.active_record.table_name_prefix</code>
116
145
  * <code>config.active_record.table_name_suffix</code>
117
146
 
118
- === View Support
147
+ View Support
148
+ ------------
119
149
 
120
150
  The plugin provides a mechanism for creating and dropping views as well as
121
151
  preserving views when performing a schema dump:
122
152
 
153
+ ```ruby
123
154
  create_view :normal_customers, "SELECT * FROM customers WHERE status = 'normal'"
124
155
  drop_view :normal_customers
156
+ ```
125
157
 
126
- === Model Indexes
158
+ Model Indexes
159
+ -------------
127
160
 
128
161
  ActiveRecord::Base already provides a method on connection for obtaining the
129
162
  indexes for a given table. This plugin now makes it possible to obtain the
130
163
  indexes for a given model--<code>ActiveRecord::Base</code>--class. For example:
131
164
 
165
+ ```ruby
132
166
  Invoice.indexes
167
+ ```
133
168
 
134
169
  Would return all the indexes for the +invoices+ table.
135
170
 
136
- === Schema Defining
171
+ Schema Defining
172
+ ---------------
137
173
 
138
174
  The plugin also adds a method--<code>defining?()</code>--to
139
175
  <code>ActiveRecord::Schema</code> to indicate when <code>define()</code> is running. This is necessary
140
176
  as some migration plugins must change their behaviour accordingly.
141
177
 
142
- === Case-insensitive Indexes
178
+ Case-insensitive Indexes
179
+ ------------------------
143
180
 
144
181
  For PostgreSQL, you can add an option <code>:case_sensitive => false</code> to <code>add_index</code>
145
182
  which will generate an expression index of the form:
@@ -154,8 +191,11 @@ are able to use the indexes rather require, in the worst case, full-table scans.
154
191
 
155
192
  Note also that this ties in well with Rails built-in support for case-insensitive searching:
156
193
 
194
+ ```ruby
157
195
  validates_uniqueness_of :name, :case_sensitive => false
196
+ ```
158
197
 
159
- === See Also
198
+ See Also
199
+ --------
160
200
 
161
201
  * Foreign Key Migrations (foreign_key_migrations)
data/README_DEV.md ADDED
@@ -0,0 +1,41 @@
1
+ # Information for developers
2
+
3
+ We need to run it against multiple versions of rails. There are
4
+ several tools already available to manage running against multiple versions of
5
+ Ruby (e.g. rvm), and there are even some multi-rails tools (e.g. multi-rails)
6
+ but we haven't found one that does exactly what we need here, so we've rolled
7
+ our own.
8
+
9
+ This method is the same used in rspec-rails
10
+
11
+ ## The short version
12
+
13
+ thor gemfile:use 3.0.6
14
+ rake
15
+
16
+ ## The long version
17
+
18
+ ### thor gemfile:use
19
+
20
+ The `thor rails:use` task accepts any released version of rails, or either the
21
+ 3-0-stable or master branches.
22
+
23
+ thor gemfile:use master
24
+ thor gemfile:use 3.1.0.rc1
25
+ thor gemfile:use 3-0-stable
26
+ thor gemfile:use 3.0.9
27
+ thor gemfile:use 3.0.8
28
+ thor gemfile:use 3.0.7
29
+
30
+ It then does several things:
31
+
32
+ * generates a .gemfile file with the version listed. This is used internally by
33
+ assorted rake tasks.
34
+ * installs the bundle using the appropriate file in the gemfiles directory
35
+ ** this includes binstubs, which are stored in ./gemfiles/bin
36
+ * symlinks the gemfiles/bin directory to ./bin (in the project root) to support
37
+ running bin/rspec from the project root
38
+
39
+ At any time, if you want to change rails versions, run `thor gemfile:use` with a
40
+ new version number. To play it safe, you probably want to also run `rake
41
+ clobber` to delete all the code generated by the previous rails version.
data/Rakefile CHANGED
@@ -1,4 +1,24 @@
1
- require 'bundler'
1
+ require 'pathname'
2
+ ENV["BUNDLE_GEMFILE"] ||= begin
3
+ version = if File.exist?("./.gemfile")
4
+ File.read("./.gemfile").chomp
5
+ else
6
+ "rails-3.0.7"
7
+ end
8
+ File.expand_path("../gemfiles/#{version}", __FILE__)
9
+ end
10
+ puts "Using gemfile: #{ENV["BUNDLE_GEMFILE"].gsub(Pathname.new(__FILE__).dirname.to_s,'').sub(/^\//,'')}"
11
+ require "bundler"
12
+ begin
13
+ Bundler.setup
14
+ rescue
15
+ if ENV["CI"]
16
+ sh "bundle install"
17
+ Bundler.setup
18
+ else
19
+ raise "You need to install a bundle first. Try 'thor gemfile:use 3.0.7'"
20
+ end
21
+ end
2
22
  Bundler::GemHelper.install_tasks
3
23
 
4
24
  require 'rspec/core/rake_task'
@@ -10,19 +30,28 @@ require 'rspec/core/rake_task'
10
30
  end
11
31
  end
12
32
 
33
+ task :default => [:create_databases, :spec]
34
+
13
35
  desc 'Run postgresql and mysql tests'
14
36
  task :spec do
15
37
  %w[postgresql mysql mysql2 sqlite3].each do |adapter|
38
+ puts "\n\e[1;33m[#{ENV["BUNDLE_GEMFILE"]}] #{adapter}\e[m\n"
16
39
  Rake::Task["#{adapter}:spec"].invoke
17
40
  end
18
41
  end
19
42
 
20
- task :default => :spec
43
+ desc 'Create databases'
44
+ task :create_databases do
45
+ %w[postgresql mysql].each do |adapter|
46
+ Rake::Task["#{adapter}:build_databases"].invoke
47
+ end
48
+ end
21
49
 
22
50
  namespace :postgresql do
23
51
  desc 'Build the PostgreSQL test databases'
24
52
  task :build_databases do
25
- %x( createdb -E UTF8 rh_core_unittest )
53
+ system "psql -c 'create database redhillonrails_core;' -U postgres >/dev/null"
54
+ abort "failed to create postgres database" unless $?.success?
26
55
  end
27
56
 
28
57
  desc 'Drop the PostgreSQL test databases'
@@ -34,26 +63,27 @@ namespace :postgresql do
34
63
  task :rebuild_databases => [:drop_databases, :build_databases]
35
64
  end
36
65
 
37
- task :build_postgresql_databases => 'postgresql:build_databases'
38
- task :drop_postgresql_databases => 'postgresql:drop_databases'
39
- task :rebuild_postgresql_databases => 'postgresql:rebuild_databases'
40
-
41
- MYSQL_DB_USER = 'rh_core'
42
66
  namespace :mysql do
43
67
  desc 'Build the MySQL test databases'
44
68
  task :build_databases do
45
- %x( echo "create DATABASE rh_core_unittest DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_unicode_ci " | mysql --user=#{MYSQL_DB_USER})
69
+ system "mysql -e 'create database redhillonrails_core default character set utf8 default collate utf8_unicode_ci;' >/dev/null"
70
+ abort "failed to create mysql database" unless $?.success?
46
71
  end
47
72
 
48
73
  desc 'Drop the MySQL test databases'
49
74
  task :drop_databases do
50
- %x( mysqladmin --user=#{MYSQL_DB_USER} -f drop rh_core_unittest )
75
+ %x( mysqladmin -f drop redhillonrails_core )
51
76
  end
52
77
 
53
78
  desc 'Rebuild the MySQL test databases'
54
79
  task :rebuild_databases => [:drop_databases, :build_databases]
55
80
  end
56
81
 
57
- task :build_mysql_databases => 'mysql:build_databases'
58
- task :drop_mysql_databases => 'mysql:drop_databases'
59
- task :rebuild_mysql_databases => 'mysql:rebuild_databases'
82
+ desc 'clobber generated files'
83
+ task :clobber do
84
+ rm_rf "pkg"
85
+ rm_rf "tmp"
86
+ rm "Gemfile.lock" if File.exist?("Gemfile.lock")
87
+ end
88
+
89
+ task :default => :spec
data/Thorfile ADDED
@@ -0,0 +1,45 @@
1
+ class Gemfile < Thor
2
+ desc "use VERSION", "installs the bundle using gemfiles/rails-VERSION"
3
+ def use(version)
4
+ with(version, %w[bundle install --binstubs])
5
+ unless version =~ /^\d\.\d\.\d/
6
+ "bundle update rails".tap do |m|
7
+ say m
8
+ system m
9
+ end
10
+ end
11
+ say `ln -s gemfiles/bin` unless File.exist?('bin')
12
+ `echo rails-#{version} > ./.gemfile`
13
+ end
14
+
15
+ desc "with VERSION COMMAND", "executes COMMAND with the gemfile for VERSION"
16
+ def with(version, *command)
17
+ "gemfiles/rails-#{version}".tap do |gemfile|
18
+ ENV["BUNDLE_GEMFILE"] = File.expand_path(gemfile)
19
+ say "BUNDLE_GEMFILE=#{gemfile}"
20
+ end
21
+ command.join(' ').tap do |m|
22
+ say m
23
+ system m
24
+ end
25
+ end
26
+
27
+ desc "which", "print out the configured gemfile"
28
+ def which
29
+ say `cat ./.gemfile`
30
+ end
31
+
32
+ desc "list", "list the available options for 'thor gemfile:use'"
33
+ def list
34
+ all = `ls gemfiles`.chomp.split.grep(/^rails/).reject {|i| i =~ /lock$/}
35
+
36
+ versions = all.grep(/^rails-\d\.\d/)
37
+ branches = all - versions
38
+
39
+ puts "releases:"
40
+ versions.sort.reverse.each {|i| puts i}
41
+ puts
42
+ puts "branches:"
43
+ branches.sort.reverse.each {|i| puts i}
44
+ end
45
+ end
@@ -0,0 +1,13 @@
1
+ source :rubygems
2
+
3
+ gem 'rake', '0.9.2'
4
+ gem 'rspec', '~> 2.6.0'
5
+
6
+ gem "rails", "3.0.7"
7
+
8
+ group :db do
9
+ gem "pg", ">= 0.9.0"
10
+ gem "mysql", ">= 2.8.1"
11
+ gem "mysql2", "~> 0.2.6"
12
+ gem "sqlite3", "~> 1.3.3"
13
+ end
@@ -0,0 +1,90 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ abstract (1.0.0)
5
+ actionmailer (3.0.7)
6
+ actionpack (= 3.0.7)
7
+ mail (~> 2.2.15)
8
+ actionpack (3.0.7)
9
+ activemodel (= 3.0.7)
10
+ activesupport (= 3.0.7)
11
+ builder (~> 2.1.2)
12
+ erubis (~> 2.6.6)
13
+ i18n (~> 0.5.0)
14
+ rack (~> 1.2.1)
15
+ rack-mount (~> 0.6.14)
16
+ rack-test (~> 0.5.7)
17
+ tzinfo (~> 0.3.23)
18
+ activemodel (3.0.7)
19
+ activesupport (= 3.0.7)
20
+ builder (~> 2.1.2)
21
+ i18n (~> 0.5.0)
22
+ activerecord (3.0.7)
23
+ activemodel (= 3.0.7)
24
+ activesupport (= 3.0.7)
25
+ arel (~> 2.0.2)
26
+ tzinfo (~> 0.3.23)
27
+ activeresource (3.0.7)
28
+ activemodel (= 3.0.7)
29
+ activesupport (= 3.0.7)
30
+ activesupport (3.0.7)
31
+ arel (2.0.10)
32
+ builder (2.1.2)
33
+ diff-lcs (1.1.2)
34
+ erubis (2.6.6)
35
+ abstract (>= 1.0.0)
36
+ i18n (0.5.0)
37
+ mail (2.2.19)
38
+ activesupport (>= 2.3.6)
39
+ i18n (>= 0.4.0)
40
+ mime-types (~> 1.16)
41
+ treetop (~> 1.4.8)
42
+ mime-types (1.16)
43
+ mysql (2.8.1)
44
+ mysql2 (0.2.10)
45
+ pg (0.11.0)
46
+ polyglot (0.3.1)
47
+ rack (1.2.3)
48
+ rack-mount (0.6.14)
49
+ rack (>= 1.0.0)
50
+ rack-test (0.5.7)
51
+ rack (>= 1.0)
52
+ rails (3.0.7)
53
+ actionmailer (= 3.0.7)
54
+ actionpack (= 3.0.7)
55
+ activerecord (= 3.0.7)
56
+ activeresource (= 3.0.7)
57
+ activesupport (= 3.0.7)
58
+ bundler (~> 1.0)
59
+ railties (= 3.0.7)
60
+ railties (3.0.7)
61
+ actionpack (= 3.0.7)
62
+ activesupport (= 3.0.7)
63
+ rake (>= 0.8.7)
64
+ thor (~> 0.14.4)
65
+ rake (0.9.2)
66
+ rspec (2.6.0)
67
+ rspec-core (~> 2.6.0)
68
+ rspec-expectations (~> 2.6.0)
69
+ rspec-mocks (~> 2.6.0)
70
+ rspec-core (2.6.4)
71
+ rspec-expectations (2.6.0)
72
+ diff-lcs (~> 1.1.2)
73
+ rspec-mocks (2.6.0)
74
+ sqlite3 (1.3.3)
75
+ thor (0.14.6)
76
+ treetop (1.4.9)
77
+ polyglot (>= 0.3.1)
78
+ tzinfo (0.3.28)
79
+
80
+ PLATFORMS
81
+ ruby
82
+
83
+ DEPENDENCIES
84
+ mysql (>= 2.8.1)
85
+ mysql2 (~> 0.2.6)
86
+ pg (>= 0.9.0)
87
+ rails (= 3.0.7)
88
+ rake (= 0.9.2)
89
+ rspec (~> 2.6.0)
90
+ sqlite3 (~> 1.3.3)