rails_pending_migration_errors 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7eef8c4257d60313f2710c1dc334ee00ded3bcef
4
- data.tar.gz: e3fa6ec2d241f6b2733ff0118f48841f52c24f0f
3
+ metadata.gz: 2a7eeed644aca9bc2ae160d7919bba47901ab4cd
4
+ data.tar.gz: c65db9bf6ce93b7b2fd32d9b7835c2013ea9b359
5
5
  SHA512:
6
- metadata.gz: 04909b3bc42a3b5ace7fe31793502f81fb837c85dc2b8d5182bacba43773bc6920614cb565fe55639eeb204705186e6784b9029ceefad24c60a5387cdd2231e6
7
- data.tar.gz: 01099cd05d31a4d1c03879dcb24aa73549dccdb15f0dc997c1c3b2c3b67a5554443a458c6ed8de0f5865bfeb7a78c0e852fc6aa1621f00ade22b7aa98f054beb
6
+ metadata.gz: 3ce97f8b0d78160a3ae15ee7cadf7be5265366af89a7f84744f736c5e353a46691d27a716fd790a539478b4d922bfb52ce4c1524203764b1fd8d2791a2779279
7
+ data.tar.gz: 07dc7c20e81ce6da82cc71a5050d71f96d3359ca6ddd17f03a428c6952970e661c82ddc435366c2a066221631620dff0239eb561fae1c1868caef709a64cba97
data/README.md CHANGED
@@ -1,10 +1,8 @@
1
1
  # Rails Pending Migration Errors
2
2
 
3
- Raise errors in development mode when there are pending migrations to run.
3
+ Append warnings or raise an exception in development mode when there are pending migrations to run.
4
4
 
5
- It is essentially a backport of [this feature](https://github.com/rails/rails/pull/6665) that made it in Rails 4.
6
-
7
- ![Example](http://f.cl.ly/items/3a3Q0i3e1D0s12420t0v/Screen%20Shot%202013-10-09%20at%207.19.28%20PM.png "Example")
5
+ It is inspired by [this feature](https://github.com/rails/rails/pull/6665) that made it in Rails 4.
8
6
 
9
7
  **Note:** this has only been tested against Rails 3.2.13 on ruby 2.0.0p247.
10
8
 
@@ -17,3 +15,9 @@ Add this line to your application's Gemfile:
17
15
  And then execute:
18
16
 
19
17
  $ bundle
18
+
19
+ If you want to raise errors on page load instead of the default warning, add this to `config/environments/development.rb`:
20
+
21
+ config.after_initialize do
22
+ RailsPendingMigrationErrors.page_load = true
23
+ end
@@ -15,30 +15,50 @@ module RailsPendingMigrationErrors
15
15
  end
16
16
 
17
17
  def call(env)
18
- ActiveRecord::Base.logger.quietly do
19
- check_pending_migrations!
18
+ status, headers, response = @app.call(env)
19
+ response_body = nil
20
+
21
+ return [status, headers, response] unless html_request?(headers, response)
22
+
23
+ if RailsPendingMigrationErrors.needs_migrations?
24
+ if RailsPendingMigrationErrors.page_load
25
+ raise ActiveRecord::PendingMigrationError
26
+
27
+ else
28
+ response_body = append_response_body(headers, response)
29
+
30
+ end
20
31
  end
21
32
 
22
- @app.call(env)
33
+ [status, headers, response_body ? [response_body] : response]
23
34
  end
24
35
 
25
36
  private
26
37
 
27
- def check_pending_migrations!
28
- raise ActiveRecord::PendingMigrationError if needs_migrations?
38
+ def append_response_body(headers, response)
39
+ response_body = response_body(response)
40
+ response_body << "<div #{footer_div_style}>Migrations are pending; run 'bin/rake db:migrate RAILS_ENV=#{::Rails.env}' to resolve this issue.</div>"
41
+ headers['Content-Length'] = response_body.bytesize.to_s
42
+ response_body
29
43
  end
30
44
 
31
- def needs_migrations?
32
- (file_versions - db_versions).size > 0
45
+ def html_request?(headers, response)
46
+ headers['Content-Type'] && headers['Content-Type'].include?('text/html') && response_body(response).include?("<html")
33
47
  end
34
48
 
35
- def file_versions
36
- ActiveRecord::Migrator.migrations( ActiveRecord::Migrator.migrations_paths ).map(&:version)
49
+ def response_body(response)
50
+ Array === response.body ? response.body.first : response.body
37
51
  end
38
52
 
39
- def db_versions
40
- ActiveRecord::Migrator.get_all_versions
53
+ def footer_div_style
54
+ <<EOF
55
+ style="position: fixed; bottom: 0; left: 0; cursor: pointer;
56
+ border-style: solid; border-color: red; border-width: 2px 2px 0 0;
57
+ padding: 6px; background: #FFB7B1; border-top-right-radius: 10px;
58
+ color: red; font-weight: bold; font-size: 18px; z-index: 100000;"
59
+ EOF
41
60
  end
42
61
 
62
+
43
63
  end
44
64
  end
@@ -1,3 +1,3 @@
1
1
  module RailsPendingMigrationErrors
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -3,4 +3,17 @@ require "rails_pending_migration_errors/middleware"
3
3
  require "rails_pending_migration_errors/rails"
4
4
 
5
5
  module RailsPendingMigrationErrors
6
+ mattr_accessor :page_load
7
+
8
+ def self.needs_migrations?
9
+ (file_versions - db_versions).size > 0
10
+ end
11
+
12
+ def self.file_versions
13
+ ActiveRecord::Migrator.migrations( ActiveRecord::Migrator.migrations_paths ).map(&:version)
14
+ end
15
+
16
+ def self.db_versions
17
+ ActiveRecord::Migrator.get_all_versions
18
+ end
6
19
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_pending_migration_errors
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vincent Roy
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-10-09 00:00:00.000000000 Z
11
+ date: 2013-10-19 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler