diff --git a/migrations/postgres/000016_pairs_created_at.down.sql b/migrations/postgres/000016_pairs_created_at.down.sql new file mode 100644 index 0000000..7326fc4 --- /dev/null +++ b/migrations/postgres/000016_pairs_created_at.down.sql @@ -0,0 +1 @@ +ALTER TABLE pairs DROP COLUMN created_at; diff --git a/migrations/postgres/000016_pairs_created_at.up.sql b/migrations/postgres/000016_pairs_created_at.up.sql new file mode 100644 index 0000000..400d416 --- /dev/null +++ b/migrations/postgres/000016_pairs_created_at.up.sql @@ -0,0 +1 @@ +ALTER TABLE pairs ADD COLUMN created_at BIGINT NOT NULL DEFAULT 0; diff --git a/migrations/sqlite/000016_pairs_created_at.down.sql b/migrations/sqlite/000016_pairs_created_at.down.sql new file mode 100644 index 0000000..7326fc4 --- /dev/null +++ b/migrations/sqlite/000016_pairs_created_at.down.sql @@ -0,0 +1 @@ +ALTER TABLE pairs DROP COLUMN created_at; diff --git a/migrations/sqlite/000016_pairs_created_at.up.sql b/migrations/sqlite/000016_pairs_created_at.up.sql new file mode 100644 index 0000000..d2af423 --- /dev/null +++ b/migrations/sqlite/000016_pairs_created_at.up.sql @@ -0,0 +1 @@ +ALTER TABLE pairs ADD COLUMN created_at INTEGER NOT NULL DEFAULT 0; diff --git a/postgres.go b/postgres.go index 24d8fa2..04be02d 100644 --- a/postgres.go +++ b/postgres.go @@ -64,8 +64,8 @@ func (r *pgRepo) Register(key, platform string, chatID int64) (bool, string, err } _, err = r.db.Exec( - "INSERT INTO pairs (tg_chat_id, max_chat_id, prefix) VALUES ($1, $2, 0) ON CONFLICT (tg_chat_id, max_chat_id) DO NOTHING", - tgID, maxID) + "INSERT INTO pairs (tg_chat_id, max_chat_id, prefix, created_at) VALUES ($1, $2, 0, $3) ON CONFLICT (tg_chat_id, max_chat_id) DO NOTHING", + tgID, maxID, time.Now().Unix()) return true, "", err } diff --git a/sqlite.go b/sqlite.go index 031c602..93cc3e1 100644 --- a/sqlite.go +++ b/sqlite.go @@ -60,7 +60,10 @@ func (r *sqliteRepo) Register(key, platform string, chatID int64) (bool, string, tgID, maxID = peerChatID, chatID } - _, err = r.db.Exec("INSERT OR REPLACE INTO pairs (tg_chat_id, max_chat_id, prefix) VALUES (?, ?, 0)", tgID, maxID) + _, err = r.db.Exec( + `INSERT INTO pairs (tg_chat_id, max_chat_id, prefix, created_at) VALUES (?, ?, 0, ?) + ON CONFLICT(tg_chat_id, max_chat_id) DO UPDATE SET prefix = 0`, + tgID, maxID, time.Now().Unix()) return true, "", err }