Class: ActiveRecord::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/activerecord-sqlserver-adapter-mirroring/mirroring.rb

Class Method Summary collapse

Class Method Details

.db_mirroring_active?Boolean

Returns true if current database is db mirroring principal

Returns:

  • (Boolean)


26
27
28
# File 'lib/activerecord-sqlserver-adapter-mirroring/mirroring.rb', line 26

def self.db_mirroring_active?
  db_mirroring_status["mirroring_role_desc"] == "PRINCIPAL"
end

.db_mirroring_statusObject



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/activerecord-sqlserver-adapter-mirroring/mirroring.rb', line 3

def self.db_mirroring_status

  #Returns hash with db mirroring status details
  #  if mirroring is inactive for current database returns empty hash
  connection.select_one("
      SELECT 
          DB_NAME(database_id) database_name
        , mirroring_role_desc 
        , mirroring_safety_level_desc
        , mirroring_state_desc
        , mirroring_safety_sequence
        , mirroring_role_sequence
        , mirroring_partner_instance
        , mirroring_witness_name
        , mirroring_witness_state_desc
        , mirroring_failover_lsn
     FROM sys.database_mirroring
     WHERE mirroring_guid IS NOT NULL
   	   and database_id = db_id(); 
    ") || {}
end

.db_mirroring_synchronized?Boolean

Returns true if db mirroring is in synchronized state

Returns:

  • (Boolean)


31
32
33
# File 'lib/activerecord-sqlserver-adapter-mirroring/mirroring.rb', line 31

def self.db_mirroring_synchronized?
  db_mirroring_status["mirroring_state_desc"] == "SYNCHRONIZED"
end

.server_nameObject

Returns current database server name



36
37
38
# File 'lib/activerecord-sqlserver-adapter-mirroring/mirroring.rb', line 36

def self.server_name
  connection.select_value("select @@servername")
end