-
Notifications
You must be signed in to change notification settings - Fork 459
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
now support a different default schema_search_path than public
- Loading branch information
bradrobertson
committed
May 31, 2012
1 parent
2c15e0a
commit 505ea1f
Showing
11 changed files
with
121 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
if defined?(Rails) && Rails.env | ||
extend Rails::ConsoleMethods | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
module Apartment | ||
|
||
# The main entry point to Apartment functions | ||
# | ||
module Database | ||
|
||
extend self | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,41 @@ | ||
module Apartment | ||
module Test | ||
|
||
extend self | ||
|
||
def reset | ||
Apartment.excluded_models = nil | ||
Apartment.use_postgres_schemas = nil | ||
Apartment.seed_after_create = nil | ||
Apartment.default_schema = nil | ||
end | ||
|
||
def next_db | ||
@x ||= 0 | ||
"db_#{@x += 1}" | ||
end | ||
|
||
def drop_schema(schema) | ||
ActiveRecord::Base.connection.execute("DROP SCHEMA IF EXISTS #{schema} CASCADE") rescue true | ||
end | ||
|
||
|
||
# Use this if you don't want to import schema.rb etc... but need the postgres schema to exist | ||
# basically for speed purposes | ||
def create_schema(schema) | ||
ActiveRecord::Base.connection.execute("CREATE SCHEMA #{schema}") | ||
end | ||
|
||
def load_schema | ||
silence_stream(STDOUT){ load(Rails.root.join('db', 'schema.rb')) } | ||
end | ||
|
||
def migrate | ||
ActiveRecord::Migrator.migrate(Rails.root + ActiveRecord::Migrator.migrations_path) | ||
end | ||
|
||
def rollback | ||
ActiveRecord::Migrator.rollback(Rails.root + ActiveRecord::Migrator.migrations_path) | ||
end | ||
|
||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Some shared contexts for specs | ||
|
||
shared_context "with default schema", :default_schema => true do | ||
let(:default_schema){ Apartment::Test.next_db } | ||
|
||
before do | ||
Apartment::Test.create_schema(default_schema) | ||
Apartment.default_schema = default_schema | ||
end | ||
|
||
after do | ||
# resetting default_schema so we can drop and any further resets won't try to access droppped schema | ||
Apartment.default_schema = nil | ||
Apartment::Test.drop_schema(default_schema) | ||
end | ||
end |
Oops, something went wrong.