Add created_at to pairs for pair growth stats

Migration 000016. Existing 825 rows keep created_at=0 (we can't
backfill accurately); new /bridge pairs get a real unix timestamp.

SQLite uses INSERT … ON CONFLICT … DO UPDATE SET prefix=0 (previously
INSERT OR REPLACE, which would have wiped created_at on conflict).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Andrey Lugovskoy 2026-04-24 15:40:28 +04:00
parent 9b7e3cd165
commit 49af1b6432
6 changed files with 10 additions and 3 deletions

View file

@ -0,0 +1 @@
ALTER TABLE pairs DROP COLUMN created_at;

View file

@ -0,0 +1 @@
ALTER TABLE pairs ADD COLUMN created_at BIGINT NOT NULL DEFAULT 0;

View file

@ -0,0 +1 @@
ALTER TABLE pairs DROP COLUMN created_at;

View file

@ -0,0 +1 @@
ALTER TABLE pairs ADD COLUMN created_at INTEGER NOT NULL DEFAULT 0;

View file

@ -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
}

View file

@ -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
}