postgres

package
v0.46.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2026 License: Apache-2.0 Imports: 13 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

OTA - DB Schema

CREATE TABLE IF NOT EXISTS updates (
    id                UUID PRIMARY KEY,
    group_id          UUID NOT NULL,
    file_name         VARCHAR(255) NOT NULL,
    version           VARCHAR(254) NOT NULL,
    file_size         BIGINT NOT NULL DEFAULT 0,
    checksum          VARCHAR(64) NOT NULL DEFAULT '',
    description       TEXT NOT NULL DEFAULT '',
    timeout           BIGINT NOT NULL,
    created_at        TIMESTAMPTZ NOT NULL,
    targets           BIGINT NOT NULL DEFAULT 0,
    pending_count     BIGINT NOT NULL DEFAULT 0,
    downloading_count BIGINT NOT NULL DEFAULT 0,
    installing_count  BIGINT NOT NULL DEFAULT 0,
    succeeded_count   BIGINT NOT NULL DEFAULT 0,
    failed_count      BIGINT NOT NULL DEFAULT 0,
    status            VARCHAR(32) NOT NULL
);

CREATE INDEX IF NOT EXISTS idx_updates_group_id_status ON updates (group_id, status);

CREATE TABLE IF NOT EXISTS thing_updates (
    update_id        UUID NOT NULL REFERENCES updates (id) ON DELETE CASCADE,
    thing_id         UUID NOT NULL,
    status           VARCHAR(16) NOT NULL,
    error            VARCHAR(255) NOT NULL DEFAULT '',
    reported_version VARCHAR(254) NOT NULL DEFAULT '',
    updated_at       TIMESTAMPTZ NOT NULL,
    PRIMARY KEY (update_id, thing_id)
);

CREATE INDEX IF NOT EXISTS idx_thing_updates_thing_id_status ON thing_updates (thing_id, status);
CREATE INDEX IF NOT EXISTS idx_thing_updates_status_updated_at ON thing_updates (status, updated_at);
CREATE UNIQUE INDEX IF NOT EXISTS idx_thing_updates_one_active ON thing_updates (thing_id)
    WHERE status IN ('pending', 'downloading', 'installing');

timeout is stored in seconds.

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 NewUpdateRepository

func NewUpdateRepository(db dbutil.Database) ota.UpdateRepository

NewUpdateRepository instantiates a PostgreSQL implementation of update 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