ridgepole 0.6.5 → 0.6.6.beta

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: c0b8970049df58ea142eb1bc723846cb5099eb5b
4
- data.tar.gz: 886ba18f1c6b97e60756241ec8d4d6bc7e2e5c94
3
+ metadata.gz: 43b2e1e6fe82bc1adaecdf2e03682a3bd1756e2d
4
+ data.tar.gz: 30ca92eea9cd6296e88293671a04d2511a4b3141
5
5
  SHA512:
6
- metadata.gz: 9806a409967575629a43d02b7cf9bf1ee42345a89fd7d004ab41b9c853bbc340434e5c4aa8b92db6ed707a5f26c612d3cda8c1d63ecb937ff6f1b612b1a1e110
7
- data.tar.gz: d2491149f7e4d0f73747832c65e7b69b77232f6f6995a5845b90146e98fc94d5d058013242c2598282b12ba3d5cb3ccf2ccaac3741fe8cafe442808a0d08e557
6
+ metadata.gz: 6eef1346bb2cbd9884ebe22728fbb22456e393fb2fdc39b44d274f6bad03d5bffed364131216fa37500e2498ce87760786adb6e4e1141b288fe0e9327d5f9936
7
+ data.tar.gz: 073a3053fd3a2a2932d34cb03fc7122f13a283d50d7e73bca56c0bea03b7035f6d494d62d6724d1224163eadbfa53faa84c94357a428b1d6129517cea135b55e
data/.travis.yml CHANGED
@@ -5,8 +5,9 @@ cache:
5
5
  - bundler
6
6
  - apt
7
7
  rvm:
8
- - 2.2.5
9
- - 2.3.3
8
+ - 2.2.7
9
+ - 2.3.4
10
+ - 2.4.1
10
11
  before_install:
11
12
  - gem install bundler
12
13
  before_script:
data/README.md CHANGED
@@ -13,7 +13,7 @@ It defines DB schema using [Rails DSL](http://guides.rubyonrails.org/migrations.
13
13
 
14
14
  Please don't use the following nameless fk:
15
15
 
16
- ```ruby
16
+ ```ruby
17
17
  add_foreign_key :articles, :authors # without `name:`
18
18
  ```
19
19
 
@@ -69,6 +69,10 @@ add_foreign_key :articles, :authors # without `name:`
69
69
  * Support DDL Comment (Rails5 only)
70
70
  * Output schema diff when pass `--verbose`
71
71
  * Support composite primary key (Rails5 only / [pull#97](https://github.com/winebarrel/ridgepole/pull/97))
72
+ * `>= 0.6.6`
73
+ * Use `t.column` for migration ([pull#114](https://github.com/winebarrel/ridgepole/pull/114))
74
+ * Support DATABASE_URL format ([pull#118](https://github.com/winebarrel/ridgepole/pull/118))
75
+ * Add Ruby2.4 CI ([pull#119](https://github.com/winebarrel/ridgepole/pull/119))
72
76
 
73
77
  ## Installation
74
78
 
@@ -138,7 +142,9 @@ encoding: utf8
138
142
  database: blog
139
143
  username: root
140
144
 
141
- $ ridgepole -c config.yml --export -o Schemafile # or `ridgepole -c '{adapter: mysql2, database: blog}' ...`
145
+ $ ridgepole -c config.yml --export -o Schemafile
146
+ # or `ridgepole -c '{adapter: mysql2, database: blog}' ...`
147
+ # or `ridgepole -c 'mysql2://root:3306@127.0.0.1/blog' ...`
142
148
  Export Schema to `Schemafile`
143
149
 
144
150
  $ cat Schemafile
@@ -2,6 +2,6 @@
2
2
 
3
3
  source "https://rubygems.org"
4
4
 
5
- gem "activerecord", ">= 5.0.0"
5
+ gem "activerecord", "~> 5.0.0"
6
6
 
7
7
  gemspec :path => "../"
@@ -4,15 +4,16 @@ require 'yaml'
4
4
  class Ridgepole::Config
5
5
  class << self
6
6
  def load(config, env = 'development')
7
- parsed_config = if File.exist?(config)
8
- parse_config_file(config)
9
- else
10
- YAML.load(ERB.new(config).result)
11
- end
7
+ if File.exist?(config)
8
+ parsed_config = parse_config_file(config)
9
+ elsif (expanded = File.expand_path(config)) and File.exist?(expanded)
10
+ parsed_config = parse_config_file(expanded)
11
+ else
12
+ parsed_config = YAML.load(ERB.new(config).result)
13
+ end
12
14
 
13
15
  unless parsed_config.kind_of?(Hash)
14
- config = File.expand_path(config)
15
- parse_config = parse_config_file(config)
16
+ parsed_config = parse_database_url(config)
16
17
  end
17
18
 
18
19
  if parsed_config.has_key?(env.to_s)
@@ -28,5 +29,21 @@ class Ridgepole::Config
28
29
  yaml = ERB.new(File.read(path)).result
29
30
  YAML.load(yaml)
30
31
  end
31
- end # of class methods
32
+
33
+ def parse_database_url(config)
34
+ uri = URI.parse(config)
35
+
36
+ if [uri.scheme, uri.user, uri.password, uri.host, uri.path].any? {|i| i.nil? }
37
+ raise "Invalid config: #{config.inspect}"
38
+ end
39
+
40
+ {
41
+ 'adapter' => uri.scheme,
42
+ 'username' => uri.user,
43
+ 'password' => uri.password,
44
+ 'host' => uri.host,
45
+ 'database' => uri.path.sub(%r|\A/|, ''),
46
+ }
47
+ end
48
+ end # of class methods
32
49
  end
@@ -227,7 +227,7 @@ create_table(#{table_name.inspect}, #{inspect_options_include_default_proc(optio
227
227
  normalize_limit(column_type, column_options)
228
228
 
229
229
  buf.puts(<<-EOS)
230
- t.#{column_type}(#{column_name.inspect}, #{inspect_options_include_default_proc(column_options)})
230
+ t.column(#{column_name.inspect}, :#{column_type.to_s.inspect}, #{inspect_options_include_default_proc(column_options)})
231
231
  EOS
232
232
  end
233
233
 
@@ -1,3 +1,3 @@
1
1
  module Ridgepole
2
- VERSION = '0.6.5'
2
+ VERSION = '0.6.6.beta'
3
3
  end
@@ -71,6 +71,29 @@ describe Ridgepole::Config do
71
71
  end
72
72
  end
73
73
 
74
+ context 'when passed yaml file' do
75
+ let(:config) {
76
+ <<-YAML.strip_heredoc
77
+ adapter: mysql2
78
+ encoding: utf8
79
+ database: blog
80
+ username: root
81
+ YAML
82
+ }
83
+ let(:env) { 'development' }
84
+ it {
85
+ Tempfile.create("database.yml") do |f|
86
+ f.puts config
87
+ f.flush
88
+
89
+ expect(subject['adapter']).to eq "mysql2"
90
+ expect(subject['encoding']).to eq "utf8"
91
+ expect(subject['database']).to eq "blog"
92
+ expect(subject['username']).to eq "root"
93
+ end
94
+ }
95
+ end
96
+
74
97
  context 'when passed unexisting yaml' do
75
98
  let(:config) {
76
99
  'database.yml'
@@ -81,7 +104,19 @@ describe Ridgepole::Config do
81
104
  it {
82
105
  expect {
83
106
  subject
84
- }.to raise_error Errno::ENOENT
107
+ }.to raise_error 'Invalid config: "database.yml"'
108
+ }
109
+ end
110
+
111
+ context 'when passed DATABASE_URL' do
112
+ let(:config) { 'mysql2://root:1234@127.0.0.1/blog' }
113
+ let(:env) { 'development' }
114
+
115
+ it {
116
+ expect(subject['adapter']).to eq "mysql2"
117
+ expect(subject['database']).to eq "blog"
118
+ expect(subject['username']).to eq "root"
119
+ expect(subject['password']).to eq "1234"
85
120
  }
86
121
  end
87
122
  end
@@ -19,8 +19,8 @@ describe 'Ridgepole::Client#diff -> migrate' do
19
19
 
20
20
  expect(delta.script).to match_fuzzy <<-EOS
21
21
  create_table("employee_clubs", {:options=>"ENGINE=MyISAM CHARSET=utf8"}) do |t|
22
- t.integer("emp_no", {:null=>false, :unsigned=>true, :limit=>4})
23
- t.integer("club_id", {:null=>false, :unsigned=>true, :limit=>4})
22
+ t.column("emp_no", :"integer", {:null=>false, :unsigned=>true, :limit=>4})
23
+ t.column("club_id", :"integer", {:null=>false, :unsigned=>true, :limit=>4})
24
24
  end
25
25
  add_index("employee_clubs", ["emp_no", "club_id"], {:name=>"idx_emp_no_club_id", :using=>:btree})
26
26
  EOS
@@ -135,22 +135,22 @@ describe 'Ridgepole::Client#diff -> migrate' do
135
135
  expect(delta.differ?).to be_truthy
136
136
  expect(delta.script).to match_fuzzy erbh(<<-EOS)
137
137
  create_table("clubs", <%= unsigned(true) %>) do |t|
138
- t.string("name", <%= limit(255) >> {default: "", null: false, limit: 255} %>)
138
+ t.column("name", :"string", <%= limit(255) >> {default: "", null: false, limit: 255} %>)
139
139
  end
140
140
  add_index("clubs", ["name"], {:name=>"idx_name", :unique=>true, :using=>:btree})
141
141
 
142
142
  create_table("employee_clubs", <%= unsigned(true) %>) do |t|
143
- t.integer("emp_no", <%= limit(4) >> {null: false, limit: 4} + unsigned(true) %>)
144
- t.integer("club_id", <%= limit(4) >> {null: false, limit: 4} + unsigned(true) %>)
143
+ t.column("emp_no", :"integer", <%= limit(4) >> {null: false, limit: 4} + unsigned(true) %>)
144
+ t.column("club_id", :"integer", <%= limit(4) >> {null: false, limit: 4} + unsigned(true) %>)
145
145
  end
146
146
  add_index("employee_clubs", ["emp_no", "club_id"], {:name=>"idx_emp_no_club_id", :using=>:btree})
147
147
 
148
148
  create_table("employees", <%= {primary_key: "emp_no"} + unsigned(true) %>) do |t|
149
- t.date("birth_date", {:null=>false})
150
- t.string("first_name", {:limit=>14, :null=>false})
151
- t.string("last_name", {:limit=>16, :null=>false})
152
- t.string("gender", {:limit=>1, :null=>false})
153
- t.date("hire_date", {:null=>false})
149
+ t.column("birth_date", :"date", {:null=>false})
150
+ t.column("first_name", :"string", {:limit=>14, :null=>false})
151
+ t.column("last_name", :"string", {:limit=>16, :null=>false})
152
+ t.column("gender", :"string", {:limit=>1, :null=>false})
153
+ t.column("hire_date", :"date", {:null=>false})
154
154
  end
155
155
  EOS
156
156
  }
@@ -134,21 +134,21 @@ describe 'Ridgepole::Client#diff -> migrate' do
134
134
  expect(delta.differ?).to be_truthy
135
135
  expect(delta.script).to match_fuzzy <<-EOS
136
136
  create_table("clubs", {}) do |t|
137
- t.string("name", {:limit=>255, :default=>"", :null=>false})
137
+ t.column("name", :"string", {:limit=>255, :default=>"", :null=>false})
138
138
  end
139
139
  add_index("clubs", ["name"], {:name=>"idx_name", :unique=>true, :using=>:btree})
140
140
 
141
141
  create_table("employee_clubs", {}) do |t|
142
- t.integer("emp_no", {:null=>false})
143
- t.integer("club_id", {:null=>false})
142
+ t.column("emp_no", :"integer", {:null=>false})
143
+ t.column("club_id", :"integer", {:null=>false})
144
144
  end
145
145
  add_index("employee_clubs", ["emp_no", "club_id"], {:name=>"idx_employee_clubs_emp_no_club_id", :using=>:btree})
146
146
 
147
147
  create_table("employees", {:primary_key=>"emp_no"}) do |t|
148
- t.date("birth_date", {:null=>false})
149
- t.string("first_name", {:limit=>14, :null=>false})
150
- t.string("last_name", {:limit=>16, :null=>false})
151
- t.date("hire_date", {:null=>false})
148
+ t.column("birth_date", :"date", {:null=>false})
149
+ t.column("first_name", :"string", {:limit=>14, :null=>false})
150
+ t.column("last_name", :"string", {:limit=>16, :null=>false})
151
+ t.column("hire_date", :"date", {:null=>false})
152
152
  end
153
153
  EOS
154
154
  }
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.6.5
4
+ version: 0.6.6.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-01-13 00:00:00.000000000 Z
11
+ date: 2017-06-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -360,12 +360,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
360
360
  version: '0'
361
361
  required_rubygems_version: !ruby/object:Gem::Requirement
362
362
  requirements:
363
- - - ">="
363
+ - - ">"
364
364
  - !ruby/object:Gem::Version
365
- version: '0'
365
+ version: 1.3.1
366
366
  requirements: []
367
367
  rubyforge_project:
368
- rubygems_version: 2.5.1
368
+ rubygems_version: 2.5.2
369
369
  signing_key:
370
370
  specification_version: 4
371
371
  summary: Ridgepole is a tool to manage DB schema.