-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix issue with automatically tracked packages not getting notificatio…
…ns and not being unfollowable
- Loading branch information
Showing
4 changed files
with
52 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -33,3 +33,4 @@ deobfuscated | |
paczkobot.db | ||
|
||
.DS_Store | ||
*.db |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package paczkobot | ||
|
||
import ( | ||
"log" | ||
|
||
"gorm.io/gorm" | ||
) | ||
|
||
func MigrateBadInpostAccounts(db *gorm.DB) error { | ||
// Begin a new transaction | ||
tx := db.Begin() | ||
if tx.Error != nil { | ||
return tx.Error | ||
} | ||
|
||
// copy telegram_user_id to telegram_chat_id if telegram_chat_id is 0 in inpost_credentials | ||
result := tx.Exec(` | ||
UPDATE inpost_credentials | ||
SET telegram_chat_id = telegram_user_id | ||
WHERE telegram_chat_id = 0 | ||
`) | ||
if result.Error != nil { | ||
tx.Rollback() | ||
return result.Error | ||
} | ||
log.Printf("Updated rows in inpost_credentials: %d", result.RowsAffected) | ||
|
||
// copy telegram_user_id to chat_id if chat_id is 0 in followed_package_telegram_users | ||
result = tx.Exec(` | ||
UPDATE followed_package_telegram_users | ||
SET chat_id = telegram_user_id | ||
WHERE chat_id = 0 | ||
`) | ||
if result.Error != nil { | ||
tx.Rollback() | ||
return result.Error | ||
} | ||
log.Printf("Updated rows in followed_package_telegram_users: %d", result.RowsAffected) | ||
|
||
// Commit the transaction | ||
if err := tx.Commit().Error; err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |