Documentation
¶
Overview ¶
Package database provides an interface for interacting with the SQLite database used by the application.
Index ¶
- func RegisterMigration(version string, up migrationfun, down migrationfun)
- func RunMigrationsUp(db *sql.DB) error
- type Database
- func (d *Database) Close() error
- func (d *Database) CreateRegistration(tsaService *tsaservice.TSAService, certificateData *models.CertificateData, ...) error
- func (d *Database) CreateRelyingParty(rp *models.RelyingParty, clientSecret string) error
- func (d *Database) DeleteRelyingParty(id int) error
- func (d *Database) GetRegistration(organizationIdentifier string) (string, *models.ContractForm, string, error)
- func (d *Database) GetRegistrations() ([]Registration, error)
- func (d *Database) GetRelyingParty(clientID string) (*models.RelyingParty, error)
- func (d *Database) ListRelyingParties() ([]models.RelyingParty, error)
- func (d *Database) UpdateRelyingParty(rp *models.RelyingParty, clientSecret string) error
- func (d *Database) UpsertRelyingParty(rp *models.RelyingParty, clientSecret string) error
- func (d *Database) ValidateClientSecret(clientID, clientSecret string) (bool, error)
- type Registration
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 ¶
RunMigrationsUp ensures the database migrations table exists and applies any pending migrations.
RunMigrationsUp performs the following steps:
- Ensures the migrations table exists by executing createMigrationsTableSQL.
- 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.
- Collects available migrations from the global `migrations` map, sorts their keys lexicographically, and iterates them in that order.
- Skips any migration whose version is less than or equal to the last applied version.
- 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 (*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 ¶
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