miguel 0.1.0.pre7 → 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/.gitignore +2 -0
- data/.yardopts +3 -0
- data/LICENSE +19 -0
- data/lib/miguel/command.rb +42 -30
- data/lib/miguel/importer.rb +48 -37
- data/miguel.gemspec +1 -1
- metadata +6 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 61b3d0863a5a9089a0d0721ada2efdb173dbfe98
|
4
|
+
data.tar.gz: d30974c4416aa48a0f9c1698877fc4851c875d3b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7036e0cea3a88e677c17dbb8cb0775b11771b74c21e38fc032326f36029347c321893e6b1fd646027b374a53707701fc75d22e75bd15dc051375775c850c0ec5
|
7
|
+
data.tar.gz: 878b6ff4b7cf5f457da0207de21335783c9a806e3fc059694cf71dbc8c7de29e1e3d3fcc16ab3fa1f3410df85688c7a4f9339f0c79921847a8c12016b4b1447e
|
data/.gitignore
CHANGED
data/.yardopts
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2015 Patrik Rak (patrik@raxoft.cz)
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/lib/miguel/command.rb
CHANGED
@@ -102,36 +102,48 @@ module Miguel
|
|
102
102
|
# Execute the command itself.
|
103
103
|
def execute( args )
|
104
104
|
command = args.shift or fail "Missing command, use -h to see usage."
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
105
|
+
method = "execute_#{command}"
|
106
|
+
fail "Invalid command, use -h to see usage." unless respond_to?( method, true )
|
107
|
+
check_args( args, method( method ).arity )
|
108
|
+
send( method, *args )
|
109
|
+
end
|
110
|
+
|
111
|
+
# Execute the show command.
|
112
|
+
def execute_show( name )
|
113
|
+
schema = get_schema( name )
|
114
|
+
print schema.dump
|
115
|
+
end
|
116
|
+
|
117
|
+
# Execute the dump command.
|
118
|
+
def execute_dump( name )
|
119
|
+
schema = get_schema( name )
|
120
|
+
show_changes( Schema.new, schema )
|
121
|
+
end
|
122
|
+
|
123
|
+
# Execute the down command.
|
124
|
+
def execute_down( name )
|
125
|
+
schema = get_schema( name )
|
126
|
+
show_changes( schema, Schema.new )
|
127
|
+
end
|
128
|
+
|
129
|
+
# Execute the diff command.
|
130
|
+
def execute_diff( old_name, new_name )
|
131
|
+
old_schema = get_schema( old_name )
|
132
|
+
new_schema = get_schema( new_name )
|
133
|
+
show_changes( old_schema, new_schema )
|
134
|
+
end
|
135
|
+
|
136
|
+
# Execute the apply command.
|
137
|
+
def execute_apply( db_name, name )
|
138
|
+
db = get_db( db_name )
|
139
|
+
schema = get_schema( name )
|
140
|
+
apply_schema( db, schema )
|
141
|
+
end
|
142
|
+
|
143
|
+
# Execute the clear command.
|
144
|
+
def execute_clear( db_name )
|
145
|
+
db = get_db( db_name )
|
146
|
+
apply_schema( db, Schema.new )
|
135
147
|
end
|
136
148
|
|
137
149
|
# Make sure the argument count is as expected.
|
data/lib/miguel/importer.rb
CHANGED
@@ -36,46 +36,48 @@ module Miguel
|
|
36
36
|
end
|
37
37
|
end
|
38
38
|
|
39
|
-
# Convert given database type to type and optional options used by our schema definitions.
|
40
|
-
|
41
|
-
|
39
|
+
# Convert given MySQL database type to type and optional options used by our schema definitions.
|
40
|
+
def revert_mysql_type( type )
|
41
|
+
case type
|
42
|
+
when /\Aint\(\d+\)\z/
|
43
|
+
return :integer, :default_size => 11
|
44
|
+
when /\Aint\(\d+\) unsigned\z/
|
45
|
+
return :integer, :unsigned => true, :default_size => 10
|
46
|
+
when /\Abigint\(\d+\)\z/
|
47
|
+
return :bigint, :default_size => 20
|
48
|
+
when /\Adecimal\(\d+,\d+\)\z/
|
49
|
+
return :decimal, :default_size => [ 10, 0 ]
|
50
|
+
when /\A(enum|set)\((.*)\)\z/
|
51
|
+
return $1.to_sym, :elements => parse_elements( $2 )
|
52
|
+
end
|
53
|
+
end
|
42
54
|
|
43
|
-
|
55
|
+
# Convert given SQLite database type to type and optional options used by our schema definitions.
|
56
|
+
def revert_sqlite_type( type )
|
57
|
+
case type
|
58
|
+
when /\Ainteger UNSIGNED\z/
|
59
|
+
return :integer, :unsigned => true
|
60
|
+
end
|
61
|
+
end
|
44
62
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
end
|
59
|
-
when :sqlite
|
60
|
-
case type
|
61
|
-
when /\Ainteger UNSIGNED\z/
|
62
|
-
return :integer, :unsigned => true
|
63
|
-
end
|
64
|
-
when :postgres
|
65
|
-
case type
|
66
|
-
when /\Acharacter varying/
|
67
|
-
return :String, :default_size => 255
|
68
|
-
when /\Acharacter/
|
69
|
-
return :String, :fixed => true, :default_size => 255
|
70
|
-
when /\Atext\z/
|
71
|
-
return :String, :text => true
|
72
|
-
when /\Abytea\z/
|
73
|
-
return :blob
|
74
|
-
when /\Atimestamp/
|
75
|
-
return :timestamp
|
76
|
-
end
|
63
|
+
# Convert given Postgres database type to type and optional options used by our schema definitions.
|
64
|
+
def revert_postgres_type( type )
|
65
|
+
case type
|
66
|
+
when /\Acharacter varying/
|
67
|
+
return :String, :default_size => 255
|
68
|
+
when /\Acharacter/
|
69
|
+
return :String, :fixed => true, :default_size => 255
|
70
|
+
when /\Atext\z/
|
71
|
+
return :String, :text => true
|
72
|
+
when /\Abytea\z/
|
73
|
+
return :blob
|
74
|
+
when /\Atimestamp/
|
75
|
+
return :timestamp
|
77
76
|
end
|
77
|
+
end
|
78
78
|
|
79
|
+
# Convert given generic database type to type and optional options used by our schema definitions.
|
80
|
+
def revert_generic_type( type )
|
79
81
|
case type
|
80
82
|
when /\Avarchar/
|
81
83
|
return :String, :default_size => 255
|
@@ -88,8 +90,17 @@ module Miguel
|
|
88
90
|
when /\A\w+\z/
|
89
91
|
return type.to_sym
|
90
92
|
end
|
93
|
+
end
|
94
|
+
|
95
|
+
# Convert given database type to type and optional options used by our schema definitions.
|
96
|
+
# The ruby type provided serves as a hint of what Sequel's idea of the type is.
|
97
|
+
def revert_type_literal_internal( type, ruby_type )
|
98
|
+
return :boolean, :default_size => 1 if ruby_type == :boolean
|
99
|
+
|
100
|
+
method = "revert_#{db.database_type}_type"
|
101
|
+
specific_type = send( method, type ) if respond_to?( method, true )
|
91
102
|
|
92
|
-
ruby_type
|
103
|
+
specific_type || revert_generic_type( type ) || ruby_type
|
93
104
|
end
|
94
105
|
|
95
106
|
# Convert given database type to type and optional options used by our schema definitions.
|
data/miguel.gemspec
CHANGED
@@ -4,7 +4,7 @@ require File.expand_path( '../lib/miguel/version', __FILE__ )
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = 'miguel'
|
7
|
-
s.version = Miguel::VERSION
|
7
|
+
s.version = Miguel::VERSION
|
8
8
|
s.summary = 'Database migrator and migration generator for Sequel.'
|
9
9
|
s.description = <<EOT
|
10
10
|
This gem makes it easy to create and maintain an up-to-date database schema
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: miguel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Patrik Rak
|
@@ -92,6 +92,8 @@ files:
|
|
92
92
|
- ".gitignore"
|
93
93
|
- ".travis.gemfile"
|
94
94
|
- ".travis.yml"
|
95
|
+
- ".yardopts"
|
96
|
+
- LICENSE
|
95
97
|
- README.md
|
96
98
|
- Rakefile
|
97
99
|
- bin/miguel
|
@@ -144,9 +146,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
144
146
|
version: 1.9.3
|
145
147
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
146
148
|
requirements:
|
147
|
-
- - "
|
149
|
+
- - ">="
|
148
150
|
- !ruby/object:Gem::Version
|
149
|
-
version:
|
151
|
+
version: '0'
|
150
152
|
requirements: []
|
151
153
|
rubyforge_project:
|
152
154
|
rubygems_version: 2.4.5.1
|
@@ -154,3 +156,4 @@ signing_key:
|
|
154
156
|
specification_version: 4
|
155
157
|
summary: Database migrator and migration generator for Sequel.
|
156
158
|
test_files: []
|
159
|
+
has_rdoc:
|