activerecord-mysql-pkdump 0.0.2 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rspec +2 -0
- data/.travis.yml +6 -0
- data/README.md +5 -1
- data/Rakefile +4 -0
- data/activerecord-mysql-pkdump.gemspec +3 -0
- data/lib/activerecord/mysql/pkdump/version.rb +1 -1
- data/spec/activerecord-mysql-pkdump_spec.rb +173 -0
- data/spec/spec_helper.rb +92 -0
- metadata +51 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9c304e333a9272b3844d1efb22311fe33e97cded
|
4
|
+
data.tar.gz: 7e3cd9e0ef4295ddaebd6e2092db4d7f1e83409f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1489c6faf9de44bdbb4771deaa6e1273585d9a9301f93d1504438db8726b9f28d8736e2d84b5074951dd76cbad75d237097711ea6953e654cc1f8c2270443d7b
|
7
|
+
data.tar.gz: 8a566e4158e0ffa397874acc2a46f1fe0442f9a92d183e4d06f32a92817f98a65e4be9acc1473d6a8142c689189afefe366179b22aae6bdc96cb46e9407d9eab
|
data/.rspec
ADDED
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -2,6 +2,10 @@
|
|
2
2
|
|
3
3
|
Dump the type information of a non-standard primary key.
|
4
4
|
|
5
|
+
[](http://badge.fury.io/rb/activerecord-mysql-pkdump)
|
6
|
+
[](https://travis-ci.org/winebarrel/activerecord-mysql-pkdump)
|
7
|
+
[](https://coveralls.io/r/winebarrel/activerecord-mysql-pkdump?branch=master)
|
8
|
+
|
5
9
|
## Installation
|
6
10
|
|
7
11
|
Add this line to your application's Gemfile:
|
@@ -31,7 +35,7 @@ ActiveRecord::Base.establish_connection(
|
|
31
35
|
|
32
36
|
ActiveRecord::SchemaDumper.dump
|
33
37
|
#=> ...
|
34
|
-
# create_table "items", primary_key: "my_id", id:
|
38
|
+
# create_table "items", primary_key: "my_id", id: "bigint(20) PRIMARY KEY auto_increment", force: true do |t|
|
35
39
|
# ...
|
36
40
|
# end
|
37
41
|
# ...
|
data/Rakefile
CHANGED
@@ -22,4 +22,7 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.add_development_dependency 'bundler'
|
23
23
|
spec.add_development_dependency 'rake', '~> 10.0'
|
24
24
|
spec.add_development_dependency 'mysql2'
|
25
|
+
spec.add_development_dependency 'rake'
|
26
|
+
spec.add_development_dependency 'rspec', '>= 3.0.0'
|
27
|
+
spec.add_development_dependency 'coveralls'
|
25
28
|
end
|
@@ -0,0 +1,173 @@
|
|
1
|
+
describe Activerecord::Mysql::Pkdump do
|
2
|
+
context 'when there is no table' do
|
3
|
+
it do
|
4
|
+
expect(dump).to eq <<-RUBY.strip
|
5
|
+
ActiveRecord::Schema.define(version: 0) do
|
6
|
+
|
7
|
+
end
|
8
|
+
RUBY
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
context 'when PK is `id`(int)' do
|
13
|
+
before do
|
14
|
+
create_tables(:id, 'int(11) primary key auto_increment')
|
15
|
+
end
|
16
|
+
|
17
|
+
it do
|
18
|
+
expect(dump).to eq <<-RUBY.strip
|
19
|
+
ActiveRecord::Schema.define(version: 0) do
|
20
|
+
|
21
|
+
create_table "authors", force: true do |t|
|
22
|
+
t.string "name", null: false
|
23
|
+
t.datetime "created_at"
|
24
|
+
t.datetime "updated_at"
|
25
|
+
end
|
26
|
+
|
27
|
+
create_table "books", force: true do |t|
|
28
|
+
t.string "title", null: false
|
29
|
+
t.integer "author_id", null: false
|
30
|
+
t.datetime "created_at"
|
31
|
+
t.datetime "updated_at"
|
32
|
+
end
|
33
|
+
|
34
|
+
end
|
35
|
+
RUBY
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context 'when PK is `my_id`(int)' do
|
40
|
+
before do
|
41
|
+
create_tables(:my_id, 'int(11) primary key auto_increment')
|
42
|
+
end
|
43
|
+
|
44
|
+
it do
|
45
|
+
expect(dump).to eq <<-RUBY.strip
|
46
|
+
ActiveRecord::Schema.define(version: 0) do
|
47
|
+
|
48
|
+
create_table "authors", primary_key: "my_id", force: true do |t|
|
49
|
+
t.string "name", null: false
|
50
|
+
t.datetime "created_at"
|
51
|
+
t.datetime "updated_at"
|
52
|
+
end
|
53
|
+
|
54
|
+
create_table "books", primary_key: "my_id", force: true do |t|
|
55
|
+
t.string "title", null: false
|
56
|
+
t.integer "author_id", null: false
|
57
|
+
t.datetime "created_at"
|
58
|
+
t.datetime "updated_at"
|
59
|
+
end
|
60
|
+
|
61
|
+
end
|
62
|
+
RUBY
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
context 'when PK is `id`(bigint)' do
|
67
|
+
before do
|
68
|
+
create_tables(:id, 'bigint primary key auto_increment')
|
69
|
+
end
|
70
|
+
|
71
|
+
it do
|
72
|
+
expect(dump).to eq <<-RUBY.strip
|
73
|
+
ActiveRecord::Schema.define(version: 0) do
|
74
|
+
|
75
|
+
create_table "authors", id: "bigint(20) PRIMARY KEY auto_increment", force: true do |t|
|
76
|
+
t.string "name", null: false
|
77
|
+
t.datetime "created_at"
|
78
|
+
t.datetime "updated_at"
|
79
|
+
end
|
80
|
+
|
81
|
+
create_table "books", id: "bigint(20) PRIMARY KEY auto_increment", force: true do |t|
|
82
|
+
t.string "title", null: false
|
83
|
+
t.integer "author_id", null: false
|
84
|
+
t.datetime "created_at"
|
85
|
+
t.datetime "updated_at"
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
89
|
+
RUBY
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
context 'when PK is `my_id`(bigint)' do
|
94
|
+
before do
|
95
|
+
create_tables(:my_id, 'bigint primary key auto_increment')
|
96
|
+
end
|
97
|
+
|
98
|
+
it do
|
99
|
+
expect(dump).to eq <<-RUBY.strip
|
100
|
+
ActiveRecord::Schema.define(version: 0) do
|
101
|
+
|
102
|
+
create_table "authors", primary_key: "my_id", id: "bigint(20) PRIMARY KEY auto_increment", force: true do |t|
|
103
|
+
t.string "name", null: false
|
104
|
+
t.datetime "created_at"
|
105
|
+
t.datetime "updated_at"
|
106
|
+
end
|
107
|
+
|
108
|
+
create_table "books", primary_key: "my_id", id: "bigint(20) PRIMARY KEY auto_increment", force: true do |t|
|
109
|
+
t.string "title", null: false
|
110
|
+
t.integer "author_id", null: false
|
111
|
+
t.datetime "created_at"
|
112
|
+
t.datetime "updated_at"
|
113
|
+
end
|
114
|
+
|
115
|
+
end
|
116
|
+
RUBY
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
context 'when PK is `id`(varchar(255))' do
|
121
|
+
before do
|
122
|
+
create_tables(:id, 'varchar(255) primary key')
|
123
|
+
end
|
124
|
+
|
125
|
+
it do
|
126
|
+
expect(dump).to eq <<-RUBY.strip
|
127
|
+
ActiveRecord::Schema.define(version: 0) do
|
128
|
+
|
129
|
+
create_table "authors", id: "varchar(255) PRIMARY KEY", force: true do |t|
|
130
|
+
t.string "name", null: false
|
131
|
+
t.datetime "created_at"
|
132
|
+
t.datetime "updated_at"
|
133
|
+
end
|
134
|
+
|
135
|
+
create_table "books", id: "varchar(255) PRIMARY KEY", force: true do |t|
|
136
|
+
t.string "title", null: false
|
137
|
+
t.integer "author_id", null: false
|
138
|
+
t.datetime "created_at"
|
139
|
+
t.datetime "updated_at"
|
140
|
+
end
|
141
|
+
|
142
|
+
end
|
143
|
+
RUBY
|
144
|
+
end
|
145
|
+
end
|
146
|
+
|
147
|
+
context 'when PK is `my_id`(varchar(255))' do
|
148
|
+
before do
|
149
|
+
create_tables(:my_id, 'varchar(255) primary key')
|
150
|
+
end
|
151
|
+
|
152
|
+
it do
|
153
|
+
expect(dump).to eq <<-RUBY.strip
|
154
|
+
ActiveRecord::Schema.define(version: 0) do
|
155
|
+
|
156
|
+
create_table "authors", primary_key: "my_id", id: "varchar(255) PRIMARY KEY", force: true do |t|
|
157
|
+
t.string "name", null: false
|
158
|
+
t.datetime "created_at"
|
159
|
+
t.datetime "updated_at"
|
160
|
+
end
|
161
|
+
|
162
|
+
create_table "books", primary_key: "my_id", id: "varchar(255) PRIMARY KEY", force: true do |t|
|
163
|
+
t.string "title", null: false
|
164
|
+
t.integer "author_id", null: false
|
165
|
+
t.datetime "created_at"
|
166
|
+
t.datetime "updated_at"
|
167
|
+
end
|
168
|
+
|
169
|
+
end
|
170
|
+
RUBY
|
171
|
+
end
|
172
|
+
end
|
173
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
if ENV['TRAVIS']
|
2
|
+
require 'simplecov'
|
3
|
+
require 'coveralls'
|
4
|
+
|
5
|
+
SimpleCov.formatter = Coveralls::SimpleCov::Formatter
|
6
|
+
SimpleCov.start do
|
7
|
+
add_filter "spec/"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
require 'active_record'
|
12
|
+
require 'activerecord-mysql-pkdump'
|
13
|
+
|
14
|
+
TEST_DATABASE = 'activerecord_mysql_pkdump_test'
|
15
|
+
|
16
|
+
RSpec.configure do |config|
|
17
|
+
config.before(:all) do
|
18
|
+
ActiveRecord::Base.establish_connection(
|
19
|
+
adapter: 'mysql2',
|
20
|
+
database: TEST_DATABASE,
|
21
|
+
)
|
22
|
+
end
|
23
|
+
|
24
|
+
config.before(:each) do
|
25
|
+
clean_database
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
def mysql
|
30
|
+
client = nil
|
31
|
+
retval = nil
|
32
|
+
|
33
|
+
begin
|
34
|
+
client = Mysql2::Client.new(
|
35
|
+
host: 'localhost',
|
36
|
+
username: 'root',
|
37
|
+
)
|
38
|
+
|
39
|
+
retval = yield(client)
|
40
|
+
ensure
|
41
|
+
client.close if client
|
42
|
+
end
|
43
|
+
|
44
|
+
retval
|
45
|
+
end
|
46
|
+
|
47
|
+
def create_database(client)
|
48
|
+
client.query("CREATE DATABASE #{TEST_DATABASE}")
|
49
|
+
end
|
50
|
+
|
51
|
+
def drop_database(client)
|
52
|
+
client.query("DROP DATABASE IF EXISTS #{TEST_DATABASE}")
|
53
|
+
end
|
54
|
+
|
55
|
+
def clean_database
|
56
|
+
mysql do |client|
|
57
|
+
drop_database(client)
|
58
|
+
create_database(client)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def create_tables(pk_name, pk_type)
|
63
|
+
mysql do |client|
|
64
|
+
client.query("USE #{TEST_DATABASE}")
|
65
|
+
|
66
|
+
client.query(<<-SQL)
|
67
|
+
CREATE TABLE books (
|
68
|
+
`#{pk_name}` #{pk_type},
|
69
|
+
`title` varchar(255) NOT NULL,
|
70
|
+
`author_id` int(10) unsigned NOT NULL,
|
71
|
+
`created_at` datetime DEFAULT NULL,
|
72
|
+
`updated_at` datetime DEFAULT NULL
|
73
|
+
) DEFAULT CHARSET=utf8
|
74
|
+
SQL
|
75
|
+
|
76
|
+
client.query(<<-SQL)
|
77
|
+
CREATE TABLE authors (
|
78
|
+
`#{pk_name}` #{pk_type},
|
79
|
+
`name` varchar(255) NOT NULL,
|
80
|
+
`created_at` datetime DEFAULT NULL,
|
81
|
+
`updated_at` datetime DEFAULT NULL
|
82
|
+
) DEFAULT CHARSET=utf8;
|
83
|
+
SQL
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def dump
|
88
|
+
conn = ActiveRecord::Base.connection
|
89
|
+
stream = StringIO.new
|
90
|
+
ActiveRecord::SchemaDumper.dump(conn, stream)
|
91
|
+
stream.string.gsub(/^#.*$/, '').strip
|
92
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activerecord-mysql-pkdump
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Genki Sugawara
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-11-
|
11
|
+
date: 2014-11-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -66,6 +66,48 @@ dependencies:
|
|
66
66
|
- - '>='
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 3.0.0
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 3.0.0
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: coveralls
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - '>='
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
69
111
|
description: Dump the type information of a non-standard primary key.
|
70
112
|
email:
|
71
113
|
- sgwr_dts@yahoo.co.jp
|
@@ -74,6 +116,8 @@ extensions: []
|
|
74
116
|
extra_rdoc_files: []
|
75
117
|
files:
|
76
118
|
- .gitignore
|
119
|
+
- .rspec
|
120
|
+
- .travis.yml
|
77
121
|
- Gemfile
|
78
122
|
- LICENSE.txt
|
79
123
|
- README.md
|
@@ -82,6 +126,8 @@ files:
|
|
82
126
|
- lib/activerecord-mysql-pkdump.rb
|
83
127
|
- lib/activerecord/mysql/pkdump.rb
|
84
128
|
- lib/activerecord/mysql/pkdump/version.rb
|
129
|
+
- spec/activerecord-mysql-pkdump_spec.rb
|
130
|
+
- spec/spec_helper.rb
|
85
131
|
homepage: https://github.com/winebarrel/activerecord-mysql-pkdump
|
86
132
|
licenses:
|
87
133
|
- MIT
|
@@ -106,4 +152,6 @@ rubygems_version: 2.0.14
|
|
106
152
|
signing_key:
|
107
153
|
specification_version: 4
|
108
154
|
summary: Dump the type information of a non-standard primary key.
|
109
|
-
test_files:
|
155
|
+
test_files:
|
156
|
+
- spec/activerecord-mysql-pkdump_spec.rb
|
157
|
+
- spec/spec_helper.rb
|