activerecord 4.0.4 → 4.1.16

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of activerecord might be problematic. Click here for more details.

Files changed (143) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +1632 -1797
  3. data/MIT-LICENSE +1 -1
  4. data/README.rdoc +2 -2
  5. data/examples/performance.rb +30 -18
  6. data/examples/simple.rb +4 -4
  7. data/lib/active_record/aggregations.rb +2 -1
  8. data/lib/active_record/association_relation.rb +4 -0
  9. data/lib/active_record/associations/alias_tracker.rb +49 -29
  10. data/lib/active_record/associations/association.rb +9 -17
  11. data/lib/active_record/associations/association_scope.rb +59 -49
  12. data/lib/active_record/associations/belongs_to_association.rb +34 -25
  13. data/lib/active_record/associations/belongs_to_polymorphic_association.rb +6 -1
  14. data/lib/active_record/associations/builder/association.rb +84 -54
  15. data/lib/active_record/associations/builder/belongs_to.rb +90 -58
  16. data/lib/active_record/associations/builder/collection_association.rb +47 -45
  17. data/lib/active_record/associations/builder/has_and_belongs_to_many.rb +119 -25
  18. data/lib/active_record/associations/builder/has_many.rb +3 -3
  19. data/lib/active_record/associations/builder/has_one.rb +5 -7
  20. data/lib/active_record/associations/builder/singular_association.rb +6 -7
  21. data/lib/active_record/associations/collection_association.rb +121 -111
  22. data/lib/active_record/associations/collection_proxy.rb +73 -18
  23. data/lib/active_record/associations/has_many_association.rb +14 -11
  24. data/lib/active_record/associations/has_many_through_association.rb +33 -6
  25. data/lib/active_record/associations/has_one_association.rb +1 -1
  26. data/lib/active_record/associations/join_dependency/join_association.rb +46 -104
  27. data/lib/active_record/associations/join_dependency/join_base.rb +6 -8
  28. data/lib/active_record/associations/join_dependency/join_part.rb +18 -37
  29. data/lib/active_record/associations/join_dependency.rb +208 -168
  30. data/lib/active_record/associations/preloader/association.rb +69 -27
  31. data/lib/active_record/associations/preloader/collection_association.rb +2 -2
  32. data/lib/active_record/associations/preloader/has_many_through.rb +1 -1
  33. data/lib/active_record/associations/preloader/singular_association.rb +3 -3
  34. data/lib/active_record/associations/preloader/through_association.rb +58 -26
  35. data/lib/active_record/associations/preloader.rb +63 -49
  36. data/lib/active_record/associations/singular_association.rb +6 -5
  37. data/lib/active_record/associations/through_association.rb +30 -9
  38. data/lib/active_record/associations.rb +116 -42
  39. data/lib/active_record/attribute_assignment.rb +6 -3
  40. data/lib/active_record/attribute_methods/before_type_cast.rb +2 -1
  41. data/lib/active_record/attribute_methods/dirty.rb +35 -26
  42. data/lib/active_record/attribute_methods/primary_key.rb +8 -1
  43. data/lib/active_record/attribute_methods/read.rb +56 -29
  44. data/lib/active_record/attribute_methods/serialization.rb +44 -12
  45. data/lib/active_record/attribute_methods/time_zone_conversion.rb +13 -1
  46. data/lib/active_record/attribute_methods/write.rb +59 -26
  47. data/lib/active_record/attribute_methods.rb +82 -43
  48. data/lib/active_record/autosave_association.rb +209 -194
  49. data/lib/active_record/base.rb +6 -2
  50. data/lib/active_record/callbacks.rb +2 -2
  51. data/lib/active_record/coders/json.rb +13 -0
  52. data/lib/active_record/connection_adapters/abstract/connection_pool.rb +5 -10
  53. data/lib/active_record/connection_adapters/abstract/database_statements.rb +14 -24
  54. data/lib/active_record/connection_adapters/abstract/query_cache.rb +13 -13
  55. data/lib/active_record/connection_adapters/abstract/quoting.rb +6 -3
  56. data/lib/active_record/connection_adapters/abstract/savepoints.rb +21 -0
  57. data/lib/active_record/connection_adapters/abstract/schema_creation.rb +90 -0
  58. data/lib/active_record/connection_adapters/abstract/schema_definitions.rb +9 -8
  59. data/lib/active_record/connection_adapters/abstract/schema_statements.rb +45 -70
  60. data/lib/active_record/connection_adapters/abstract/transaction.rb +1 -0
  61. data/lib/active_record/connection_adapters/abstract_adapter.rb +28 -96
  62. data/lib/active_record/connection_adapters/abstract_mysql_adapter.rb +74 -66
  63. data/lib/active_record/connection_adapters/column.rb +1 -35
  64. data/lib/active_record/connection_adapters/connection_specification.rb +231 -43
  65. data/lib/active_record/connection_adapters/mysql2_adapter.rb +10 -5
  66. data/lib/active_record/connection_adapters/mysql_adapter.rb +24 -17
  67. data/lib/active_record/connection_adapters/postgresql/array_parser.rb +22 -15
  68. data/lib/active_record/connection_adapters/postgresql/cast.rb +12 -4
  69. data/lib/active_record/connection_adapters/postgresql/database_statements.rb +18 -44
  70. data/lib/active_record/connection_adapters/postgresql/oid.rb +38 -14
  71. data/lib/active_record/connection_adapters/postgresql/quoting.rb +37 -12
  72. data/lib/active_record/connection_adapters/postgresql/schema_statements.rb +20 -11
  73. data/lib/active_record/connection_adapters/postgresql_adapter.rb +98 -52
  74. data/lib/active_record/connection_adapters/schema_cache.rb +8 -29
  75. data/lib/active_record/connection_adapters/sqlite3_adapter.rb +55 -60
  76. data/lib/active_record/connection_handling.rb +39 -5
  77. data/lib/active_record/core.rb +38 -54
  78. data/lib/active_record/counter_cache.rb +9 -10
  79. data/lib/active_record/dynamic_matchers.rb +6 -2
  80. data/lib/active_record/enum.rb +199 -0
  81. data/lib/active_record/errors.rb +22 -5
  82. data/lib/active_record/fixture_set/file.rb +2 -1
  83. data/lib/active_record/fixtures.rb +173 -76
  84. data/lib/active_record/gem_version.rb +15 -0
  85. data/lib/active_record/inheritance.rb +23 -9
  86. data/lib/active_record/integration.rb +54 -1
  87. data/lib/active_record/locking/optimistic.rb +7 -2
  88. data/lib/active_record/locking/pessimistic.rb +1 -1
  89. data/lib/active_record/log_subscriber.rb +6 -13
  90. data/lib/active_record/migration/command_recorder.rb +8 -2
  91. data/lib/active_record/migration.rb +91 -56
  92. data/lib/active_record/model_schema.rb +7 -14
  93. data/lib/active_record/nested_attributes.rb +25 -13
  94. data/lib/active_record/no_touching.rb +52 -0
  95. data/lib/active_record/null_relation.rb +26 -6
  96. data/lib/active_record/persistence.rb +23 -29
  97. data/lib/active_record/querying.rb +15 -12
  98. data/lib/active_record/railtie.rb +12 -61
  99. data/lib/active_record/railties/databases.rake +37 -56
  100. data/lib/active_record/readonly_attributes.rb +0 -6
  101. data/lib/active_record/reflection.rb +230 -79
  102. data/lib/active_record/relation/batches.rb +74 -24
  103. data/lib/active_record/relation/calculations.rb +52 -48
  104. data/lib/active_record/relation/delegation.rb +54 -39
  105. data/lib/active_record/relation/finder_methods.rb +210 -67
  106. data/lib/active_record/relation/merger.rb +15 -12
  107. data/lib/active_record/relation/predicate_builder/array_handler.rb +29 -0
  108. data/lib/active_record/relation/predicate_builder/relation_handler.rb +17 -0
  109. data/lib/active_record/relation/predicate_builder.rb +81 -40
  110. data/lib/active_record/relation/query_methods.rb +185 -108
  111. data/lib/active_record/relation/spawn_methods.rb +8 -5
  112. data/lib/active_record/relation.rb +79 -84
  113. data/lib/active_record/result.rb +45 -6
  114. data/lib/active_record/runtime_registry.rb +5 -0
  115. data/lib/active_record/sanitization.rb +4 -4
  116. data/lib/active_record/schema_dumper.rb +18 -6
  117. data/lib/active_record/schema_migration.rb +31 -18
  118. data/lib/active_record/scoping/default.rb +5 -18
  119. data/lib/active_record/scoping/named.rb +14 -29
  120. data/lib/active_record/scoping.rb +5 -0
  121. data/lib/active_record/store.rb +67 -18
  122. data/lib/active_record/tasks/database_tasks.rb +66 -26
  123. data/lib/active_record/tasks/mysql_database_tasks.rb +16 -10
  124. data/lib/active_record/tasks/postgresql_database_tasks.rb +1 -1
  125. data/lib/active_record/tasks/sqlite_database_tasks.rb +5 -1
  126. data/lib/active_record/timestamp.rb +6 -6
  127. data/lib/active_record/transactions.rb +10 -12
  128. data/lib/active_record/validations/presence.rb +1 -1
  129. data/lib/active_record/validations/uniqueness.rb +19 -9
  130. data/lib/active_record/version.rb +4 -7
  131. data/lib/active_record.rb +5 -7
  132. data/lib/rails/generators/active_record/migration/migration_generator.rb +4 -0
  133. data/lib/rails/generators/active_record/migration.rb +18 -0
  134. data/lib/rails/generators/active_record/model/model_generator.rb +4 -0
  135. data/lib/rails/generators/active_record.rb +2 -8
  136. metadata +18 -30
  137. data/lib/active_record/associations/has_and_belongs_to_many_association.rb +0 -65
  138. data/lib/active_record/associations/join_helper.rb +0 -45
  139. data/lib/active_record/associations/preloader/has_and_belongs_to_many.rb +0 -60
  140. data/lib/active_record/tasks/firebird_database_tasks.rb +0 -56
  141. data/lib/active_record/tasks/oracle_database_tasks.rb +0 -45
  142. data/lib/active_record/tasks/sqlserver_database_tasks.rb +0 -48
  143. data/lib/active_record/test_case.rb +0 -96
@@ -1,23 +1,17 @@
1
1
  require 'rails/generators/named_base'
2
- require 'rails/generators/migration'
3
2
  require 'rails/generators/active_model'
3
+ require 'rails/generators/active_record/migration'
4
4
  require 'active_record'
5
5
 
6
6
  module ActiveRecord
7
7
  module Generators # :nodoc:
8
8
  class Base < Rails::Generators::NamedBase # :nodoc:
9
- include Rails::Generators::Migration
9
+ include ActiveRecord::Generators::Migration
10
10
 
11
11
  # Set the current directory as base for the inherited generators.
12
12
  def self.base_root
13
13
  File.dirname(__FILE__)
14
14
  end
15
-
16
- # Implement the required interface for Rails::Generators::Migration.
17
- def self.next_migration_number(dirname)
18
- next_migration_number = current_migration_number(dirname) + 1
19
- ActiveRecord::Migration.next_migration_number(next_migration_number)
20
- end
21
15
  end
22
16
  end
23
17
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.4
4
+ version: 4.1.16
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Heinemeier Hansson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-14 00:00:00.000000000 Z
11
+ date: 2016-07-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -16,56 +16,42 @@ dependencies:
16
16
  requirements:
17
17
  - - '='
18
18
  - !ruby/object:Gem::Version
19
- version: 4.0.4
19
+ version: 4.1.16
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - '='
25
25
  - !ruby/object:Gem::Version
26
- version: 4.0.4
26
+ version: 4.1.16
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activemodel
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - '='
32
32
  - !ruby/object:Gem::Version
33
- version: 4.0.4
33
+ version: 4.1.16
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - '='
39
39
  - !ruby/object:Gem::Version
40
- version: 4.0.4
40
+ version: 4.1.16
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: arel
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 4.0.0
47
+ version: 5.0.0
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 4.0.0
55
- - !ruby/object:Gem::Dependency
56
- name: activerecord-deprecated_finders
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: 1.0.2
62
- type: :runtime
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: 1.0.2
54
+ version: 5.0.0
69
55
  description: Databases on Rails. Build a persistent domain model by mapping database
70
56
  tables to Ruby classes. Strong conventions for associations, validations, aggregations,
71
57
  migrations, and testing come baked-in.
@@ -98,7 +84,6 @@ files:
98
84
  - lib/active_record/associations/builder/singular_association.rb
99
85
  - lib/active_record/associations/collection_association.rb
100
86
  - lib/active_record/associations/collection_proxy.rb
101
- - lib/active_record/associations/has_and_belongs_to_many_association.rb
102
87
  - lib/active_record/associations/has_many_association.rb
103
88
  - lib/active_record/associations/has_many_through_association.rb
104
89
  - lib/active_record/associations/has_one_association.rb
@@ -107,12 +92,10 @@ files:
107
92
  - lib/active_record/associations/join_dependency/join_association.rb
108
93
  - lib/active_record/associations/join_dependency/join_base.rb
109
94
  - lib/active_record/associations/join_dependency/join_part.rb
110
- - lib/active_record/associations/join_helper.rb
111
95
  - lib/active_record/associations/preloader.rb
112
96
  - lib/active_record/associations/preloader/association.rb
113
97
  - lib/active_record/associations/preloader/belongs_to.rb
114
98
  - lib/active_record/associations/preloader/collection_association.rb
115
- - lib/active_record/associations/preloader/has_and_belongs_to_many.rb
116
99
  - lib/active_record/associations/preloader/has_many.rb
117
100
  - lib/active_record/associations/preloader/has_many_through.rb
118
101
  - lib/active_record/associations/preloader/has_one.rb
@@ -134,12 +117,15 @@ files:
134
117
  - lib/active_record/autosave_association.rb
135
118
  - lib/active_record/base.rb
136
119
  - lib/active_record/callbacks.rb
120
+ - lib/active_record/coders/json.rb
137
121
  - lib/active_record/coders/yaml_column.rb
138
122
  - lib/active_record/connection_adapters/abstract/connection_pool.rb
139
123
  - lib/active_record/connection_adapters/abstract/database_limits.rb
140
124
  - lib/active_record/connection_adapters/abstract/database_statements.rb
141
125
  - lib/active_record/connection_adapters/abstract/query_cache.rb
142
126
  - lib/active_record/connection_adapters/abstract/quoting.rb
127
+ - lib/active_record/connection_adapters/abstract/savepoints.rb
128
+ - lib/active_record/connection_adapters/abstract/schema_creation.rb
143
129
  - lib/active_record/connection_adapters/abstract/schema_definitions.rb
144
130
  - lib/active_record/connection_adapters/abstract/schema_dumper.rb
145
131
  - lib/active_record/connection_adapters/abstract/schema_statements.rb
@@ -165,12 +151,14 @@ files:
165
151
  - lib/active_record/core.rb
166
152
  - lib/active_record/counter_cache.rb
167
153
  - lib/active_record/dynamic_matchers.rb
154
+ - lib/active_record/enum.rb
168
155
  - lib/active_record/errors.rb
169
156
  - lib/active_record/explain.rb
170
157
  - lib/active_record/explain_registry.rb
171
158
  - lib/active_record/explain_subscriber.rb
172
159
  - lib/active_record/fixture_set/file.rb
173
160
  - lib/active_record/fixtures.rb
161
+ - lib/active_record/gem_version.rb
174
162
  - lib/active_record/inheritance.rb
175
163
  - lib/active_record/integration.rb
176
164
  - lib/active_record/locale/en.yml
@@ -182,6 +170,7 @@ files:
182
170
  - lib/active_record/migration/join_table.rb
183
171
  - lib/active_record/model_schema.rb
184
172
  - lib/active_record/nested_attributes.rb
173
+ - lib/active_record/no_touching.rb
185
174
  - lib/active_record/null_relation.rb
186
175
  - lib/active_record/persistence.rb
187
176
  - lib/active_record/query_cache.rb
@@ -200,6 +189,8 @@ files:
200
189
  - lib/active_record/relation/finder_methods.rb
201
190
  - lib/active_record/relation/merger.rb
202
191
  - lib/active_record/relation/predicate_builder.rb
192
+ - lib/active_record/relation/predicate_builder/array_handler.rb
193
+ - lib/active_record/relation/predicate_builder/relation_handler.rb
203
194
  - lib/active_record/relation/query_methods.rb
204
195
  - lib/active_record/relation/spawn_methods.rb
205
196
  - lib/active_record/result.rb
@@ -216,13 +207,9 @@ files:
216
207
  - lib/active_record/statement_cache.rb
217
208
  - lib/active_record/store.rb
218
209
  - lib/active_record/tasks/database_tasks.rb
219
- - lib/active_record/tasks/firebird_database_tasks.rb
220
210
  - lib/active_record/tasks/mysql_database_tasks.rb
221
- - lib/active_record/tasks/oracle_database_tasks.rb
222
211
  - lib/active_record/tasks/postgresql_database_tasks.rb
223
212
  - lib/active_record/tasks/sqlite_database_tasks.rb
224
- - lib/active_record/tasks/sqlserver_database_tasks.rb
225
- - lib/active_record/test_case.rb
226
213
  - lib/active_record/timestamp.rb
227
214
  - lib/active_record/transactions.rb
228
215
  - lib/active_record/translation.rb
@@ -232,6 +219,7 @@ files:
232
219
  - lib/active_record/validations/uniqueness.rb
233
220
  - lib/active_record/version.rb
234
221
  - lib/rails/generators/active_record.rb
222
+ - lib/rails/generators/active_record/migration.rb
235
223
  - lib/rails/generators/active_record/migration/migration_generator.rb
236
224
  - lib/rails/generators/active_record/migration/templates/create_table_migration.rb
237
225
  - lib/rails/generators/active_record/migration/templates/migration.rb
@@ -260,7 +248,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
260
248
  version: '0'
261
249
  requirements: []
262
250
  rubyforge_project:
263
- rubygems_version: 2.2.2
251
+ rubygems_version: 2.4.5.1
264
252
  signing_key:
265
253
  specification_version: 4
266
254
  summary: Object-relational mapper framework (part of Rails).
@@ -1,65 +0,0 @@
1
- module ActiveRecord
2
- # = Active Record Has And Belongs To Many Association
3
- module Associations
4
- class HasAndBelongsToManyAssociation < CollectionAssociation #:nodoc:
5
- attr_reader :join_table
6
-
7
- def initialize(owner, reflection)
8
- @join_table = Arel::Table.new(reflection.join_table)
9
- super
10
- end
11
-
12
- def insert_record(record, validate = true, raise = false)
13
- if record.new_record?
14
- if raise
15
- record.save!(:validate => validate)
16
- else
17
- return unless record.save(:validate => validate)
18
- end
19
- end
20
-
21
- if options[:insert_sql]
22
- owner.connection.insert(interpolate(options[:insert_sql], record))
23
- else
24
- stmt = join_table.compile_insert(
25
- join_table[reflection.foreign_key] => owner.id,
26
- join_table[reflection.association_foreign_key] => record.id
27
- )
28
-
29
- owner.class.connection.insert stmt
30
- end
31
-
32
- record
33
- end
34
-
35
- private
36
-
37
- def count_records
38
- load_target.size
39
- end
40
-
41
- def delete_records(records, method)
42
- if sql = options[:delete_sql]
43
- records = load_target if records == :all
44
- records.each { |record| owner.class.connection.delete(interpolate(sql, record)) }
45
- else
46
- relation = join_table
47
- condition = relation[reflection.foreign_key].eq(owner.id)
48
-
49
- unless records == :all
50
- condition = condition.and(
51
- relation[reflection.association_foreign_key]
52
- .in(records.map { |x| x.id }.compact)
53
- )
54
- end
55
-
56
- owner.class.connection.delete(relation.where(condition).compile_delete)
57
- end
58
- end
59
-
60
- def invertible_for?(record)
61
- false
62
- end
63
- end
64
- end
65
- end
@@ -1,45 +0,0 @@
1
- module ActiveRecord
2
- module Associations
3
- # Helper class module which gets mixed into JoinDependency::JoinAssociation and AssociationScope
4
- module JoinHelper #:nodoc:
5
-
6
- def join_type
7
- Arel::InnerJoin
8
- end
9
-
10
- private
11
-
12
- def construct_tables
13
- tables = []
14
- chain.each do |reflection|
15
- tables << alias_tracker.aliased_table_for(
16
- table_name_for(reflection),
17
- table_alias_for(reflection, reflection != self.reflection)
18
- )
19
-
20
- if reflection.source_macro == :has_and_belongs_to_many
21
- tables << alias_tracker.aliased_table_for(
22
- (reflection.source_reflection || reflection).join_table,
23
- table_alias_for(reflection, true)
24
- )
25
- end
26
- end
27
- tables
28
- end
29
-
30
- def table_name_for(reflection)
31
- reflection.table_name
32
- end
33
-
34
- def table_alias_for(reflection, join = false)
35
- name = "#{reflection.plural_name}_#{alias_suffix}"
36
- name << "_join" if join
37
- name
38
- end
39
-
40
- def join(table, constraint)
41
- table.create_join(table, table.create_on(constraint), join_type)
42
- end
43
- end
44
- end
45
- end
@@ -1,60 +0,0 @@
1
- module ActiveRecord
2
- module Associations
3
- class Preloader
4
- class HasAndBelongsToMany < CollectionAssociation #:nodoc:
5
- attr_reader :join_table
6
-
7
- def initialize(klass, records, reflection, preload_options)
8
- super
9
- @join_table = Arel::Table.new(reflection.join_table).alias('t0')
10
- end
11
-
12
- # Unlike the other associations, we want to get a raw array of rows so that we can
13
- # access the aliased column on the join table
14
- def records_for(ids)
15
- scope = super
16
- klass.connection.select_all(scope.arel, 'SQL', scope.bind_values)
17
- end
18
-
19
- def owner_key_name
20
- reflection.active_record_primary_key
21
- end
22
-
23
- def association_key_name
24
- 'ar_association_key_name'
25
- end
26
-
27
- def association_key
28
- join_table[reflection.foreign_key]
29
- end
30
-
31
- private
32
-
33
- # Once we have used the join table column (in super), we manually instantiate the
34
- # actual records, ensuring that we don't create more than one instances of the same
35
- # record
36
- def associated_records_by_owner
37
- records = {}
38
- super.each_value do |rows|
39
- rows.map! { |row| records[row[klass.primary_key]] ||= klass.instantiate(row) }
40
- end
41
- end
42
-
43
- def build_scope
44
- super.joins(join).select(join_select)
45
- end
46
-
47
- def join_select
48
- association_key.as(Arel.sql(association_key_name))
49
- end
50
-
51
- def join
52
- condition = table[reflection.association_primary_key].eq(
53
- join_table[reflection.association_foreign_key])
54
-
55
- table.create_join(join_table, table.create_on(condition))
56
- end
57
- end
58
- end
59
- end
60
- end
@@ -1,56 +0,0 @@
1
- module ActiveRecord
2
- module Tasks # :nodoc:
3
- class FirebirdDatabaseTasks # :nodoc:
4
- delegate :connection, :establish_connection, to: ActiveRecord::Base
5
-
6
- def initialize(configuration)
7
- ActiveSupport::Deprecation.warn "This database tasks were deprecated, because this tasks should be served by the 3rd party adapter."
8
- @configuration = configuration
9
- end
10
-
11
- def create
12
- $stderr.puts 'sorry, your database adapter is not supported yet, feel free to submit a patch'
13
- end
14
-
15
- def drop
16
- $stderr.puts 'sorry, your database adapter is not supported yet, feel free to submit a patch'
17
- end
18
-
19
- def purge
20
- establish_connection(:test)
21
- connection.recreate_database!
22
- end
23
-
24
- def charset
25
- $stderr.puts 'sorry, your database adapter is not supported yet, feel free to submit a patch'
26
- end
27
-
28
- def structure_dump(filename)
29
- set_firebird_env(configuration)
30
- db_string = firebird_db_string(configuration)
31
- Kernel.system "isql -a #{db_string} > #{filename}"
32
- end
33
-
34
- def structure_load(filename)
35
- set_firebird_env(configuration)
36
- db_string = firebird_db_string(configuration)
37
- Kernel.system "isql -i #{filename} #{db_string}"
38
- end
39
-
40
- private
41
-
42
- def set_firebird_env(config)
43
- ENV['ISC_USER'] = config['username'].to_s if config['username']
44
- ENV['ISC_PASSWORD'] = config['password'].to_s if config['password']
45
- end
46
-
47
- def firebird_db_string(config)
48
- FireRuby::Database.db_string_for(config.symbolize_keys)
49
- end
50
-
51
- def configuration
52
- @configuration
53
- end
54
- end
55
- end
56
- end
@@ -1,45 +0,0 @@
1
- module ActiveRecord
2
- module Tasks # :nodoc:
3
- class OracleDatabaseTasks # :nodoc:
4
- delegate :connection, :establish_connection, to: ActiveRecord::Base
5
-
6
- def initialize(configuration)
7
- ActiveSupport::Deprecation.warn "This database tasks were deprecated, because this tasks should be served by the 3rd party adapter."
8
- @configuration = configuration
9
- end
10
-
11
- def create
12
- $stderr.puts 'sorry, your database adapter is not supported yet, feel free to submit a patch'
13
- end
14
-
15
- def drop
16
- $stderr.puts 'sorry, your database adapter is not supported yet, feel free to submit a patch'
17
- end
18
-
19
- def purge
20
- establish_connection(:test)
21
- connection.structure_drop.split(";\n\n").each { |ddl| connection.execute(ddl) }
22
- end
23
-
24
- def charset
25
- $stderr.puts 'sorry, your database adapter is not supported yet, feel free to submit a patch'
26
- end
27
-
28
- def structure_dump(filename)
29
- establish_connection(configuration)
30
- File.open(filename, "w:utf-8") { |f| f << connection.structure_dump }
31
- end
32
-
33
- def structure_load(filename)
34
- establish_connection(configuration)
35
- IO.read(filename).split(";\n\n").each { |ddl| connection.execute(ddl) }
36
- end
37
-
38
- private
39
-
40
- def configuration
41
- @configuration
42
- end
43
- end
44
- end
45
- end
@@ -1,48 +0,0 @@
1
- require 'shellwords'
2
-
3
- module ActiveRecord
4
- module Tasks # :nodoc:
5
- class SqlserverDatabaseTasks # :nodoc:
6
- delegate :connection, :establish_connection, to: ActiveRecord::Base
7
-
8
- def initialize(configuration)
9
- ActiveSupport::Deprecation.warn "This database tasks were deprecated, because this tasks should be served by the 3rd party adapter."
10
- @configuration = configuration
11
- end
12
-
13
- def create
14
- $stderr.puts 'sorry, your database adapter is not supported yet, feel free to submit a patch'
15
- end
16
-
17
- def drop
18
- $stderr.puts 'sorry, your database adapter is not supported yet, feel free to submit a patch'
19
- end
20
-
21
- def purge
22
- test = configuration.deep_dup
23
- test_database = test['database']
24
- test['database'] = 'master'
25
- establish_connection(test)
26
- connection.recreate_database!(test_database)
27
- end
28
-
29
- def charset
30
- $stderr.puts 'sorry, your database adapter is not supported yet, feel free to submit a patch'
31
- end
32
-
33
- def structure_dump(filename)
34
- Kernel.system("smoscript -s #{configuration['host']} -d #{configuration['database']} -u #{configuration['username']} -p #{configuration['password']} -f #{filename} -A -U")
35
- end
36
-
37
- def structure_load(filename)
38
- Kernel.system("sqlcmd -S #{configuration['host']} -d #{configuration['database']} -U #{configuration['username']} -P #{configuration['password']} -i #{filename}")
39
- end
40
-
41
- private
42
-
43
- def configuration
44
- @configuration
45
- end
46
- end
47
- end
48
- end
@@ -1,96 +0,0 @@
1
- require 'active_support/test_case'
2
-
3
- ActiveSupport::Deprecation.warn('ActiveRecord::TestCase is deprecated, please use ActiveSupport::TestCase')
4
- module ActiveRecord
5
- # = Active Record Test Case
6
- #
7
- # Defines some test assertions to test against SQL queries.
8
- class TestCase < ActiveSupport::TestCase #:nodoc:
9
- def teardown
10
- SQLCounter.clear_log
11
- end
12
-
13
- def assert_date_from_db(expected, actual, message = nil)
14
- # SybaseAdapter doesn't have a separate column type just for dates,
15
- # so the time is in the string and incorrectly formatted
16
- if current_adapter?(:SybaseAdapter)
17
- assert_equal expected.to_s, actual.to_date.to_s, message
18
- else
19
- assert_equal expected.to_s, actual.to_s, message
20
- end
21
- end
22
-
23
- def assert_sql(*patterns_to_match)
24
- SQLCounter.clear_log
25
- yield
26
- SQLCounter.log_all
27
- ensure
28
- failed_patterns = []
29
- patterns_to_match.each do |pattern|
30
- failed_patterns << pattern unless SQLCounter.log_all.any?{ |sql| pattern === sql }
31
- end
32
- assert failed_patterns.empty?, "Query pattern(s) #{failed_patterns.map{ |p| p.inspect }.join(', ')} not found.#{SQLCounter.log.size == 0 ? '' : "\nQueries:\n#{SQLCounter.log.join("\n")}"}"
33
- end
34
-
35
- def assert_queries(num = 1, options = {})
36
- ignore_none = options.fetch(:ignore_none) { num == :any }
37
- SQLCounter.clear_log
38
- yield
39
- ensure
40
- the_log = ignore_none ? SQLCounter.log_all : SQLCounter.log
41
- if num == :any
42
- assert_operator the_log.size, :>=, 1, "1 or more queries expected, but none were executed."
43
- else
44
- mesg = "#{the_log.size} instead of #{num} queries were executed.#{the_log.size == 0 ? '' : "\nQueries:\n#{the_log.join("\n")}"}"
45
- assert_equal num, the_log.size, mesg
46
- end
47
- end
48
-
49
- def assert_no_queries(&block)
50
- assert_queries(0, :ignore_none => true, &block)
51
- end
52
-
53
- end
54
-
55
- class SQLCounter
56
- class << self
57
- attr_accessor :ignored_sql, :log, :log_all
58
- def clear_log; self.log = []; self.log_all = []; end
59
- end
60
-
61
- self.clear_log
62
-
63
- self.ignored_sql = [/^PRAGMA/, /^SELECT currval/, /^SELECT CAST/, /^SELECT @@IDENTITY/, /^SELECT @@ROWCOUNT/, /^SAVEPOINT/, /^ROLLBACK TO SAVEPOINT/, /^RELEASE SAVEPOINT/, /^SHOW max_identifier_length/, /^BEGIN/, /^COMMIT/]
64
-
65
- # FIXME: this needs to be refactored so specific database can add their own
66
- # ignored SQL, or better yet, use a different notification for the queries
67
- # instead examining the SQL content.
68
- oracle_ignored = [/^select .*nextval/i, /^SAVEPOINT/, /^ROLLBACK TO/, /^\s*select .* from all_triggers/im]
69
- mysql_ignored = [/^SHOW TABLES/i, /^SHOW FULL FIELDS/]
70
- postgresql_ignored = [/^\s*select\b.*\bfrom\b.*pg_namespace\b/im, /^\s*select\b.*\battname\b.*\bfrom\b.*\bpg_attribute\b/im, /^SHOW search_path/i]
71
- sqlite3_ignored = [/^\s*SELECT name\b.*\bFROM sqlite_master/im]
72
-
73
- [oracle_ignored, mysql_ignored, postgresql_ignored, sqlite3_ignored].each do |db_ignored_sql|
74
- ignored_sql.concat db_ignored_sql
75
- end
76
-
77
- attr_reader :ignore
78
-
79
- def initialize(ignore = Regexp.union(self.class.ignored_sql))
80
- @ignore = ignore
81
- end
82
-
83
- def call(name, start, finish, message_id, values)
84
- sql = values[:sql]
85
-
86
- # FIXME: this seems bad. we should probably have a better way to indicate
87
- # the query was cached
88
- return if 'CACHE' == values[:name]
89
-
90
- self.class.log_all << sql
91
- self.class.log << sql unless ignore =~ sql
92
- end
93
- end
94
-
95
- ActiveSupport::Notifications.subscribe('sql.active_record', SQLCounter.new)
96
- end