ridgepole 0.6.3.beta2 → 0.6.3.beta3

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: 8de78f0c1a68e3c21972a27b2181a42534920567
4
- data.tar.gz: 81b644deea5beba444ad3f4dcd79d9e816a3398f
3
+ metadata.gz: d9dccc6fb46e2a4ce256f609bc34f20d26e7ee7f
4
+ data.tar.gz: eaeb693abd59b0b18b1af4c08b732a8cee33d3e9
5
5
  SHA512:
6
- metadata.gz: fe51fa0e32f37492ab00ca349c6102d9e1db6e185c958ccbdca63375194f832ddb194f6d4c3280bf9f85e5de909d87c9b225b685afc0c793d66f096c3c103350
7
- data.tar.gz: de8500f55d963d31cf18589dfe238fa1cc6e6b2a327c8707ed6faa2d04cdb8315138d2ef9503b2ed8b8c9e5ae1f7e0cb5ba092f8ebecd17abb3ad07d98fa7bfb
6
+ metadata.gz: 8a509d05ff9be9707428841a5e3de70547a306b4f2177c78e4af3cd6d314b5178f9f7179c504ede8aa19670f3fe78d0a7bafc781f795b4a0a0aea5d6a83c471c
7
+ data.tar.gz: 85818652ad578355c891b4d1fd74669a8506c6399ac02af8996d5f079df89387d3612f071bf37a5d1c05e2f5c237c40f1ff1609534ab99e4ad1e194e0252dd38
data/.travis.yml CHANGED
@@ -8,8 +8,10 @@ script:
8
8
  - bundle exec rake
9
9
  env:
10
10
  matrix:
11
- - ENABLE_MYSQL_AWESOME=0
12
- - ENABLE_MYSQL_AWESOME=1
11
+ - ENABLE_MYSQL_AWESOME=0 ENABLE_MIGRATION_COMMENTS=0
12
+ - ENABLE_MYSQL_AWESOME=1 ENABLE_MIGRATION_COMMENTS=0
13
+ - ENABLE_MYSQL_AWESOME=0 ENABLE_MIGRATION_COMMENTS=1
14
+ - ENABLE_MYSQL_AWESOME=1 ENABLE_MIGRATION_COMMENTS=1
13
15
  - POSTGRESQL=1
14
16
  before_install:
15
17
  - sudo /etc/init.d/postgresql stop
data/README.md CHANGED
@@ -40,6 +40,7 @@ It defines DB schema using [Rails DSL](http://guides.rubyonrails.org/migrations.
40
40
  * Support [PostgreSQL columns](https://github.com/winebarrel/rails/blob/v4.2.1/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb#L79)
41
41
  * `>= 0.6.3`
42
42
  * Fix `default` option ([pull#48](https://github.com/winebarrel/ridgepole/pull/48))
43
+ * Add `--enable-migration-comments` option ([pull#50](https://github.com/winebarrel/ridgepole/pull/50))
43
44
 
44
45
  ## Installation
45
46
 
@@ -86,6 +87,7 @@ Usage: ridgepole [options]
86
87
  --enable-mysql-awesome
87
88
  --dump-without-table-options
88
89
  --index-removed-drop-column
90
+ --enable-migration-comments
89
91
  -r, --require LIBS
90
92
  --log-file LOG_FILE
91
93
  --verbose
data/bin/ridgepole CHANGED
@@ -107,6 +107,7 @@ ARGV.options do |opt|
107
107
  opt.on('', '--enable-mysql-awesome') { options[:enable_mysql_awesome] = true }
108
108
  opt.on('', '--dump-without-table-options') { options[:dump_without_table_options] = true }
109
109
  opt.on('', '--index-removed-drop-column') { options[:index_removed_drop_column] = true }
110
+ opt.on('', '--enable-migration-comments') { options[:enable_migration_comments] = true }
110
111
  opt.on('-r' , '--require LIBS', Array) {|v| v.each {|i| require i } }
111
112
  opt.on('' , '--log-file LOG_FILE') {|v| options[:log_file] = v }
112
113
  opt.on('' , '--verbose') { Ridgepole::Logger.verbose = true }
@@ -14,7 +14,15 @@ class Ridgepole::Client
14
14
  @parser = Ridgepole::DSLParser.new(@options)
15
15
  @diff = Ridgepole::Diff.new(@options)
16
16
 
17
+ if @options[:enable_migration_comments]
18
+ require 'migration_comments'
19
+ end
20
+
17
21
  if @options[:enable_mysql_awesome]
22
+ if @options[:enable_migration_comments]
23
+ require 'ridgepole/ext/migration_comments'
24
+ end
25
+
18
26
  require 'activerecord/mysql/awesome/base'
19
27
  end
20
28
  end
@@ -0,0 +1,37 @@
1
+ require 'migration_comments/active_record/schema_dumper'
2
+
3
+ module MigrationComments::ActiveRecord
4
+ module SchemaDumper
5
+ def append_comments(table, stream)
6
+ table_name = table.inspect.gsub('"', '')
7
+ column_comments = @connection.retrieve_column_comments(table_name)
8
+ comment_stream = StringIO.new
9
+ lines = []
10
+ col_names = {}
11
+
12
+ while (line = stream.gets)
13
+ content = line.chomp
14
+
15
+ if content =~ /t\.\w+\s+"(\w+)"/
16
+ col_names[lines.size] = $1.to_sym
17
+ end
18
+
19
+ lines << content
20
+ end
21
+
22
+ len = col_names.keys.map{|index| lines[index]}.map(&:length).max + 2 unless col_names.empty?
23
+
24
+ lines.each_with_index do |line, index|
25
+ if col_names[index]
26
+ comment = column_comments[col_names[index]]
27
+ line << ' ' * (len - line.length) << "# #{comment}" unless comment.blank?
28
+ end
29
+
30
+ comment_stream.puts line
31
+ end
32
+
33
+ comment_stream.rewind
34
+ comment_stream
35
+ end
36
+ end
37
+ end
@@ -1,3 +1,3 @@
1
1
  module Ridgepole
2
- VERSION = '0.6.3.beta2'
2
+ VERSION = '0.6.3.beta3'
3
3
  end
data/ridgepole.gemspec CHANGED
@@ -26,4 +26,5 @@ Gem::Specification.new do |spec|
26
26
  spec.add_development_dependency 'pg'
27
27
  spec.add_development_dependency 'coveralls'
28
28
  spec.add_development_dependency 'activerecord-mysql-awesome', '>= 0.0.7'
29
+ spec.add_development_dependency 'migration_comments'
29
30
  end
@@ -0,0 +1,45 @@
1
+ unless postgresql?
2
+ if migration_comments_enabled?
3
+ if mysql_awesome_enabled?
4
+ describe 'Ridgepole::Client#diff -> migrate' do
5
+ context 'when change column (add comment)' do
6
+ let(:dsl) {
7
+ <<-RUBY
8
+ create_table "employee_clubs", unsigned: true, force: :cascade, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='テーブルコメント'" do |t|
9
+ t.integer "emp_no", limit: 4, null: false, unsigned: true
10
+ t.integer "club_id", limit: 4, null: false
11
+ t.string "string", limit: 255, null: false, collation: "utf8mb4_bin" # カラムコメント
12
+ t.text "text", limit: 65535, null: false
13
+ end
14
+ RUBY
15
+ }
16
+
17
+ before do
18
+ subject.diff('').migrate
19
+
20
+ ActiveRecord::Base.connection.raw_connection.query(<<-EOS)
21
+ CREATE TABLE `employee_clubs` (
22
+ `id` int(11) unsigned NOT NULL AUTO_INCREMENT,
23
+ `emp_no` int(11) unsigned NOT NULL ,
24
+ `club_id` int(11) NOT NULL ,
25
+ `string` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_bin NOT NULL COMMENT 'カラムコメント',
26
+ `text` text NOT NULL,
27
+ PRIMARY KEY (`id`)
28
+ ) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='テーブルコメント';
29
+ EOS
30
+ end
31
+
32
+ subject do
33
+ client(enable_migration_comments: true, dump_without_table_options: false)
34
+ end
35
+
36
+ it {
37
+ delta = subject.diff(dsl)
38
+ expect(delta.differ?).to be_falsey
39
+ expect(subject.dump).to eq dsl.strip_heredoc.strip
40
+ }
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,183 @@
1
+ unless postgresql?
2
+ if migration_comments_enabled?
3
+ unless mysql_awesome_enabled?
4
+ describe 'Ridgepole::Client#diff -> migrate' do
5
+ context 'when change column (add comment)' do
6
+ let(:actual_dsl) {
7
+ <<-RUBY
8
+ create_table "employee_clubs", force: :cascade do |t|
9
+ t.integer "emp_no", limit: 4, null: false
10
+ t.integer "club_id", limit: 4, null: false
11
+ t.string "string", limit: 255, null: false
12
+ t.text "text", limit: 65535, null: false
13
+ end
14
+ RUBY
15
+ }
16
+
17
+ let(:expected_dsl) {
18
+ <<-RUBY
19
+ create_table "employee_clubs", force: :cascade do |t|
20
+ t.integer "emp_no", limit: 4, null: false, comment: "any comment"
21
+ t.integer "club_id", limit: 4, null: false, comment: "any comment2"
22
+ t.string "string", limit: 255, null: false, comment: "any comment3"
23
+ t.text "text", limit: 65535, null: false, comment: "any comment4"
24
+ end
25
+ RUBY
26
+ }
27
+
28
+ before { subject.diff(actual_dsl).migrate }
29
+ subject { client(enable_migration_comments: true) }
30
+
31
+ it {
32
+ delta = subject.diff(expected_dsl)
33
+ expect(delta.differ?).to be_truthy
34
+ expect(subject.dump).to eq actual_dsl.strip_heredoc.strip
35
+ delta.migrate
36
+ expect(subject.dump).to eq expected_dsl.strip_heredoc.strip
37
+ }
38
+ end
39
+
40
+ context 'when change column (delete comment)' do
41
+ let(:actual_dsl) {
42
+ <<-RUBY
43
+ create_table "employee_clubs", force: :cascade do |t|
44
+ t.integer "emp_no", limit: 4, null: false, comment: "any comment"
45
+ t.integer "club_id", limit: 4, null: false, comment: "any comment2"
46
+ t.string "string", limit: 255, null: false, comment: "any comment3"
47
+ t.text "text", limit: 65535, null: false, comment: "any comment4"
48
+ end
49
+ RUBY
50
+ }
51
+
52
+ let(:expected_dsl) {
53
+ <<-RUBY
54
+ create_table "employee_clubs", force: :cascade do |t|
55
+ t.integer "emp_no", limit: 4, null: false
56
+ t.integer "club_id", limit: 4, null: false
57
+ t.string "string", limit: 255, null: false
58
+ t.text "text", limit: 65535, null: false
59
+ end
60
+ RUBY
61
+ }
62
+
63
+ before { subject.diff(actual_dsl).migrate }
64
+ subject { client(enable_migration_comments: true) }
65
+
66
+ it {
67
+ delta = subject.diff(expected_dsl)
68
+ expect(delta.differ?).to be_truthy
69
+ expect(subject.dump).to eq actual_dsl.strip_heredoc.strip
70
+ delta.migrate
71
+ expect(subject.dump).to eq expected_dsl.strip_heredoc.strip
72
+ }
73
+ end
74
+
75
+ context 'when change column (change comment)' do
76
+ let(:actual_dsl) {
77
+ <<-RUBY
78
+ create_table "employee_clubs", force: :cascade do |t|
79
+ t.integer "emp_no", limit: 4, null: false, comment: "any comment"
80
+ t.integer "club_id", limit: 4, null: false, comment: "any comment2"
81
+ t.string "string", limit: 255, null: false, comment: "any comment3"
82
+ t.text "text", limit: 65535, null: false, comment: "any comment4"
83
+ end
84
+ RUBY
85
+ }
86
+
87
+ let(:expected_dsl) {
88
+ <<-RUBY
89
+ create_table "employee_clubs", force: :cascade do |t|
90
+ t.integer "emp_no", limit: 4, null: false, comment: "other comment"
91
+ t.integer "club_id", limit: 4, null: false, comment: "other comment2"
92
+ t.string "string", limit: 255, null: false, comment: "other comment3"
93
+ t.text "text", limit: 65535, null: false, comment: "other comment4"
94
+ end
95
+ RUBY
96
+ }
97
+
98
+ before { subject.diff(actual_dsl).migrate }
99
+ subject { client(enable_migration_comments: true) }
100
+
101
+ it {
102
+ delta = subject.diff(expected_dsl)
103
+ expect(delta.differ?).to be_truthy
104
+ expect(subject.dump).to eq actual_dsl.strip_heredoc.strip
105
+ delta.migrate
106
+ expect(subject.dump).to eq expected_dsl.strip_heredoc.strip
107
+ }
108
+ end
109
+
110
+ context 'when change column (no change comment)' do
111
+ let(:actual_dsl) {
112
+ <<-RUBY
113
+ create_table "employee_clubs", force: :cascade do |t|
114
+ t.integer "emp_no", limit: 4, null: false, comment: "any comment"
115
+ t.integer "club_id", limit: 4, null: false, comment: "any comment2"
116
+ t.string "string", limit: 255, null: false, comment: "any comment3"
117
+ t.text "text", limit: 65535, null: false, comment: "any comment4"
118
+ end
119
+ RUBY
120
+ }
121
+
122
+ before { subject.diff(actual_dsl).migrate }
123
+ subject { client(enable_migration_comments: true) }
124
+
125
+ it {
126
+ delta = subject.diff(actual_dsl)
127
+ expect(delta.differ?).to be_falsey
128
+ expect(subject.dump).to eq actual_dsl.strip_heredoc.strip
129
+ delta.migrate
130
+ expect(subject.dump).to eq actual_dsl.strip_heredoc.strip
131
+ }
132
+ end
133
+
134
+ context 'when create table (with comment)' do
135
+ let(:expected_dsl) {
136
+ <<-RUBY
137
+ create_table "employee_clubs", force: :cascade, comment: "table comment" do |t|
138
+ t.integer "emp_no", limit: 4, null: false, comment: "other comment"
139
+ t.integer "club_id", limit: 4, null: false, comment: "other comment2"
140
+ t.string "string", limit: 255, null: false, comment: "other comment3"
141
+ t.text "text", limit: 65535, null: false, comment: "other comment4"
142
+ end
143
+ RUBY
144
+ }
145
+
146
+ subject { client(enable_migration_comments: true) }
147
+
148
+ it {
149
+ delta = subject.diff(expected_dsl)
150
+ expect(delta.differ?).to be_truthy
151
+ expect(subject.dump.strip).to be_empty
152
+ delta.migrate
153
+ expect(subject.dump).to eq expected_dsl.strip_heredoc.strip
154
+ }
155
+ end
156
+
157
+ context 'when drop table (with comment)' do
158
+ let(:actual_dsl) {
159
+ <<-RUBY
160
+ create_table "employee_clubs", force: :cascade, comment: "table comment" do |t|
161
+ t.integer "emp_no", limit: 4, null: false, comment: "other comment"
162
+ t.integer "club_id", limit: 4, null: false, comment: "other comment2"
163
+ t.string "string", limit: 255, null: false, comment: "other comment3"
164
+ t.text "text", limit: 65535, null: false, comment: "other comment4"
165
+ end
166
+ RUBY
167
+ }
168
+
169
+ before { subject.diff(actual_dsl).migrate }
170
+ subject { client(enable_migration_comments: true) }
171
+
172
+ it {
173
+ delta = subject.diff('')
174
+ expect(delta.differ?).to be_truthy
175
+ expect(subject.dump).to eq actual_dsl.strip_heredoc.strip
176
+ delta.migrate
177
+ expect(subject.dump).to be_empty
178
+ }
179
+ end
180
+ end
181
+ end
182
+ end
183
+ end
@@ -38,6 +38,7 @@ describe 'ridgepole' do
38
38
  --enable-mysql-awesome
39
39
  --dump-without-table-options
40
40
  --index-removed-drop-column
41
+ --enable-migration-comments
41
42
  -r, --require LIBS
42
43
  --log-file LOG_FILE
43
44
  --verbose
@@ -1,7 +1,3 @@
1
- CREATE DATABASE ridgepole_test;
2
-
3
- \c ridgepole_test;
4
-
5
1
  CREATE EXTENSION hstore;
6
2
  CREATE EXTENSION ltree;
7
3
  CREATE EXTENSION citext;
@@ -1,5 +1,3 @@
1
- \c ridgepole_test;
2
-
3
1
  DROP TABLE IF EXISTS clubs;
4
2
  CREATE TABLE clubs (
5
3
  id serial PRIMARY KEY,
data/spec/spec_helper.rb CHANGED
@@ -48,14 +48,21 @@ def restore_database
48
48
  end
49
49
  end
50
50
 
51
+ def system_raise_on_fail(*args)
52
+ unless system(*args)
53
+ raise RuntimeError.new("Failed to run: #{args}")
54
+ end
55
+ end
56
+
51
57
  def restore_database_mysql
52
58
  sql_file = File.expand_path('../mysql/ridgepole_test_database.sql', __FILE__)
53
- system("mysql -uroot < #{sql_file}")
59
+ system_raise_on_fail("mysql -uroot < #{sql_file}")
54
60
  end
55
61
 
56
62
  def restore_database_postgresql
57
63
  sql_file = File.expand_path('../postgresql/ridgepole_test_database.sql', __FILE__)
58
- system("psql #{travis? ? '-U postgres' : ''} --set ON_ERROR_STOP=off -q -f #{sql_file} 2>/dev/null")
64
+ system("createdb ridgepole_test #{travis? ? '-U postgres' : ''} 2>/dev/null")
65
+ system_raise_on_fail("psql ridgepole_test #{travis? ? '-U postgres' : ''} --set ON_ERROR_STOP=off -q -f #{sql_file} 2>/dev/null")
59
66
  end
60
67
 
61
68
  def restore_tables
@@ -68,12 +75,12 @@ end
68
75
 
69
76
  def restore_tables_mysql
70
77
  sql_file = File.expand_path('../mysql/ridgepole_test_tables.sql', __FILE__)
71
- system("mysql -uroot < #{sql_file}")
78
+ system_raise_on_fail("mysql -uroot < #{sql_file}")
72
79
  end
73
80
 
74
81
  def restore_tables_postgresql
75
82
  sql_file = File.expand_path('../postgresql/ridgepole_test_tables.sql', __FILE__)
76
- system("psql #{travis? ? '-U postgres' : ''} -q -f #{sql_file} 2>/dev/null")
83
+ system_raise_on_fail("psql ridgepole_test #{travis? ? '-U postgres' : ''} -q -f #{sql_file} 2>/dev/null")
77
84
  end
78
85
 
79
86
  def client(options = {}, config = {})
@@ -86,7 +93,6 @@ def client(options = {}, config = {})
86
93
  if mysql_awesome_enabled?
87
94
  default_options[:enable_mysql_awesome] = true
88
95
  default_options[:dump_without_table_options] = true
89
- default_options[:mysql_awesome_unsigned_pk] = true
90
96
  end
91
97
 
92
98
  options = default_options.merge(options)
@@ -193,6 +199,10 @@ def mysql_awesome_enabled?
193
199
  ENV['ENABLE_MYSQL_AWESOME'] == '1'
194
200
  end
195
201
 
202
+ def migration_comments_enabled?
203
+ ENV['ENABLE_MIGRATION_COMMENTS'] == '1'
204
+ end
205
+
196
206
  def postgresql?
197
207
  ENV['POSTGRESQL'] == '1'
198
208
  end
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.3.beta2
4
+ version: 0.6.3.beta3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Genki Sugawara
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-07-15 00:00:00.000000000 Z
11
+ date: 2015-07-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -122,6 +122,20 @@ dependencies:
122
122
  - - '>='
123
123
  - !ruby/object:Gem::Version
124
124
  version: 0.0.7
125
+ - !ruby/object:Gem::Dependency
126
+ name: migration_comments
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - '>='
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - '>='
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
125
139
  description: Ridgepole is a tool to manage DB schema. It defines DB schema using Rails
126
140
  DSL, and updates DB schema according to DSL.
127
141
  email:
@@ -148,11 +162,14 @@ files:
148
162
  - lib/ridgepole/dsl_parser.rb
149
163
  - lib/ridgepole/dumper.rb
150
164
  - lib/ridgepole/execute_expander.rb
165
+ - lib/ridgepole/ext/migration_comments.rb
151
166
  - lib/ridgepole/logger.rb
152
167
  - lib/ridgepole/migration_ext.rb
153
168
  - lib/ridgepole/schema_dumper_ext.rb
154
169
  - lib/ridgepole/version.rb
155
170
  - ridgepole.gemspec
171
+ - spec/mysql/0_comment/comment_mysql_awesome_spec.rb
172
+ - spec/mysql/0_comment/comment_spec.rb
156
173
  - spec/mysql/bigint_pk/bigint_pkspec.rb
157
174
  - spec/mysql/cli/config_spec.rb
158
175
  - spec/mysql/cli/ridgepole_spec.rb
@@ -256,6 +273,8 @@ signing_key:
256
273
  specification_version: 4
257
274
  summary: Ridgepole is a tool to manage DB schema.
258
275
  test_files:
276
+ - spec/mysql/0_comment/comment_mysql_awesome_spec.rb
277
+ - spec/mysql/0_comment/comment_spec.rb
259
278
  - spec/mysql/bigint_pk/bigint_pkspec.rb
260
279
  - spec/mysql/cli/config_spec.rb
261
280
  - spec/mysql/cli/ridgepole_spec.rb