Add database migrations and handle leaving private chat portals. Fixes #7
This commit is contained in:
25
database/upgrades/2019-05-16-message-delete-cascade.go
Normal file
25
database/upgrades/2019-05-16-message-delete-cascade.go
Normal file
@ -0,0 +1,25 @@
|
||||
package upgrades
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
)
|
||||
|
||||
func init() {
|
||||
upgrades[1] = upgrade{"Add ON DELETE CASCADE to message table", func(dialect Dialect, tx *sql.Tx) error {
|
||||
if dialect == SQLite {
|
||||
// SQLite doesn't support constraint updates, but it isn't that careful with constraints anyway.
|
||||
return nil
|
||||
}
|
||||
_, err := tx.Exec("ALTER TABLE message DROP CONSTRAINT message_chat_jid_fkey")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
_, err = tx.Exec(`ALTER TABLE message ADD CONSTRAINT message_chat_jid_fkey
|
||||
FOREIGN KEY (chat_jid, chat_receiver) REFERENCES portal(jid, receiver)
|
||||
ON DELETE CASCADE`)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
}}
|
||||
}
|
Reference in New Issue
Block a user