database

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2025 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Overview

Package database provides an interface for interacting with the SQLite database used by the application.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterMigration

func RegisterMigration(version string, up migrationfun, down migrationfun)

RegisterMigration is called by the migration functions in their init() to register a migration. version must be a timestamp in the format YYYYMMDDTHHMMSS (YearMonthDayTHoursMinutesSeconds), like '20251102T203201'. The migrations are ordered by timestamp before being applied. This guarantees that migrations are applied in the correct order, independent from the order in which the init() functions have run. Both an UP migration and a DOWN migration can be registered, with nil if no action has to be taken. If a registered migration function returns an error, the migration is cancelled. Each migration function is run inside a SQLite SAVEPOINT, which allows nesting in case that the migration function needs nested savepoints.

func RunMigrationsUp

func RunMigrationsUp(db *sql.DB) error

RunMigrationsUp ensures the database migrations table exists and applies any pending migrations.

RunMigrationsUp performs the following steps:

  1. Ensures the migrations table exists by executing createMigrationsTableSQL.
  2. Reads the version of the last applied migration from the migrations table using "SELECT version FROM migrations ORDER BY version DESC LIMIT 1". If the table is empty, no rows is treated as no previously applied migrations.
  3. Collects available migrations from the global `migrations` map, sorts their keys lexicographically, and iterates them in that order.
  4. Skips any migration whose version is less than or equal to the last applied version.
  5. For each pending migration, calls applyMigration(db, migration) to apply it, logs successful application, and stops on the first error returned by applyMigration.

Notes and expectations:

  • Version comparison is lexicographical string comparison; migration version keys must be chosen so that lexicographical order corresponds to the intended application order.
  • Recommended version format is a timestamp in the format YYYYMMDDTHHMMSS (YearMonthDayTHoursMinutesSeconds), like '20251102T203201'.

Types

type Database

type Database struct {
	// contains filtered or unexported fields
}

Database manages SQLite operations

func New

func New(dbname string) (*Database, error)

New creates a new database instance

func (*Database) Close

func (d *Database) Close() error

Close closes the database connection

func (*Database) CreateRegistration

func (d *Database) CreateRegistration(tsaService *tsaservice.TSAService, certificateData *models.CertificateData, email string, formData *models.ContractForm) error

func (*Database) CreateRelyingParty

func (d *Database) CreateRelyingParty(rp *models.RelyingParty, clientSecret string) error

CreateRelyingParty creates a new relying party

func (*Database) DeleteRelyingParty

func (d *Database) DeleteRelyingParty(id int) error

DeleteRelyingParty deletes a relying party If the relying party is not found, it returns an error

func (*Database) GetRegistration

func (d *Database) GetRegistration(organizationIdentifier string) (string, *models.ContractForm, string, error)

GetRegistration retrieves a registration by organization identifier. Returns the email, form data, and EIDAS certificate.

func (*Database) GetRegistrations

func (d *Database) GetRegistrations() ([]Registration, error)

func (*Database) GetRelyingParty

func (d *Database) GetRelyingParty(clientID string) (*models.RelyingParty, error)

GetRelyingParty retrieves a relying party by client ID If the relying party is not found, it returns nil, nil

func (*Database) ListRelyingParties

func (d *Database) ListRelyingParties() ([]models.RelyingParty, error)

ListRelyingParties retrieves all relying parties If no relying parties are found, it returns an empty slice, nil

func (*Database) UpdateRelyingParty

func (d *Database) UpdateRelyingParty(rp *models.RelyingParty, clientSecret string) error

UpdateRelyingParty updates an existing relying party

func (*Database) UpsertRelyingParty

func (d *Database) UpsertRelyingParty(rp *models.RelyingParty, clientSecret string) error

UpsertRelyingParty inserts or updates a relying party

func (*Database) ValidateClientSecret

func (d *Database) ValidateClientSecret(clientID, clientSecret string) (bool, error)

ValidateClientSecret validates a client secret against the stored hash

type Registration

type Registration struct {
	Email     string
	FormData  string
	EidasCert string
}

Jump to

Keyboard shortcuts

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