aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2020-02-28 16:55:45 +0100
committerAlex Auvolat <alex@adnab.me>2020-02-28 16:55:45 +0100
commiteaf245e3eed04aec1b5aa3941ee7f54d62b6b149 (patch)
tree7eedb724820a8b9f9f54141a4acf63b1650f8bc3
parent5398e9fc0f4e7b971221b80c490fea8c24287081 (diff)
downloadeasybridge-eaf245e3eed04aec1b5aa3941ee7f54d62b6b149.tar.gz
easybridge-eaf245e3eed04aec1b5aa3941ee7f54d62b6b149.zip
Fix db models to use text instead of varchar; remove unused columns & fix index names
-rw-r--r--db.go64
1 files changed, 31 insertions, 33 deletions
diff --git a/db.go b/db.go
index c4d7fa4..e38a8eb 100644
--- a/db.go
+++ b/db.go
@@ -29,19 +29,19 @@ func InitDb() error {
db.AutoMigrate(&DbAccountConfig{})
- db.AutoMigrate(&DbKv{})
+ db.AutoMigrate(&DbJoinedRoom{})
+ db.Model(&DbJoinedRoom{}).AddIndex("idx_joined_room_user_protocol_account", "mx_user_id", "protocol", "account_name")
db.AutoMigrate(&DbUserMap{})
- db.Model(&DbUserMap{}).AddIndex("idx_protocol_user", "protocol", "user_id")
+ db.Model(&DbUserMap{}).AddIndex("idx_user_map_protocol_user", "protocol", "user_id")
db.AutoMigrate(&DbRoomMap{})
- db.Model(&DbRoomMap{}).AddIndex("idx_protocol_room", "protocol", "room_id")
+ db.Model(&DbRoomMap{}).AddIndex("idx_room_map_protocol_room", "protocol", "room_id")
db.AutoMigrate(&DbPmRoomMap{})
- db.Model(&DbPmRoomMap{}).AddIndex("idx_protocol_user_account_user", "protocol", "user_id", "mx_user_id", "account_name")
+ db.Model(&DbPmRoomMap{}).AddIndex("idx_pm_room_map_protocol_user_account_user", "protocol", "user_id", "mx_user_id", "account_name")
- db.AutoMigrate(&DbJoinedRoom{})
- db.Model(&DbJoinedRoom{}).AddIndex("idx_user_protocol_account", "mx_user_id", "protocol", "account_name")
+ db.AutoMigrate(&DbKv{})
dbCache, err = lru.New2Q(10000)
if err != nil {
@@ -55,70 +55,68 @@ func InitDb() error {
type DbAccountConfig struct {
gorm.Model
- MxUserID string `gorm:"index:account_mxuserid"`
- Name string
- Protocol string
- Config string
+ MxUserID string `gorm:"type:text;index"`
+ Name string `gorm:"type:text"`
+ Protocol string `gorm:"type:text"`
+ Config string `gorm:"type:text"`
}
// List of joined channels to be re-joined on reconnect
type DbJoinedRoom struct {
- gorm.Model
+ ID uint `gorm:"primary_key"`
// User id and account name
- MxUserID string
- Protocol string
- AccountName string
+ MxUserID string `gorm:"type:text"`
+ Protocol string `gorm:"type:text"`
+ AccountName string `gorm:"type:text"`
// Room ID
- RoomID connector.RoomID
+ RoomID connector.RoomID `gorm:"type:text"`
}
// User mapping between protocol user IDs and puppeted matrix ids
type DbUserMap struct {
- gorm.Model
+ ID uint `gorm:"primary_key"`
- Protocol string
- UserID connector.UserID
- MxUserID string `gorm:"index:usermap_mxuserid"`
+ Protocol string `gorm:"type:text"`
+ UserID connector.UserID `gorm:"type:text"`
+ MxUserID string `gorm:"type:text;index"`
}
// Room mapping between Matrix rooms and outside rooms
type DbRoomMap struct {
- gorm.Model
+ ID uint `gorm:"primary_key"`
// Network protocol
- Protocol string
+ Protocol string `gorm:"type:text"`
// Room id on the bridged network
- RoomID connector.RoomID
+ RoomID connector.RoomID `gorm:"type:text"`
// Bridged room matrix id
- MxRoomID string `gorm:"index:mxroomid"`
+ MxRoomID string `gorm:"type:text;index"`
}
// Room mapping between Matrix rooms and private messages
type DbPmRoomMap struct {
- gorm.Model
+ ID uint `gorm:"primary_key"`
// User id and account name of the local end viewed on Matrix
- MxUserID string
- Protocol string
- AccountName string
+ MxUserID string `gorm:"type:text"`
+ Protocol string `gorm:"type:text"`
+ AccountName string `gorm:"type:text"`
// User id to reach them
- UserID connector.UserID
+ UserID connector.UserID `gorm:"type:text"`
// Bridged room for PMs
- MxRoomID string `gorm:"index:mxroomoid"`
+ MxRoomID string `gorm:"type:text;index"`
}
// Key-value store for various things
type DbKv struct {
- gorm.Model
-
- Key string `gorm:"unique_index"`
- Value string
+ Key string `gorm:"type:text;primary_key"`
+ Value string `gorm:"type:text"`
}
// ---- Simple locking mechanism