From b436e46e2aa7f8ab0c067a7fff95ee51bb121aa6 Mon Sep 17 00:00:00 2001 From: DcruBro Date: Sat, 5 Sep 2026 19:57:41 +0200 Subject: [PATCH] sqlc fix --- internal/db/db.go | 32 +++++ internal/db/keys.sql.go | 45 +++++++ internal/db/models.go | 124 ++++++++++++++++++ migrations/{001-Types.sql => 001_types.sql} | 0 migrations/{002-Core.sql => 002_core.sql} | 0 migrations/{003-API.sql => 003_api.sql} | 0 .../{004-Logbook.sql => 004_logbook.sql} | 0 .../{004-Privacy.sql => 004_privacy.sql} | 0 sqlc.yaml | 8 +- 9 files changed, 205 insertions(+), 4 deletions(-) create mode 100644 internal/db/db.go create mode 100644 internal/db/keys.sql.go create mode 100644 internal/db/models.go rename migrations/{001-Types.sql => 001_types.sql} (100%) rename migrations/{002-Core.sql => 002_core.sql} (100%) rename migrations/{003-API.sql => 003_api.sql} (100%) rename migrations/{004-Logbook.sql => 004_logbook.sql} (100%) rename migrations/{004-Privacy.sql => 004_privacy.sql} (100%) diff --git a/internal/db/db.go b/internal/db/db.go new file mode 100644 index 0000000..468d1fa --- /dev/null +++ b/internal/db/db.go @@ -0,0 +1,32 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.31.1 + +package db + +import ( + "context" + + "github.com/jackc/pgx/v5" + "github.com/jackc/pgx/v5/pgconn" +) + +type DBTX interface { + Exec(context.Context, string, ...interface{}) (pgconn.CommandTag, error) + Query(context.Context, string, ...interface{}) (pgx.Rows, error) + QueryRow(context.Context, string, ...interface{}) pgx.Row +} + +func New(db DBTX) *Queries { + return &Queries{db: db} +} + +type Queries struct { + db DBTX +} + +func (q *Queries) WithTx(tx pgx.Tx) *Queries { + return &Queries{ + db: tx, + } +} diff --git a/internal/db/keys.sql.go b/internal/db/keys.sql.go new file mode 100644 index 0000000..62248c7 --- /dev/null +++ b/internal/db/keys.sql.go @@ -0,0 +1,45 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.31.1 +// source: keys.sql + +package db + +import ( + "context" + + "github.com/jackc/pgx/v5/pgtype" +) + +const getKeyByHash = `-- name: GetKeyByHash :one +SELECT k.id, k.owner_id, k.scopes, k.quota_tier, k.status, k.expires_at, + o.status AS owner_status +FROM api.keys k +JOIN api.owners o ON o.id = k.owner_id +WHERE k.key_hash = $1 AND k.status = 'active' +` + +type GetKeyByHashRow struct { + ID int64 + OwnerID int64 + Scopes []string + QuotaTier string + Status string + ExpiresAt pgtype.Timestamptz + OwnerStatus string +} + +func (q *Queries) GetKeyByHash(ctx context.Context, keyHash []byte) (GetKeyByHashRow, error) { + row := q.db.QueryRow(ctx, getKeyByHash, keyHash) + var i GetKeyByHashRow + err := row.Scan( + &i.ID, + &i.OwnerID, + &i.Scopes, + &i.QuotaTier, + &i.Status, + &i.ExpiresAt, + &i.OwnerStatus, + ) + return i, err +} diff --git a/internal/db/models.go b/internal/db/models.go new file mode 100644 index 0000000..03dbeac --- /dev/null +++ b/internal/db/models.go @@ -0,0 +1,124 @@ +// Code generated by sqlc. DO NOT EDIT. +// versions: +// sqlc v1.31.1 + +package db + +import ( + "github.com/jackc/pgx/v5/pgtype" +) + +// Several active keys per owner is intentional: people leak keys into public repositories, and rotating needs an overlap window where both the old and new key work. +type ApiKey struct { + ID int64 + OwnerID int64 + KeyHash []byte + KeyPrefix string + Label *string + Scopes []string + QuotaTier string + Status string + CreatedAt pgtype.Timestamptz + ExpiresAt pgtype.Timestamptz + LastUsedAt pgtype.Timestamptz + RevokedAt pgtype.Timestamptz + RevokedReason *string +} + +// Registrants for API keys. Holds PII from an international user base, so the deletion path in 005_privacy.sql applies here too, not just to Discord users. +type ApiOwner struct { + ID int64 + Email interface{} + EmailVerifiedAt pgtype.Timestamptz + Callsign interface{} + CallsignVerifiedAt pgtype.Timestamptz + Status string + CreatedAt pgtype.Timestamptz + UpdatedAt pgtype.Timestamptz +} + +type ApiUsageDaily struct { + KeyID int64 + Day pgtype.Date + Endpoint string + Calls int64 + Errors int64 + DistinctUsers int32 +} + +type CoreSubscription struct { + ID int64 + GuildID *int64 + ChannelID int64 + UserID *int64 + Kind string + Filters []byte + Enabled bool + CreatedAt pgtype.Timestamptz + UpdatedAt pgtype.Timestamptz +} + +// One row per Discord user who has interacted with a stateful command. Deliberately no soft-delete column: a deletion request must actually remove the row, so there is nothing left to resurrect. +type CoreUser struct { + ID int64 + DiscordID int64 + Callsign interface{} + CallsignVerifiedAt pgtype.Timestamptz + VerificationMethod *string + Grid interface{} + Timezone *string + CreatedAt pgtype.Timestamptz + UpdatedAt pgtype.Timestamptz +} + +type CoreVerification struct { + ID int64 + UserID int64 + Method string + Callsign interface{} + Status string + ChallengeHash []byte + Detail []byte + CreatedAt pgtype.Timestamptz + ExpiresAt pgtype.Timestamptz + CompletedAt pgtype.Timestamptz +} + +type LogbookImport struct { + ID int64 + UserID int64 + Filename *string + Source *string + Status string + RowsTotal int32 + RowsAccepted int32 + RowsDuplicate int32 + RowsRejected int32 + Error *string + StartedAt pgtype.Timestamptz + FinishedAt pgtype.Timestamptz +} + +type LogbookQso struct { + ID int64 + UserID int64 + ImportID *int64 + Callsign interface{} + QsoAt pgtype.Timestamptz + // Truncated copy of qso_at used only for duplicate detection. Do not query it directly; use qso_at. + QsoMinute pgtype.Timestamp + Band *string + Mode *string + Submode *string + FreqHz *int64 + RstSent *string + RstRcvd *string + Grid interface{} + Dxcc *int32 + CqZone *int16 + ItuZone *int16 + TxPowerW pgtype.Numeric + Comment *string + Extra []byte + CreatedAt pgtype.Timestamptz +} diff --git a/migrations/001-Types.sql b/migrations/001_types.sql similarity index 100% rename from migrations/001-Types.sql rename to migrations/001_types.sql diff --git a/migrations/002-Core.sql b/migrations/002_core.sql similarity index 100% rename from migrations/002-Core.sql rename to migrations/002_core.sql diff --git a/migrations/003-API.sql b/migrations/003_api.sql similarity index 100% rename from migrations/003-API.sql rename to migrations/003_api.sql diff --git a/migrations/004-Logbook.sql b/migrations/004_logbook.sql similarity index 100% rename from migrations/004-Logbook.sql rename to migrations/004_logbook.sql diff --git a/migrations/004-Privacy.sql b/migrations/004_privacy.sql similarity index 100% rename from migrations/004-Privacy.sql rename to migrations/004_privacy.sql diff --git a/sqlc.yaml b/sqlc.yaml index 7ed1be5..221fde1 100644 --- a/sqlc.yaml +++ b/sqlc.yaml @@ -4,10 +4,10 @@ sql: - engine: "postgresql" queries: "queries" schema: - - "migrations/002_types.sql" - - "migrations/003_core.sql" - - "migrations/004_api.sql" - - "migrations/005_logbook.sql" + - "migrations/001_types.sql" + - "migrations/002_core.sql" + - "migrations/003_api.sql" + - "migrations/004_logbook.sql" gen: go: package: "db"