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(&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.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.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.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.AutoMigrate(&DbKv{})
|
||||||
db.Model(&DbJoinedRoom{}).AddIndex("idx_user_protocol_account", "mx_user_id", "protocol", "account_name")
|
|
||||||
|
|
||||||
dbCache, err = lru.New2Q(10000)
|
dbCache, err = lru.New2Q(10000)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -55,70 +55,68 @@ func InitDb() error {
|
||||||
type DbAccountConfig struct {
|
type DbAccountConfig struct {
|
||||||
gorm.Model
|
gorm.Model
|
||||||
|
|
||||||
MxUserID string `gorm:"index:account_mxuserid"`
|
MxUserID string `gorm:"type:text;index"`
|
||||||
Name string
|
Name string `gorm:"type:text"`
|
||||||
Protocol string
|
Protocol string `gorm:"type:text"`
|
||||||
Config string
|
Config string `gorm:"type:text"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// List of joined channels to be re-joined on reconnect
|
// List of joined channels to be re-joined on reconnect
|
||||||
type DbJoinedRoom struct {
|
type DbJoinedRoom struct {
|
||||||
gorm.Model
|
ID uint `gorm:"primary_key"`
|
||||||
|
|
||||||
// User id and account name
|
// User id and account name
|
||||||
MxUserID string
|
MxUserID string `gorm:"type:text"`
|
||||||
Protocol string
|
Protocol string `gorm:"type:text"`
|
||||||
AccountName string
|
AccountName string `gorm:"type:text"`
|
||||||
|
|
||||||
// Room ID
|
// Room ID
|
||||||
RoomID connector.RoomID
|
RoomID connector.RoomID `gorm:"type:text"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// User mapping between protocol user IDs and puppeted matrix ids
|
// User mapping between protocol user IDs and puppeted matrix ids
|
||||||
type DbUserMap struct {
|
type DbUserMap struct {
|
||||||
gorm.Model
|
ID uint `gorm:"primary_key"`
|
||||||
|
|
||||||
Protocol string
|
Protocol string `gorm:"type:text"`
|
||||||
UserID connector.UserID
|
UserID connector.UserID `gorm:"type:text"`
|
||||||
MxUserID string `gorm:"index:usermap_mxuserid"`
|
MxUserID string `gorm:"type:text;index"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Room mapping between Matrix rooms and outside rooms
|
// Room mapping between Matrix rooms and outside rooms
|
||||||
type DbRoomMap struct {
|
type DbRoomMap struct {
|
||||||
gorm.Model
|
ID uint `gorm:"primary_key"`
|
||||||
|
|
||||||
// Network protocol
|
// Network protocol
|
||||||
Protocol string
|
Protocol string `gorm:"type:text"`
|
||||||
|
|
||||||
// Room id on the bridged network
|
// Room id on the bridged network
|
||||||
RoomID connector.RoomID
|
RoomID connector.RoomID `gorm:"type:text"`
|
||||||
|
|
||||||
// Bridged room matrix id
|
// Bridged room matrix id
|
||||||
MxRoomID string `gorm:"index:mxroomid"`
|
MxRoomID string `gorm:"type:text;index"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Room mapping between Matrix rooms and private messages
|
// Room mapping between Matrix rooms and private messages
|
||||||
type DbPmRoomMap struct {
|
type DbPmRoomMap struct {
|
||||||
gorm.Model
|
ID uint `gorm:"primary_key"`
|
||||||
|
|
||||||
// User id and account name of the local end viewed on Matrix
|
// User id and account name of the local end viewed on Matrix
|
||||||
MxUserID string
|
MxUserID string `gorm:"type:text"`
|
||||||
Protocol string
|
Protocol string `gorm:"type:text"`
|
||||||
AccountName string
|
AccountName string `gorm:"type:text"`
|
||||||
|
|
||||||
// User id to reach them
|
// User id to reach them
|
||||||
UserID connector.UserID
|
UserID connector.UserID `gorm:"type:text"`
|
||||||
|
|
||||||
// Bridged room for PMs
|
// Bridged room for PMs
|
||||||
MxRoomID string `gorm:"index:mxroomoid"`
|
MxRoomID string `gorm:"type:text;index"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// Key-value store for various things
|
// Key-value store for various things
|
||||||
type DbKv struct {
|
type DbKv struct {
|
||||||
gorm.Model
|
Key string `gorm:"type:text;primary_key"`
|
||||||
|
Value string `gorm:"type:text"`
|
||||||
Key string `gorm:"unique_index"`
|
|
||||||
Value string
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ---- Simple locking mechanism
|
// ---- Simple locking mechanism
|
||||||
|
|
Loading…
Reference in a new issue