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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c9d433cde1f5c11fbaa6f05447d646c48164a9ae
4
- data.tar.gz: fc5cdeef2a2ddd96b23fdc815dbfd4e7befd91d8
3
+ metadata.gz: 61b3d0863a5a9089a0d0721ada2efdb173dbfe98
4
+ data.tar.gz: d30974c4416aa48a0f9c1698877fc4851c875d3b
5
5
  SHA512:
6
- metadata.gz: e3f618e52170198078448a50a0fb7673958a5ed3ef7e01eb42226035008e7219d61e5851d7c4b7ceed82bb5e0c878ca95c6cc5b813fbf09684af94e28eaaacb7
7
- data.tar.gz: dd7b64ea4f90f82af8112405a268690311f2ad6d82fce7beab3c7c042394dbf1d0d482c91c8e24b9c12a493e22c3d72f4cb70248158c31adb9d914295486b337
6
+ metadata.gz: 7036e0cea3a88e677c17dbb8cb0775b11771b74c21e38fc032326f36029347c321893e6b1fd646027b374a53707701fc75d22e75bd15dc051375775c850c0ec5
7
+ data.tar.gz: 878b6ff4b7cf5f457da0207de21335783c9a806e3fc059694cf71dbc8c7de29e1e3d3fcc16ab3fa1f3410df85688c7a4f9339f0c79921847a8c12016b4b1447e
data/.gitignore CHANGED
@@ -1,3 +1,5 @@
1
1
  *~
2
2
  /miguel-*.gem
3
3
  /coverage
4
+ /doc
5
+ /.yardoc
@@ -0,0 +1,3 @@
1
+ --markup-provider redcarpet
2
+ --markup markdown
3
+ - README.md LICENSE
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.
@@ -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
- case command
106
- when 'show'
107
- check_args( args, 1 )
108
- schema = get_schema( args.shift )
109
- print schema.dump
110
- when 'dump'
111
- check_args( args, 1 )
112
- schema = get_schema( args.shift )
113
- show_changes( Schema.new, schema )
114
- when 'down'
115
- check_args( args, 1 )
116
- schema = get_schema( args.shift )
117
- show_changes( schema, Schema.new )
118
- when 'diff'
119
- check_args( args, 2 )
120
- old_schema = get_schema( args.shift )
121
- new_schema = get_schema( args.shift )
122
- show_changes( old_schema, new_schema )
123
- when 'apply'
124
- check_args( args, 2 )
125
- db = get_db( args.shift )
126
- schema = get_schema( args.shift )
127
- apply_schema( db, schema )
128
- when 'clear'
129
- check_args( args, 1 )
130
- db = get_db( args.shift )
131
- apply_schema( db, Schema.new )
132
- else
133
- fail "Invalid command, use -h to see usage."
134
- end
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.
@@ -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
- # The ruby type provided serves as a hint of what Sequel's idea of the type is.
41
- def revert_type_literal_internal( type, ruby_type )
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
- return :boolean, :default_size => 1 if ruby_type == :boolean
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
- case db.database_type
46
- when :mysql
47
- case type
48
- when /\Aint\(\d+\)\z/
49
- return :integer, :default_size => 11
50
- when /\Aint\(\d+\) unsigned\z/
51
- return :integer, :unsigned => true, :default_size => 10
52
- when /\Abigint\(\d+\)\z/
53
- return :bigint, :default_size => 20
54
- when /\Adecimal\(\d+,\d+\)\z/
55
- return :decimal, :default_size => [ 10, 0 ]
56
- when /\A(enum|set)\((.*)\)\z/
57
- return $1.to_sym, :elements => parse_elements( $2 )
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.
@@ -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 + '.pre7'
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.pre7
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: 1.3.1
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: