activerecord-mysql-structure 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +13 -0
- data/README.md +26 -0
- data/Rakefile +7 -0
- data/activerecord-mysql-structure.gemspec +26 -0
- data/lib/activerecord-mysql-structure.rb +15 -0
- data/lib/activerecord-mysql-structure/active_record/v3/connection_adapters/abstract_mysql_adapter.rb +27 -0
- data/lib/activerecord-mysql-structure/base.rb +5 -0
- data/lib/activerecord-mysql-structure/railtie.rb +13 -0
- data/lib/activerecord-mysql-structure/version.rb +7 -0
- data/spec/activerecord/mysql/structure_spec.rb +58 -0
- data/spec/spec_helper.rb +2 -0
- metadata +117 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9e8079dbc65050e8cd8e2533b2580eb1c6931ea3
|
4
|
+
data.tar.gz: e72fac50dbe88c0db284679643405d7d0a396e14
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cc78a906a23c9009aba879cdb885b5db1bfedd9fa53154d13bfb117904dc10e513ef849d17577d4c70c6259be80cb87701933fdd4467ce95a63416243e25fcc7
|
7
|
+
data.tar.gz: 1df09131d3bb0c325a1dd1a73320e0e2b2bae84f6933505945c07fea7c0af432c8e742fc3b979fea2696d723ff8ff2b9f1208785f05bb3386fafc6ccee83955e
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
#License and Copyright
|
2
|
+
Copyright (c) 2014, PagerDuty
|
3
|
+
All rights reserved.
|
4
|
+
|
5
|
+
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
|
6
|
+
|
7
|
+
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
|
8
|
+
|
9
|
+
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
|
10
|
+
|
11
|
+
* Neither the name of activerecord-mysql-structure nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
|
12
|
+
|
13
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
data/README.md
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# ActiveRecord::Mysql::Structure
|
2
|
+
|
3
|
+
This gem improves ActiveRecord's dumping of MySQL schema to a `structure.sql` file.
|
4
|
+
- `AUTO_INCREMENT` values will not be written, preventing noisy diffs
|
5
|
+
- `DROP TABLE IF EXISTS` statements will be prepended to `CREATE_TABLE` statements, mimicking the `force: true` option normally captured in `schema.rb`
|
6
|
+
- adds newline to EOF
|
7
|
+
|
8
|
+
It is intended for use with ActiveRecord 3 only.
|
9
|
+
The `AUTO_INCREMENT` functionality is unlikely to ever be added to Rails master as it uses the `mysqldump` command directly.
|
10
|
+
As of this writing, `mysqldump` has no support for ignoring `AUTO_INCREMENT` output.
|
11
|
+
|
12
|
+
## Installation
|
13
|
+
|
14
|
+
Add this line to your application's Gemfile:
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
gem 'activerecord-mysql-structure'
|
18
|
+
```
|
19
|
+
|
20
|
+
And then execute:
|
21
|
+
|
22
|
+
$ bundle
|
23
|
+
|
24
|
+
Or install it yourself as:
|
25
|
+
|
26
|
+
$ gem install activerecord-mysql-structure
|
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'activerecord-mysql-structure/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'activerecord-mysql-structure'
|
8
|
+
spec.version = ActiveRecord::Mysql::Structure::VERSION
|
9
|
+
spec.authors = ['Steve Rice']
|
10
|
+
spec.email = ['steve@pagerduty.com']
|
11
|
+
spec.summary = 'Cleaner structure.sql for MySQL.'
|
12
|
+
spec.description = ''
|
13
|
+
spec.homepage = 'https://github.com/PagerDuty/activerecord-mysql-structure'
|
14
|
+
spec.license = 'Apache 2'
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ['lib']
|
20
|
+
|
21
|
+
spec.add_development_dependency 'bundler', '~> 1.7'
|
22
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
23
|
+
spec.add_development_dependency 'rspec'
|
24
|
+
|
25
|
+
spec.add_runtime_dependency 'activerecord', '~> 3'
|
26
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'active_support'
|
2
|
+
|
3
|
+
begin
|
4
|
+
require 'rails'
|
5
|
+
rescue LoadError
|
6
|
+
# nothing to do! yay!
|
7
|
+
end
|
8
|
+
|
9
|
+
if defined? Rails
|
10
|
+
require 'activerecord-mysql-structure/railtie'
|
11
|
+
else
|
12
|
+
ActiveSupport.on_load :active_record do
|
13
|
+
require 'activerecord-mysql-structure/base'
|
14
|
+
end
|
15
|
+
end
|
data/lib/activerecord-mysql-structure/active_record/v3/connection_adapters/abstract_mysql_adapter.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'active_record/connection_adapters/abstract_mysql_adapter'
|
2
|
+
|
3
|
+
module ActiveRecord
|
4
|
+
module ConnectionAdapters
|
5
|
+
class AbstractMysqlAdapter < AbstractAdapter
|
6
|
+
|
7
|
+
# Override this to add DROP TABLE IF EXISTS statements to each CREATE TABLE
|
8
|
+
def structure_dump #:nodoc:
|
9
|
+
if supports_views?
|
10
|
+
sql = "SHOW FULL TABLES WHERE Table_type = 'BASE TABLE'"
|
11
|
+
else
|
12
|
+
sql = "SHOW TABLES"
|
13
|
+
end
|
14
|
+
|
15
|
+
select_all(sql).map { |table|
|
16
|
+
table.delete('Table_type')
|
17
|
+
sql = "SHOW CREATE TABLE #{quote_table_name(table.to_a.first.last)}"
|
18
|
+
"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
|
+
}.join.gsub(/\s+AUTO_INCREMENT=\d+\s+/, ' ') # CHANGE 2 of 2 FROM RAILS
|
20
|
+
end
|
21
|
+
|
22
|
+
def dump_schema_information #:nodoc:
|
23
|
+
"#{super}\n"
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module ActiveRecord
|
2
|
+
module Mysql
|
3
|
+
module Structure
|
4
|
+
class Railtie < Rails::Railtie
|
5
|
+
initializer 'activerecord-mysql-structure' do
|
6
|
+
ActiveSupport.on_load :active_record do
|
7
|
+
require 'activerecord-mysql-structure/base'
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'active_record'
|
3
|
+
require 'activerecord-mysql-structure/base'
|
4
|
+
|
5
|
+
describe ActiveRecord::Mysql::Structure do
|
6
|
+
it 'has a version number' do
|
7
|
+
expect(ActiveRecord::Mysql::Structure::VERSION).not_to be nil
|
8
|
+
end
|
9
|
+
|
10
|
+
context 'AbstractMysqlAdapter' do
|
11
|
+
let(:adapter) { ActiveRecord::ConnectionAdapters::AbstractMysqlAdapter.new(nil, nil, nil, prepared_statements: true) }
|
12
|
+
|
13
|
+
describe '#structure_dump' do
|
14
|
+
before do
|
15
|
+
expect(adapter).to receive(:select_all).with(anything).and_return [{'Tables_in_database' => 'foobar'}]
|
16
|
+
expect(adapter).to receive(:structure_dump).and_call_original
|
17
|
+
expect(adapter).to receive(:supports_views?).and_return false
|
18
|
+
expect(adapter).to receive(:exec_query).and_return [{
|
19
|
+
'Create Table' => <<-sql
|
20
|
+
CREATE TABLE `foobar` (
|
21
|
+
`id` int(11) NOT NULL AUTO_INCREMENT,
|
22
|
+
`some_column` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL
|
23
|
+
PRIMARY KEY (`id`)
|
24
|
+
) ENGINE=InnoDB AUTO_INCREMENT=#{(0..1000).to_a.sample} DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci ROW_FORMAT=DYNAMIC;
|
25
|
+
sql
|
26
|
+
}]
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'adds DROP TABLE IF EXISTS statements' do
|
30
|
+
expect(adapter.structure_dump).to include 'DROP TABLE IF EXISTS `foobar`'
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'does not include AUTO_INCREMENT value' do
|
34
|
+
expect(adapter.structure_dump).not_to include 'AUTO_INCREMENT='
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'ends with a newline' do
|
38
|
+
expect(adapter.structure_dump.slice(-1)).to eq "\n"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe '#dump_schema_information' do
|
43
|
+
before do
|
44
|
+
expect(adapter).to receive(:select_values).and_return %w(
|
45
|
+
20140407202440
|
46
|
+
20140407220022
|
47
|
+
20140407220125
|
48
|
+
20140409230054
|
49
|
+
20140424221613
|
50
|
+
)
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'ends with a newline' do
|
54
|
+
expect(adapter.dump_schema_information.slice(-1)).to eq "\n"
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: activerecord-mysql-structure
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Steve Rice
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-11-02 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.7'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.7'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: activerecord
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '3'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '3'
|
69
|
+
description: ''
|
70
|
+
email:
|
71
|
+
- steve@pagerduty.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- ".rspec"
|
78
|
+
- ".travis.yml"
|
79
|
+
- Gemfile
|
80
|
+
- LICENSE.txt
|
81
|
+
- README.md
|
82
|
+
- Rakefile
|
83
|
+
- activerecord-mysql-structure.gemspec
|
84
|
+
- lib/activerecord-mysql-structure.rb
|
85
|
+
- lib/activerecord-mysql-structure/active_record/v3/connection_adapters/abstract_mysql_adapter.rb
|
86
|
+
- lib/activerecord-mysql-structure/base.rb
|
87
|
+
- lib/activerecord-mysql-structure/railtie.rb
|
88
|
+
- lib/activerecord-mysql-structure/version.rb
|
89
|
+
- spec/activerecord/mysql/structure_spec.rb
|
90
|
+
- spec/spec_helper.rb
|
91
|
+
homepage: https://github.com/PagerDuty/activerecord-mysql-structure
|
92
|
+
licenses:
|
93
|
+
- Apache 2
|
94
|
+
metadata: {}
|
95
|
+
post_install_message:
|
96
|
+
rdoc_options: []
|
97
|
+
require_paths:
|
98
|
+
- lib
|
99
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
105
|
+
requirements:
|
106
|
+
- - ">="
|
107
|
+
- !ruby/object:Gem::Version
|
108
|
+
version: '0'
|
109
|
+
requirements: []
|
110
|
+
rubyforge_project:
|
111
|
+
rubygems_version: 2.2.2
|
112
|
+
signing_key:
|
113
|
+
specification_version: 4
|
114
|
+
summary: Cleaner structure.sql for MySQL.
|
115
|
+
test_files:
|
116
|
+
- spec/activerecord/mysql/structure_spec.rb
|
117
|
+
- spec/spec_helper.rb
|