From 7035afe00800cef2398e5a5179976ce573e4cfc2 Mon Sep 17 00:00:00 2001 From: Tine Date: Tue, 27 Feb 2024 15:55:35 +0100 Subject: [PATCH] fix: oauth2 query --- database/sqlite/migrations/2024-02-27-initial.sql | 12 +++++++----- deploy/fly.toml | 4 ++-- internal/services/oauth2_state.go | 2 +- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/database/sqlite/migrations/2024-02-27-initial.sql b/database/sqlite/migrations/2024-02-27-initial.sql index cd4fbde..3a4e305 100644 --- a/database/sqlite/migrations/2024-02-27-initial.sql +++ b/database/sqlite/migrations/2024-02-27-initial.sql @@ -1,7 +1,8 @@ -- +migrate Up CREATE TABLE oauth2_states ( - state TEXT, - expiry DATETIME, + state TEXT, + expires_at DATETIME DEFAULT CURRENT_TIMESTAMP, + PRIMARY KEY (state) ); @@ -33,7 +34,8 @@ CREATE TABLE worker_groups ( CREATE TABLE monitor_worker_groups ( worker_group_slug TEXT, - monitor_slug TEXT, + monitor_slug TEXT, + PRIMARY KEY (worker_group_slug,monitor_slug), CONSTRAINT fk_monitor_worker_groups_worker_group FOREIGN KEY (worker_group_slug) REFERENCES worker_groups(slug), CONSTRAINT fk_monitor_worker_groups_monitor FOREIGN KEY (monitor_slug) REFERENCES monitors(slug) @@ -41,8 +43,8 @@ CREATE TABLE monitor_worker_groups ( CREATE TABLE monitor_histories ( monitor_slug TEXT, - status TEXT, - note TEXT, + status TEXT, + note TEXT, created_at DATETIME DEFAULT CURRENT_TIMESTAMP, diff --git a/deploy/fly.toml b/deploy/fly.toml index 506100d..ffc54b6 100644 --- a/deploy/fly.toml +++ b/deploy/fly.toml @@ -17,8 +17,8 @@ primary_region = 'waw' ROOT_URL = 'https://zdravko.mnts.dev' TEMPORAL_SERVER_HOST = 'server.process.zdravko.internal:7233' - TEMPORAL_DATABASE_PATH = '/data/temporal-5.db' - DATABASE_PATH = '/data/zdravko-5.db' + TEMPORAL_DATABASE_PATH = '/data/temporal-6.db' + DATABASE_PATH = '/data/zdravko-6.db' [processes] server = '--temporal --server' diff --git a/internal/services/oauth2_state.go b/internal/services/oauth2_state.go index 1572f5c..9894685 100644 --- a/internal/services/oauth2_state.go +++ b/internal/services/oauth2_state.go @@ -16,7 +16,7 @@ func CreateOAuth2State(ctx context.Context, db *sqlx.DB, oauth2State *models.OAu } func DeleteOAuth2State(ctx context.Context, db *sqlx.DB, state string) (deleted bool, err error) { - res, err := db.ExecContext(ctx, "DELETE FROM oauth2_states WHERE state = $1 AND expires_at > NOW()", state) + res, err := db.ExecContext(ctx, "DELETE FROM oauth2_states WHERE state = $1 AND expires_at > datetime('now')", state) if err != nil { return false, err }