mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-10-30 01:34:59 +03:00
fix(database): keep the legacy tag cleanup from colliding with an existing tag (#6592)
* fix(database): avoid legacy inbound tag cleanup collisions * test(database): assert the legacy tag cleanup keeps the migration green The collision guard's test asserted only that the colliding tag was left alone, which an unguarded cleanup also produces: the UPDATE fails on the unique index and the row is unchanged either way. The cleanup shares a transaction with every other requirement, so that failure rolls all of them back on every boot and only reaches the log. Assert the call itself succeeds, which is what actually distinguishes the two. --------- Co-authored-by: n0ctal <n0ctal@users.noreply.github.com>
This commit is contained in:
@@ -263,11 +263,21 @@ func (s *InboundService) MigrationRequirements() (err error) {
|
||||
// Must be cross-DB: INSTR/REPLACE work on SQLite; Postgres needs position().
|
||||
tagCleanup := `UPDATE inbounds
|
||||
SET tag = REPLACE(tag, '0.0.0.0:', '')
|
||||
WHERE INSTR(tag, '0.0.0.0:') > 0;`
|
||||
WHERE INSTR(tag, '0.0.0.0:') > 0
|
||||
AND NOT EXISTS (
|
||||
SELECT 1 FROM inbounds AS other
|
||||
WHERE other.id <> inbounds.id
|
||||
AND other.tag = REPLACE(inbounds.tag, '0.0.0.0:', '')
|
||||
);`
|
||||
if database.IsPostgres() {
|
||||
tagCleanup = `UPDATE inbounds
|
||||
tagCleanup = `UPDATE inbounds AS i
|
||||
SET tag = REPLACE(tag, '0.0.0.0:', '')
|
||||
WHERE position('0.0.0.0:' in tag) > 0;`
|
||||
WHERE position('0.0.0.0:' in tag) > 0
|
||||
AND NOT EXISTS (
|
||||
SELECT 1 FROM inbounds AS other
|
||||
WHERE other.id <> i.id
|
||||
AND other.tag = REPLACE(i.tag, '0.0.0.0:', '')
|
||||
);`
|
||||
}
|
||||
err = tx.Exec(tagCleanup).Error
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user