Files
.examples
.github
alerting
client
config
controller
core
docs
jsonpath
metric
pattern
security
storage
store
common
memory
sql
specific_postgres.go
specific_sqlite.go
sql.go
sql_test.go
store.go
store_bench_test.go
store_test.go
config.go
type.go
test
util
vendor
watchdog
web
.dockerignore
.gitattributes
.gitignore
Dockerfile
LICENSE
Makefile
README.md
config.yaml
go.mod
go.sum
main.go
gatus/storage/store/sql/specific_sqlite.go
TwiN 6ed93d4b82 Rename Service to Endpoint ()
* Add clarifications in comments

* : Rename Service to Endpoint
2021-10-23 16:47:12 -04:00

70 lines
1.9 KiB
Go

package sql
func (s *Store) createSQLiteSchema() error {
_, err := s.db.Exec(`
CREATE TABLE IF NOT EXISTS endpoints (
endpoint_id INTEGER PRIMARY KEY,
endpoint_key TEXT UNIQUE,
endpoint_name TEXT,
endpoint_group TEXT,
UNIQUE(endpoint_name, endpoint_group)
)
`)
if err != nil {
return err
}
_, err = s.db.Exec(`
CREATE TABLE IF NOT EXISTS endpoint_events (
endpoint_event_id INTEGER PRIMARY KEY,
endpoint_id INTEGER REFERENCES endpoints(endpoint_id) ON DELETE CASCADE,
event_type TEXT,
event_timestamp TIMESTAMP
)
`)
if err != nil {
return err
}
_, err = s.db.Exec(`
CREATE TABLE IF NOT EXISTS endpoint_results (
endpoint_result_id INTEGER PRIMARY KEY,
endpoint_id INTEGER REFERENCES endpoints(endpoint_id) ON DELETE CASCADE,
success INTEGER,
errors TEXT,
connected INTEGER,
status INTEGER,
dns_rcode TEXT,
certificate_expiration INTEGER,
hostname TEXT,
ip TEXT,
duration INTEGER,
timestamp TIMESTAMP
)
`)
if err != nil {
return err
}
_, err = s.db.Exec(`
CREATE TABLE IF NOT EXISTS endpoint_result_conditions (
endpoint_result_condition_id INTEGER PRIMARY KEY,
endpoint_result_id INTEGER REFERENCES endpoint_results(endpoint_result_id) ON DELETE CASCADE,
condition TEXT,
success INTEGER
)
`)
if err != nil {
return err
}
_, err = s.db.Exec(`
CREATE TABLE IF NOT EXISTS endpoint_uptimes (
endpoint_uptime_id INTEGER PRIMARY KEY,
endpoint_id INTEGER REFERENCES endpoints(endpoint_id) ON DELETE CASCADE,
hour_unix_timestamp INTEGER,
total_executions INTEGER,
successful_executions INTEGER,
total_response_time INTEGER,
UNIQUE(endpoint_id, hour_unix_timestamp)
)
`)
return err
}