mirror of
https://github.com/Dvorinka/Containr.git
synced 2026-10-28 07:41:27 +00:00
Phase D3. Managed databases can ship backup archives to a configured S3-compatible destination (AWS S3, MinIO, Garage, …) while the local copy remains intact. - backup_targets table: owner-scoped endpoint/bucket/region/prefix + encrypted access/secret keys (enc:v1:, never returned, has_credentials) - create/update probe bucket access before storing; empty keys on update keep stored credentials; delete refused (409) while referenced - databases.backup_target_id assigns a target; external DBs rejected - backup pipeline uploads via a holder container over docker cp streams; remote failure keeps the local archive (logged), row gets remote:true - restore prefers the local archive; on a missing local copy it downloads the remote object into the backup volume first - holder containers must be started before archive ops — docker cp does not resolve volume mounts on never-started (Created) containers, and removing the source mid-stream stalls the reader without EOF - CLI: backup-targets list|add|update|remove|test + databases update --backup-target; MCP: 5 new tools; Settings UI card + per-database target picker + offsite badge on backups; OpenAPI + llms.txt + CLI.md Generated with [Devin](https://devin.ai) Co-Authored-By: Devin <158243242+devin-ai-integration[bot]@users.noreply.github.com>
254 lines
7.3 KiB
Go
254 lines
7.3 KiB
Go
// Code generated by sqlc. DO NOT EDIT.
|
|
// versions:
|
|
// sqlc v1.31.1
|
|
// source: backup_targets.sql
|
|
|
|
package sqlcdb
|
|
|
|
import (
|
|
"context"
|
|
"database/sql"
|
|
)
|
|
|
|
const countDatabasesUsingBackupTarget = `-- name: CountDatabasesUsingBackupTarget :one
|
|
SELECT COUNT(*)
|
|
FROM database_services
|
|
WHERE backup_target_id = $1
|
|
`
|
|
|
|
func (q *Queries) CountDatabasesUsingBackupTarget(ctx context.Context, targetID sql.NullString) (int64, error) {
|
|
row := q.db.QueryRowContext(ctx, countDatabasesUsingBackupTarget, targetID)
|
|
var count int64
|
|
err := row.Scan(&count)
|
|
return count, err
|
|
}
|
|
|
|
const createBackupTarget = `-- name: CreateBackupTarget :exec
|
|
INSERT INTO backup_targets (id, user_id, name, endpoint, bucket, region, prefix, access_key, secret_key, use_tls, created_at, updated_at)
|
|
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10, $11, $12)
|
|
`
|
|
|
|
type CreateBackupTargetParams struct {
|
|
ID string `json:"id"`
|
|
UserID string `json:"user_id"`
|
|
Name string `json:"name"`
|
|
Endpoint string `json:"endpoint"`
|
|
Bucket string `json:"bucket"`
|
|
Region string `json:"region"`
|
|
Prefix string `json:"prefix"`
|
|
AccessKey string `json:"access_key"`
|
|
SecretKey string `json:"secret_key"`
|
|
UseTls bool `json:"use_tls"`
|
|
CreatedAt sql.NullTime `json:"created_at"`
|
|
UpdatedAt sql.NullTime `json:"updated_at"`
|
|
}
|
|
|
|
func (q *Queries) CreateBackupTarget(ctx context.Context, arg CreateBackupTargetParams) error {
|
|
_, err := q.db.ExecContext(ctx, createBackupTarget,
|
|
arg.ID,
|
|
arg.UserID,
|
|
arg.Name,
|
|
arg.Endpoint,
|
|
arg.Bucket,
|
|
arg.Region,
|
|
arg.Prefix,
|
|
arg.AccessKey,
|
|
arg.SecretKey,
|
|
arg.UseTls,
|
|
arg.CreatedAt,
|
|
arg.UpdatedAt,
|
|
)
|
|
return err
|
|
}
|
|
|
|
const deleteBackupTargetByIDAndUser = `-- name: DeleteBackupTargetByIDAndUser :exec
|
|
DELETE FROM backup_targets
|
|
WHERE id = $1 AND user_id = $2
|
|
`
|
|
|
|
type DeleteBackupTargetByIDAndUserParams struct {
|
|
ID string `json:"id"`
|
|
UserID string `json:"user_id"`
|
|
}
|
|
|
|
func (q *Queries) DeleteBackupTargetByIDAndUser(ctx context.Context, arg DeleteBackupTargetByIDAndUserParams) error {
|
|
_, err := q.db.ExecContext(ctx, deleteBackupTargetByIDAndUser, arg.ID, arg.UserID)
|
|
return err
|
|
}
|
|
|
|
const getBackupTargetByID = `-- name: GetBackupTargetByID :one
|
|
SELECT backup_targets.id, backup_targets.user_id, backup_targets.name, backup_targets.endpoint, backup_targets.bucket, backup_targets.region, backup_targets.prefix, backup_targets.access_key, backup_targets.secret_key, backup_targets.use_tls, backup_targets.created_at, backup_targets.updated_at
|
|
FROM backup_targets
|
|
WHERE id = $1
|
|
`
|
|
|
|
func (q *Queries) GetBackupTargetByID(ctx context.Context, id string) (BackupTarget, error) {
|
|
row := q.db.QueryRowContext(ctx, getBackupTargetByID, id)
|
|
var i BackupTarget
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.UserID,
|
|
&i.Name,
|
|
&i.Endpoint,
|
|
&i.Bucket,
|
|
&i.Region,
|
|
&i.Prefix,
|
|
&i.AccessKey,
|
|
&i.SecretKey,
|
|
&i.UseTls,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const getBackupTargetByIDAndUser = `-- name: GetBackupTargetByIDAndUser :one
|
|
SELECT backup_targets.id, backup_targets.user_id, backup_targets.name, backup_targets.endpoint, backup_targets.bucket, backup_targets.region, backup_targets.prefix, backup_targets.access_key, backup_targets.secret_key, backup_targets.use_tls, backup_targets.created_at, backup_targets.updated_at
|
|
FROM backup_targets
|
|
WHERE id = $1 AND user_id = $2
|
|
`
|
|
|
|
type GetBackupTargetByIDAndUserParams struct {
|
|
ID string `json:"id"`
|
|
UserID string `json:"user_id"`
|
|
}
|
|
|
|
func (q *Queries) GetBackupTargetByIDAndUser(ctx context.Context, arg GetBackupTargetByIDAndUserParams) (BackupTarget, error) {
|
|
row := q.db.QueryRowContext(ctx, getBackupTargetByIDAndUser, arg.ID, arg.UserID)
|
|
var i BackupTarget
|
|
err := row.Scan(
|
|
&i.ID,
|
|
&i.UserID,
|
|
&i.Name,
|
|
&i.Endpoint,
|
|
&i.Bucket,
|
|
&i.Region,
|
|
&i.Prefix,
|
|
&i.AccessKey,
|
|
&i.SecretKey,
|
|
&i.UseTls,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
)
|
|
return i, err
|
|
}
|
|
|
|
const listBackupTargetsByUser = `-- name: ListBackupTargetsByUser :many
|
|
SELECT backup_targets.id, backup_targets.user_id, backup_targets.name, backup_targets.endpoint, backup_targets.bucket, backup_targets.region, backup_targets.prefix, backup_targets.access_key, backup_targets.secret_key, backup_targets.use_tls, backup_targets.created_at, backup_targets.updated_at
|
|
FROM backup_targets
|
|
WHERE user_id = $1
|
|
ORDER BY created_at DESC
|
|
`
|
|
|
|
func (q *Queries) ListBackupTargetsByUser(ctx context.Context, userID string) ([]BackupTarget, error) {
|
|
rows, err := q.db.QueryContext(ctx, listBackupTargetsByUser, userID)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer rows.Close()
|
|
items := []BackupTarget{}
|
|
for rows.Next() {
|
|
var i BackupTarget
|
|
if err := rows.Scan(
|
|
&i.ID,
|
|
&i.UserID,
|
|
&i.Name,
|
|
&i.Endpoint,
|
|
&i.Bucket,
|
|
&i.Region,
|
|
&i.Prefix,
|
|
&i.AccessKey,
|
|
&i.SecretKey,
|
|
&i.UseTls,
|
|
&i.CreatedAt,
|
|
&i.UpdatedAt,
|
|
); err != nil {
|
|
return nil, err
|
|
}
|
|
items = append(items, i)
|
|
}
|
|
if err := rows.Close(); err != nil {
|
|
return nil, err
|
|
}
|
|
if err := rows.Err(); err != nil {
|
|
return nil, err
|
|
}
|
|
return items, nil
|
|
}
|
|
|
|
const setDatabaseBackupRemoteKeyByID = `-- name: SetDatabaseBackupRemoteKeyByID :exec
|
|
UPDATE database_backups
|
|
SET remote_key = $1
|
|
WHERE id = $2
|
|
`
|
|
|
|
type SetDatabaseBackupRemoteKeyByIDParams struct {
|
|
RemoteKey sql.NullString `json:"remote_key"`
|
|
ID string `json:"id"`
|
|
}
|
|
|
|
func (q *Queries) SetDatabaseBackupRemoteKeyByID(ctx context.Context, arg SetDatabaseBackupRemoteKeyByIDParams) error {
|
|
_, err := q.db.ExecContext(ctx, setDatabaseBackupRemoteKeyByID, arg.RemoteKey, arg.ID)
|
|
return err
|
|
}
|
|
|
|
const setDatabaseBackupTargetByIDAndUser = `-- name: SetDatabaseBackupTargetByIDAndUser :exec
|
|
UPDATE database_services
|
|
SET backup_target_id = $1, updated_at = $2
|
|
WHERE id = $3 AND user_id = $4
|
|
`
|
|
|
|
type SetDatabaseBackupTargetByIDAndUserParams struct {
|
|
BackupTargetID sql.NullString `json:"backup_target_id"`
|
|
UpdatedAt sql.NullTime `json:"updated_at"`
|
|
ID string `json:"id"`
|
|
UserID string `json:"user_id"`
|
|
}
|
|
|
|
func (q *Queries) SetDatabaseBackupTargetByIDAndUser(ctx context.Context, arg SetDatabaseBackupTargetByIDAndUserParams) error {
|
|
_, err := q.db.ExecContext(ctx, setDatabaseBackupTargetByIDAndUser,
|
|
arg.BackupTargetID,
|
|
arg.UpdatedAt,
|
|
arg.ID,
|
|
arg.UserID,
|
|
)
|
|
return err
|
|
}
|
|
|
|
const updateBackupTargetByIDAndUser = `-- name: UpdateBackupTargetByIDAndUser :exec
|
|
UPDATE backup_targets
|
|
SET name = $1, endpoint = $2, bucket = $3, region = $4, prefix = $5, access_key = $6, secret_key = $7, use_tls = $8, updated_at = $9
|
|
WHERE id = $10 AND user_id = $11
|
|
`
|
|
|
|
type UpdateBackupTargetByIDAndUserParams struct {
|
|
Name string `json:"name"`
|
|
Endpoint string `json:"endpoint"`
|
|
Bucket string `json:"bucket"`
|
|
Region string `json:"region"`
|
|
Prefix string `json:"prefix"`
|
|
AccessKey string `json:"access_key"`
|
|
SecretKey string `json:"secret_key"`
|
|
UseTls bool `json:"use_tls"`
|
|
UpdatedAt sql.NullTime `json:"updated_at"`
|
|
ID string `json:"id"`
|
|
UserID string `json:"user_id"`
|
|
}
|
|
|
|
func (q *Queries) UpdateBackupTargetByIDAndUser(ctx context.Context, arg UpdateBackupTargetByIDAndUserParams) error {
|
|
_, err := q.db.ExecContext(ctx, updateBackupTargetByIDAndUser,
|
|
arg.Name,
|
|
arg.Endpoint,
|
|
arg.Bucket,
|
|
arg.Region,
|
|
arg.Prefix,
|
|
arg.AccessKey,
|
|
arg.SecretKey,
|
|
arg.UseTls,
|
|
arg.UpdatedAt,
|
|
arg.ID,
|
|
arg.UserID,
|
|
)
|
|
return err
|
|
}
|