[migration] Remove Orphaned Traffics

This commit is contained in:
Alireza Ahmadi
2023-04-13 16:31:35 +02:00
parent 6a18ba48aa
commit fb15248030
2 changed files with 12 additions and 0 deletions

View File

@@ -489,6 +489,17 @@ func (s *InboundService) DisableInvalidClients() (int64, error) {
count := result.RowsAffected
return count, err
}
func (s *InboundService) RemoveOrphanedTraffics() {
db := database.GetDB()
db.Exec(`
DELETE FROM client_traffics
WHERE email NOT IN (
SELECT JSON_EXTRACT(client.value, '$.email')
FROM inbounds,
JSON_EACH(JSON_EXTRACT(inbounds.settings, '$.clients')) AS client
)
`)
}
func (s *InboundService) AddClientStat(inboundId int, client *model.Client) error {
db := database.GetDB()