Skip to content

Commit

Permalink
feat: refactor, renames almost working workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
mentos1386 committed May 23, 2024
1 parent 73835b5 commit 0f28cdf
Show file tree
Hide file tree
Showing 80 changed files with 1,848 additions and 960 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

Golang selfhosted Status/Healthcheck monitoring app.

Mostly just a project to test [temporal.io](https://temporal.io/).

### Roadmap
- [x] SSO Support for authentication.
- [x] SQLite for database.
Expand Down Expand Up @@ -37,9 +35,12 @@ Demo is available at https://zdravko.mnts.dev.

```sh
# Configure
# You will need to configure an SSO provider
# This can be github for example.
cp example.env .env

# Generate JWT key
# Copy the values to your .env
just generate-jwt-key

# Start development environment
Expand Down
8 changes: 4 additions & 4 deletions cmd/zdravko/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (
"sync"
"syscall"

"code.tjo.space/mentos1386/zdravko/internal/config"
"code.tjo.space/mentos1386/zdravko/pkg/server"
"code.tjo.space/mentos1386/zdravko/pkg/temporal"
"code.tjo.space/mentos1386/zdravko/pkg/worker"
"github.com/mentos1386/zdravko/internal/config"
"github.com/mentos1386/zdravko/pkg/server"
"github.com/mentos1386/zdravko/pkg/temporal"
"github.com/mentos1386/zdravko/pkg/worker"
)

type StartableAndStoppable interface {
Expand Down
2 changes: 1 addition & 1 deletion internal/kv/badger.go → database/badger.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package kv
package database

import (
"time"
Expand Down
2 changes: 1 addition & 1 deletion internal/kv/kv.go → database/kv.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package kv
package database

import "time"

Expand Down
97 changes: 43 additions & 54 deletions database/models/models.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,6 @@ type OAuth2State struct {
ExpiresAt *Time `db:"expires_at"`
}

type CheckStatus string

const (
CheckStatusSuccess CheckStatus = "SUCCESS"
CheckStatusFailure CheckStatus = "FAILURE"
CheckStatusError CheckStatus = "ERROR"
CheckStatusUnknown CheckStatus = "UNKNOWN"
)

type CheckState string

const (
Expand All @@ -62,45 +53,24 @@ const (
CheckStateUnknown CheckState = "UNKNOWN"
)

type CheckVisibility string

const (
CheckVisibilityPublic CheckVisibility = "PUBLIC"
CheckVisibilityPrivate CheckVisibility = "PRIVATE"
CheckVisibilityUnknown CheckVisibility = "UNKNOWN"
)

type Check struct {
CreatedAt *Time `db:"created_at"`
UpdatedAt *Time `db:"updated_at"`

Id string `db:"id"`
Name string `db:"name"`
Group string `db:"group"`
Visibility CheckVisibility `db:"visibility"`
Id string `db:"id"`
Name string `db:"name"`

Schedule string `db:"schedule"`
Script string `db:"script"`
Filter string `db:"filter"`
}

type CheckWithWorkerGroups struct {
Check

// List of worker group names
WorkerGroups []string
}

type CheckHistory struct {
CreatedAt *Time `db:"created_at"`

CheckId string `db:"check_id"`
Status CheckStatus `db:"status"`
Note string `db:"note"`

WorkerGroupId string `db:"worker_group_id"`
WorkerGroupName string `db:"worker_group_name"`
}

type WorkerGroup struct {
CreatedAt *Time `db:"created_at"`
UpdatedAt *Time `db:"updated_at"`
Expand All @@ -116,15 +86,6 @@ type WorkerGroupWithChecks struct {
Checks []string
}

type TriggerStatus string

const (
TriggerStatusSuccess TriggerStatus = "SUCCESS"
TriggerStatusFailure TriggerStatus = "FAILURE"
TriggerStatusError TriggerStatus = "ERROR"
TriggerStatusUnknown TriggerStatus = "UNKNOWN"
)

type TriggerState string

const (
Expand All @@ -133,14 +94,6 @@ const (
TriggerStateUnknown TriggerState = "UNKNOWN"
)

type TriggerVisibility string

const (
TriggerVisibilityPublic TriggerVisibility = "PUBLIC"
TriggerVisibilityPrivate TriggerVisibility = "PRIVATE"
TriggerVisibilityUnknown TriggerVisibility = "UNKNOWN"
)

type Trigger struct {
CreatedAt *Time `db:"created_at"`
UpdatedAt *Time `db:"updated_at"`
Expand All @@ -150,10 +103,46 @@ type Trigger struct {
Script string `db:"script"`
}

type TriggerHistory struct {
type TargetVisibility string

const (
TargetVisibilityPublic TargetVisibility = "PUBLIC"
TargetVisibilityPrivate TargetVisibility = "PRIVATE"
TargetVisibilityUnknown TargetVisibility = "UNKNOWN"
)

type TargetState string

const (
TargetStateActive TargetState = "ACTIVE"
TargetStatePaused TargetState = "PAUSED"
TargetStateUnknown TargetState = "UNKNOWN"
)

type Target struct {
CreatedAt *Time `db:"created_at"`
UpdatedAt *Time `db:"updated_at"`

Id string `db:"id"`
Name string `db:"name"`
Group string `db:"group"`
Visibility TargetVisibility `db:"visibility"`
State TargetState `db:"state"`
Metadata string `db:"metadata"`
}

type TargetStatus string

const (
TargetStatusSuccess TargetStatus = "SUCCESS"
TargetStatusFailure TargetStatus = "FAILURE"
TargetStatusUnknown TargetStatus = "UNKNOWN"
)

type TargetHistory struct {
CreatedAt *Time `db:"created_at"`

TriggerId string `db:"trigger_id"`
Status TriggerStatus `db:"status"`
Note string `db:"note"`
TargetId string `db:"target_id"`
Status TargetStatus `db:"status"`
Note string `db:"note"`
}
53 changes: 27 additions & 26 deletions database/sqlite/migrations/2024-02-27-initial.sql
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,17 @@ CREATE TABLE oauth2_states (
CREATE TABLE checks (
id TEXT NOT NULL,
name TEXT NOT NULL,
"group" TEXT NOT NULL,
schedule TEXT NOT NULL,
script TEXT NOT NULL,

visibility TEXT NOT NULL,
filter TEXT NOT NULL,

created_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ')),
updated_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ')),

PRIMARY KEY (id),
CONSTRAINT unique_checks_name UNIQUE (name)
) STRICT;


-- +migrate StatementBegin
CREATE TRIGGER checks_updated_timestamp AFTER UPDATE ON checks BEGIN
UPDATE checks SET updated_at = strftime('%Y-%m-%dT%H:%M:%fZ') WHERE id = NEW.id;
Expand All @@ -39,7 +36,6 @@ CREATE TABLE worker_groups (
PRIMARY KEY (id),
CONSTRAINT unique_worker_groups_name UNIQUE (name)
) STRICT;

-- +migrate StatementBegin
CREATE TRIGGER worker_groups_updated_timestamp AFTER UPDATE ON worker_groups BEGIN
UPDATE worker_groups SET updated_at = strftime('%Y-%m-%dT%H:%M:%fZ') WHERE id = NEW.id;
Expand All @@ -55,19 +51,6 @@ CREATE TABLE check_worker_groups (
CONSTRAINT fk_check_worker_groups_check FOREIGN KEY (check_id) REFERENCES checks(id) ON DELETE CASCADE
) STRICT;

CREATE TABLE check_histories (
check_id TEXT NOT NULL,
worker_group_id TEXT NOT NULL,

status TEXT NOT NULL,
note TEXT NOT NULL,

created_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ')),

PRIMARY KEY (check_id, worker_group_id, created_at),
CONSTRAINT fk_check_histories_check FOREIGN KEY (check_id) REFERENCES checks(id) ON DELETE CASCADE,
CONSTRAINT fk_check_histories_worker_group FOREIGN KEY (worker_group_id) REFERENCES worker_groups(id) ON DELETE CASCADE
) STRICT;

CREATE TABLE triggers (
id TEXT NOT NULL,
Expand All @@ -80,34 +63,52 @@ CREATE TABLE triggers (
PRIMARY KEY (id),
CONSTRAINT unique_triggers_name UNIQUE (name)
) STRICT;


-- +migrate StatementBegin
CREATE TRIGGER triggers_updated_timestamp AFTER UPDATE ON triggers BEGIN
UPDATE triggers SET updated_at = strftime('%Y-%m-%dT%H:%M:%fZ') WHERE id = NEW.id;
END;
-- +migrate StatementEnd

CREATE TABLE trigger_histories (
trigger_id TEXT NOT NULL,
CREATE TABLE targets (
id TEXT NOT NULL,
name TEXT NOT NULL,
"group" TEXT NOT NULL,

visibility TEXT NOT NULL,
state TEXT NOT NULL,

metadata TEXT NOT NULL,

created_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ')),
updated_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ')),

PRIMARY KEY (id),
CONSTRAINT unique_targets_name UNIQUE (name)
) STRICT;
-- +migrate StatementBegin
CREATE TRIGGER targets_updated_timestamp AFTER UPDATE ON targets BEGIN
UPDATE targets SET updated_at = strftime('%Y-%m-%dT%H:%M:%fZ') WHERE id = NEW.id;
END;
-- +migrate StatementEnd

CREATE TABLE target_histories (
target_id TEXT NOT NULL,

status TEXT NOT NULL,
note TEXT NOT NULL,

created_at TEXT NOT NULL DEFAULT (strftime('%Y-%m-%dT%H:%M:%fZ')),

PRIMARY KEY (trigger_id, created_at),
CONSTRAINT fk_trigger_histories_trigger FOREIGN KEY (trigger_id) REFERENCES triggers(id) ON DELETE CASCADE
PRIMARY KEY (target_id, created_at),
CONSTRAINT fk_target_histories_target FOREIGN KEY (target_id) REFERENCES targets(id) ON DELETE CASCADE
) STRICT;

-- +migrate Down
DROP TABLE oauth2_states;
DROP TABLE check_worker_groups;
DROP TABLE worker_groups;
DROP TRIGGER worker_groups_updated_timestamp;
DROP TABLE check_histories;
DROP TABLE checks;
DROP TRIGGER checks_updated_timestamp;
DROP TABLE triggers;
DROP TABLE trigger_histories;
DROP TRIGGER triggers_updated_timestamp;
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module code.tjo.space/mentos1386/zdravko
module github.com/mentos1386/zdravko

go 1.21.6

Expand Down
11 changes: 0 additions & 11 deletions internal/activities/activities.go

This file was deleted.

Loading

0 comments on commit 0f28cdf

Please sign in to comment.