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
@@ -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.8"
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.8)
6
+ actionpack (= 3.0.8)
7
+ mail (~> 2.2.19)
8
+ actionpack (3.0.8)
9
+ activemodel (= 3.0.8)
10
+ activesupport (= 3.0.8)
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.8)
19
+ activesupport (= 3.0.8)
20
+ builder (~> 2.1.2)
21
+ i18n (~> 0.5.0)
22
+ activerecord (3.0.8)
23
+ activemodel (= 3.0.8)
24
+ activesupport (= 3.0.8)
25
+ arel (~> 2.0.10)
26
+ tzinfo (~> 0.3.23)
27
+ activeresource (3.0.8)
28
+ activemodel (= 3.0.8)
29
+ activesupport (= 3.0.8)
30
+ activesupport (3.0.8)
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.8)
53
+ actionmailer (= 3.0.8)
54
+ actionpack (= 3.0.8)
55
+ activerecord (= 3.0.8)
56
+ activeresource (= 3.0.8)
57
+ activesupport (= 3.0.8)
58
+ bundler (~> 1.0)
59
+ railties (= 3.0.8)
60
+ railties (3.0.8)
61
+ actionpack (= 3.0.8)
62
+ activesupport (= 3.0.8)
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.8)
88
+ rake (= 0.9.2)
89
+ rspec (~> 2.6.0)
90
+ sqlite3 (~> 1.3.3)
@@ -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.9"
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,92 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ abstract (1.0.0)
5
+ actionmailer (3.0.9)
6
+ actionpack (= 3.0.9)
7
+ mail (~> 2.2.19)
8
+ actionpack (3.0.9)
9
+ activemodel (= 3.0.9)
10
+ activesupport (= 3.0.9)
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.9)
19
+ activesupport (= 3.0.9)
20
+ builder (~> 2.1.2)
21
+ i18n (~> 0.5.0)
22
+ activerecord (3.0.9)
23
+ activemodel (= 3.0.9)
24
+ activesupport (= 3.0.9)
25
+ arel (~> 2.0.10)
26
+ tzinfo (~> 0.3.23)
27
+ activeresource (3.0.9)
28
+ activemodel (= 3.0.9)
29
+ activesupport (= 3.0.9)
30
+ activesupport (3.0.9)
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.9)
53
+ actionmailer (= 3.0.9)
54
+ actionpack (= 3.0.9)
55
+ activerecord (= 3.0.9)
56
+ activeresource (= 3.0.9)
57
+ activesupport (= 3.0.9)
58
+ bundler (~> 1.0)
59
+ railties (= 3.0.9)
60
+ railties (3.0.9)
61
+ actionpack (= 3.0.9)
62
+ activesupport (= 3.0.9)
63
+ rake (>= 0.8.7)
64
+ rdoc (~> 3.4)
65
+ thor (~> 0.14.4)
66
+ rake (0.9.2)
67
+ rdoc (3.6.1)
68
+ rspec (2.6.0)
69
+ rspec-core (~> 2.6.0)
70
+ rspec-expectations (~> 2.6.0)
71
+ rspec-mocks (~> 2.6.0)
72
+ rspec-core (2.6.4)
73
+ rspec-expectations (2.6.0)
74
+ diff-lcs (~> 1.1.2)
75
+ rspec-mocks (2.6.0)
76
+ sqlite3 (1.3.3)
77
+ thor (0.14.6)
78
+ treetop (1.4.9)
79
+ polyglot (>= 0.3.1)
80
+ tzinfo (0.3.28)
81
+
82
+ PLATFORMS
83
+ ruby
84
+
85
+ DEPENDENCIES
86
+ mysql (>= 2.8.1)
87
+ mysql2 (~> 0.2.6)
88
+ pg (>= 0.9.0)
89
+ rails (= 3.0.9)
90
+ rake (= 0.9.2)
91
+ rspec (~> 2.6.0)
92
+ sqlite3 (~> 1.3.3)
@@ -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.1.0.rc5"
7
+
8
+ group :db do
9
+ gem "pg", ">= 0.11.0"
10
+ gem "mysql", ">= 2.8.1"
11
+ gem "mysql2", ">= 0.3.0"
12
+ gem "sqlite3", "~> 1.3.3"
13
+ end
@@ -0,0 +1,106 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ actionmailer (3.1.0.rc5)
5
+ actionpack (= 3.1.0.rc5)
6
+ mail (~> 2.3.0)
7
+ actionpack (3.1.0.rc5)
8
+ activemodel (= 3.1.0.rc5)
9
+ activesupport (= 3.1.0.rc5)
10
+ builder (~> 3.0.0)
11
+ erubis (~> 2.7.0)
12
+ i18n (~> 0.6)
13
+ rack (~> 1.3.1)
14
+ rack-cache (~> 1.0.2)
15
+ rack-mount (~> 0.8.1)
16
+ rack-test (~> 0.6.0)
17
+ sprockets (~> 2.0.0.beta.12)
18
+ activemodel (3.1.0.rc5)
19
+ activesupport (= 3.1.0.rc5)
20
+ bcrypt-ruby (~> 2.1.4)
21
+ builder (~> 3.0.0)
22
+ i18n (~> 0.6)
23
+ activerecord (3.1.0.rc5)
24
+ activemodel (= 3.1.0.rc5)
25
+ activesupport (= 3.1.0.rc5)
26
+ arel (~> 2.1.4)
27
+ tzinfo (~> 0.3.29)
28
+ activeresource (3.1.0.rc5)
29
+ activemodel (= 3.1.0.rc5)
30
+ activesupport (= 3.1.0.rc5)
31
+ activesupport (3.1.0.rc5)
32
+ multi_json (~> 1.0)
33
+ arel (2.1.4)
34
+ bcrypt-ruby (2.1.4)
35
+ builder (3.0.0)
36
+ diff-lcs (1.1.2)
37
+ erubis (2.7.0)
38
+ hike (1.2.0)
39
+ i18n (0.6.0)
40
+ mail (2.3.0)
41
+ i18n (>= 0.4.0)
42
+ mime-types (~> 1.16)
43
+ treetop (~> 1.4.8)
44
+ mime-types (1.16)
45
+ multi_json (1.0.3)
46
+ mysql (2.8.1)
47
+ mysql2 (0.3.6)
48
+ pg (0.11.0)
49
+ polyglot (0.3.2)
50
+ rack (1.3.2)
51
+ rack-cache (1.0.2)
52
+ rack (>= 0.4)
53
+ rack-mount (0.8.1)
54
+ rack (>= 1.0.0)
55
+ rack-ssl (1.3.2)
56
+ rack
57
+ rack-test (0.6.1)
58
+ rack (>= 1.0)
59
+ rails (3.1.0.rc5)
60
+ actionmailer (= 3.1.0.rc5)
61
+ actionpack (= 3.1.0.rc5)
62
+ activerecord (= 3.1.0.rc5)
63
+ activeresource (= 3.1.0.rc5)
64
+ activesupport (= 3.1.0.rc5)
65
+ bundler (~> 1.0)
66
+ railties (= 3.1.0.rc5)
67
+ railties (3.1.0.rc5)
68
+ actionpack (= 3.1.0.rc5)
69
+ activesupport (= 3.1.0.rc5)
70
+ rack-ssl (~> 1.3.2)
71
+ rake (>= 0.8.7)
72
+ rdoc (~> 3.4)
73
+ thor (~> 0.14.6)
74
+ rake (0.9.2)
75
+ rdoc (3.8)
76
+ rspec (2.6.0)
77
+ rspec-core (~> 2.6.0)
78
+ rspec-expectations (~> 2.6.0)
79
+ rspec-mocks (~> 2.6.0)
80
+ rspec-core (2.6.4)
81
+ rspec-expectations (2.6.0)
82
+ diff-lcs (~> 1.1.2)
83
+ rspec-mocks (2.6.0)
84
+ sprockets (2.0.0.beta.12)
85
+ hike (~> 1.2)
86
+ rack (~> 1.0)
87
+ tilt (~> 1.1, != 1.3.0)
88
+ sqlite3 (1.3.4)
89
+ thor (0.14.6)
90
+ tilt (1.3.2)
91
+ treetop (1.4.10)
92
+ polyglot
93
+ polyglot (>= 0.3.1)
94
+ tzinfo (0.3.29)
95
+
96
+ PLATFORMS
97
+ ruby
98
+
99
+ DEPENDENCIES
100
+ mysql (>= 2.8.1)
101
+ mysql2 (>= 0.3.0)
102
+ pg (>= 0.11.0)
103
+ rails (= 3.1.0.rc5)
104
+ rake (= 0.9.2)
105
+ rspec (~> 2.6.0)
106
+ sqlite3 (~> 1.3.3)
@@ -9,6 +9,12 @@ module RedhillonrailsCore
9
9
  module ActiveRecord
10
10
  extend ActiveSupport::Autoload
11
11
 
12
+ module Migration
13
+ extend ActiveSupport::Autoload
14
+
15
+ autoload :CommandRecorder
16
+ end
17
+
12
18
  autoload :Base
13
19
  autoload :Schema
14
20
  autoload :SchemaDumper
@@ -42,6 +48,12 @@ module RedhillonrailsCore
42
48
  ::ActiveRecord::ConnectionAdapters::AbstractAdapter.send(:include, RedhillonrailsCore::ActiveRecord::ConnectionAdapters::AbstractAdapter)
43
49
  ::ActiveRecord::ConnectionAdapters::SchemaStatements.send(:include, RedhillonrailsCore::ActiveRecord::ConnectionAdapters::SchemaStatements)
44
50
 
51
+ if defined?(::ActiveRecord::Migration::CommandRecorder)
52
+ ::ActiveRecord::Migration::CommandRecorder.class_eval do
53
+ include RedhillonrailsCore::ActiveRecord::Migration::CommandRecorder
54
+ end
55
+ end
56
+
45
57
  self.loaded_into_rails_core = true
46
58
  end
47
59
  end
@@ -26,7 +26,7 @@ module RedhillonrailsCore::ActiveRecord
26
26
  end
27
27
 
28
28
  def pluralized_table_name(table_name)
29
- ActiveRecord::Base.pluralize_table_names ? table_name.to_s.pluralize : table_name
29
+ ::ActiveRecord::Base.pluralize_table_names ? table_name.to_s.pluralize : table_name
30
30
  end
31
31
 
32
32
  def indexes
@@ -18,8 +18,15 @@ module RedhillonrailsCore::ActiveRecord::ConnectionAdapters
18
18
  end
19
19
 
20
20
  def to_sql
21
- sql = name ? "CONSTRAINT #{name} " : ""
22
- sql << "FOREIGN KEY (#{Array(quoted_column_names).join(", ")}) REFERENCES #{quoted_references_table_name} (#{Array(quoted_references_column_names).join(", ")})"
21
+ if name
22
+ sql = "CONSTRAINT #{name} "
23
+ elsif table_name.present?
24
+ sql = "CONSTRAINT #{table_name}_#{Array(column_names).join('_')}_fkey "
25
+ else
26
+ sql = ""
27
+ end
28
+
29
+ sql << "FOREIGN KEY (#{quoted_column_names.join(", ")}) REFERENCES #{quoted_references_table_name} (#{quoted_references_column_names.join(", ")})"
23
30
  sql << " ON UPDATE #{ACTIONS[on_update]}" if on_update
24
31
  sql << " ON DELETE #{ACTIONS[on_delete]}" if on_delete
25
32
  sql << " DEFERRABLE" if deferrable
@@ -36,10 +43,10 @@ module RedhillonrailsCore::ActiveRecord::ConnectionAdapters
36
43
  Array(references_column_names).collect { |name| ::ActiveRecord::Base.connection.quote_column_name(name) }
37
44
  end
38
45
 
39
- # def quoted_table_name
40
- # ::ActiveRecord::Base.connection.quote_table_name(table_name)
41
- # end
42
- #
46
+ def quoted_table_name
47
+ ::ActiveRecord::Base.connection.quote_table_name(table_name)
48
+ end
49
+
43
50
  def quoted_references_table_name
44
51
  ::ActiveRecord::Base.connection.quote_table_name(references_table_name)
45
52
  end
@@ -1,5 +1,8 @@
1
1
  module RedhillonrailsCore::ActiveRecord::ConnectionAdapters
2
2
  module IndexDefinition
3
+ # Using accessors in postgresql
4
+ attr_accessor :conditions, :expression, :kind
5
+
3
6
  def case_sensitive?
4
7
  @case_sensitive.nil? ? true : @case_sensitive
5
8
  end
@@ -26,10 +26,14 @@ module RedhillonrailsCore::ActiveRecord::ConnectionAdapters
26
26
  adapter_module = RedhillonrailsCore::ActiveRecord::ConnectionAdapters.const_get(adapter)
27
27
  self.class.send(:include, adapter_module) unless self.class.include?(adapter_module)
28
28
  end
29
- # Needed from mysql2 >= 0.2.7
29
+ # Mysql2 gem adds own Mysql2IndexDefinition in versions from 0.2.7 to 0.2.11.
30
+ # We must include RedhillonrailsCore IndexDefinition to support case sensitivness.
31
+ # 0.3 line of mysql2 removes it again so hopefully we'll remove that obsure piece of code too.
30
32
  if adapter_name =~ /^Mysql2/i && defined?(ActiveRecord::ConnectionAdapters::Mysql2IndexDefinition)
31
33
  index_definition_module = RedhillonrailsCore::ActiveRecord::ConnectionAdapters::IndexDefinition
32
- ActiveRecord::ConnectionAdapters::Mysql2IndexDefinition.send(:include, index_definition_module) unless ActiveRecord::ConnectionAdapters::Mysql2IndexDefinition.include?(index_definition_module)
34
+ unless ActiveRecord::ConnectionAdapters::Mysql2IndexDefinition.include?(index_definition_module)
35
+ ActiveRecord::ConnectionAdapters::Mysql2IndexDefinition.send(:include, index_definition_module)
36
+ end
33
37
  end
34
38
  end
35
39
 
@@ -57,12 +61,12 @@ module RedhillonrailsCore::ActiveRecord::ConnectionAdapters
57
61
  end
58
62
 
59
63
  def add_foreign_key(table_name, column_names, references_table_name, references_column_names, options = {})
60
- foreign_key = ForeignKeyDefinition.new(options[:name], table_name, column_names, ActiveRecord::Migrator.proper_table_name(references_table_name), references_column_names, options[:on_update], options[:on_delete], options[:deferrable])
61
- execute "ALTER TABLE #{table_name} ADD #{foreign_key}"
64
+ foreign_key = ForeignKeyDefinition.new(options[:name], table_name, column_names, ::ActiveRecord::Migrator.proper_table_name(references_table_name), references_column_names, options[:on_update], options[:on_delete], options[:deferrable])
65
+ execute "ALTER TABLE #{quote_table_name(table_name)} ADD #{foreign_key}"
62
66
  end
63
67
 
64
- def remove_foreign_key(table_name, foreign_key_name)
65
- execute "ALTER TABLE #{table_name} DROP CONSTRAINT #{foreign_key_name}"
68
+ def remove_foreign_key(table_name, foreign_key_name, options = {})
69
+ execute "ALTER TABLE #{quote_table_name(table_name)} DROP CONSTRAINT #{foreign_key_name}"
66
70
  end
67
71
 
68
72
  def drop_table_with_redhillonrails_core(name, options = {})