mirror of
https://github.com/BEARlogin/max-telegram-bridge-bot.git
synced 2026-04-28 03:39:46 +00:00
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:
parent
9b7e3cd165
commit
49af1b6432
6 changed files with 10 additions and 3 deletions
1
migrations/postgres/000016_pairs_created_at.down.sql
Normal file
1
migrations/postgres/000016_pairs_created_at.down.sql
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
ALTER TABLE pairs DROP COLUMN created_at;
|
||||||
1
migrations/postgres/000016_pairs_created_at.up.sql
Normal file
1
migrations/postgres/000016_pairs_created_at.up.sql
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
ALTER TABLE pairs ADD COLUMN created_at BIGINT NOT NULL DEFAULT 0;
|
||||||
1
migrations/sqlite/000016_pairs_created_at.down.sql
Normal file
1
migrations/sqlite/000016_pairs_created_at.down.sql
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
ALTER TABLE pairs DROP COLUMN created_at;
|
||||||
1
migrations/sqlite/000016_pairs_created_at.up.sql
Normal file
1
migrations/sqlite/000016_pairs_created_at.up.sql
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
ALTER TABLE pairs ADD COLUMN created_at INTEGER NOT NULL DEFAULT 0;
|
||||||
|
|
@ -64,8 +64,8 @@ func (r *pgRepo) Register(key, platform string, chatID int64) (bool, string, err
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err = r.db.Exec(
|
_, 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",
|
"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)
|
tgID, maxID, time.Now().Unix())
|
||||||
return true, "", err
|
return true, "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,10 @@ func (r *sqliteRepo) Register(key, platform string, chatID int64) (bool, string,
|
||||||
tgID, maxID = peerChatID, chatID
|
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
|
return true, "", err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue