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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fb2cc4a45fe2ff12dbbc37559613548fd347c3c2
|
4
|
+
data.tar.gz: 796b0354d817c2d1dcbe262bd13afec01f61a89a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ad93e0ae55774a145eddcb6724857008d2bf0d7b1e784d0968259e7899c29b9eda835ae418a827407ee2890f98099405089051b1e00449ef65efd9d4d835f2f2
|
7
|
+
data.tar.gz: 9ec8b022a26ee1cef07503939f7b22716be498a08d8ce23c7735b282e9139b46155710ce2078349183a494540a88e1e8a9db8e57d01b0de5c351226c99423a0e
|
data/.travis.yml
CHANGED
data/lib/activerecord-mysql-structure/active_record/v3/connection_adapters/abstract_mysql_adapter.rb
CHANGED
@@ -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
|
-
#
|
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
|
-
|
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:
|
@@ -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.
|
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:
|
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.
|
111
|
+
rubygems_version: 2.6.12
|
112
112
|
signing_key:
|
113
113
|
specification_version: 4
|
114
114
|
summary: Cleaner structure.sql for MySQL.
|