Fix db models to use text instead of varchar; remove unused columns & fix index names
This commit is contained in:
parent
5398e9fc0f
commit
eaf245e3ee
1 changed files with 31 additions and 33 deletions
64
db.go
64
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
|
||||
|
|
Loading…
Reference in a new issue