schema_plus_foreign_keys 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/lib/schema_plus/foreign_keys/active_record/connection_adapters/abstract_adapter.rb +0 -23
- data/lib/schema_plus/foreign_keys/active_record/connection_adapters/foreign_key_definition.rb +0 -4
- data/lib/schema_plus/foreign_keys/active_record/connection_adapters/mysql2_adapter.rb +0 -5
- data/lib/schema_plus/foreign_keys/active_record/connection_adapters/postgresql_adapter.rb +0 -5
- data/lib/schema_plus/foreign_keys/middleware/migration.rb +15 -0
- data/lib/schema_plus/foreign_keys/version.rb +1 -1
- data/schema_plus_foreign_keys.gemspec +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 18b2164c375e6447f51ff241d12deaa5748736e4
|
4
|
+
data.tar.gz: 0c46ee8eb9792365ae22ecc13ecf305afde81a39
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b930008367e71b0c7b53771be9974d61e37c5ed8ba2c3a6ec049a41185299656c8126c1f097155b0776d9210c7bf295ea8a5a7e4014df52bbc9a954e87a8de64
|
7
|
+
data.tar.gz: bc1f9db77881d39cc24f418458711b486cabed9a7c3b1d479d1af9eb3ac8fe4ab1129cac8c0efe66938b437a0626e6e1b25ae63cb75637b6bdada084a89d6f7c
|
data/README.md
CHANGED
@@ -149,6 +149,7 @@ SchemaPlus::ForeignKeys is tested on:
|
|
149
149
|
|
150
150
|
## History
|
151
151
|
|
152
|
+
* 0.1.1 - Cleanup; use (new) core Migration::RenameTable stack rather than monkey patching.
|
152
153
|
* 0.1.0 - Initial release, brought over from schema_plus 1.x via 2.0.0.pre*
|
153
154
|
|
154
155
|
## Development & Testing
|
@@ -126,29 +126,6 @@ module SchemaPlus::ForeignKeys
|
|
126
126
|
end
|
127
127
|
|
128
128
|
|
129
|
-
# called from individual adpaters, after renaming table from old
|
130
|
-
# name to
|
131
|
-
def rename_foreign_keys(oldname, newname) #:nodoc:
|
132
|
-
foreign_keys(newname).each do |fk|
|
133
|
-
index = indexes(newname).find{|index| index.name == ForeignKeyDefinition.auto_index_name(oldname, fk.column)}
|
134
|
-
begin
|
135
|
-
remove_foreign_key(newname, name: fk.name)
|
136
|
-
rescue NotImplementedError
|
137
|
-
# sqlite3 can't remove foreign keys, so just skip it
|
138
|
-
end
|
139
|
-
# rename the index only when the fk constraint doesn't exist.
|
140
|
-
# mysql doesn't allow the rename (which is a delete & add)
|
141
|
-
# if the index is on a foreign key constraint
|
142
|
-
rename_index(newname, index.name, ForeignKeyDefinition.auto_index_name(newname, index.columns)) if index
|
143
|
-
begin
|
144
|
-
add_foreign_key(newname, fk.to_table, :column => fk.column, :primary_key => fk.primary_key, :name => fk.name.sub(/#{oldname}/, newname), :on_update => fk.on_update, :on_delete => fk.on_delete, :deferrable => fk.deferrable)
|
145
|
-
rescue NotImplementedError
|
146
|
-
# sqlite3 can't add foreign keys, so just skip it
|
147
|
-
end
|
148
|
-
end
|
149
|
-
end
|
150
|
-
|
151
|
-
|
152
129
|
#####################################################################
|
153
130
|
#
|
154
131
|
# The functions below here are abstract; each subclass should
|
data/lib/schema_plus/foreign_keys/active_record/connection_adapters/foreign_key_definition.rb
CHANGED
@@ -116,10 +116,6 @@ module SchemaPlus::ForeignKeys
|
|
116
116
|
"fk_#{fixup_schema_name(from_table)}_#{Array.wrap(column).join('_and_')}"
|
117
117
|
end
|
118
118
|
|
119
|
-
def self.auto_index_name(from_table, column_name)
|
120
|
-
"fk__#{fixup_schema_name(from_table)}_#{Array.wrap(column_name).join('_and_')}"
|
121
|
-
end
|
122
|
-
|
123
119
|
def self.fixup_schema_name(table_name)
|
124
120
|
# replace . with _
|
125
121
|
table_name.to_s.gsub(/[.]/, '_')
|
@@ -14,11 +14,6 @@ module SchemaPlus::ForeignKeys
|
|
14
14
|
super table_name, column_name, type, options
|
15
15
|
end
|
16
16
|
|
17
|
-
def rename_table(oldname, newname)
|
18
|
-
super
|
19
|
-
rename_foreign_keys(oldname, newname)
|
20
|
-
end
|
21
|
-
|
22
17
|
def remove_foreign_key(*args)
|
23
18
|
from_table, to_table, options = normalize_remove_foreign_key_args(*args)
|
24
19
|
if options[:if_exists]
|
@@ -6,11 +6,6 @@ module SchemaPlus::ForeignKeys
|
|
6
6
|
# enhancements
|
7
7
|
module PostgresqlAdapter
|
8
8
|
|
9
|
-
def rename_table(oldname, newname) #:nodoc:
|
10
|
-
super
|
11
|
-
rename_foreign_keys(oldname, newname)
|
12
|
-
end
|
13
|
-
|
14
9
|
def foreign_keys(table_name, name = nil) #:nodoc:
|
15
10
|
load_foreign_keys(<<-SQL, name)
|
16
11
|
SELECT f.conname, pg_get_constraintdef(f.oid), t.relname
|
@@ -15,6 +15,21 @@ module SchemaPlus::ForeignKeys
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
+
module RenameTable
|
19
|
+
def after(env)
|
20
|
+
oldname = env.table_name
|
21
|
+
newname = env.new_name
|
22
|
+
env.connection.foreign_keys(newname).each do |fk|
|
23
|
+
begin
|
24
|
+
env.connection.remove_foreign_key(newname, name: fk.name)
|
25
|
+
env.connection.add_foreign_key(newname, fk.to_table, :column => fk.column, :primary_key => fk.primary_key, :name => fk.name.sub(/#{oldname}/, newname), :on_update => fk.on_update, :on_delete => fk.on_delete, :deferrable => fk.deferrable)
|
26
|
+
rescue NotImplementedError
|
27
|
+
# sqlite3 can't remote or add foreign keys, so just skip it
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
18
33
|
module Column
|
19
34
|
|
20
35
|
#
|
@@ -19,7 +19,7 @@ Gem::Specification.new do |gem|
|
|
19
19
|
gem.require_paths = ["lib"]
|
20
20
|
|
21
21
|
gem.add_dependency "activerecord", "~> 4.2"
|
22
|
-
gem.add_dependency "schema_plus_core", "~> 0.
|
22
|
+
gem.add_dependency "schema_plus_core", "~> 0.5"
|
23
23
|
gem.add_dependency "valuable"
|
24
24
|
|
25
25
|
gem.add_development_dependency "bundler", "~> 1.7"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: schema_plus_foreign_keys
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ronen barzel
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05-
|
11
|
+
date: 2015-05-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '0.
|
33
|
+
version: '0.5'
|
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: '0.
|
40
|
+
version: '0.5'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: valuable
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|