bin/ridgepole in ridgepole-0.0.1 vs bin/ridgepole in ridgepole-0.1.0
- old
+ new
@@ -10,25 +10,35 @@
config = nil
mode = nil
file = DEFAULT_FILENAME
output_file = '-'
+split = false
options = {
:dry_run => false,
:debug => false,
}
+set_mode = proc do |m|
+ raise 'More than one mode is specified' if mode
+ mode = m
+end
+
ARGV.options do |opt|
begin
- opt.on('-c', '--config CONF_OR_FILE') {|v| config = v }
- opt.on('-a', '--apply') { mode = :apply }
- opt.on('-f', '--file FILE') {|v| file = v }
- opt.on('', '--dry-run') { options[:dry_run] = true }
- opt.on('-e', '--export') { mode = :export }
- opt.on('-o', '--output FILE') {|v| output_file = v }
- opt.on('' , '--debug') { options[:debug] = true }
+ opt.on('-c', '--config CONF_OR_FILE') {|v| config = v }
+ opt.on('-a', '--apply') { set_mode[:apply] }
+ opt.on('-m', '--merge') { set_mode[:apply]; options[:merge] = true }
+ opt.on('-f', '--file FILE') {|v| file = v }
+ opt.on('', '--dry-run') { options[:dry_run] = true }
+ opt.on('-e', '--export') { set_mode[:export] }
+ opt.on('', '--split') {|v| split = true }
+ opt.on('-o', '--output FILE') {|v| output_file = v }
+ opt.on('-t', '--tables TABLES', Array) {|v| options[:tables] = v }
+ opt.on('', '--disable-mysql-unsigned') { options[:disable_mysql_unsigned] = true }
+ opt.on('' , '--debug') { options[:debug] = true }
opt.parse!
unless config and mode
puts opt.help
exit 1
@@ -47,27 +57,52 @@
config = YAML.load(config)
client = Ridgepole::Client.new(config, options)
case mode
when :export
- if output_file == '-'
- logger.info('# Export Schema')
- puts client.dump
+ if split
+ logger.info('Export Schema')
+
+ output_file = DEFAULT_FILENAME if output_file == '-'
+ requires = []
+
+ client.dump do |name, definition|
+ schema_file = File.join(File.dirname(output_file), "#{name}.schema")
+ requires << schema_file
+ logger.info(" write `#{schema_file}`")
+
+ open(schema_file, 'wb') do |f|
+ f.puts definition
+ end
+ end
+
+ logger.info(" write `#{output_file}`")
+
+ open(output_file, 'wb') do |f|
+ requires.each do |schema_file|
+ f.puts "require '#{File.basename schema_file}'"
+ end
+ end
else
- logger.info("Export Schema to `#{output_file}`")
- open(output_file, 'wb') {|f| f.puts client.dump }
+ if output_file == '-'
+ logger.info('# Export Schema')
+ puts client.dump
+ else
+ logger.info("Export Schema to `#{output_file}`")
+ open(output_file, 'wb') {|f| f.puts client.dump }
+ end
end
when :apply
unless File.exist?(file)
raise "No Schemafile found (looking for: #{file})"
end
- msg = "Apply `#{file}`"
+ msg = (options[:merge] ? 'Merge' : 'Apply') + " `#{file}`"
msg << ' (dry-run)' if options[:dry_run]
logger.info(msg)
dsl = open(file) {|f| f.read }
- delta = client.diff(dsl)
+ delta = client.diff(dsl, :path => file)
if options[:dry_run]
puts delta.script if delta.differ?
else
delta.migrate