postgres

package
v0.38.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 13, 2026 License: Apache-2.0 Imports: 15 Imported by: 0

README

Rules - DB Schema

CREATE TABLE IF NOT EXISTS rules (
    id          UUID PRIMARY KEY,
    group_id    UUID NOT NULL, 
    name        VARCHAR(254) NOT NULL,
    description VARCHAR(1024),
    conditions  JSONB NOT NULL,
    operator    VARCHAR(3) NOT NULL,
    actions     JSONB NOT NULL
);

CREATE TABLE IF NOT EXISTS rules_things (
    rule_id   UUID NOT NULL REFERENCES rules(id) ON DELETE CASCADE,
    thing_id  UUID NOT NULL,
    PRIMARY KEY (rule_id, thing_id)
);

CREATE TABLE IF NOT EXISTS lua_scripts (
    id          UUID NOT NULL,
    group_id    UUID NOT NULL,
    script      VARCHAR(65535) NOT NULL,
    name        VARCHAR NOT NULL,
    description VARCHAR NOT NULL,
    PRIMARY KEY (id)
);

CREATE TABLE IF NOT EXISTS lua_scripts_things (
    thing_id      UUID NOT NULL,
    lua_script_id UUID NOT NULL,
    PRIMARY KEY (thing_id, lua_script_id),
    FOREIGN KEY (lua_script_id) REFERENCES lua_scripts (id) ON DELETE CASCADE
);

CREATE TABLE IF NOT EXISTS lua_script_runs (
    id          UUID NOT NULL,
    script_id   UUID NOT NULL,
    thing_id    UUID NOT NULL,
    logs        JSONB NOT NULL,
    started_at  TIMESTAMPTZ NOT NULL,
    finished_at TIMESTAMPTZ NOT NULL,
    status      TEXT NOT NULL,
    error       TEXT NULL,
    PRIMARY KEY (id),
    FOREIGN KEY (script_id) REFERENCES lua_scripts (id)
);

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Connect

func Connect(cfg Config) (*sqlx.DB, error)

Connect creates a connection to the PostgreSQL instance and applies any unapplied database migrations. A non-nil error is returned to indicate failure.

func NewRuleRepository

func NewRuleRepository(db dbutil.Database) rules.Repository

NewRuleRepository instantiates a PostgreSQL implementation of rule repository.

Types

type Config

type Config struct {
	Host        string
	Port        string
	User        string
	Pass        string
	Name        string
	SSLMode     string
	SSLCert     string
	SSLKey      string
	SSLRootCert string
}

Config defines the options that are used when connecting to a PostgreSQL instance.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL