miguel 0.1.0 → 0.2.0.pre1
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/.travis.yml +10 -3
- data/README.md +3 -1
- data/lib/miguel/importer.rb +2 -0
- data/lib/miguel/schema.rb +7 -7
- data/lib/miguel/version.rb +1 -1
- data/miguel.gemspec +1 -1
- data/test/data/schema.rb +5 -0
- data/test/helper.rb +6 -7
- data/test/test_importer.rb +4 -0
- data/test/test_schema.rb +59 -0
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db64f119440c5bd20619f533da327d507a3eeba4
|
4
|
+
data.tar.gz: 6e01ec299c5885be17dfd67e392310aec359e490
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9256996f5840ec7d95c46c537120dccbdd40ab13ba9e679eaef08145f38b104389792c841697a13b62bdc3a892d36c2ef90d5fa2ce9265aeb410eb50bc66e40e
|
7
|
+
data.tar.gz: 7ad8d557c2c4aacbe3e9a5152f252517148920a8aa6cc5cba5775cd9ccb009d8b42157fe160dbe3864d9f2900643a1eeef2c1201ad003c43b7509198b8a7a4dd
|
data/.travis.yml
CHANGED
@@ -3,11 +3,15 @@
|
|
3
3
|
language: ruby
|
4
4
|
rvm:
|
5
5
|
- ruby-head
|
6
|
-
- 2.
|
7
|
-
- 2.
|
6
|
+
- 2.6.3
|
7
|
+
- 2.5.5
|
8
|
+
- 2.4.6
|
9
|
+
- 2.3.8
|
10
|
+
- 2.2.10
|
11
|
+
- 2.1.10
|
8
12
|
- 2.0.0
|
9
13
|
- 1.9.3
|
10
|
-
- rbx-
|
14
|
+
- rbx-3
|
11
15
|
- jruby-head
|
12
16
|
- jruby-19mode
|
13
17
|
gemfile: .travis.gemfile
|
@@ -15,9 +19,12 @@ env:
|
|
15
19
|
global:
|
16
20
|
# travis encrypt CODECLIMATE_REPO_TOKEN=???
|
17
21
|
secure: WjkizgQWf8gx1KIfPsX99TR6uJgnF9ybHUtu/kz0JHWYNif8IJ7qsO+kCXzdGtTiwMgQL4cHzYqbGa6VAiiPQMmG9NPLZ1Q4STLW9W4afg2lOqQmyGk0iSapEu/YXlWM6kZW4IcY/4BG8DzgfJnzy6+4yWBGZFdMwcpJEVZpy02c3Y6RBsrFJ6wz1BpWZR8bHaFXrLzfpHeS8t8h1OYetf1RLg9MvPvankkoIBBxw6ahV9QhG1O2cXyzlfH30wQA90stTFOybUkJ/hVLlCXyxEbjuhUKTWeU4s/Uw5XhA3k5ll0GWyaTUQU3aSWwTDv2Z/dncwR2y8RMuGJqHVLcTz2jtb+NINncrYq5ybGUaCNpdJea7/OS4R6M9t2VS666j5dPN4tVsTgyAONzgHHEmTYwHk3s9s4EKyoHAl398Kv/dazwSmBasvc1kIDzsi6n83k4MHMSNFTBlA4Jz0LaQ7Qx0hxS7MIsGhDmVeeEOQOw1idof6hQdBCpcLfO9NCxqRFWYAgK99U5mXjqRWBeQGyEwrtgbvyweanDrFfHtVEQpUrW1Do4zNz9jZ+MS43hKViu3loH3y20w8Vi96UXWoDp/RreLGMpM33V3xzCC+U3Ex1Dckoq0TgQ8RFD3U/d0KdQJ02B8C3iRmNqD43jGJEJl5USnT58gwgPumLwoCs=
|
22
|
+
after_success:
|
23
|
+
- bundle exec codeclimate-test-reporter
|
18
24
|
matrix:
|
19
25
|
allow_failures:
|
20
26
|
- rvm: ruby-head
|
27
|
+
- rvm: rbx-3
|
21
28
|
- rvm: jruby-19mode
|
22
29
|
- rvm: jruby-head
|
23
30
|
before_script:
|
data/README.md
CHANGED
@@ -139,6 +139,8 @@ Finally, the `timestamps` helper can be used to create the
|
|
139
139
|
If you pass the `mysql_timestamps: true` option to `define`,
|
140
140
|
the `update_time` timestamp will have the MySQL auto-update feature enabled,
|
141
141
|
and timestamps will use the `'0000-00-00 00:00:00'` default by default.
|
142
|
+
The latter can be also enabled and disabled explicitly by setting
|
143
|
+
the `zero_timestamps` option to `true` or `false`, respectively.
|
142
144
|
|
143
145
|
## Using the command
|
144
146
|
|
@@ -208,7 +210,7 @@ and adjust the schema description accordingly.
|
|
208
210
|
|
209
211
|
## Credits
|
210
212
|
|
211
|
-
Copyright © 2015 Patrik Rak
|
213
|
+
Copyright © 2015-2019 Patrik Rak
|
212
214
|
|
213
215
|
Miguel is released under the MIT license.
|
214
216
|
|
data/lib/miguel/importer.rb
CHANGED
@@ -45,6 +45,8 @@ module Miguel
|
|
45
45
|
return :integer, :unsigned => true, :default_size => 10
|
46
46
|
when /\Abigint\(\d+\)\z/
|
47
47
|
return :bigint, :default_size => 20
|
48
|
+
when /\Abigint\(\d+\) unsigned\z/
|
49
|
+
return :bigint, :unsigned => true, :default_size => 20
|
48
50
|
when /\Adecimal\(\d+,\d+\)\z/
|
49
51
|
return :decimal, :default_size => [ 10, 0 ]
|
50
52
|
when /\A(enum|set)\((.*)\)\z/
|
data/lib/miguel/schema.rb
CHANGED
@@ -158,7 +158,7 @@ module Miguel
|
|
158
158
|
# Default options implied for certain types.
|
159
159
|
DEFAULT_OPTS = {
|
160
160
|
:string => { :size => 255, :text => false },
|
161
|
-
:bigint => { :size => 20 },
|
161
|
+
:bigint => { :size => 20, :unsigned => false },
|
162
162
|
:decimal => { :size => [ 10, 0 ] },
|
163
163
|
:integer => { :unsigned => false },
|
164
164
|
:time => { :only_time => true },
|
@@ -302,7 +302,7 @@ module Miguel
|
|
302
302
|
|
303
303
|
# The +method_missing+ doesn't take care of constant like methods (like String :name),
|
304
304
|
# so those have to be defined explicitly for each such supported type.
|
305
|
-
for type in Sequel::Schema::Generator::GENERIC_TYPES
|
305
|
+
for type in (defined?(Sequel::Schema::CreateTableGenerator) ? Sequel::Schema::CreateTableGenerator::GENERIC_TYPES : Sequel::Schema::Generator::GENERIC_TYPES)
|
306
306
|
class_eval( "def #{type}(*args) ; @table.add_definition(:#{type},*args) ; end", __FILE__, __LINE__ )
|
307
307
|
end
|
308
308
|
|
@@ -317,7 +317,7 @@ module Miguel
|
|
317
317
|
# automatically updated, and let the create one to be set manually.
|
318
318
|
# Also, Sequel doesn't currently honor :on_update for column definitions,
|
319
319
|
# so we have to use default literal to make it work. Sigh.
|
320
|
-
timestamp :create_time, :null => false, :default => ZERO_TIME
|
320
|
+
timestamp :create_time, :null => false, :default => ( opts[ :zero_timestamps ] == false ? DEFAULT_TIME : ZERO_TIME )
|
321
321
|
timestamp :update_time, :null => false, :default => Sequel.lit( 'CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP' )
|
322
322
|
else
|
323
323
|
Time :create_time
|
@@ -371,9 +371,9 @@ module Miguel
|
|
371
371
|
end
|
372
372
|
|
373
373
|
# Add foreign key definition.
|
374
|
-
def add_foreign_key( columns, table_name,
|
375
|
-
add_column( :integer, columns,
|
376
|
-
@foreign_keys << ForeignKey.new( columns, table_name,
|
374
|
+
def add_foreign_key( columns, table_name, opts = {} )
|
375
|
+
add_column( opts[:type] || :integer, columns, opts ) unless columns.is_a? Array
|
376
|
+
@foreign_keys << ForeignKey.new( columns, table_name, opts )
|
377
377
|
end
|
378
378
|
|
379
379
|
# Add definition of column, index or foreign key.
|
@@ -580,7 +580,7 @@ module Miguel
|
|
580
580
|
# we have to be careful to turn off the MySQL autoupdate behavior.
|
581
581
|
# That's why we have to set defaults explicitly.
|
582
582
|
|
583
|
-
default_time = opts[ :mysql_timestamps ] ? ZERO_TIME : DEFAULT_TIME
|
583
|
+
default_time = ( opts[ :zero_timestamps ] || ( opts[ :mysql_timestamps ] && opts[ :zero_timestamps ].nil? ) ) ? ZERO_TIME : DEFAULT_TIME
|
584
584
|
set_defaults :Time, :timestamp, :default => default_time
|
585
585
|
set_defaults :Time?, :timestamp, :default => nil
|
586
586
|
|
data/lib/miguel/version.rb
CHANGED
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 + '.pre1'
|
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
|
data/test/data/schema.rb
CHANGED
@@ -76,6 +76,11 @@ Miguel::Schema.define( use_defaults: false ) do
|
|
76
76
|
index :user_id
|
77
77
|
end
|
78
78
|
|
79
|
+
table :bigint do
|
80
|
+
primary_key :id, type: :bigint
|
81
|
+
foreign_key :bigint_id, :bigint, type: :bigint
|
82
|
+
end if mysql
|
83
|
+
|
79
84
|
table :reuse do
|
80
85
|
primary_key :user_id
|
81
86
|
foreign_key [:user_id], :users
|
data/test/helper.rb
CHANGED
@@ -6,18 +6,17 @@ def jruby?
|
|
6
6
|
defined?( RUBY_ENGINE ) and RUBY_ENGINE == 'jruby'
|
7
7
|
end
|
8
8
|
|
9
|
-
if ENV[ 'COVERAGE' ]
|
10
|
-
require 'simplecov'
|
11
|
-
SimpleCov.start
|
12
|
-
end
|
13
|
-
|
14
9
|
begin
|
15
10
|
require 'codeclimate-test-reporter'
|
16
|
-
CodeClimate::TestReporter.start
|
17
11
|
ENV[ 'COVERAGE' ] = 'on'
|
18
12
|
rescue LoadError
|
19
13
|
end unless jruby?
|
20
14
|
|
15
|
+
if ENV[ 'COVERAGE' ]
|
16
|
+
require 'simplecov'
|
17
|
+
SimpleCov.start
|
18
|
+
end
|
19
|
+
|
21
20
|
# Setup helpers.
|
22
21
|
|
23
22
|
DATA_DIR = File.expand_path( "#{__FILE__}/../data" )
|
@@ -35,7 +34,7 @@ class Bacon::Context
|
|
35
34
|
end
|
36
35
|
|
37
36
|
def lines( s )
|
38
|
-
s.to_s.lines.map.with_index{ |l, i| "#{i}:#{l.strip}" }
|
37
|
+
s.to_s.lines.map.with_index{ |l, i| "#{i}:#{l.strip}" } << :EOF
|
39
38
|
end
|
40
39
|
|
41
40
|
def match( a, b )
|
data/test/test_importer.rb
CHANGED
@@ -15,6 +15,10 @@ describe Miguel::Importer do
|
|
15
15
|
{},
|
16
16
|
{ unsigned_keys: true },
|
17
17
|
{ mysql_timestamps: true },
|
18
|
+
{ mysql_timestamps: true, zero_timestamps: true },
|
19
|
+
{ mysql_timestamps: true, zero_timestamps: false },
|
20
|
+
{ zero_timestamps: true },
|
21
|
+
{ zero_timestamps: false },
|
18
22
|
]
|
19
23
|
when :postgres
|
20
24
|
[ signed_unsigned: true ]
|
data/test/test_schema.rb
CHANGED
@@ -229,6 +229,65 @@ describe Miguel::Schema do
|
|
229
229
|
end
|
230
230
|
end
|
231
231
|
|
232
|
+
should 'control zero timestamps explicitly' do
|
233
|
+
match_schema <<-EOT, zero_timestamps: false do
|
234
|
+
table :timestamps do
|
235
|
+
timestamp :t1, :null => false, :default => "2000-01-01 00:00:00"
|
236
|
+
timestamp :t2, :null => true, :default => nil
|
237
|
+
timestamp :create_time, :null => false, :default => "2000-01-01 00:00:00"
|
238
|
+
timestamp :update_time, :null => false, :default => "2000-01-01 00:00:00"
|
239
|
+
end
|
240
|
+
EOT
|
241
|
+
table :timestamps do
|
242
|
+
Time :t1
|
243
|
+
Time? :t2
|
244
|
+
timestamps
|
245
|
+
end
|
246
|
+
end
|
247
|
+
match_schema <<-EOT, zero_timestamps: true do
|
248
|
+
table :timestamps do
|
249
|
+
timestamp :t1, :null => false, :default => "0000-00-00 00:00:00"
|
250
|
+
timestamp :t2, :null => true, :default => nil
|
251
|
+
timestamp :create_time, :null => false, :default => "0000-00-00 00:00:00"
|
252
|
+
timestamp :update_time, :null => false, :default => "0000-00-00 00:00:00"
|
253
|
+
end
|
254
|
+
EOT
|
255
|
+
table :timestamps do
|
256
|
+
Time :t1
|
257
|
+
Time? :t2
|
258
|
+
timestamps
|
259
|
+
end
|
260
|
+
end
|
261
|
+
match_schema <<-EOT, mysql_timestamps: true, zero_timestamps: true do
|
262
|
+
table :timestamps do
|
263
|
+
timestamp :t1, :null => false, :default => "0000-00-00 00:00:00"
|
264
|
+
timestamp :t2, :null => true, :default => nil
|
265
|
+
timestamp :create_time, :null => false, :default => "0000-00-00 00:00:00"
|
266
|
+
timestamp :update_time, :null => false, :default => Sequel.lit("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP")
|
267
|
+
end
|
268
|
+
EOT
|
269
|
+
table :timestamps do
|
270
|
+
Time :t1
|
271
|
+
Time? :t2
|
272
|
+
timestamps
|
273
|
+
end
|
274
|
+
end
|
275
|
+
match_schema <<-EOT, mysql_timestamps: true, zero_timestamps: false do
|
276
|
+
table :timestamps do
|
277
|
+
timestamp :t1, :null => false, :default => "2000-01-01 00:00:00"
|
278
|
+
timestamp :t2, :null => true, :default => nil
|
279
|
+
timestamp :create_time, :null => false, :default => "2000-01-01 00:00:00"
|
280
|
+
timestamp :update_time, :null => false, :default => Sequel.lit("CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP")
|
281
|
+
end
|
282
|
+
EOT
|
283
|
+
table :timestamps do
|
284
|
+
Time :t1
|
285
|
+
Time? :t2
|
286
|
+
timestamps
|
287
|
+
end
|
288
|
+
end
|
289
|
+
end
|
290
|
+
|
232
291
|
should 'support auto-incrementing primary keys' do
|
233
292
|
match_schema <<-EOT do
|
234
293
|
table :pk do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: miguel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0.pre1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Patrik Rak
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-05-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sequel
|
@@ -146,9 +146,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
146
146
|
version: 1.9.3
|
147
147
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
148
148
|
requirements:
|
149
|
-
- - "
|
149
|
+
- - ">"
|
150
150
|
- !ruby/object:Gem::Version
|
151
|
-
version:
|
151
|
+
version: 1.3.1
|
152
152
|
requirements: []
|
153
153
|
rubyforge_project:
|
154
154
|
rubygems_version: 2.4.5.1
|