ridgepole 0.7.0.alpha3 → 0.7.0.beta

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5cbdcb1cafcede044e48cfd8b7a9c2799c96c98a
4
- data.tar.gz: 6c9a147a2162f3c51110d9b1ee6051229638760c
3
+ metadata.gz: 396b70e0da23ec61bcfcbf048b12ddce3b982372
4
+ data.tar.gz: 42cd06dddcc39e058530cb7593bfa24163ad3252
5
5
  SHA512:
6
- metadata.gz: e9f9c72ae55df7d7dce3dd7a68fd4d5b37bdd5a43df49ed5c8038ad272242cbfdf305e2f5af415f6606057a94505f61b00f7dd9e6a23bfa43b6d9d980ac27dbf
7
- data.tar.gz: 6356712998757d48fc5c54e3feef06e4c3580eed2d5cb81b265af9267fb3ebf3def563e81d38dc3761c5b1dcfe3e251399fcb22787df3b84c242023d03108b92
6
+ metadata.gz: 055eff66d521e0a05b3d7bd5000833cd59abc9f93d363dd2dba91ace2cd0d5812c77fc197d5a0d16033d280d414a7da6974daf3b35af41f5981fb16a331656e4
7
+ data.tar.gz: a2340a631b404bf1341c0a6d9de8350fdb221ac33492ba16b3d08161fc362ff46f9e838d502c1a161734e77424e2004761e1b5e85562cf2e514de60ecadae2ee
data/README.md CHANGED
@@ -6,21 +6,10 @@ It defines DB schema using [Rails DSL](http://guides.rubyonrails.org/migrations.
6
6
  (like Chef/Puppet)
7
7
 
8
8
  [![Gem Version](https://badge.fury.io/rb/ridgepole.svg)](http://badge.fury.io/rb/ridgepole)
9
+ [![Edge Version](https://img.shields.io/badge/edge%20version-0.7.0.beta-green.svg)](https://rubygems.org/gems/ridgepole/versions/0.7.0.beta)
9
10
  [![Build Status](https://travis-ci.org/winebarrel/ridgepole.svg?branch=master)](https://travis-ci.org/winebarrel/ridgepole)
10
11
  [![Coverage Status](https://coveralls.io/repos/winebarrel/ridgepole/badge.svg?branch=master)](https://coveralls.io/r/winebarrel/ridgepole?branch=master)
11
12
 
12
- **Important**
13
-
14
- Please don't use the following nameless fk:
15
-
16
- ```ruby
17
- add_foreign_key :articles, :authors # without `name:`
18
- ```
19
-
20
- **It is highly recommended to give a name to the fk explicitly.**
21
-
22
- ![](https://cdn.pbrd.co/images/8Ymz6nU5x.gif)
23
-
24
13
  **Notice**
25
14
 
26
15
  * `>= 0.4.8`
@@ -80,6 +69,8 @@ add_foreign_key :articles, :authors # without `name:`
80
69
  * Add `--skip-drop-table` option
81
70
  * Support foreign key without name
82
71
  * Support MySQL JSON Type and Generated Columns
72
+ * Add `--mysql-change-table-options` option
73
+ * Pass config from env
83
74
 
84
75
  ## Installation
85
76
 
@@ -130,6 +121,7 @@ Usage: ridgepole [options]
130
121
  --dump-with-default-fk-name
131
122
  --index-removed-drop-column
132
123
  --skip-drop-table
124
+ --mysql-change-table-options
133
125
  -r, --require LIBS
134
126
  --log-file LOG_FILE
135
127
  --verbose
@@ -151,7 +143,8 @@ username: root
151
143
 
152
144
  $ ridgepole -c config.yml --export -o Schemafile
153
145
  # or `ridgepole -c '{adapter: mysql2, database: blog}' ...`
154
- # or `ridgepole -c 'mysql2://root:3306@127.0.0.1/blog' ...`
146
+ # or `ridgepole -c 'mysql2://root:pass@127.0.0.1:3306/blog' ...`
147
+ # or `export DB_URL='mysql2://...'; ridgepole -c env:DB_URL ...`
155
148
  Export Schema to `Schemafile`
156
149
 
157
150
  $ cat Schemafile
@@ -230,10 +223,6 @@ add_index "child", ["parent_id"], name: "par_ind", using: :btree
230
223
  add_foreign_key "child", "parent", name: "child_ibfk_1"
231
224
  ```
232
225
 
233
- **Notice:** **It is highly recommended to give a name to the fk explicitly.**
234
-
235
- Please pass `--dump-with-default-fk-name` option if you want to use the nameless index.
236
-
237
226
  ## Collation/Charset
238
227
  You can use the column collation by passing `--enable-mysql-awesome` ([activerecord-mysql-awesome](https://github.com/kamipo/activerecord-mysql-awesome) is required)
239
228
 
data/bin/ridgepole CHANGED
@@ -114,6 +114,7 @@ ARGV.options do |opt|
114
114
  opt.on('', '--dump-with-default-fk-name') { options[:dump_with_default_fk_name] = true }
115
115
  opt.on('', '--index-removed-drop-column') { options[:index_removed_drop_column] = true }
116
116
  opt.on('', '--skip-drop-table') { options[:skip_drop_table] = true }
117
+ opt.on('', '--mysql-change-table-options') { options[:mysql_change_table_options] = true }
117
118
  opt.on('-r', '--require LIBS', Array) {|v| v.each {|i| require i } }
118
119
  opt.on('' , '--log-file LOG_FILE') {|v| options[:log_file] = v }
119
120
  opt.on('' , '--verbose') { Ridgepole::Logger.verbose = true }
@@ -4,6 +4,10 @@ require 'yaml'
4
4
  class Ridgepole::Config
5
5
  class << self
6
6
  def load(config, env = 'development')
7
+ if config =~ /\Aenv:(.+)\z/
8
+ config = ENV.fetch($1)
9
+ end
10
+
7
11
  if File.exist?(config)
8
12
  parsed_config = parse_config_file(config)
9
13
  elsif (expanded = File.expand_path(config)) and File.exist?(expanded)
@@ -22,7 +22,9 @@ class Ridgepole::Client
22
22
  require 'ridgepole/ext/schema_dumper'
23
23
  end
24
24
 
25
- require 'ridgepole/ext/abstract_mysql_adapter/disable_table_options'
25
+ if @options[:dump_without_table_options]
26
+ require 'ridgepole/ext/abstract_mysql_adapter/disable_table_options'
27
+ end
26
28
  end
27
29
 
28
30
  def dump(&block)
@@ -269,10 +269,20 @@ drop_table(#{table_name.inspect})
269
269
  buf.puts
270
270
  end
271
271
 
272
+ def append_change_table_options(table_name, table_options, buf)
273
+ # XXX: MySQL only
274
+ buf.puts(<<-EOS)
275
+ execute "ALTER TABLE #{ActiveRecord::Base.connection.quote_table_name(table_name)} #{table_options}"
276
+ EOS
277
+
278
+ buf.puts
279
+ end
280
+
272
281
  def append_change(table_name, attrs, buf, buf_for_fk)
273
282
  definition = attrs[:definition] || {}
274
283
  indices = attrs[:indices] || {}
275
284
  foreign_keys = attrs[:foreign_keys] || {}
285
+ table_options = attrs[:table_options]
276
286
 
277
287
  if not definition.empty? or not indices.empty?
278
288
  append_change_table(table_name, buf) do
@@ -285,6 +295,10 @@ drop_table(#{table_name.inspect})
285
295
  append_change_foreign_keys(table_name, foreign_keys, buf_for_fk, @options)
286
296
  end
287
297
 
298
+ if table_options
299
+ append_change_table_options(table_name, table_options, buf)
300
+ end
301
+
288
302
  buf.puts
289
303
  buf_for_fk.puts
290
304
  end
@@ -101,10 +101,21 @@ class Ridgepole::Diff
101
101
 
102
102
  normalize_default_proc_options!(from, to)
103
103
 
104
+ from_options = from[:options] || {}
105
+ to_options = to[:options] || {}
106
+
107
+ if @options[:mysql_change_table_options] and from_options != to_options and Ridgepole::ConnectionAdapters.mysql?
108
+ from.delete(:options)
109
+ to.delete(:options)
110
+ table_delta[:table_options] = to_options
111
+ end
112
+
104
113
  unless from == to
105
- Ridgepole::Logger.instance.warn("[WARNING] No difference of schema configuration for table `#{table_name}` but table options differ.")
106
- Ridgepole::Logger.instance.warn(" from: #{from}")
107
- Ridgepole::Logger.instance.warn(" to: #{to}")
114
+ @logger.warn(<<-EOS)
115
+ [WARNING] No difference of schema configuration for table `#{table_name}` but table options differ.
116
+ from: #{from}
117
+ to: #{to}
118
+ EOS
108
119
  end
109
120
  end
110
121
 
@@ -1,3 +1,3 @@
1
1
  module Ridgepole
2
- VERSION = '0.7.0.alpha3'
2
+ VERSION = '0.7.0.beta'
3
3
  end
@@ -0,0 +1,38 @@
1
+ describe 'Ridgepole::Client#diff -> migrate' do
2
+ context 'when change mysql table options' do
3
+ let(:actual_dsl) {
4
+ erbh(<<-EOS)
5
+ create_table "employees", primary_key: "emp_no", force: :cascade, options: "ENGINE=MyISAM DEFAULT CHARSET=utf8" do |t|
6
+ t.date "birth_date", null: false
7
+ t.string "first_name", limit: 14, null: false
8
+ t.string "last_name", limit: 16, null: false
9
+ t.string "gender", limit: 1, null: false
10
+ t.date "hire_date", null: false
11
+ end
12
+ EOS
13
+ }
14
+
15
+ let(:expected_dsl) {
16
+ erbh(<<-EOS)
17
+ create_table "employees", primary_key: "emp_no", force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=ascii" do |t|
18
+ t.date "birth_date", null: false
19
+ t.string "first_name", limit: 14, null: false
20
+ t.string "last_name", limit: 16, null: false
21
+ t.string "gender", limit: 1, null: false
22
+ t.date "hire_date", null: false
23
+ end
24
+ EOS
25
+ }
26
+
27
+ before { subject.diff(actual_dsl).migrate }
28
+ subject { client(dump_without_table_options: false, mysql_change_table_options: true) }
29
+
30
+ it {
31
+ delta = subject.diff(expected_dsl)
32
+ expect(delta.differ?).to be_truthy
33
+ expect(subject.dump).to match_fuzzy actual_dsl
34
+ delta.migrate
35
+ expect(subject.dump).to match_fuzzy expected_dsl
36
+ }
37
+ end
38
+ end
@@ -109,14 +109,33 @@ describe Ridgepole::Config do
109
109
  end
110
110
 
111
111
  context 'when passed DATABASE_URL' do
112
- let(:config) { 'mysql2://root:1234@127.0.0.1/blog' }
112
+ let(:config) { 'mysql2://root:pass@127.0.0.1:3307/blog' }
113
113
  let(:env) { 'development' }
114
114
 
115
115
  it {
116
116
  expect(subject['adapter']).to eq "mysql2"
117
117
  expect(subject['database']).to eq "blog"
118
118
  expect(subject['username']).to eq "root"
119
- expect(subject['password']).to eq "1234"
119
+ expect(subject['password']).to eq "pass"
120
+ expect(subject['port']).to eq 3307
121
+ }
122
+ end
123
+
124
+ context 'when passed DATABASE_URL from ENV' do
125
+ let(:config) { 'env:DATABASE_URL' }
126
+ let(:env) { 'development' }
127
+
128
+ before {
129
+ allow(ENV).to receive(:fetch).with('DATABASE_URL').
130
+ and_return('mysql2://root:pass@127.0.0.1:3307/blog')
131
+ }
132
+
133
+ it {
134
+ expect(subject['adapter']).to eq "mysql2"
135
+ expect(subject['database']).to eq "blog"
136
+ expect(subject['username']).to eq "root"
137
+ expect(subject['password']).to eq "pass"
138
+ expect(subject['port']).to eq 3307
120
139
  }
121
140
  end
122
141
  end
@@ -45,6 +45,7 @@ describe 'ridgepole' do
45
45
  --dump-with-default-fk-name
46
46
  --index-removed-drop-column
47
47
  --skip-drop-table
48
+ --mysql-change-table-options
48
49
  -r, --require LIBS
49
50
  --log-file LOG_FILE
50
51
  --verbose
@@ -28,9 +28,11 @@ describe 'Ridgepole::Client#diff -> migrate' do
28
28
  subject { client }
29
29
 
30
30
  it {
31
- expect(Ridgepole::Logger.instance).to receive(:warn).with("[WARNING] No difference of schema configuration for table `employees` but table options differ.")
32
- expect(Ridgepole::Logger.instance).to receive(:warn).with(erbh(%Q! from: {:primary_key=>"emp_no"}!))
33
- expect(Ridgepole::Logger.instance).to receive(:warn).with(erbh(%Q! to: {:primary_key=>"emp_no2"}!))
31
+ expect(Ridgepole::Logger.instance).to receive(:warn).with(<<-EOS)
32
+ [WARNING] No difference of schema configuration for table `employees` but table options differ.
33
+ from: {:primary_key=>"emp_no"}
34
+ to: {:primary_key=>"emp_no2"}
35
+ EOS
34
36
  delta = subject.diff(expected_dsl)
35
37
  expect(delta.differ?).to be_falsey
36
38
  expect(subject.dump).to match_fuzzy actual_dsl
@@ -39,9 +41,11 @@ describe 'Ridgepole::Client#diff -> migrate' do
39
41
  }
40
42
 
41
43
  it {
42
- expect(Ridgepole::Logger.instance).to receive(:warn).with("[WARNING] No difference of schema configuration for table `employees` but table options differ.")
43
- expect(Ridgepole::Logger.instance).to receive(:warn).with(erbh(%Q! from: {:primary_key=>"emp_no2"}!))
44
- expect(Ridgepole::Logger.instance).to receive(:warn).with(erbh(%Q! to: {:primary_key=>"emp_no"}!))
44
+ expect(Ridgepole::Logger.instance).to receive(:warn).with(<<-EOS)
45
+ [WARNING] No difference of schema configuration for table `employees` but table options differ.
46
+ from: {:primary_key=>"emp_no2"}
47
+ to: {:primary_key=>"emp_no"}
48
+ EOS
45
49
  delta = Ridgepole::Client.diff(actual_dsl, expected_dsl, reverse: true)
46
50
  expect(delta.differ?).to be_falsey
47
51
  }
@@ -78,9 +78,11 @@ describe 'Ridgepole::Client#diff -> migrate' do
78
78
  subject { client }
79
79
 
80
80
  it {
81
- expect(Ridgepole::Logger.instance).to receive(:warn).with("[WARNING] No difference of schema configuration for table `users` but table options differ.")
82
- expect(Ridgepole::Logger.instance).to receive(:warn).with(erbh(%Q! from: {:id=>:uuid, :default=>"uuid_generate_v1()"}!))
83
- expect(Ridgepole::Logger.instance).to receive(:warn).with(erbh(%Q! to: {:id=>:uuid, :default=>"uuid_generate_v4()"}!))
81
+ expect(Ridgepole::Logger.instance).to receive(:warn).with(<<-EOS)
82
+ [WARNING] No difference of schema configuration for table `users` but table options differ.
83
+ from: {:id=>:uuid, :default=>"uuid_generate_v1()"}
84
+ to: {:id=>:uuid, :default=>"uuid_generate_v4()"}
85
+ EOS
84
86
 
85
87
  delta = subject.diff(expected_dsl)
86
88
  expect(delta.differ?).to be_falsey
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ridgepole
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0.alpha3
4
+ version: 0.7.0.beta
5
5
  platform: ruby
6
6
  authors:
7
7
  - Genki Sugawara
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-25 00:00:00.000000000 Z
11
+ date: 2017-06-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -244,6 +244,7 @@ files:
244
244
  - spec/cli_helper.rb
245
245
  - spec/erb_helper.rb
246
246
  - spec/hide_pending_formatter.rb
247
+ - spec/mysql/_migrate/migrate_change_table_option_spec.rb
247
248
  - spec/mysql/bigint_pk/bigint_pk_spec.rb
248
249
  - spec/mysql/bigint_pk/int_pk_spec.rb
249
250
  - spec/mysql/cli/config_spec.rb
@@ -384,6 +385,7 @@ test_files:
384
385
  - spec/cli_helper.rb
385
386
  - spec/erb_helper.rb
386
387
  - spec/hide_pending_formatter.rb
388
+ - spec/mysql/_migrate/migrate_change_table_option_spec.rb
387
389
  - spec/mysql/bigint_pk/bigint_pk_spec.rb
388
390
  - spec/mysql/bigint_pk/int_pk_spec.rb
389
391
  - spec/mysql/cli/config_spec.rb