diff options
| author | Hamidreza Ghavami <hamid.r.gh.1998@gmail.com> | 2023-05-05 22:52:39 +0300 |
|---|---|---|
| committer | Hamidreza Ghavami <hamid.r.gh.1998@gmail.com> | 2023-05-05 22:52:39 +0300 |
| commit | 26f160fb89f1356f9ec69e2bdfad32d5b543325a (patch) | |
| tree | 73389e77f5ca2369e5fff721667d653ba99ec227 /web/service | |
| parent | 0a5811adf8077aa008d4ff795092d8ca547999e1 (diff) | |
add MigrateDB func for a single source of truth
Diffstat (limited to 'web/service')
| -rw-r--r-- | web/service/inbound.go | 11 | ||||
| -rw-r--r-- | web/service/server.go | 3 |
2 files changed, 11 insertions, 3 deletions
diff --git a/web/service/inbound.go b/web/service/inbound.go index 5d80c816..3c81998e 100644 --- a/web/service/inbound.go +++ b/web/service/inbound.go @@ -595,6 +595,7 @@ func (s *InboundService) DisableInvalidInbounds() (int64, error) { count := result.RowsAffected return count, err } + func (s *InboundService) DisableInvalidClients() (int64, error) { db := database.GetDB() now := time.Now().Unix() * 1000 @@ -605,7 +606,8 @@ func (s *InboundService) DisableInvalidClients() (int64, error) { count := result.RowsAffected return count, err } -func (s *InboundService) RemoveOrphanedTraffics() { + +func (s *InboundService) MigrationRemoveOrphanedTraffics() { db := database.GetDB() db.Exec(` DELETE FROM client_traffics @@ -616,6 +618,7 @@ func (s *InboundService) RemoveOrphanedTraffics() { ) `) } + func (s *InboundService) AddClientStat(inboundId int, client *model.Client) error { db := database.GetDB() @@ -634,6 +637,7 @@ func (s *InboundService) AddClientStat(inboundId int, client *model.Client) erro } return nil } + func (s *InboundService) UpdateClientStat(email string, client *model.Client) error { db := database.GetDB() @@ -1055,3 +1059,8 @@ func (s *InboundService) MigrationRequirements() { // Remove orphaned traffics db.Where("inbound_id = 0").Delete(xray.ClientTraffic{}) } + +func (s *InboundService) MigrateDB() { + s.MigrationRequirements() + s.MigrationRemoveOrphanedTraffics() +} diff --git a/web/service/server.go b/web/service/server.go index 06ce08c5..36d79b8b 100644 --- a/web/service/server.go +++ b/web/service/server.go @@ -469,8 +469,7 @@ func (s *ServerService) ImportDB(file multipart.File) error { defer os.Rename(fallbackPath, config.GetDBPath()) return common.NewErrorf("Error migrating db: %v", err) } - s.inboundService.MigrationRequirements() - s.inboundService.RemoveOrphanedTraffics() + s.inboundService.MigrateDB() // remove fallback file defer os.Remove(fallbackPath) |
