Skip to content

Commit

Permalink
Merge branch '0.7' into enable_Style/RedundantSelf
Browse files Browse the repository at this point in the history
  • Loading branch information
winebarrel committed Jun 11, 2018
2 parents 4045385 + c9c2d0d commit 166bfb6
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 88 deletions.
10 changes: 0 additions & 10 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,8 @@ AllCops:
Bundler/OrderedGems:
Include:
- 'Appraisals'
Layout/DefEndAlignment:
Enabled: false
Layout/EmptyLineAfterMagicComment:
Enabled: false
Layout/IndentArray:
Enabled: false
Layout/IndentHeredoc:
Enabled: false
Layout/MultilineOperationIndentation:
Expand Down Expand Up @@ -81,17 +77,11 @@ Style/MixinUsage:
Enabled: false
Style/MutableConstant:
Enabled: false
Style/Next:
Enabled: false
Style/NumericLiterals:
Enabled: false
Style/PerlBackrefs:
Enabled: false
Style/RedundantParentheses:
Enabled: false
Style/RescueStandardError:
Enabled: false
Style/Semicolon:
Enabled: false
Layout/ClosingHeredocIndentation:
Enabled: false
7 changes: 5 additions & 2 deletions bin/ridgepole
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ def noop_migrate(delta, options)
if line =~ /\A\s+/
puts "# #{line}"
else
puts line.strip.gsub(/([^\d])([(),])([^\d])/) { "#{$1}#{$2}\n#{$3}" }.each_line.map { |i| "# #{i.gsub(/^\s+/, '')}" }.join + "\n"
puts line.strip.gsub(/([^\d])([(),])([^\d])/) { "#{Regexp.last_match(1)}#{Regexp.last_match(2)}\n#{Regexp.last_match(3)}" }.each_line.map { |i| "# #{i.gsub(/^\s+/, '')}" }.join + "\n"
end
end
end
Expand All @@ -76,7 +76,10 @@ ARGV.options do |opt|
opt.on('-c', '--config CONF_OR_FILE') { |v| config = v }
opt.on('-E', '--env ENVIRONMENT') { |v| env = v }
opt.on('-a', '--apply') { set_mode[:apply] }
opt.on('-m', '--merge') { set_mode[:apply]; options[:merge] = true }
opt.on('-m', '--merge') do
set_mode[:apply]
options[:merge] = true
end
opt.on('-f', '--file SCHEMAFILE') { |v| file = v }
opt.on('', '--dry-run') { options[:dry_run] = true }
opt.on('', '--table-options OPTIONS') { |v| options[:table_options] = v }
Expand Down
6 changes: 3 additions & 3 deletions lib/ridgepole/cli/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class Ridgepole::Config
class << self
def load(config, env = 'development')
if config =~ /\Aenv:(.+)\z/
config = ENV.fetch($1)
config = ENV.fetch(Regexp.last_match(1))
end

if File.exist?(config)
Expand Down Expand Up @@ -49,6 +49,6 @@ def parse_database_url(config)
'port' => uri.port,
'database' => uri.path.sub(%r{\A/}, '')
}
end
end # of class methods
end
end # of class methods
end
94 changes: 45 additions & 49 deletions lib/ridgepole/diff.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,26 +58,25 @@ def scan_table_rename(from, to, delta, _options = {})
to.dup.each do |table_name, to_attrs|
next unless target?(table_name)

if (from_table_name = (to_attrs[:options] || {}).delete(:renamed_from))
from_table_name = from_table_name.to_s if from_table_name
next unless (from_table_name = (to_attrs[:options] || {}).delete(:renamed_from))
from_table_name = from_table_name.to_s if from_table_name

# Already renamed
if from[table_name]
@logger.warn("[WARNING] The table `#{from_table_name}` has already been renamed to the table `#{table_name}`.")
next
end
# Already renamed
if from[table_name]
@logger.warn("[WARNING] The table `#{from_table_name}` has already been renamed to the table `#{table_name}`.")
next
end

unless from[from_table_name]
@logger.warn("[WARNING] The table `#{from_table_name}` to be renamed does not exist.")
next
end
unless from[from_table_name]
@logger.warn("[WARNING] The table `#{from_table_name}` to be renamed does not exist.")
next
end

delta[:rename] ||= {}
delta[:rename][table_name] = from_table_name
delta[:rename] ||= {}
delta[:rename][table_name] = from_table_name

from.delete(from_table_name)
to.delete(table_name)
end
from.delete(from_table_name)
to.delete(table_name)
end
end

Expand Down Expand Up @@ -246,25 +245,24 @@ def scan_definition_change(from, to, from_indices, table_name, table_options, ta
definition_delta[:delete] ||= {}
definition_delta[:delete][column_name] = from_attrs

if from_indices
modified_indices = []
next unless from_indices
modified_indices = []

from_indices.each do |name, attrs|
if attrs[:column_name].is_a?(Array) && attrs[:column_name].delete(column_name)
modified_indices << name
end
from_indices.each do |name, attrs|
if attrs[:column_name].is_a?(Array) && attrs[:column_name].delete(column_name)
modified_indices << name
end
end

# In PostgreSQL, the index is deleted when the column is deleted
if @options[:index_removed_drop_column]
from_indices.reject! do |name, _attrs|
modified_indices.include?(name)
end
# In PostgreSQL, the index is deleted when the column is deleted
if @options[:index_removed_drop_column]
from_indices.reject! do |name, _attrs|
modified_indices.include?(name)
end
end

from_indices.reject! do |_name, attrs|
attrs[:column_name].is_a?(Array) && attrs[:column_name].empty?
end
from_indices.reject! do |_name, attrs|
attrs[:column_name].is_a?(Array) && attrs[:column_name].empty?
end
end
end
Expand All @@ -276,22 +274,21 @@ def scan_definition_change(from, to, from_indices, table_name, table_options, ta

def scan_column_rename(from, to, definition_delta)
to.dup.each do |column_name, to_attrs|
if (from_column_name = (to_attrs[:options] || {}).delete(:renamed_from))
from_column_name = from_column_name.to_s if from_column_name
next unless (from_column_name = (to_attrs[:options] || {}).delete(:renamed_from))
from_column_name = from_column_name.to_s if from_column_name

# Already renamed
next if from[column_name]
# Already renamed
next if from[column_name]

unless from.key?(from_column_name)
raise "Column `#{from_column_name}` not found"
end
unless from.key?(from_column_name)
raise "Column `#{from_column_name}` not found"
end

definition_delta[:rename] ||= {}
definition_delta[:rename][column_name] = from_column_name
definition_delta[:rename] ||= {}
definition_delta[:rename][column_name] = from_column_name

from.delete(from_column_name)
to.delete(column_name)
end
from.delete(from_column_name)
to.delete(column_name)
end
end

Expand Down Expand Up @@ -560,17 +557,16 @@ def scan_relation_info(relation_info)
}.fetch(column_info[:type], column_info[:type])
end

if parent_column_info != child_column_info
parent_label = "#{parent_table}.id"
child_label = "#{child_table}.#{column_name}"
label_len = [parent_label.length, child_label.length].max
next unless parent_column_info != child_column_info
parent_label = "#{parent_table}.id"
child_label = "#{child_table}.#{column_name}"
label_len = [parent_label.length, child_label.length].max

@logger.warn(<<-MSG % [label_len, parent_label, label_len, child_label])
@logger.warn(<<-MSG % [label_len, parent_label, label_len, child_label])
[WARNING] Relation column type is different.
%*s: #{parent_column_info}
%*s: #{child_column_info}
MSG
end
MSG
end
end
end
Expand Down
27 changes: 13 additions & 14 deletions lib/ridgepole/external_sql_executer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,22 @@ def execute(sql)
until files.empty?
ready = IO.select(files)

if ready
readable = ready[0]
next unless ready
readable = ready[0]

readable.each do |f|
begin
data = f.read_nonblock(1024)
next if data.nil?
data.chomp!
readable.each do |f|
begin
data = f.read_nonblock(1024)
next if data.nil?
data.chomp!

if f == stderr
@logger.warn("[WARNING] #{script_basename}: #{data}")
else
@logger.info("#{script_basename}: #{data}")
end
rescue EOFError
files.delete f
if f == stderr
@logger.warn("[WARNING] #{script_basename}: #{data}")
else
@logger.info("#{script_basename}: #{data}")
end
rescue EOFError
files.delete f
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/ridgepole/migration_ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ def parse_text(text)

case text
when /\A--\s+(.+)\Z/
time_recorder.add_key($1)
time_recorder.add_key(Regexp.last_match(1))
when /\A\s+->\s+(\d+\.\d+)s\Z/
time_recorder.add_value($1.to_f)
time_recorder.add_value(Regexp.last_match(1).to_f)
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/ridgepole/schema_statements_ext.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Ridgepole
module SchemaStatementsExt
def index_name_exists?(*)
if Ridgepole::ExecuteExpander.noop
caller_methods = caller.map { |i| i =~ /:\d+:in `(.+)'/ ? $1 : '' }
caller_methods = caller.map { |i| i =~ /:\d+:in `(.+)'/ ? Regexp.last_match(1) : '' }
if caller_methods.any? { |i| i =~ /\Aremove_index/ }
true
elsif caller_methods.any? { |i| i =~ /\Aadd_index/ }
Expand Down
14 changes: 7 additions & 7 deletions spec/mysql/dump/dump_some_tables_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,13 @@
before { restore_tables }
subject do
client(ignore_tables: [
/^clubs$/,
/^departments$/,
/^dept_emp$/,
/^dept_manager$/,
/^employee_clubs$/,
/^titles$/
])
/^clubs$/,
/^departments$/,
/^dept_emp$/,
/^dept_manager$/,
/^employee_clubs$/,
/^titles$/
])
end

it {
Expand Down

0 comments on commit 166bfb6

Please sign in to comment.