Class | Sequel::Schema::Generator |
In: |
lib/sequel/extensions/schema_dumper.rb
|
Parent: | Object |
Dump this generator‘s columns to a string that could be evaled inside another instance to represent the same columns
# File lib/sequel/extensions/schema_dumper.rb, line 387 387: def dump_columns 388: strings = [] 389: cols = columns.dup 390: cols.each do |x| 391: x.delete(:on_delete) if x[:on_delete] == :no_action 392: x.delete(:on_update) if x[:on_update] == :no_action 393: end 394: if pkn = primary_key_name 395: cols.delete_if{|x| x[:name] == pkn} 396: pk = @primary_key.dup 397: pkname = pk.delete(:name) 398: @db.serial_primary_key_options.each{|k,v| pk.delete(k) if v == pk[k]} 399: strings << "primary_key #{pkname.inspect}#{opts_inspect(pk)}" 400: end 401: cols.each do |c| 402: c = c.dup 403: name = c.delete(:name) 404: strings << if table = c.delete(:table) 405: c.delete(:type) if c[:type] == Integer || c[:type] == 'integer' 406: "foreign_key #{name.inspect}, #{table.inspect}#{opts_inspect(c)}" 407: else 408: type = c.delete(:type) 409: opts = opts_inspect(c) 410: if type.is_a?(Class) 411: "#{type.name} #{name.inspect}#{opts}" 412: else 413: "column #{name.inspect}, #{type.inspect}#{opts}" 414: end 415: end 416: end 417: strings.join("\n") 418: end
Dump this generator‘s constraints to a string that could be evaled inside another instance to represent the same constraints
# File lib/sequel/extensions/schema_dumper.rb, line 422 422: def dump_constraints 423: cs = constraints.map do |c| 424: c = c.dup 425: type = c.delete(:type) 426: case type 427: when :check 428: raise(Error, "can't dump check/constraint specified with Proc") if c[:check].is_a?(Proc) 429: name = c.delete(:name) 430: if !name and c[:check].length == 1 and c[:check].first.is_a?(Hash) 431: "check #{c[:check].first.inspect[1...-1]}" 432: else 433: "#{name ? "constraint #{name.inspect}," : 'check'} #{c[:check].map{|x| x.inspect}.join(', ')}" 434: end 435: when :foreign_key 436: c.delete(:on_delete) if c[:on_delete] == :no_action 437: c.delete(:on_update) if c[:on_update] == :no_action 438: c.delete(:deferrable) unless c[:deferrable] 439: cols = c.delete(:columns) 440: table = c.delete(:table) 441: "#{type} #{cols.inspect}, #{table.inspect}#{opts_inspect(c)}" 442: else 443: cols = c.delete(:columns) 444: "#{type} #{cols.inspect}#{opts_inspect(c)}" 445: end 446: end 447: cs.join("\n") 448: end
Dump this generator‘s indexes to a string that could be evaled inside another instance to represent the same indexes. Options:
# File lib/sequel/extensions/schema_dumper.rb, line 457 457: def dump_indexes(options={}) 458: is = indexes.map do |c| 459: c = c.dup 460: cols = c.delete(:columns) 461: if table = options[:add_index] || options[:drop_index] 462: "#{options[:drop_index] ? 'drop' : 'add'}_index #{table.inspect}, #{cols.inspect}#{', :ignore_errors=>true' if options[:ignore_errors]}#{opts_inspect(c)}" 463: else 464: "index #{cols.inspect}#{opts_inspect(c)}" 465: end 466: end 467: is = is.reverse if options[:drop_index] 468: is.join("\n") 469: end