1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Revert "When creating database with rake, create schemas in schema_search_path if it doesn't exist."

This reverts commit 6c2a0675f1.

Reverting because it breaks the ability to run tests using a non-superuser.

Conflicts:

	activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
	activerecord/lib/active_record/railties/databases.rake
This commit is contained in:
Michael Koziarski 2010-04-09 11:29:53 +12:00
parent 82514c2897
commit 1e3dce08e1
4 changed files with 1 additions and 41 deletions

View file

@ -658,27 +658,6 @@ module ActiveRecord
end
end
# Creates a schema for the given user
#
# Example:
# create_schema('products', 'postgres')
def create_schema(schema_name, pg_username)
execute("CREATE SCHEMA \"#{schema_name}\" AUTHORIZATION \"#{pg_username}\"")
end
# Drops a schema
#
# Example:
# drop_schema('products')
def drop_schema(schema_name)
execute("DROP SCHEMA \"#{schema_name}\"")
end
# Returns an array of all schemas in the database
def all_schemas
query('SELECT schema_name FROM information_schema.schemata').flatten
end
# Returns the list of all tables in the schema search path or a specified schema.
def tables(name = nil)
query(<<-SQL, name).map { |row| row[0] }

View file

@ -84,15 +84,9 @@ namespace :db do
end
end
when 'postgresql'
@encoding = config['encoding'] || ENV['CHARSET'] || 'utf8'
schema_search_path = config['schema_search_path'] || 'public'
first_in_schema_search_path = schema_search_path.split(',').first.strip
@encoding = config[:encoding] || ENV['CHARSET'] || 'utf8'
begin
ActiveRecord::Base.establish_connection(config.merge('database' => 'postgres', 'schema_search_path' => 'public'))
unless ActiveRecord::Base.connection.all_schemas.include?(first_in_schema_search_path)
ActiveRecord::Base.connection.create_schema(first_in_schema_search_path, config['username'])
$stderr.puts "Schema #{first_in_schema_search_path} has been created."
end
ActiveRecord::Base.connection.create_database(config['database'], config.merge('encoding' => @encoding))
ActiveRecord::Base.establish_connection(config)
rescue

View file

@ -17,13 +17,6 @@ class PostgresqlActiveSchemaTest < Test::Unit::TestCase
assert_equal %(CREATE DATABASE "aimonetti" ENCODING = 'latin1'), create_database(:aimonetti, :encoding => :latin1)
end
def test_create_schema
assert_equal %(CREATE SCHEMA "rizwan" AUTHORIZATION "postgres"), create_schema(:rizwan, :postgres)
end
def test_drop_schema
assert_equal %(DROP SCHEMA "rizwan"), drop_schema(:rizwan)
end
private
def method_missing(method_symbol, *arguments)
ActiveRecord::Base.connection.send(method_symbol, *arguments)

View file

@ -81,12 +81,6 @@ class AdapterTest < ActiveRecord::TestCase
def test_encoding
assert_not_nil @connection.encoding
end
def test_all_schemas
@connection.create_schema(:test_schema, :postgres)
assert @connection.all_schemas.include?('test_schema')
@connection.drop_schema(:test_schema)
end
end
def test_table_alias