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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dd82359f12e9dfcd2ee7413a727637098fa160a3
4
- data.tar.gz: c8b86be4f354952b4f64c5681c28336b4c77153a
3
+ metadata.gz: 18b2164c375e6447f51ff241d12deaa5748736e4
4
+ data.tar.gz: 0c46ee8eb9792365ae22ecc13ecf305afde81a39
5
5
  SHA512:
6
- metadata.gz: ac770774c777fbae496152c989b884f613148eefbcc2574a7e0359fa8f95ec34514b58329b965200aa46f3da628ae5b026104bdd6a3f75df0a9e4ea6aff360a4
7
- data.tar.gz: fd9687b783c5204c743f9646187751b8f519f1e847326a796cb88817a1a0e79d3d6d63c71cad4b99f15545a6aa820420ea4552cf78c50d7d1e068ddf85ca99ea
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
@@ -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
  #
@@ -1,5 +1,5 @@
1
1
  module SchemaPlus
2
2
  module ForeignKeys
3
- VERSION = "0.1.0"
3
+ VERSION = "0.1.1"
4
4
  end
5
5
  end
@@ -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.4"
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.0
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-17 00:00:00.000000000 Z
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.4'
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.4'
40
+ version: '0.5'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: valuable
43
43
  requirement: !ruby/object:Gem::Requirement