scheman 0.0.4 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -0
- data/CHANGELOG.md +3 -0
- data/README.md +41 -20
- data/Rakefile +3 -0
- data/lib/scheman/parsers/mysql.rb +6 -8
- data/lib/scheman/version.rb +1 -1
- data/spec/scheman/parsers/mysql_spec.rb +11 -1
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2fc602f3aa02ac3f06f48d632a05ffa7f7784fd7
|
4
|
+
data.tar.gz: f44bbc67da9d9bae8e12ff783d186f305e355181
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: acd3b64fdcd250a3af7883586527239f115ac5104e5f236baed6cd366dffc7984336ffaa1afb7f94dadfd7881b2c534418c5b06c72c1674945d86389ed9a1aa7
|
7
|
+
data.tar.gz: bfe6787b4b0b10ec11ff296c72cf1157a191856611a35b7e2d9dc48830958cb70769a173faf877ead5b222b1b7f7f869084b52754a9573aeae2c8383454dd8cb
|
data/.travis.yml
ADDED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,55 +1,50 @@
|
|
1
|
-
# Scheman
|
1
|
+
# Scheman [![Build Status](https://travis-ci.org/r7kamura/scheman.svg?branch=master)](https://travis-ci.org/r7kamura/scheman)
|
2
2
|
SQL schema parser.
|
3
3
|
|
4
4
|
## Usage
|
5
|
-
Create diff from 2 schema files.
|
5
|
+
Create diff from 2 schema files or input.
|
6
6
|
|
7
|
-
```
|
8
|
-
|
9
|
-
|
10
|
-
before = <<-SQL
|
7
|
+
```sql
|
8
|
+
# before.sql
|
11
9
|
CREATE TABLE `table1` (
|
12
|
-
`column1` INTEGER(11) PRIMARY KEY NOT NULL
|
10
|
+
`column1` INTEGER(11) PRIMARY KEY NOT NULL AUTO_INCREMENT,
|
13
11
|
`column2` DATETIME DEFAULT NOW()
|
14
12
|
);
|
15
13
|
|
16
14
|
CREATE TABLE `table2` (
|
17
|
-
`column1` INTEGER(11) NOT NULL
|
15
|
+
`column1` INTEGER(11) NOT NULL AUTO_INCREMENT,
|
18
16
|
PRIMARY KEY (`column1`)
|
19
17
|
);
|
20
|
-
|
18
|
+
```
|
21
19
|
|
22
|
-
|
20
|
+
```sql
|
21
|
+
# after.sql
|
23
22
|
CREATE TABLE `table1` (
|
24
|
-
`column1` CHAR(11) NOT NULL
|
23
|
+
`column1` CHAR(11) NOT NULL AUTO_INCREMENT,
|
25
24
|
`column2` DATETIME DEFAULT CURRENT_TIMESTAMP(),
|
26
25
|
`column3` VARCHAR(255) NOT NULL DEFAULT "a",
|
27
26
|
PRIMARY KEY (`column2`)
|
28
27
|
);
|
29
28
|
|
30
29
|
CREATE TABLE `table3` (
|
31
|
-
`column1` INTEGER(11) NOT NULL
|
30
|
+
`column1` INTEGER(11) NOT NULL AUTO_INCREMENT,
|
32
31
|
PRIMARY KEY (`column1`)
|
33
32
|
);
|
34
|
-
SQL
|
35
|
-
|
36
|
-
puts Scheman::Diff.new(before: before, after: after, type: "mysql")
|
37
33
|
```
|
38
34
|
|
39
|
-
|
40
|
-
|
41
|
-
```sql
|
35
|
+
```sh
|
36
|
+
$ scheman diff --before before.sql --after after.sql
|
42
37
|
BEGIN;
|
43
38
|
|
44
39
|
SET foreign_key_checks=0;
|
45
40
|
|
46
41
|
CREATE TABLE `table3` (
|
47
|
-
`column1` INTEGER(11) NOT NULL
|
42
|
+
`column1` INTEGER(11) NOT NULL AUTO_INCREMENT,
|
48
43
|
PRIMARY KEY (`column1`)
|
49
44
|
);
|
50
45
|
|
51
46
|
ALTER TABLE `table1` ADD COLUMN `column3` VARCHAR(255) NOT NULL DEFAULT "a",
|
52
|
-
CHANGE COLUMN `column1` CHAR(11) NOT NULL
|
47
|
+
CHANGE COLUMN `column1` CHAR(11) NOT NULL AUTO_INCREMENT,
|
53
48
|
DROP PRIMARY KEY,
|
54
49
|
ADD PRIMARY KEY `column2`;
|
55
50
|
|
@@ -59,3 +54,29 @@ SET foreign_key_checks=1;
|
|
59
54
|
|
60
55
|
COMMIT;
|
61
56
|
```
|
57
|
+
|
58
|
+
### STDIN
|
59
|
+
You can input schema data into `scheman diff` command via STDIN, instead of --before.
|
60
|
+
For instance, this interface is useful when you want to use `mysqldump` command to get your current schema.
|
61
|
+
|
62
|
+
```sh
|
63
|
+
$ mysqldump --no-data --compact db_name | scheman diff --after after.sql
|
64
|
+
```
|
65
|
+
|
66
|
+
### ./schema.sql
|
67
|
+
Scheman use `./schema.sql` as a default value of --after option.
|
68
|
+
|
69
|
+
```sh
|
70
|
+
$ mysqldump --no-data --compact db_name | scheman diff
|
71
|
+
```
|
72
|
+
|
73
|
+
### Pipes
|
74
|
+
Here is an example workflow of schema modification, using UNIX pipes.
|
75
|
+
|
76
|
+
```sh
|
77
|
+
$ vi schema.sql
|
78
|
+
$ mysqldump --no-data --compact db_name | scheman diff | mysql db_name
|
79
|
+
```
|
80
|
+
|
81
|
+
### Rails
|
82
|
+
[scheman-rails](https://github.com/r7kamura/scheman-rails) provides some rake tasks to use scheman with Rails.
|
data/Rakefile
CHANGED
@@ -195,17 +195,17 @@ module Scheman
|
|
195
195
|
end
|
196
196
|
|
197
197
|
rule(:comment_table_option) do
|
198
|
-
case_insensitive_str("comment") >> spaces? >> str("=") >> spaces? >> single_quoted(match("[^']").repeat(1))
|
198
|
+
case_insensitive_str("comment") >> (spaces? >> str("=") >> spaces? | spaces) >> single_quoted(match("[^']").repeat(1))
|
199
199
|
end
|
200
200
|
|
201
201
|
rule(:charset_table_option) do
|
202
202
|
case_insensitive_str("default ").maybe >>
|
203
203
|
(case_insensitive_str("charset") | case_insensitive_str("character set")) >>
|
204
|
-
spaces? >> str("=") >> spaces? >> word
|
204
|
+
(spaces? >> str("=") >> spaces? | spaces) >> word
|
205
205
|
end
|
206
206
|
|
207
207
|
rule(:other_table_option) do
|
208
|
-
word >> spaces? >> str("=") >> spaces? >> (word | single_quoted(word) | double_quoted(word))
|
208
|
+
word >> (spaces? >> str("=") >> spaces? | spaces) >> (word | single_quoted(word) | double_quoted(word))
|
209
209
|
end
|
210
210
|
|
211
211
|
rule(:table_components) do
|
@@ -273,7 +273,7 @@ module Scheman
|
|
273
273
|
end
|
274
274
|
|
275
275
|
rule(:index_name) do
|
276
|
-
identifier.as(:index_name)
|
276
|
+
(quoted_identifier | identifier).as(:index_name)
|
277
277
|
end
|
278
278
|
|
279
279
|
# TODO: Fix spaces not to allow no space
|
@@ -403,7 +403,7 @@ module Scheman
|
|
403
403
|
end
|
404
404
|
|
405
405
|
rule(:column_name) do
|
406
|
-
quoted_identifier.as(:column_name)
|
406
|
+
(quoted_identifier | identifier).as(:column_name)
|
407
407
|
end
|
408
408
|
|
409
409
|
rule(:value) do
|
@@ -442,9 +442,7 @@ module Scheman
|
|
442
442
|
|
443
443
|
rule(:quoted_identifier) do
|
444
444
|
(
|
445
|
-
|
446
|
-
double_quoted(match('[^"]').repeat(1)) |
|
447
|
-
back_quoted(match("[^`]").repeat(1))
|
445
|
+
back_quoted(match("[^`]").repeat(1))
|
448
446
|
).as(:quoted_identifier)
|
449
447
|
end
|
450
448
|
|
data/lib/scheman/version.rb
CHANGED
@@ -417,7 +417,7 @@ describe Scheman::Parsers::Mysql do
|
|
417
417
|
|
418
418
|
context "with KEY" do
|
419
419
|
let(:str) do
|
420
|
-
"CREATE TABLE `table1` (`column1` INTEGER, KEY index1 (`column1`));"
|
420
|
+
"CREATE TABLE `table1` (`column1` INTEGER, KEY `index1` (`column1`));"
|
421
421
|
end
|
422
422
|
|
423
423
|
it "succeeds in parse" do
|
@@ -554,5 +554,15 @@ describe Scheman::Parsers::Mysql do
|
|
554
554
|
expect { subject }.not_to raise_error
|
555
555
|
end
|
556
556
|
end
|
557
|
+
|
558
|
+
context "'=' character is optional in create table options" do
|
559
|
+
let(:str) do
|
560
|
+
"CREATE TABLE `table1` (`column1` INTEGER) COMMENT 'hoge' ENGINE MyISAM DEFAULT CHARACTER SET latin1;"
|
561
|
+
end
|
562
|
+
|
563
|
+
it "succeeds in parse" do
|
564
|
+
expect { subject }.not_to raise_error
|
565
|
+
end
|
566
|
+
end
|
557
567
|
end
|
558
568
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scheman
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryo Nakamura
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-02-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -117,6 +117,7 @@ extensions: []
|
|
117
117
|
extra_rdoc_files: []
|
118
118
|
files:
|
119
119
|
- ".gitignore"
|
120
|
+
- ".travis.yml"
|
120
121
|
- CHANGELOG.md
|
121
122
|
- Gemfile
|
122
123
|
- LICENSE.txt
|
@@ -161,7 +162,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
161
162
|
version: '0'
|
162
163
|
requirements: []
|
163
164
|
rubyforge_project:
|
164
|
-
rubygems_version: 2.
|
165
|
+
rubygems_version: 2.4.5
|
165
166
|
signing_key:
|
166
167
|
specification_version: 4
|
167
168
|
summary: SQL schema parser.
|