postgres

package
v0.28.3 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2025 License: Apache-2.0 Imports: 17 Imported by: 0

README

Things - DB Schema

CREATE TABLE group_roles (
    group_id   UUID NOT NULL,
    member_id  UUID NOT NULL,
    role       VARCHAR(15),

    CONSTRAINT group_policies_pkey PRIMARY KEY (group_id, member_id),
    CONSTRAINT group_policies_group_id_fkey FOREIGN KEY (group_id) REFERENCES groups(id) ON DELETE CASCADE
);

CREATE TABLE groups (
    id          UUID UNIQUE NOT NULL,
    org_id      UUID NOT NULL,
    name        VARCHAR(254) NOT NULL,
    description VARCHAR(1024),
    metadata    JSONB,
    created_at  TIMESTAMP WITH TIME ZONE,
    updated_at  TIMESTAMP WITH TIME ZONE,

    CONSTRAINT  groups_pkey PRIMARY KEY (id),
    CONSTRAINT  org_name UNIQUE (org_id, name)
);

CREATE TABLE profiles (
    id        UUID UNIQUE NOT NULL,
    group_id  UUID NOT NULL,
    name      VARCHAR(1024) NOT NULL,
    config    JSONB,
    metadata  JSONB,

    CONSTRAINT group_name_prs UNIQUE (group_id, name),
    CONSTRAINT profiles_pkey PRIMARY KEY (id),
    CONSTRAINT channels_group_id_fkey FOREIGN KEY (group_id) REFERENCES groups(id) ON UPDATE CASCADE ON DELETE CASCADE
);

CREATE TABLE things (
    id         UUID UNIQUE NOT NULL,
    group_id   UUID NOT NULL,
    key        VARCHAR(4096) UNIQUE NOT NULL,
    name       VARCHAR(1024) NOT NULL,
    metadata   JSONB,
    profile_id UUID NOT NULL,

    CONSTRAINT group_name_ths UNIQUE (group_id, name),
    CONSTRAINT things_pkey PRIMARY KEY (id),
    CONSTRAINT fk_things_profile_id FOREIGN KEY (profile_id) REFERENCES profiles(id) ON UPDATE CASCADE ON DELETE RESTRICT,
    CONSTRAINT things_group_id_fkey FOREIGN KEY (group_id) REFERENCES groups(id) ON UPDATE CASCADE ON DELETE CASCADE
);

Documentation

Overview

Package postgres contains repository implementations using PostgreSQL as the underlying database.

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 NewGroupMembersRepository added in v0.26.0

func NewGroupMembersRepository(db dbutil.Database) things.GroupMembersRepository

NewGroupMembersRepository instantiates a PostgreSQL implementation of members repository.

func NewGroupRepository

func NewGroupRepository(db dbutil.Database) things.GroupRepository

NewGroupRepository instantiates a PostgreSQL implementation of group repository.

func NewProfileRepository added in v0.24.0

func NewProfileRepository(db dbutil.Database) things.ProfileRepository

NewProfileRepository instantiates a PostgreSQL implementation of profile repository.

func NewThingRepository

func NewThingRepository(db dbutil.Database) things.ThingRepository

NewThingRepository instantiates a PostgreSQL implementation of thing 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