Skip to content

Commit

Permalink
add ActiveRecord::AbstractAdapter#extensions and ActiveRecord::Connec…
Browse files Browse the repository at this point in the history
…tionAdapters::PostgreSQLAdapter#extensions to allow dumping of enabled extensions to schema.rb, add ActiveRecord::SchemaDumper#extensions to dump extensions to schema.rb
  • Loading branch information
jaggederest committed Feb 7, 2013
1 parent e2fdfa9 commit fba496f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
Expand Up @@ -177,6 +177,12 @@ def supports_extensions?
false
end

# A list of extensions, to be filled in by databases that
# support them (at the moment, postgresql)
def extensions
[]
end

# QUOTING ==================================================

# Returns a bind substitution value given a +column+ and list of current
Expand Down
Expand Up @@ -605,6 +605,15 @@ def extension_enabled?(name)
end
end

def extensions
if supports_extensions?
res = exec_query "SELECT extname from pg_extension", "SCHEMA"
res.rows.map { |r| res.column_types['extname'].type_cast r.first }
else
[]
end
end

# Returns the configured supported identifier length supported by PostgreSQL
def table_alias_length
@table_alias_length ||= query('SHOW max_identifier_length', 'SCHEMA')[0][0].to_i
Expand Down
12 changes: 12 additions & 0 deletions activerecord/lib/active_record/schema_dumper.rb
Expand Up @@ -24,6 +24,7 @@ def self.dump(connection=ActiveRecord::Base.connection, stream=STDOUT)

def dump(stream)
header(stream)
extensions(stream)
tables(stream)
trailer(stream)
stream
Expand Down Expand Up @@ -66,6 +67,17 @@ def trailer(stream)
stream.puts "end"
end

def extensions(stream)
return unless @connection.supports_extensions?
extensions = @connection.extensions
stream.puts <<EXTENSIONS
# These are extensions that must be enabled in order to support this database
EXTENSIONS
extensions.each do |extension|
stream.puts " enable_extension #{extension.inspect}"
end
end

def tables(stream)
@connection.tables.sort.each do |tbl|
next if ['schema_migrations', ignore_tables].flatten.any? do |ignored|
Expand Down

0 comments on commit fba496f

Please sign in to comment.