composite_primary_keys 9.0.4 → 9.0.5
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.
- checksums.yaml +4 -4
- data/History.rdoc +20 -0
- data/Rakefile +37 -34
- data/lib/composite_primary_keys.rb +5 -10
- data/lib/composite_primary_keys/arel/in.rb +6 -6
- data/lib/composite_primary_keys/arel/sqlserver.rb +36 -0
- data/lib/composite_primary_keys/associations/association_scope.rb +51 -29
- data/lib/composite_primary_keys/attribute_methods/read.rb +3 -1
- data/lib/composite_primary_keys/connection_adapters/abstract_mysql_adapter.rb +22 -0
- data/lib/composite_primary_keys/relation.rb +30 -0
- data/lib/composite_primary_keys/relation/query_methods.rb +25 -36
- data/lib/composite_primary_keys/sanitization.rb +31 -47
- data/lib/composite_primary_keys/version.rb +1 -1
- data/tasks/databases/mysql.rake +40 -42
- data/tasks/databases/oracle.rake +29 -15
- data/tasks/databases/postgresql.rake +38 -47
- data/tasks/databases/sqlite.rake +25 -0
- data/tasks/databases/sqlserver.rake +32 -16
- data/test/abstract_unit.rb +12 -11
- data/test/connections/connection_spec.rb +27 -18
- data/test/connections/databases.ci.yml +5 -4
- data/test/connections/databases.example.yml +19 -4
- data/test/connections/databases.yml +25 -4
- data/test/fixtures/article.rb +6 -5
- data/test/fixtures/db_definitions/mysql.sql +16 -7
- data/test/fixtures/db_definitions/oracle.drop.sql +2 -0
- data/test/fixtures/db_definitions/oracle.sql +25 -15
- data/test/fixtures/db_definitions/postgresql.sql +11 -2
- data/test/fixtures/db_definitions/sqlite.sql +8 -0
- data/test/fixtures/db_definitions/sqlserver.sql +19 -33
- data/test/fixtures/pk_called_id.rb +5 -0
- data/test/fixtures/pk_called_ids.yml +11 -0
- data/test/test_associations.rb +334 -332
- data/test/test_create.rb +9 -1
- data/test/test_delete.rb +17 -39
- data/test/test_ids.rb +113 -109
- data/test/test_preload.rb +94 -0
- data/test/test_suite.rb +1 -1
- data/test/test_update.rb +12 -7
- metadata +14 -24
- data/lib/composite_primary_keys/associations/singular_association.rb +0 -14
- data/lib/composite_primary_keys/connection_adapters/abstract/connection_specification_changes.rb +0 -71
- data/lib/composite_primary_keys/connection_adapters/postgresql_adapter.rb +0 -50
- data/lib/composite_primary_keys/dirty.rb +0 -19
- data/lib/composite_primary_keys/validations/uniqueness.rb +0 -41
- data/tasks/databases/oracle_enhanced.rake +0 -27
- data/tasks/databases/sqlite3.rake +0 -27
- data/test/connections/native_ibm_db/connection.rb +0 -19
- data/test/connections/native_mysql/connection.rb +0 -17
- data/test/connections/native_oracle/connection.rb +0 -11
- data/test/connections/native_oracle_enhanced/connection.rb +0 -16
- data/test/connections/native_postgresql/connection.rb +0 -13
- data/test/connections/native_sqlite3/connection.rb +0 -9
- data/test/connections/native_sqlserver/connection.rb +0 -11
- data/test/fixtures/db_definitions/sqlserver.drop.sql +0 -92
- data/test/test_delete_all.rb +0 -29
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: composite_primary_keys
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 9.0.
|
4
|
+
version: 9.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Charlie Savage
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -25,7 +25,7 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 5.0.0
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
@@ -39,7 +39,7 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: mysql2
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
@@ -53,7 +53,7 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: sqlite3
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
59
|
- - ">="
|
@@ -67,7 +67,7 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: pg
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - ">="
|
@@ -92,6 +92,7 @@ files:
|
|
92
92
|
- Rakefile
|
93
93
|
- lib/composite_primary_keys.rb
|
94
94
|
- lib/composite_primary_keys/arel/in.rb
|
95
|
+
- lib/composite_primary_keys/arel/sqlserver.rb
|
95
96
|
- lib/composite_primary_keys/arel/to_sql.rb
|
96
97
|
- lib/composite_primary_keys/associations/association.rb
|
97
98
|
- lib/composite_primary_keys/associations/association_scope.rb
|
@@ -102,7 +103,6 @@ files:
|
|
102
103
|
- lib/composite_primary_keys/associations/join_dependency/join_association.rb
|
103
104
|
- lib/composite_primary_keys/associations/preloader/association.rb
|
104
105
|
- lib/composite_primary_keys/associations/preloader/belongs_to.rb
|
105
|
-
- lib/composite_primary_keys/associations/singular_association.rb
|
106
106
|
- lib/composite_primary_keys/attribute_methods.rb
|
107
107
|
- lib/composite_primary_keys/attribute_methods/primary_key.rb
|
108
108
|
- lib/composite_primary_keys/attribute_methods/read.rb
|
@@ -112,12 +112,10 @@ files:
|
|
112
112
|
- lib/composite_primary_keys/composite_arrays.rb
|
113
113
|
- lib/composite_primary_keys/composite_predicates.rb
|
114
114
|
- lib/composite_primary_keys/composite_relation.rb
|
115
|
-
- lib/composite_primary_keys/connection_adapters/abstract/connection_specification_changes.rb
|
116
115
|
- lib/composite_primary_keys/connection_adapters/abstract_adapter.rb
|
117
|
-
- lib/composite_primary_keys/connection_adapters/
|
116
|
+
- lib/composite_primary_keys/connection_adapters/abstract_mysql_adapter.rb
|
118
117
|
- lib/composite_primary_keys/connection_adapters/sqlserver_adapter.rb
|
119
118
|
- lib/composite_primary_keys/core.rb
|
120
|
-
- lib/composite_primary_keys/dirty.rb
|
121
119
|
- lib/composite_primary_keys/fixtures.rb
|
122
120
|
- lib/composite_primary_keys/locking/optimistic.rb
|
123
121
|
- lib/composite_primary_keys/nested_attributes.rb
|
@@ -130,16 +128,14 @@ files:
|
|
130
128
|
- lib/composite_primary_keys/relation/query_methods.rb
|
131
129
|
- lib/composite_primary_keys/relation/where_clause.rb
|
132
130
|
- lib/composite_primary_keys/sanitization.rb
|
133
|
-
- lib/composite_primary_keys/validations/uniqueness.rb
|
134
131
|
- lib/composite_primary_keys/version.rb
|
135
132
|
- scripts/console.rb
|
136
133
|
- scripts/txt2html
|
137
134
|
- scripts/txt2js
|
138
135
|
- tasks/databases/mysql.rake
|
139
136
|
- tasks/databases/oracle.rake
|
140
|
-
- tasks/databases/oracle_enhanced.rake
|
141
137
|
- tasks/databases/postgresql.rake
|
142
|
-
- tasks/databases/
|
138
|
+
- tasks/databases/sqlite.rake
|
143
139
|
- tasks/databases/sqlserver.rake
|
144
140
|
- tasks/website.rake
|
145
141
|
- test/README_tests.rdoc
|
@@ -148,13 +144,6 @@ files:
|
|
148
144
|
- test/connections/databases.ci.yml
|
149
145
|
- test/connections/databases.example.yml
|
150
146
|
- test/connections/databases.yml
|
151
|
-
- test/connections/native_ibm_db/connection.rb
|
152
|
-
- test/connections/native_mysql/connection.rb
|
153
|
-
- test/connections/native_oracle/connection.rb
|
154
|
-
- test/connections/native_oracle_enhanced/connection.rb
|
155
|
-
- test/connections/native_postgresql/connection.rb
|
156
|
-
- test/connections/native_sqlite3/connection.rb
|
157
|
-
- test/connections/native_sqlserver/connection.rb
|
158
147
|
- test/db_test.rb
|
159
148
|
- test/fixtures/article.rb
|
160
149
|
- test/fixtures/articles.yml
|
@@ -169,7 +158,6 @@ files:
|
|
169
158
|
- test/fixtures/db_definitions/oracle.sql
|
170
159
|
- test/fixtures/db_definitions/postgresql.sql
|
171
160
|
- test/fixtures/db_definitions/sqlite.sql
|
172
|
-
- test/fixtures/db_definitions/sqlserver.drop.sql
|
173
161
|
- test/fixtures/db_definitions/sqlserver.sql
|
174
162
|
- test/fixtures/department.rb
|
175
163
|
- test/fixtures/departments.yml
|
@@ -185,6 +173,8 @@ files:
|
|
185
173
|
- test/fixtures/membership_status.rb
|
186
174
|
- test/fixtures/membership_statuses.yml
|
187
175
|
- test/fixtures/memberships.yml
|
176
|
+
- test/fixtures/pk_called_id.rb
|
177
|
+
- test/fixtures/pk_called_ids.yml
|
188
178
|
- test/fixtures/product.rb
|
189
179
|
- test/fixtures/product_tariff.rb
|
190
180
|
- test/fixtures/product_tariffs.yml
|
@@ -239,7 +229,6 @@ files:
|
|
239
229
|
- test/test_counter_cache.rb
|
240
230
|
- test/test_create.rb
|
241
231
|
- test/test_delete.rb
|
242
|
-
- test/test_delete_all.rb
|
243
232
|
- test/test_dumpable.rb
|
244
233
|
- test/test_dup.rb
|
245
234
|
- test/test_enum.rb
|
@@ -254,6 +243,7 @@ files:
|
|
254
243
|
- test/test_pagination.rb
|
255
244
|
- test/test_polymorphic.rb
|
256
245
|
- test/test_predicates.rb
|
246
|
+
- test/test_preload.rb
|
257
247
|
- test/test_santiago.rb
|
258
248
|
- test/test_serialize.rb
|
259
249
|
- test/test_suite.rb
|
@@ -281,7 +271,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
281
271
|
version: '0'
|
282
272
|
requirements: []
|
283
273
|
rubyforge_project:
|
284
|
-
rubygems_version: 2.6.
|
274
|
+
rubygems_version: 2.6.8
|
285
275
|
signing_key:
|
286
276
|
specification_version: 4
|
287
277
|
summary: Composite key support for ActiveRecord
|
@@ -300,7 +290,6 @@ test_files:
|
|
300
290
|
- test/test_counter_cache.rb
|
301
291
|
- test/test_create.rb
|
302
292
|
- test/test_delete.rb
|
303
|
-
- test/test_delete_all.rb
|
304
293
|
- test/test_dumpable.rb
|
305
294
|
- test/test_dup.rb
|
306
295
|
- test/test_enum.rb
|
@@ -315,6 +304,7 @@ test_files:
|
|
315
304
|
- test/test_pagination.rb
|
316
305
|
- test/test_polymorphic.rb
|
317
306
|
- test/test_predicates.rb
|
307
|
+
- test/test_preload.rb
|
318
308
|
- test/test_santiago.rb
|
319
309
|
- test/test_serialize.rb
|
320
310
|
- test/test_suite.rb
|
@@ -1,14 +0,0 @@
|
|
1
|
-
module CompositePrimaryKeys
|
2
|
-
module SingularAssociation
|
3
|
-
def get_records
|
4
|
-
cpk_applies = (target && target.composite?) ||
|
5
|
-
(owner && owner.composite?) ||
|
6
|
-
(options[:primary_key] && options[:primary_key].kind_of?(Array)) ||
|
7
|
-
(options[:foreign_key] && options[:foreign_key].kind_of?(Array))
|
8
|
-
return scope.limit(1).to_a if cpk_applies
|
9
|
-
super
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
ActiveRecord::Associations::SingularAssociation.prepend CompositePrimaryKeys::SingularAssociation
|
data/lib/composite_primary_keys/connection_adapters/abstract/connection_specification_changes.rb
DELETED
@@ -1,71 +0,0 @@
|
|
1
|
-
module ActiveRecord
|
2
|
-
class Base
|
3
|
-
def self.load_cpk_adapter(adapter)
|
4
|
-
if adapter.to_s =~ /postgresql/ || adapter.to_s =~ /postgis/
|
5
|
-
require "composite_primary_keys/connection_adapters/postgresql_adapter.rb"
|
6
|
-
end
|
7
|
-
if adapter.to_s =~ /sqlserver/
|
8
|
-
require "composite_primary_keys/connection_adapters/sqlserver_adapter.rb"
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
def self.establish_connection(spec = nil)
|
13
|
-
spec ||= ActiveRecord::ConnectionHandling::DEFAULT_ENV.call.to_sym
|
14
|
-
resolver = ConnectionAdapters::ConnectionSpecification::Resolver.new configurations
|
15
|
-
spec = resolver.spec(spec, self == Base ? "primary" : name)
|
16
|
-
self.connection_specification_name = spec.name
|
17
|
-
|
18
|
-
# CPK
|
19
|
-
load_cpk_adapter(spec.config[:adapter])
|
20
|
-
|
21
|
-
unless respond_to?(spec.adapter_method)
|
22
|
-
raise AdapterNotFound, "database configuration specifies nonexistent #{spec.config[:adapter]} adapter"
|
23
|
-
end
|
24
|
-
|
25
|
-
remove_connection
|
26
|
-
connection_handler.establish_connection spec
|
27
|
-
end
|
28
|
-
|
29
|
-
class << self
|
30
|
-
# Returns the connection currently associated with the class. This can
|
31
|
-
# also be used to "borrow" the connection to do database work unrelated
|
32
|
-
# to any of the specific Active Records.
|
33
|
-
def connection
|
34
|
-
retrieve_connection
|
35
|
-
end
|
36
|
-
|
37
|
-
# Returns the configuration of the associated connection as a hash:
|
38
|
-
#
|
39
|
-
# ActiveRecord::Base.connection_config
|
40
|
-
# # => {:pool=>5, :timeout=>5000, :database=>"db/development.sqlite3", :adapter=>"sqlite3"}
|
41
|
-
#
|
42
|
-
# Please use only for reading.
|
43
|
-
def connection_config
|
44
|
-
connection_pool.spec.config
|
45
|
-
end
|
46
|
-
|
47
|
-
def connection_pool
|
48
|
-
connection_handler.retrieve_connection_pool(connection_specification_name)
|
49
|
-
end
|
50
|
-
|
51
|
-
def retrieve_connection
|
52
|
-
connection_handler.retrieve_connection(connection_specification_name)
|
53
|
-
end
|
54
|
-
|
55
|
-
# Returns true if Active Record is connected.
|
56
|
-
def connected?
|
57
|
-
connection_handler.connected?(connection_specification_name)
|
58
|
-
end
|
59
|
-
|
60
|
-
def remove_connection(id = connection_specification_name)
|
61
|
-
connection_handler.remove_connection(id)
|
62
|
-
end
|
63
|
-
|
64
|
-
def clear_active_connections!
|
65
|
-
connection_handler.clear_active_connections!
|
66
|
-
end
|
67
|
-
|
68
|
-
delegate :clear_reloadable_connections!, :clear_all_connections!, :to => :connection_handler
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
@@ -1,50 +0,0 @@
|
|
1
|
-
module ActiveRecord
|
2
|
-
module ConnectionAdapters
|
3
|
-
class PostgreSQLAdapter
|
4
|
-
def insert_sql(sql, name = nil, pk = nil, id_value = nil, sequence_name = nil)
|
5
|
-
unless pk
|
6
|
-
# Extract the table from the insert sql. Yuck.
|
7
|
-
table_ref = extract_table_ref_from_insert_sql(sql)
|
8
|
-
pk = primary_key(table_ref) if table_ref
|
9
|
-
end
|
10
|
-
|
11
|
-
if pk && use_insert_returning?
|
12
|
-
# CPK
|
13
|
-
# select_value("#{sql} RETURNING #{quote_column_names(pk)}")
|
14
|
-
select_value("#{sql} RETURNING #{quote_column_names(pk)}")
|
15
|
-
elsif pk
|
16
|
-
super
|
17
|
-
last_insert_id_value(sequence_name || default_sequence_name(table_ref, pk))
|
18
|
-
else
|
19
|
-
super
|
20
|
-
end
|
21
|
-
end
|
22
|
-
alias :create :insert
|
23
|
-
|
24
|
-
def sql_for_insert(sql, pk, id_value, sequence_name, binds)
|
25
|
-
unless pk
|
26
|
-
# Extract the table from the insert sql. Yuck.
|
27
|
-
table_ref = extract_table_ref_from_insert_sql(sql)
|
28
|
-
pk = primary_key(table_ref) if table_ref
|
29
|
-
end
|
30
|
-
|
31
|
-
if pk && use_insert_returning?
|
32
|
-
# CPK
|
33
|
-
# sql = "#{sql} RETURNING #{quote_column_names(pk)}"
|
34
|
-
sql = "#{sql} RETURNING #{quote_column_names(pk)}"
|
35
|
-
end
|
36
|
-
|
37
|
-
[sql, binds]
|
38
|
-
end
|
39
|
-
|
40
|
-
# Returns a single value if query returns a single element
|
41
|
-
# otherwise returns an array corresponding to the composite keys
|
42
|
-
def last_inserted_id(result)
|
43
|
-
row = result && result.rows.first
|
44
|
-
if Array === row
|
45
|
-
row.size == 1 ? row[0] : row
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
module ActiveModel
|
2
|
-
module Dirty
|
3
|
-
def can_change_primary_key?
|
4
|
-
true
|
5
|
-
end
|
6
|
-
|
7
|
-
def primary_key_changed?
|
8
|
-
!!changed.detect { |key| ids_hash.keys.include?(key.to_s) }
|
9
|
-
end
|
10
|
-
|
11
|
-
def primary_key_was
|
12
|
-
ids_hash.keys.inject(Hash.new) do |result, attribute_name|
|
13
|
-
result[attribute_name] = attribute_was(attribute_name.to_s)
|
14
|
-
result
|
15
|
-
end
|
16
|
-
end
|
17
|
-
alias_method :ids_hash_was, :primary_key_was
|
18
|
-
end
|
19
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
module ActiveRecord
|
2
|
-
module Validations
|
3
|
-
# class UniquenessValidator
|
4
|
-
# def validate_each(record, attribute, value)
|
5
|
-
# finder_class = find_finder_class_for(record)
|
6
|
-
# table = finder_class.arel_table
|
7
|
-
# value = map_enum_attribute(finder_class, attribute, value)
|
8
|
-
#
|
9
|
-
# begin
|
10
|
-
# relation = build_relation(finder_class, table, attribute, value)
|
11
|
-
# # CPK
|
12
|
-
# # relation = relation.and(table[finder_class.primary_key.to_sym].not_eq(record.id)) if record.persisted?
|
13
|
-
# if record.persisted?
|
14
|
-
# not_eq_conditions = Array(finder_class.primary_key).zip(Array(record.send(:id))).map do |name, value|
|
15
|
-
# table[name.to_sym].not_eq(value)
|
16
|
-
# end
|
17
|
-
#
|
18
|
-
# condition = not_eq_conditions.shift
|
19
|
-
# not_eq_conditions.each do |not_eq_condition|
|
20
|
-
# condition = condition.or(not_eq_condition)
|
21
|
-
# end
|
22
|
-
# relation = relation.and(condition)
|
23
|
-
# end
|
24
|
-
# # End CPK
|
25
|
-
# relation = scope_relation(record, table, relation)
|
26
|
-
# relation = finder_class.unscoped.where(relation)
|
27
|
-
# relation = relation.merge(options[:conditions]) if options[:conditions]
|
28
|
-
# rescue RangeError
|
29
|
-
# relation = finder_class.none
|
30
|
-
# end
|
31
|
-
#
|
32
|
-
# if relation.exists?
|
33
|
-
# error_options = options.except(:case_sensitive, :scope, :conditions)
|
34
|
-
# error_options[:value] = value
|
35
|
-
#
|
36
|
-
# record.errors.add(attribute, :taken, error_options)
|
37
|
-
# end
|
38
|
-
# end
|
39
|
-
# end
|
40
|
-
end
|
41
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
require File.join(PROJECT_ROOT, 'lib', 'composite_primary_keys')
|
2
|
-
require File.join(PROJECT_ROOT, 'test', 'connections', 'connection_spec')
|
3
|
-
|
4
|
-
namespace :oracle_enhanced do
|
5
|
-
desc 'Build the Oracle test database'
|
6
|
-
task :build_database => :load_connection do
|
7
|
-
options_str = connection_string
|
8
|
-
|
9
|
-
sql = File.join(PROJECT_ROOT, 'test', 'fixtures', 'db_definitions', 'oracle.sql')
|
10
|
-
sh %( sqlplus #{options_str} < #{sql} )
|
11
|
-
end
|
12
|
-
|
13
|
-
desc 'Drop the Oracle test database'
|
14
|
-
task :drop_database => :load_connection do
|
15
|
-
options_str = connection_string
|
16
|
-
|
17
|
-
sql = File.join(PROJECT_ROOT, 'test', 'fixtures', 'db_definitions', 'oracle.drop.sql')
|
18
|
-
sh %( sqlplus #{options_str} < #{sql} )
|
19
|
-
end
|
20
|
-
|
21
|
-
desc 'Rebuild the Oracle test database'
|
22
|
-
task :rebuild_database => [:drop_database, :build_database]
|
23
|
-
|
24
|
-
task :load_connection do
|
25
|
-
require File.join(PROJECT_ROOT, "test", "connections", "native_oracle_enhanced", "connection")
|
26
|
-
end
|
27
|
-
end
|
@@ -1,27 +0,0 @@
|
|
1
|
-
require File.join(PROJECT_ROOT, 'lib', 'composite_primary_keys')
|
2
|
-
require File.join(PROJECT_ROOT, 'test', 'connections', 'connection_spec')
|
3
|
-
|
4
|
-
namespace :sqlite3 do
|
5
|
-
desc 'Build the sqlite test database'
|
6
|
-
task :build_database => :load_connection do
|
7
|
-
schema = File.join(PROJECT_ROOT, 'test', 'fixtures', 'db_definitions', 'sqlite.sql')
|
8
|
-
dbfile = File.join(PROJECT_ROOT, connection_string)
|
9
|
-
FileUtils.mkdir_p(File.dirname(dbfile))
|
10
|
-
cmd = "sqlite3 #{dbfile} < #{schema}"
|
11
|
-
puts cmd
|
12
|
-
sh %{ #{cmd} }
|
13
|
-
end
|
14
|
-
|
15
|
-
desc 'Drop the sqlite test database'
|
16
|
-
task :drop_database => :load_connection do
|
17
|
-
dbfile = connection_string
|
18
|
-
sh %{ rm -f #{dbfile} }
|
19
|
-
end
|
20
|
-
|
21
|
-
desc 'Rebuild the sqlite test database'
|
22
|
-
task :rebuild_database => [:drop_database, :build_database]
|
23
|
-
|
24
|
-
task :load_connection do
|
25
|
-
require File.join(PROJECT_ROOT, "test", "connections", "native_sqlite3", "connection")
|
26
|
-
end
|
27
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
print "Using IBM2 \n"
|
2
|
-
|
3
|
-
gem 'ibm_db'
|
4
|
-
require 'IBM_DB'
|
5
|
-
|
6
|
-
RAILS_CONNECTION_ADAPTERS = %w( mysql postgresql sqlite firebird sqlserver db2 oracle sybase openbase frontbase ibm_db )
|
7
|
-
|
8
|
-
db1 = 'composite_primary_keys_unittest'
|
9
|
-
|
10
|
-
connection_options = {
|
11
|
-
:adapter => "ibm_db",
|
12
|
-
:database => "ocdpdev",
|
13
|
-
:username => "db2inst1",
|
14
|
-
:password => "password",
|
15
|
-
:host => '192.168.2.21'
|
16
|
-
}
|
17
|
-
|
18
|
-
ActiveRecord::Base.configurations = { db1 => connection_options }
|
19
|
-
ActiveRecord::Base.establish_connection(connection_options)
|
@@ -1,17 +0,0 @@
|
|
1
|
-
print "Using native MySQL\n"
|
2
|
-
|
3
|
-
def connection_string
|
4
|
-
options = {}
|
5
|
-
options['u'] = SPEC['username'] if SPEC['username']
|
6
|
-
options['p'] = SPEC['password'] if SPEC['password']
|
7
|
-
options['S'] = SPEC['sock'] if SPEC['sock']
|
8
|
-
options.map { |key, value| "-#{key}#{value}" }.join(" ")
|
9
|
-
end
|
10
|
-
|
11
|
-
# Adapter config setup in test/connections/databases.yml
|
12
|
-
SPEC = CompositePrimaryKeys::ConnectionSpec['mysql']
|
13
|
-
|
14
|
-
def establish_connection
|
15
|
-
ActiveRecord::Base.establish_connection(SPEC)
|
16
|
-
end
|
17
|
-
establish_connection
|