activerecord-referential_integrity 1.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +6 -6
- data/activerecord-referential_integrity.gemspec +3 -3
- data/lib/activerecord/referential_integrity/active_record/connection_adapters/abstract_adapter.rb +4 -4
- data/lib/activerecord/referential_integrity/active_record/connection_adapters/postgresql_adapter.rb +4 -10
- data/lib/activerecord/referential_integrity/active_record/migration/command_recorder.rb +4 -4
- data/lib/activerecord/referential_integrity/version.rb +1 -1
- metadata +15 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 08474bec273e1d3087ba4479837c3aae401adb64
|
4
|
+
data.tar.gz: 1cd937521eb16cdc78dba3fe785eb0ab8d641502
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1d85e24eb16ef0d5e4cd8f59c9d43f0b014a71fdeaae647e4957415430633a9b7597f485fa3f3f283b6a62fd1b90906be4d58600353b82333f41db6605e528fe
|
7
|
+
data.tar.gz: e185e1ea66d4506de636a09d2a208f85f834529010079b8c4d1c546b193062790eae1621a26af0984ce2b96d370141bc9ea8ef586bf9a14b286f959cc03a7c80
|
data/README.md
CHANGED
@@ -1,10 +1,10 @@
|
|
1
1
|
# Referential Integrity for ActiveRecord
|
2
2
|
|
3
|
-
Adds as reversible `
|
4
|
-
creates a database level foreign key constraint, this ensures that records
|
3
|
+
Adds as reversible `add_referential_integrity` migration to Rails. `add_referential_integrity`
|
4
|
+
creates a database level foreign key constraint, this ensures that records
|
5
5
|
cannot reference foreign keys in other tables that do not exist.
|
6
6
|
|
7
|
-
See [PostgreSQL foreign key constraint documentation](http://www.postgresql.org/docs/9.3/static/ddl-constraints.html#DDL-CONSTRAINTS-FK)
|
7
|
+
See [PostgreSQL foreign key constraint documentation](http://www.postgresql.org/docs/9.3/static/ddl-constraints.html#DDL-CONSTRAINTS-FK)
|
8
8
|
for more.
|
9
9
|
|
10
10
|
## Limitations
|
@@ -28,7 +28,7 @@ Or install it yourself as:
|
|
28
28
|
|
29
29
|
## Usage
|
30
30
|
|
31
|
-
Inside your migrations, call `
|
31
|
+
Inside your migrations, call `add_referential_integrity`, passing in the table and a hash of column => table pairs.
|
32
32
|
|
33
33
|
For example:
|
34
34
|
```ruby
|
@@ -39,8 +39,8 @@ class CreateUserSettings < ActiveRecord::Migration
|
|
39
39
|
# or t.integer :user_id, null: false
|
40
40
|
[...]
|
41
41
|
end
|
42
|
-
|
43
|
-
|
42
|
+
|
43
|
+
add_referential_integrity :user_settings, user_id: :users
|
44
44
|
end
|
45
45
|
end
|
46
46
|
```
|
@@ -8,8 +8,8 @@ Gem::Specification.new do |spec|
|
|
8
8
|
spec.version = ActiveRecord::ReferentialIntegrity::VERSION
|
9
9
|
spec.authors = ['Martin Tithonium', 'John Wulff']
|
10
10
|
spec.email = ['marty@orcasnet.com', 'johnw@orcasnet.com']
|
11
|
-
spec.summary = %q{Adds
|
12
|
-
spec.description = %q{Adds as reversible
|
11
|
+
spec.summary = %q{Adds add_referential_integrity to Rails migrations with relevant databases}
|
12
|
+
spec.description = %q{Adds as reversible add_referential_integrity migration to Rails. Currently supports only PostgreSQL}
|
13
13
|
spec.homepage = 'https://github.com/orcasnet/activerecord-referential_integrity'
|
14
14
|
spec.license = 'MIT'
|
15
15
|
|
@@ -18,7 +18,7 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
19
|
spec.require_paths = ['lib']
|
20
20
|
|
21
|
-
spec.add_dependency 'activerecord', '
|
21
|
+
spec.add_dependency 'activerecord', '> 3.2.16'
|
22
22
|
spec.add_development_dependency 'bundler', '~> 1.5'
|
23
23
|
spec.add_development_dependency 'rake'
|
24
24
|
end
|
data/lib/activerecord/referential_integrity/active_record/connection_adapters/abstract_adapter.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
class ActiveRecord::ConnectionAdapters::AbstractAdapter
|
2
|
-
def
|
3
|
-
raise NotImplementedError, '
|
2
|
+
def add_referential_integrity(table, keypairs)
|
3
|
+
raise NotImplementedError, 'add_referential_integrity is not implemented'
|
4
4
|
end
|
5
5
|
|
6
|
-
def
|
7
|
-
raise NotImplementedError, '
|
6
|
+
def drop_referential_integrity(table, keys)
|
7
|
+
raise NotImplementedError, 'drop_referential_integrity is not implemented'
|
8
8
|
end
|
9
9
|
end
|
data/lib/activerecord/referential_integrity/active_record/connection_adapters/postgresql_adapter.rb
CHANGED
@@ -1,19 +1,13 @@
|
|
1
1
|
class ActiveRecord::ConnectionAdapters::PostgreSQLAdapter < ActiveRecord::ConnectionAdapters::AbstractAdapter
|
2
|
-
def
|
2
|
+
def add_referential_integrity(table, keypairs)
|
3
3
|
keypairs.each_pair do |foreign_key, foreign_table|
|
4
|
-
|
5
|
-
sql << "ADD CONSTRAINT #{table}_fk_#{foreign_key} "
|
6
|
-
sql << "FOREIGN KEY (#{foreign_key}) "
|
7
|
-
sql << "REFERENCES #{foreign_table} (id)"
|
8
|
-
execute sql
|
4
|
+
execute "ALTER TABLE #{table} ADD CONSTRAINT #{table}_fk_#{foreign_key} FOREIGN KEY (#{foreign_key}) REFERENCES #{foreign_table} (id)"
|
9
5
|
end
|
10
6
|
end
|
11
7
|
|
12
|
-
def
|
8
|
+
def drop_referential_integrity(table, keys)
|
13
9
|
keys.each do |foreign_key|
|
14
|
-
|
15
|
-
sql << "DROP CONSTRAINT IF EXISTS #{table}_fk_#{foreign_key} "
|
16
|
-
execute sql
|
10
|
+
execute "ALTER TABLE #{table} DROP CONSTRAINT IF EXISTS #{table}_fk_#{foreign_key}"
|
17
11
|
end
|
18
12
|
end
|
19
13
|
end
|
@@ -1,11 +1,11 @@
|
|
1
1
|
class ActiveRecord::Migration::CommandRecorder
|
2
|
-
def
|
3
|
-
record(:
|
2
|
+
def add_referential_integrity(*args)
|
3
|
+
record(:add_referential_integrity, args)
|
4
4
|
end
|
5
5
|
|
6
6
|
private
|
7
7
|
|
8
|
-
def
|
9
|
-
[:
|
8
|
+
def invert_add_referential_integrity(args)
|
9
|
+
[:drop_referential_integrity, [args.first, args.last.keys]]
|
10
10
|
end
|
11
11
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-referential_integrity
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Martin Tithonium
|
@@ -9,52 +9,52 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-06-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: activerecord
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
|
-
- -
|
18
|
+
- - '>'
|
19
19
|
- !ruby/object:Gem::Version
|
20
20
|
version: 3.2.16
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
|
-
- -
|
25
|
+
- - '>'
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
version: 3.2.16
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: bundler
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
32
|
-
- -
|
32
|
+
- - ~>
|
33
33
|
- !ruby/object:Gem::Version
|
34
34
|
version: '1.5'
|
35
35
|
type: :development
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
|
-
- -
|
39
|
+
- - ~>
|
40
40
|
- !ruby/object:Gem::Version
|
41
41
|
version: '1.5'
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: rake
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
45
45
|
requirements:
|
46
|
-
- -
|
46
|
+
- - '>='
|
47
47
|
- !ruby/object:Gem::Version
|
48
48
|
version: '0'
|
49
49
|
type: :development
|
50
50
|
prerelease: false
|
51
51
|
version_requirements: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
|
-
- -
|
53
|
+
- - '>='
|
54
54
|
- !ruby/object:Gem::Version
|
55
55
|
version: '0'
|
56
|
-
description: Adds as reversible
|
57
|
-
only PostgreSQL
|
56
|
+
description: Adds as reversible add_referential_integrity migration to Rails. Currently
|
57
|
+
supports only PostgreSQL
|
58
58
|
email:
|
59
59
|
- marty@orcasnet.com
|
60
60
|
- johnw@orcasnet.com
|
@@ -62,7 +62,7 @@ executables: []
|
|
62
62
|
extensions: []
|
63
63
|
extra_rdoc_files: []
|
64
64
|
files:
|
65
|
-
-
|
65
|
+
- .gitignore
|
66
66
|
- Gemfile
|
67
67
|
- LICENSE.txt
|
68
68
|
- README.md
|
@@ -83,18 +83,18 @@ require_paths:
|
|
83
83
|
- lib
|
84
84
|
required_ruby_version: !ruby/object:Gem::Requirement
|
85
85
|
requirements:
|
86
|
-
- -
|
86
|
+
- - '>='
|
87
87
|
- !ruby/object:Gem::Version
|
88
88
|
version: '0'
|
89
89
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
90
|
requirements:
|
91
|
-
- -
|
91
|
+
- - '>='
|
92
92
|
- !ruby/object:Gem::Version
|
93
93
|
version: '0'
|
94
94
|
requirements: []
|
95
95
|
rubyforge_project:
|
96
|
-
rubygems_version: 2.
|
96
|
+
rubygems_version: 2.0.3
|
97
97
|
signing_key:
|
98
98
|
specification_version: 4
|
99
|
-
summary: Adds
|
99
|
+
summary: Adds add_referential_integrity to Rails migrations with relevant databases
|
100
100
|
test_files: []
|