Public Instance methods
dump_columns()
Dump this generator’s columns to a string that could be evaled inside another instance to represent the same columns
[show source]
# File lib/sequel/extensions/schema_dumper.rb 430 def dump_columns 431 strings = [] 432 cols = columns.dup 433 cols.each do |x| 434 x.delete(:on_delete) if x[:on_delete] == :no_action 435 x.delete(:on_update) if x[:on_update] == :no_action 436 end 437 if (pkn = primary_key_name) && !@primary_key[:keep_order] 438 cols.delete_if{|x| x[:name] == pkn} 439 pk = @primary_key.dup 440 pkname = pk.delete(:name) 441 @db.serial_primary_key_options.each{|k,v| pk.delete(k) if v == pk[k]} 442 strings << "primary_key #{pkname.inspect}#{opts_inspect(pk)}" 443 end 444 cols.each do |c| 445 c = c.dup 446 name = c.delete(:name) 447 strings << if table = c.delete(:table) 448 c.delete(:type) if c[:type] == Integer || c[:type] == 'integer' 449 "foreign_key #{name.inspect}, #{table.inspect}#{opts_inspect(c)}" 450 elsif pkn == name 451 @db.serial_primary_key_options.each{|k,v| c.delete(k) if v == c[k]} 452 "primary_key #{name.inspect}#{opts_inspect(c)}" 453 else 454 type = c.delete(:type) 455 opts = opts_inspect(c) 456 case type 457 when Class 458 "#{type.name} #{name.inspect}#{opts}" 459 when :Bignum 460 "Bignum #{name.inspect}#{opts}" 461 else 462 "column #{name.inspect}, #{type.inspect}#{opts}" 463 end 464 end 465 end 466 strings.join("\n") 467 end
dump_constraints()
Dump this generator’s constraints to a string that could be evaled inside another instance to represent the same constraints
[show source]
# File lib/sequel/extensions/schema_dumper.rb 471 def dump_constraints 472 cs = constraints.map do |c| 473 c = c.dup 474 type = c.delete(:type) 475 case type 476 when :check 477 raise(Error, "can't dump check/constraint specified with Proc") if c[:check].is_a?(Proc) 478 name = c.delete(:name) 479 if !name and c[:check].length == 1 and c[:check].first.is_a?(Hash) 480 "check #{c[:check].first.inspect[1...-1]}" 481 else 482 "#{name ? "constraint #{name.inspect}," : 'check'} #{c[:check].map(&:inspect).join(', ')}" 483 end 484 when :foreign_key 485 c.delete(:on_delete) if c[:on_delete] == :no_action 486 c.delete(:on_update) if c[:on_update] == :no_action 487 c.delete(:deferrable) unless c[:deferrable] 488 cols = c.delete(:columns) 489 table = c.delete(:table) 490 "#{type} #{cols.inspect}, #{table.inspect}#{opts_inspect(c)}" 491 else 492 cols = c.delete(:columns) 493 "#{type} #{cols.inspect}#{opts_inspect(c)}" 494 end 495 end 496 cs.join("\n") 497 end
dump_indexes(options=OPTS)
Dump this generator’s indexes to a string that could be evaled inside another instance to represent the same indexes. Options:
:add_index |
Use add_index instead of index, so the methods can be called outside of a generator but inside a migration. The value of this option should be the table name to use. |
:drop_index |
Same as add_index, but create drop_index statements. |
:ignore_errors |
Add the ignore_errors option to the outputted indexes |
[show source]
# File lib/sequel/extensions/schema_dumper.rb 506 def dump_indexes(options=OPTS) 507 is = indexes.map do |c| 508 c = c.dup 509 cols = c.delete(:columns) 510 if table = options[:add_index] || options[:drop_index] 511 "#{options[:drop_index] ? 'drop' : 'add'}_index #{table.inspect}, #{cols.inspect}#{', :ignore_errors=>true' if options[:ignore_errors]}#{opts_inspect(c)}" 512 else 513 "index #{cols.inspect}#{opts_inspect(c)}" 514 end 515 end 516 is = is.reverse if options[:drop_index] 517 is.join("\n") 518 end