Skip to content

Commit

Permalink
Use transactions to delete a federation
Browse files Browse the repository at this point in the history
Signed-off-by: ATechnoHazard <[email protected]>
  • Loading branch information
SphericalKat committed Oct 20, 2019
1 parent f4541da commit 20553f0
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
12 changes: 8 additions & 4 deletions go_bot/modules/sql/feds_sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,21 @@ func NewFed(ownerId string, fedId string, fedName string) bool {
} // No dirty read

func DelFed(fedId string) {
tx := SESSION.Begin()

fed := &Federation{}
SESSION.Where("id = ?", fedId).Delete(fed)
tx.Where("id = ?", fedId).Delete(fed)

chat := &FedChat{}
SESSION.Model(chat).Where("id = ?", fedId).Delete(chat)
tx.Model(chat).Where("id = ?", fedId).Delete(chat)

admins := &FedAdmin{}
SESSION.Model(&admins).Where("id = ?", fedId).Delete(admins)
tx.Model(&admins).Where("id = ?", fedId).Delete(admins)

bans := &FedBan{}
SESSION.Model(bans).Where("id = ?", fedId).Delete(bans)
tx.Model(bans).Where("id = ?", fedId).Delete(bans)

tx.Commit()
} // No dirty reads

func IsUserFedAdmin(fedId string, userId string) string {
Expand Down
3 changes: 2 additions & 1 deletion go_bot/modules/sql/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func init() {
log.Println("Database connected")

// Create tables if they don't exist
SESSION.AutoMigrate(&User{}, &Chat{}, &Warns{}, &WarnFilters{}, &WarnSettings{}, &BlackListFilters{}, &Federation{}, &FedChat{}, &FedAdmin{}, &FedBan{}, &Note{}, &Button{})
SESSION.AutoMigrate(&User{}, &Chat{}, &Warns{}, &WarnFilters{}, &WarnSettings{}, &BlackListFilters{}, &Federation{},
&FedChat{}, &FedAdmin{}, &FedBan{}, &Note{}, &Button{})
log.Println("Auto-migrated database schema")
}

0 comments on commit 20553f0

Please sign in to comment.