dev: automated commit - 2025-06-17 16:15:21

This commit is contained in:
Mariano Z. 2025-06-17 16:15:21 -03:00
parent 73e91db78b
commit 27775e6b29
16 changed files with 1860 additions and 1240 deletions

View file

@ -10,23 +10,22 @@ ON CONFLICT DO UPDATE SET
domain = excluded.domain,
update_period = excluded.update_period;
-- name: DeleteAllConfig :exec
DELETE FROM config;
-- name: InsertConfig :exec
INSERT INTO config (api_token, zone_id, domain, update_period)
VALUES (?, ?, ?, ?);
-- name: InitSchema :exec
-- This query is used to ensure the schema is set up properly
CREATE TABLE IF NOT EXISTS config (
api_token TEXT,
zone_id TEXT,
api_token TEXT NOT NULL DEFAULT '',
zone_id TEXT NOT NULL DEFAULT '',
domain TEXT NOT NULL DEFAULT 'mz.uy',
update_period TEXT NOT NULL DEFAULT '0 */6 * * *'
);
CREATE TRIGGER IF NOT EXISTS enforce_single_config
BEFORE INSERT ON config
WHEN (SELECT COUNT(*) FROM config) > 0
BEGIN
SELECT RAISE(FAIL, 'Only one config record allowed');
END;
-- Insert default config if none exists
INSERT OR IGNORE INTO config (domain, update_period)
SELECT 'mz.uy', '0 */6 * * *'
INSERT OR IGNORE INTO config (api_token, zone_id, domain, update_period)
SELECT '', '', 'mz.uy', '0 */6 * * *'
WHERE NOT EXISTS (SELECT 1 FROM config);

View file

@ -9,6 +9,15 @@ import (
"context"
)
const deleteAllConfig = `-- name: DeleteAllConfig :exec
DELETE FROM config
`
func (q *Queries) DeleteAllConfig(ctx context.Context) error {
_, err := q.db.ExecContext(ctx, deleteAllConfig)
return err
}
const getConfig = `-- name: GetConfig :one
SELECT api_token, zone_id, domain, update_period FROM config LIMIT 1
`
@ -27,19 +36,40 @@ func (q *Queries) GetConfig(ctx context.Context) (Config, error) {
const initSchema = `-- name: InitSchema :exec
CREATE TABLE IF NOT EXISTS config (
api_token TEXT,
zone_id TEXT,
api_token TEXT NOT NULL DEFAULT '',
zone_id TEXT NOT NULL DEFAULT '',
domain TEXT NOT NULL DEFAULT 'mz.uy',
update_period TEXT NOT NULL DEFAULT '0 */6 * * *'
)
`
// This query is used to ensure the schema is set up properly
func (q *Queries) InitSchema(ctx context.Context) error {
_, err := q.db.ExecContext(ctx, initSchema)
return err
}
const insertConfig = `-- name: InsertConfig :exec
INSERT INTO config (api_token, zone_id, domain, update_period)
VALUES (?, ?, ?, ?)
`
type InsertConfigParams struct {
ApiToken string `json:"api_token"`
ZoneID string `json:"zone_id"`
Domain string `json:"domain"`
UpdatePeriod string `json:"update_period"`
}
func (q *Queries) InsertConfig(ctx context.Context, arg InsertConfigParams) error {
_, err := q.db.ExecContext(ctx, insertConfig,
arg.ApiToken,
arg.ZoneID,
arg.Domain,
arg.UpdatePeriod,
)
return err
}
const upsertConfig = `-- name: UpsertConfig :exec
INSERT INTO config (api_token, zone_id, domain, update_period)
VALUES (?, ?, ?, ?)