postgres

package
v0.0.11 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2025 License: MIT Imports: 10 Imported by: 0

README

Database — PostgreSQL (High‑level schema)

This document summarizes the high‑level schema and design decisions for the PostgreSQL backend. It mirrors the system‑wide API key and UID design and avoids implementation details.

Core entities

  • Logbook

    • Internal primary key: id (sequential, used for joins)
    • External identifier: uid (immutable, opaque; used in client/server protocols)
    • Metadata: name, callsign, description, created_at, modified_at
  • API keys (per logbook)

    • Each logbook can have one or more API keys
    • Key format presented to clients: prefix.secretHex
    • prefix: independent random hex string (e.g., 12–16 chars); not derived from secretHex
    • secretHex: 64 hex chars from 32 random bytes
    • Stored digest: hash of secretHex (e.g., SHA‑512 hex) or HMAC with a server‑side pepper
    • Operational metadata: created/last used, expires/revoked, optional scopes and allowed IPs
    • Lookup pattern: resolve uidlogbook_id, then (logbook_id, key_prefix)
  • QSO

    • Each QSO belongs to exactly one logbook
    • Core fields: call, band, mode, freq, qso_date, time_on/off, rst_sent/rcvd, optional country
    • Flexible additional_data JSONB for extra fields, with a guard against duplicating core fields

Deletion policy

  • No soft deletes in the server‑side schema.
  • Deleting a logbook cascades hard deletes to its QSOs and API keys (non‑recoverable).
  • Deleting a QSO is non‑recoverable.
  • At most one active (non‑revoked) API key per logbook is enforced by a partial unique index; rotate by creating a new key before revoking the old one, or revoke then create.

High‑level flows

  • Registration

    • Client registers a logbook; server creates uid and issues an API key (prefix.secretHex)
    • Client stores uid and the full API key locally
  • Authentication and authorisation

    • Requests include Authorization: ApiKey <prefix>.<secretHex> and uid
    • Server resolves uid to logbook_id, finds an active key by (logbook_id, key_prefix), and validates digest
  • Rotation and revocation

    • Keys can be revoked or rotated; policy can allow multiple active keys or restrict to one

Integrity rules (application‑enforced)

  • Logging station callsign must match the logbook’s callsign on writes
  • Contacted station callsign (qso.call) is unconstrained relative to the logbook’s callsign

Notes

  • Sequential IDs remain internal; uid is the stable external reference
  • Prefix is independent random for zero leakage; it is not derived from secretHex
  • SQL models are generated from the migrations and can be re‑generated after schema changes

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyInitialSchemaSimple added in v0.0.8

func ApplyInitialSchemaSimple(handle *sql.DB) error

ApplyInitialSchemaSimple is a fallback initializer that applies the initial schema without using golang-migrate. It is intended for development/debugging where the standard migrator may be blocked by environment constraints.

func BootstrapExec added in v0.0.8

func BootstrapExec(handle *sql.DB) error

BootstrapExec executes the initial up migration directly for first-time initialization when the schema is entirely missing. This avoids potential issues with external migration locking on brand new databases.

func GetMigrationDrivers

func GetMigrationDrivers(handle *sql.DB) (source.Driver, database.Driver, error)

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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