From ee4cc06785b6ef4ac4746a8dc03e4555fc8435e2 Mon Sep 17 00:00:00 2001 From: oddyamill <43600905+oddyamill@users.noreply.github.com> Date: Mon, 28 Oct 2024 00:00:44 +0700 Subject: [PATCH] chore(users): better columns types --- internal/users/users.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/internal/users/users.go b/internal/users/users.go index 49b7a0d..ac7f524 100644 --- a/internal/users/users.go +++ b/internal/users/users.go @@ -11,7 +11,7 @@ import ( _ "github.com/lib/pq" ) -type UserState int +type UserState int8 const ( Unknown UserState = iota @@ -65,12 +65,12 @@ func createTable() { CREATE TABLE IF NOT EXISTS users ( id SERIAL PRIMARY KEY, telegram_id BIGINT NOT NULL UNIQUE, - discord_id TEXT UNIQUE, + discord_id VARCHAR(19) UNIQUE, access_token TEXT UNIQUE, - refresh_token VARCHAR(96) UNIQUE, + refresh_token CHAR(96) UNIQUE, student_id INTEGER, student_name_acronym TEXT, - state INTEGER NOT NULL DEFAULT 2, + state SMALLINT NOT NULL DEFAULT 2, last_marks_update TIMESTAMP DEFAULT CURRENT_TIMESTAMP, cache BOOLEAN DEFAULT TRUE ) @@ -83,8 +83,9 @@ func createIndex() { } func migrate() { - query("UPDATE users SET state = 2 WHERE state = 0") - query("ALTER TABLE users ADD COLUMN IF NOT EXISTS cache BOOLEAN DEFAULT TRUE") + query("ALTER TABLE users ALTER COLUMN state SET DATA TYPE SMALLINT") + query("ALTER TABLE users ALTER COLUMN discord_id SET DATA TYPE VARCHAR(19)") + query("ALTER TABLE users ALTER COLUMN refresh_token SET DATA TYPE CHAR(96)") } func query(query string, args ...any) {