bleib 0.0.8 → 0.0.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f4179c2fc5fecac31c6e9a78def4cc26732055829dab659d6228c47fd942b8bd
4
- data.tar.gz: 3f9651be9c35735ad1f41cf068610b44e94433ae65989c277eb0c61471de9538
3
+ metadata.gz: f0026c9589d77a8763ca098abe295bfbe5bffde917753aab9a32c2743648cab3
4
+ data.tar.gz: 79a70f7065aa9e5a34a941eb371275c5c442f1a46f27d6e1c4d67c2beab83c3f
5
5
  SHA512:
6
- metadata.gz: e04ab8ca2f1d598dcad1ec87c9c52845bcec3e415a936cd4d47b380be948dcce4a804e15c39335d8db934637b547ae63906ca36c9defbcfe571dbbfcbf70dc5b
7
- data.tar.gz: b6ffd596ca831e4939aad7b2da4304e25f62a595e3497fb75b09784893b4286f0aba2e9aa94c845d25dc8e88a2a7039778c84ab88c548b2a2679ec97015e5ba6
6
+ metadata.gz: 5cf13688c65d9cbc2a88255c00029fdbf67febd13b6a07888954f95ed87db11a52a8712fc369434926d7c3a455235418f92762d627fde845408e660672a8dbeb
7
+ data.tar.gz: 221c1440dcc7249edcf5de75734a53f4a8165aafbdc3b9cd08eb41a5a9dff268ac2417b60f95226b9668c0568e476d730157c3ca9aa396ee7b85b0a75ce3536c
@@ -9,7 +9,7 @@ module Bleib
9
9
  DEFAULT_CHECK_MIGRATIONS_INTERVAL = 5 # Seconds
10
10
  DEFAULT_DATABASE_YML_PATH = 'config/database'
11
11
 
12
- SUPPORTED_ADAPTERS = %w(postgresql postgis)
12
+ SUPPORTED_ADAPTERS = %w(postgresql postgis mysql2)
13
13
 
14
14
  def self.from_environment
15
15
  check_database_interval = interval_or_default(
@@ -40,26 +40,38 @@ module Bleib
40
40
  logger.debug('Database check succeeded')
41
41
 
42
42
  false
43
- rescue PG::ConnectionBad => e
44
- # On stopped database:
45
- # PG::ConnectionBad: could not connect to server: Connection refused
46
- # Is the server running on host "127.0.0.1" and accepting
47
- # TCP/IP connections on port 5432?
48
- # On wrong/missing user:
49
- # PG::ConnectionBad: FATAL: password authentication failed for user "wrong"
50
- # On wrong password:
51
- # PG::ConnectionBad: FATAL: password authentication failed for user "user"
43
+ rescue Exception => e
44
+ raise e unless database_down_exception?(e)
52
45
 
53
46
  logger.debug("Database check failed: #{e}")
54
-
55
47
  true
56
- rescue ActiveRecord::NoDatabaseError
57
- # On missing database:
58
- # ActiveRecord::NoDatabaseError: FATAL: database "wrong" does not exist
59
-
60
- logger.debug("Database check failed: #{e}")
48
+ end
61
49
 
62
- true
50
+ def database_down_exception?(exception)
51
+ # Matching by class name because only constants defined by
52
+ # the used database adapter will be loaded.
53
+ case exception.class.name
54
+ when 'PG::ConnectionBad'
55
+ # On stopped database:
56
+ # PG::ConnectionBad: could not connect to server: Connection refused
57
+ # Is the server running on host "127.0.0.1" and accepting
58
+ # TCP/IP connections on port 5432?
59
+ # On wrong/missing user/password:
60
+ # PG::ConnectionBad: FATAL: password authentication failed for user "wrong"
61
+ true
62
+ when 'Mysql2::Error'
63
+ # On stopped database:
64
+ # Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
65
+ # On wrong/missing user/password:
66
+ # Access denied for user 'sraeze'@'localhost' (using password: YES)
67
+ true
68
+ when 'ActiveRecord::NoDatabaseError'
69
+ # On missing database:
70
+ # ActiveRecord::NoDatabaseError: FATAL: database "wrong" does not exist
71
+ true
72
+ else
73
+ false
74
+ end
63
75
  end
64
76
 
65
77
  def remove_connection
@@ -1,3 +1,3 @@
1
1
  module Bleib
2
- VERSION = '0.0.8'.freeze
2
+ VERSION = '0.0.9'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bleib
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Puzzle ITC