Module: Legion::Data::Settings

Extended by:
Logging::Helper
Defined in:
lib/legion/data/settings.rb

Constant Summary collapse

CREDS =
{
  sqlite:   {
    database: 'legionio.db'
  },
  mysql2:   {
    username: 'legion',
    password: 'legion',
    database: 'legionio',
    host:     '127.0.0.1',
    port:     3306
  },
  postgres: {
    user:     'legion',
    password: 'legion',
    database: 'legionio',
    host:     '127.0.0.1',
    port:     5432
  }
}.freeze

Class Method Summary collapse

Methods included from Logging::Helper

handle_exception

Class Method Details

.archivalObject



119
120
121
122
123
124
125
# File 'lib/legion/data/settings.rb', line 119

def self.archival
  {
    retention_days:  90,
    batch_size:      1000,
    storage_backend: nil
  }
end

.cacheObject



127
128
129
130
131
132
133
134
# File 'lib/legion/data/settings.rb', line 127

def self.cache
  {
    connected:    false,
    auto_enable:  Legion::Settings[:cache][:connected],
    static_cache: false,
    ttl:          60
  }
end

.creds(adapter = nil) ⇒ Object



114
115
116
117
# File 'lib/legion/data/settings.rb', line 114

def self.creds(adapter = nil)
  adapter = (adapter || :sqlite).to_sym
  CREDS.fetch(adapter, CREDS[:sqlite]).dup
end

.defaultObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/legion/data/settings.rb', line 30

def self.default
  {
    adapter:                       'sqlite',
    connected:                     false,

    # Connection pool
    max_connections:               25,
    pool_timeout:                  5,
    preconnect:                    false,
    single_threaded:               false,
    test:                          true,
    name:                          nil,

    # Logging
    log:                           false,
    query_log:                     false,
    log_connection_info:           false,
    log_warn_duration:             1,
    sql_log_level:                 'debug',

    # Connection health (network adapters only, ignored for sqlite)
    # Validation is disabled by default: the connection_validator extension issues a
    # SELECT NULL on every checkout/checkin and before real queries, which kills
    # throughput. Connection errors are already rescued and reconnected at query time.
    # When enabled, connection_validation_timeout: -1 validates on every checkout
    # (catches stale connections from VPN/sleep/network changes immediately).
    connection_validation:         false,
    connection_validation_timeout: -1,
    connection_expiration:         true,
    connection_expiration_timeout: 14_400,

    # Adapter-specific (nil = use adapter built-in default)
    connect_timeout:               nil,
    read_timeout:                  nil,
    write_timeout:                 nil,
    encoding:                      nil,
    sql_mode:                      nil,
    sslmode:                       nil,
    sslrootcert:                   nil,
    search_path:                   nil,
    timeout:                       nil,
    readonly:                      nil,
    disable_dqs:                   nil,

    # Grouped settings
    creds:                         creds,
    cache:                         cache,
    migrations:                    migrations,
    models:                        models,
    local:                         local,
    dev_mode:                      false,
    dev_fallback:                  true,
    connect_on_start:              true,
    read_replica_url:              nil,
    replicas:                      [],
    archival:                      archival
  }
end

.localObject



89
90
91
92
93
94
95
96
# File 'lib/legion/data/settings.rb', line 89

def self.local
  {
    enabled:    true,
    database:   'legionio_local.db',
    query_log:  false,
    migrations: { auto_migrate: true }
  }
end

.migrationsObject



105
106
107
108
109
110
111
112
# File 'lib/legion/data/settings.rb', line 105

def self.migrations
  {
    continue_on_fail: false,
    auto_migrate:     true,
    ran:              false,
    version:          nil
  }
end

.modelsObject



98
99
100
101
102
103
# File 'lib/legion/data/settings.rb', line 98

def self.models
  {
    continue_on_load_fail: false,
    autoload:              true
  }
end