apartment 0.14.0 → 0.14.1

Sign up to get free protection for your applications and to get access to all the features.
data/HISTORY.md CHANGED
@@ -1,19 +1,29 @@
1
+ # 0.14.1
2
+ * Dec 13, 2011
3
+
4
+ - Fix ActionDispatch::Callbacks deprecation warnings
5
+
6
+ # 0.14.0
7
+ * Dec 13, 2011
8
+
9
+ - Rails 3.1 Support
10
+
1
11
  # 0.13.1
2
12
  * Nov 8, 2011
3
-
13
+
4
14
  - Reset prepared statement cache for rails 3.1.1 before switching dbs when using postgresql schemas
5
15
  - Only necessary until the next release which will be more schema aware
6
16
 
7
17
  # 0.13.0
8
18
  * Oct 25, 2011
9
-
19
+
10
20
  - `process` will now rescue with reset if the previous schema/db is no longer available
11
21
  - `create` now takes an optional block which allows you to process within the newly created db
12
22
  - Fixed Rails version >= 3.0.10 and < 3.1 because there have been significant testing problems with 3.1, next version will hopefully fix this
13
-
23
+
14
24
  # 0.12.0
15
25
  * Oct 4, 2011
16
-
26
+
17
27
  - Added a `drop` method for removing databases/schemas
18
28
  - Refactored abstract adapter to further remove duplication in concrete implementations
19
29
  - Excluded models now take string references so they are properly reloaded in development
@@ -21,7 +31,7 @@
21
31
 
22
32
  # 0.11.1
23
33
  * Sep 22, 2011
24
-
34
+
25
35
  - Better use of Railties for initializing apartment
26
36
  - The following changes were necessary as I haven't figured out how to properly hook into Rails reloading
27
37
  - Added reloader middleware in development to init Apartment on each request
@@ -29,88 +39,88 @@
29
39
 
30
40
  # 0.11.0
31
41
  * Sep 20, 2011
32
-
42
+
33
43
  - Excluded models no longer use a different connection when using postgresql schemas. Instead their table_name is prefixed with `public.`
34
44
 
35
45
  # 0.10.3
36
46
  * Sep 20, 2011
37
-
47
+
38
48
  - Fix improper raising of exceptions on create and reset
39
49
 
40
50
  # 0.10.2
41
51
  * Sep 15, 2011
42
-
52
+
43
53
  - Remove all the annoying logging for loading db schema and seeding on create
44
54
 
45
55
  # 0.10.1
46
56
  * Aug 11, 2011
47
-
57
+
48
58
  - Fixed bug in DJ where new objects (that hadn't been pulled from the db) didn't have the proper database assigned
49
59
 
50
60
  # 0.10.0
51
61
  * July 29, 2011
52
-
62
+
53
63
  - Added better support for Delayed Job
54
64
  - New config option that enables Delayed Job wrappers
55
65
  - Note that DJ support uses a work-around in order to get queues stored in the public schema, not sure why it doesn't work out of the box, will look into it, until then, see documentation on queue'ng jobs
56
-
66
+
57
67
  # 0.9.2
58
68
  * July 4, 2011
59
-
69
+
60
70
  - Migrations now run associated rails migration fully, fixes schema.rb not being reloaded after migrations
61
71
 
62
72
  # 0.9.1
63
73
  * June 24, 2011
64
-
74
+
65
75
  - Hooks now take the payload object as an argument to fetch the proper db for DJ hooks
66
76
 
67
77
  # 0.9.0
68
78
  * June 23, 2011
69
-
79
+
70
80
  - Added module to provide delayed job hooks
71
81
 
72
82
  # 0.8.0
73
83
  * June 23, 2011
74
-
84
+
75
85
  - Added #current_database which will return the current database (or schema) name
76
86
 
77
87
  # 0.7.0
78
88
  * June 22, 2011
79
-
89
+
80
90
  - Added apartment:seed rake task for seeding all dbs
81
91
 
82
92
  # 0.6.0
83
93
  * June 21, 2011
84
-
94
+
85
95
  - Added #process to connect to new db, perform operations, then ensure a reset
86
96
 
87
97
  # 0.5.1
88
98
  * June 21, 2011
89
-
99
+
90
100
  - Fixed db migrate up/down/rollback
91
101
  - added db:redo
92
102
 
93
103
  # 0.5.0
94
104
  * June 20, 2011
95
-
105
+
96
106
  - Added the concept of an "Elevator", a rack based strategy for db switching
97
107
  - Added the Subdomain Elevator middleware to enabled db switching based on subdomain
98
108
 
99
109
  # 0.4.0
100
110
  * June 14, 2011
101
-
111
+
102
112
  - Added `configure` method on Apartment instead of using yml file, allows for dynamic setting of db names to migrate for rake task
103
113
  - Added `seed_after_create` config option to import seed data to new db on create
104
-
114
+
105
115
  # 0.3.0
106
116
  * June 10, 2011
107
-
117
+
108
118
  - Added full support for database migration
109
119
  - Added in method to establish new connection for excluded models on startup rather than on each switch
110
-
120
+
111
121
  # 0.2.0
112
122
  * June 6, 2011 *
113
-
123
+
114
124
  - Refactor to use more rails/active_support functionality
115
125
  - Refactor config to lazily load apartment.yml if exists
116
126
  - Remove OStruct and just use hashes for fetching methods
data/README.md CHANGED
@@ -17,7 +17,10 @@ Add the following to your Gemfile:
17
17
  That's all you need to set up the Apartment libraries. If you want to switch databases
18
18
  on a per-user basis, look under "Usage - Switching databases per request", below.
19
19
 
20
- *NOTE: If using [postgresl schemas](http://www.postgresql.org/docs/9.0/static/ddl-schemas.html) you must use Rails >= 3.0.10, it contains a [patch](https://github.com/rails/rails/pull/1607) that has better postgresql schema support*
20
+ > NOTE: If using [postgresl schemas](http://www.postgresql.org/docs/9.0/static/ddl-schemas.html) you must use:
21
+ >
22
+ > * for Rails 3.0.x: _Rails ~> 3.0.10_, it contains a [patch](https://github.com/rails/rails/pull/1607) that has better postgresql schema support
23
+ > * for Rails 3.1.x: _Rails ~> 3.1.2_, it contains a [patch](https://github.com/rails/rails/pull/3232) that makes prepared statements work with multiple schemas
21
24
 
22
25
  ## Usage
23
26
 
@@ -1,61 +1,61 @@
1
1
  module Apartment
2
-
2
+
3
3
  module Database
4
-
4
+
5
5
  def self.postgresql_adapter(config)
6
- Apartment.use_postgres_schemas ?
6
+ Apartment.use_postgres_schemas ?
7
7
  Adapters::PostgresqlSchemaAdapter.new(config, :schema_search_path => ActiveRecord::Base.connection.schema_search_path) :
8
8
  Adapters::PostgresqlAdapter.new(config)
9
9
  end
10
-
10
+
11
11
  end
12
-
12
+
13
13
  module Adapters
14
-
14
+
15
15
  # Default adapter when not using Postgresql Schemas
16
16
  class PostgresqlAdapter < AbstractAdapter
17
-
17
+
18
18
  protected
19
-
19
+
20
20
  # Connect to new database
21
21
  # Abstract adapter will catch generic ActiveRecord error
22
22
  # Catch specific adapter errors here
23
- #
23
+ #
24
24
  # @param {String} database Database name
25
- #
25
+ #
26
26
  def connect_to_new(database)
27
27
  super
28
- rescue PGError => e
28
+ rescue PGError
29
29
  raise DatabaseNotFound, "Cannot find database #{environmentify(database)}"
30
30
  end
31
-
31
+
32
32
  end
33
-
33
+
34
34
  # Separate Adapter for Postgresql when using schemas
35
35
  class PostgresqlSchemaAdapter < AbstractAdapter
36
-
36
+
37
37
  # Get the current schema search path
38
- #
38
+ #
39
39
  # @return {String} current schema search path
40
- #
40
+ #
41
41
  def current_database
42
42
  ActiveRecord::Base.connection.schema_search_path
43
43
  end
44
-
44
+
45
45
  # Drop the database schema
46
- #
46
+ #
47
47
  # @param {String} database Database (schema) to drop
48
- #
48
+ #
49
49
  def drop(database)
50
50
  ActiveRecord::Base.connection.execute("DROP SCHEMA #{database} CASCADE")
51
-
52
- rescue ActiveRecord::StatementInvalid => e
51
+
52
+ rescue ActiveRecord::StatementInvalid
53
53
  raise SchemaNotFound, "The schema #{database.inspect} cannot be found."
54
54
  end
55
55
 
56
56
  # Reset search path to default search_path
57
57
  # Set the table_name to always use the public namespace for excluded models
58
- #
58
+ #
59
59
  def process_excluded_models
60
60
  Apartment.excluded_models.each do |excluded_model|
61
61
  # Note that due to rails reloading, we now take string references to classes rather than
@@ -64,9 +64,9 @@ module Apartment
64
64
  warn "[Deprecation Warning] Passing class references to excluded models is now deprecated, please use a string instead"
65
65
  excluded_model = excluded_model.name
66
66
  end
67
-
67
+
68
68
  excluded_model.constantize.tap do |klass|
69
- # some models (such as delayed_job) seem to load and cache their column names before this,
69
+ # some models (such as delayed_job) seem to load and cache their column names before this,
70
70
  # so would never get the public prefix, so reset first
71
71
  klass.reset_column_information
72
72
 
@@ -78,11 +78,11 @@ module Apartment
78
78
  end
79
79
  end
80
80
  end
81
-
81
+
82
82
  # Reset schema search path to the default schema_search_path
83
- #
83
+ #
84
84
  # @return {String} default schema search path
85
- #
85
+ #
86
86
  def reset
87
87
  ActiveRecord::Base.connection.schema_search_path = @defaults[:schema_search_path]
88
88
  end
@@ -90,25 +90,25 @@ module Apartment
90
90
  protected
91
91
 
92
92
  # Set schema search path to new schema
93
- #
93
+ #
94
94
  def connect_to_new(database = nil)
95
95
  return reset if database.nil?
96
96
  ActiveRecord::Base.connection.schema_search_path = database
97
97
 
98
- rescue ActiveRecord::StatementInvalid => e
98
+ rescue ActiveRecord::StatementInvalid
99
99
  raise SchemaNotFound, "The schema #{database.inspect} cannot be found."
100
100
  end
101
101
 
102
102
  # Create the new schema
103
- #
103
+ #
104
104
  def create_database(database)
105
105
  ActiveRecord::Base.connection.execute("CREATE SCHEMA #{database}")
106
106
 
107
- rescue ActiveRecord::StatementInvalid => e
107
+ rescue ActiveRecord::StatementInvalid
108
108
  raise SchemaExists, "The schema #{database} already exists."
109
109
  end
110
-
110
+
111
111
  end
112
-
112
+
113
113
  end
114
114
  end
@@ -5,7 +5,7 @@
5
5
  def reload!(print=true)
6
6
  puts "Reloading..." if print
7
7
  # This triggers the to_prepare callbacks
8
- ActionDispatch::Callbacks.new(Proc.new {}, false).call({})
8
+ ActionDispatch::Callbacks.new(Proc.new {}).call({})
9
9
  # Manually init Apartment again once classes are reloaded
10
10
  Apartment::Database.init
11
11
  true
@@ -1,22 +1,24 @@
1
1
  module Apartment
2
-
2
+
3
3
  class Reloader
4
-
4
+
5
5
  # Middleware used in development to init Apartment for each request
6
- # Necessary due to code reload (annoying). I couldn't figure out how to properly hook into
7
- # the Rails reload process *after* files are reloaded, so I've used this in the meantime.
8
- #
6
+ # Necessary due to code reload (annoying). When models are reloaded, they no longer have the proper table_name
7
+ # That is prepended with the schema (if using postgresql schemas)
8
+ # I couldn't figure out how to properly hook into the Rails reload process *after* files are reloaded
9
+ # so I've used this in the meantime.
10
+ #
9
11
  # Also see apartment/console for the re-definition of reload! that re-init's Apartment
10
- #
12
+ #
11
13
  def initialize(app)
12
14
  @app = app
13
15
  end
14
-
16
+
15
17
  def call(env)
16
18
  Database.init
17
19
  @app.call(env)
18
20
  end
19
-
21
+
20
22
  end
21
-
23
+
22
24
  end
@@ -1,3 +1,3 @@
1
1
  module Apartment
2
- VERSION = "0.14.0"
2
+ VERSION = "0.14.1"
3
3
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: apartment
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.14.0
5
+ version: 0.14.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Ryan Brunner
@@ -225,7 +225,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
225
225
  requirements:
226
226
  - - ">="
227
227
  - !ruby/object:Gem::Version
228
- hash: 538032595049641835
228
+ hash: -3913333331910434381
229
229
  segments:
230
230
  - 0
231
231
  version: "0"
@@ -234,7 +234,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
234
234
  requirements:
235
235
  - - ">="
236
236
  - !ruby/object:Gem::Version
237
- hash: 538032595049641835
237
+ hash: -3913333331910434381
238
238
  segments:
239
239
  - 0
240
240
  version: "0"