lib/torque/postgresql/adapter/schema_dumper.rb in torque-postgresql-2.2.4 vs lib/torque/postgresql/adapter/schema_dumper.rb in torque-postgresql-2.3.0

- old
+ new

@@ -12,10 +12,11 @@ stream end def extensions(stream) # :nodoc: super + user_defined_schemas(stream) user_defined_types(stream) end # Translate +:enum_set+ into +:enum+ def schema_type(column) @@ -39,11 +40,13 @@ column.sql_type.to_sym.inspect if column.type == :enum || column.type == :enum_set end def tables(stream) # :nodoc: inherited_tables = @connection.inherited_tables - sorted_tables = @connection.tables.sort - @connection.views + sorted_tables = (@connection.tables - @connection.views).sort_by do |table_name| + table_name.split(/(?:public)?\./).reverse + end stream.puts " # These are the common tables" (sorted_tables - inherited_tables.keys).each do |table_name| table(table_name, stream) unless ignored?(table_name) end @@ -56,11 +59,11 @@ sub_stream = StringIO.new table(table_name, sub_stream) # Add the inherits setting sub_stream.rewind - inherits.map!(&:to_sym) + inherits.map! { |parent| parent.to_s.sub(/\Apublic\./, '') } inherits = inherits.first if inherits.size === 1 inherits = ", inherits: #{inherits.inspect} do |t|" table_dump = sub_stream.read.gsub(/ do \|t\|$/, inherits) # Ensure bodyless definitions @@ -80,9 +83,23 @@ views(stream) if defined?(::Scenic) # FX integration functions(stream) if defined?(::Fx::SchemaDumper::Function) triggers(stream) if defined?(::Fx::SchemaDumper::Trigger) + end + + # Make sure to remove the schema from the table name + def remove_prefix_and_suffix(table) + super(table.sub(/\A[a-z0-9_]*\./, '')) + end + + # Dump user defined schemas + def user_defined_schemas(stream) + return if (list = (@connection.user_defined_schemas - ['public'])).empty? + + stream.puts " # Custom schemas defined in this database." + list.each { |name| stream.puts " create_schema \"#{name}\", force: :cascade" } + stream.puts end # Dump user defined types like enum def user_defined_types(stream) types = @connection.user_defined_types('e')