Class ActiveRecord::SchemaDumper
In: lib/rails_pg_procs.rb
Parent: Object

This class is used to dump the database schema for some connection to some output format (i.e., ActiveRecord::Schema).

Methods

get_type   indexes   postgres?   procedures   tables   triggers   types  

Included Modules

SchemaProcs

External Aliases

tables -> procless_tables
indexes -> indexes_before_triggers

Public Instance methods

TODO -Implement checks on SchemaDumper instance to ensure we do this only when using pg db.

[Source]

    # File lib/rails_pg_procs.rb, line 62
62:     def postgres?
63:       adapter_name == 'PostgreSQL'
64:     end

Private Instance methods

[Source]

    # File lib/rails_pg_procs.rb, line 66
66:       def get_type(types)
67:         case types
68:           when Array
69:             types.collect {|type|
70:               get_type(type)
71:             }.join(", ")
72:           when String && /^\d+$/
73:             type = @connection.select_value("SELECT typname FROM pg_type WHERE oid = '#{types}'")
74:             return type = 'nil' if type == 'void'
75:             get_type(type)
76:           when String
77:             return %("#{types}") if types =~ /[\s\(]/
78:             Inflector.symbolize(types)
79:         end
80:       end

[Source]

     # File lib/rails_pg_procs.rb, line 127
127:       def indexes(table, stream)
128:         indexes_before_triggers(table, stream)
129:         triggers(table, stream)
130:       end

TODO - Facilitate create_proc(name, [argname, argtype] and create_proc(name, [argmode, argname, argtype] …

[Source]

     # File lib/rails_pg_procs.rb, line 83
 83:       def procedures(stream, conditions=nil)
 84:         @connection.procedures(conditions).each { |proc_row|
 85:           oid, name, namespace, owner, lang, is_agg, sec_def, is_strict, ret_set, volatile, nargs, ret_type, arg_types, arg_names, src, bin, acl = proc_row
 86:           is_agg    = is_agg    == 't'
 87:           is_strict = is_strict == 't'
 88:           ret_set   = ret_set   == 't'
 89:           arg_names ||= ''
 90:           args      = get_type(arg_types.split(" "))#.zip(arg_names.split(" "))
 91: 
 92:           stream.print "  create_proc(#{Inflector.symbolize(name)}, [#{args}], :return => #{get_type(ret_type)}"
 93:           stream.print ", :resource => ['#{bin}', '#{src}']" unless bin == '-'
 94:           stream.print ", :set => true" if ret_set
 95:           stream.print ", :strict => true" if is_strict
 96:           stream.print ", :behavior => '#{behavior(volatile)}'" unless volatile == 'v'
 97:           stream.print ", :lang => '#{lang}')"
 98:           stream.print " {\n    <<-#{Inflector.underscore(name)}_sql\n#{src.chomp}\n    #{Inflector.underscore(name)}_sql\n  }" if bin == '-'
 99:           stream.print "\n"
100:         }
101:       end

[Source]

     # File lib/rails_pg_procs.rb, line 119
119:       def tables(stream)
120:         types(stream)
121:         procedures(stream, "!= 'sql'")
122:         procless_tables(stream)
123:         procedures(stream, "= 'sql'")
124:       end

[Source]

     # File lib/rails_pg_procs.rb, line 102
102:       def triggers(table_name, stream)
103:         triggers = @connection.triggers(table_name)
104:         triggers.each {|trigger|
105:           stream.puts trigger.to_rdl
106:         }
107:         stream.puts unless triggers.empty?
108:       end

[Source]

     # File lib/rails_pg_procs.rb, line 110
110:       def types(stream)
111:         @connection.types.each {|type|
112:           stream.print "  create_type(#{Inflector.symbolize(type.name)}, "
113:           stream.print "#{ type.columns.collect{|column, type| "[#{Inflector.symbolize(column)}, #{get_type(type)}]"}.join(", ") }"
114:           stream.puts  ")"
115:         }
116:       end

[Validate]