activerecord-mysql-structure 0.0.2 → 0.0.3

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: 9e8079dbc65050e8cd8e2533b2580eb1c6931ea3
4
- data.tar.gz: e72fac50dbe88c0db284679643405d7d0a396e14
3
+ metadata.gz: fb2cc4a45fe2ff12dbbc37559613548fd347c3c2
4
+ data.tar.gz: 796b0354d817c2d1dcbe262bd13afec01f61a89a
5
5
  SHA512:
6
- metadata.gz: cc78a906a23c9009aba879cdb885b5db1bfedd9fa53154d13bfb117904dc10e513ef849d17577d4c70c6259be80cb87701933fdd4467ce95a63416243e25fcc7
7
- data.tar.gz: 1df09131d3bb0c325a1dd1a73320e0e2b2bae84f6933505945c07fea7c0af432c8e742fc3b979fea2696d723ff8ff2b9f1208785f05bb3386fafc6ccee83955e
6
+ metadata.gz: ad93e0ae55774a145eddcb6724857008d2bf0d7b1e784d0968259e7899c29b9eda835ae418a827407ee2890f98099405089051b1e00449ef65efd9d4d835f2f2
7
+ data.tar.gz: 9ec8b022a26ee1cef07503939f7b22716be498a08d8ce23c7735b282e9139b46155710ce2078349183a494540a88e1e8a9db8e57d01b0de5c351226c99423a0e
@@ -1,4 +1,6 @@
1
1
  language: ruby
2
+ before_install:
3
+ - travis_retry gem install bundler -v 1.7
2
4
  rvm:
3
5
  - 1.9.3
4
6
  - 2.1.2
@@ -3,20 +3,24 @@ require 'active_record/connection_adapters/abstract_mysql_adapter'
3
3
  module ActiveRecord
4
4
  module ConnectionAdapters
5
5
  class AbstractMysqlAdapter < AbstractAdapter
6
-
7
- # Override this to add DROP TABLE IF EXISTS statements to each CREATE TABLE
6
+ # Override this to disable FOREIGN_KEY_CHECK at the start of the structure file
7
+ # and re-enable it at the end and to add DROP TABLE IF EXISTS statements to each CREATE TABLE
8
8
  def structure_dump #:nodoc:
9
9
  if supports_views?
10
10
  sql = "SHOW FULL TABLES WHERE Table_type = 'BASE TABLE'"
11
11
  else
12
12
  sql = "SHOW TABLES"
13
13
  end
14
-
15
- select_all(sql).map { |table|
14
+ # https://lists.mysql.com/announce/166
15
+ # only disable FOREIGN_KEY_CHECK when mysql version is 4.0.14 or later
16
+ structure = "/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;\n\n"
17
+ structure += select_all(sql).map { |table|
16
18
  table.delete('Table_type')
17
19
  sql = "SHOW CREATE TABLE #{quote_table_name(table.to_a.first.last)}"
18
20
  "DROP TABLE IF EXISTS #{quote_table_name(table.to_a.first.last)};\n\n" + exec_query(sql).first['Create Table'] + ";\n\n" # CHANGE 1 of 2 FROM RAILS
19
21
  }.join.gsub(/\s+AUTO_INCREMENT=\d+\s+/, ' ') # CHANGE 2 of 2 FROM RAILS
22
+ structure += "/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;\n\n"
23
+ structure
20
24
  end
21
25
 
22
26
  def dump_schema_information #:nodoc:
@@ -1,7 +1,7 @@
1
1
  module ActiveRecord
2
2
  module Mysql
3
3
  module Structure
4
- VERSION = '0.0.2'
4
+ VERSION = '0.0.3'
5
5
  end
6
6
  end
7
7
  end
@@ -26,6 +26,14 @@ describe ActiveRecord::Mysql::Structure do
26
26
  }]
27
27
  end
28
28
 
29
+ it 'starts with FOREIGN_KEY_CHECKS disable' do
30
+ expect(adapter.structure_dump.lines.to_a[0]).to eq "/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;\n"
31
+ end
32
+
33
+ it 'includes FOREIGN_KEY_CHECKS re-enable at the end' do
34
+ expect(adapter.structure_dump.lines.to_a[-2]).to eq "/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;\n"
35
+ end
36
+
29
37
  it 'adds DROP TABLE IF EXISTS statements' do
30
38
  expect(adapter.structure_dump).to include 'DROP TABLE IF EXISTS `foobar`'
31
39
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-mysql-structure
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Rice
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-02 00:00:00.000000000 Z
11
+ date: 2017-08-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -108,7 +108,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
108
  version: '0'
109
109
  requirements: []
110
110
  rubyforge_project:
111
- rubygems_version: 2.2.2
111
+ rubygems_version: 2.6.12
112
112
  signing_key:
113
113
  specification_version: 4
114
114
  summary: Cleaner structure.sql for MySQL.