feat: v2 to v3 data conversion (#1164)

* fix: user update group notification, group member face url

* fix: user update group notification, group member face url

* feat: v2 to v3 data conversion

* feat: v2 to v3 data conversion
This commit is contained in:
withchao
2023-10-08 12:11:42 +08:00
committed by GitHub
parent 8dd6a05d38
commit 717ed8fd12
27 changed files with 1023 additions and 0 deletions
@@ -0,0 +1,32 @@
package conversion
import (
"fmt"
"gorm.io/gorm"
"gorm.io/gorm/schema"
)
func FindAndInsert[V2 any, V3 schema.Tabler](v2db *gorm.DB, v3db *gorm.DB, fn func(V2) V3) (string, error) {
var t V3
name := t.TableName()
if err := v3db.AutoMigrate(&t); err != nil {
return name, fmt.Errorf("auto migrate v3 %s failed %w", name, err)
}
const size = 100
for i := 0; ; i++ {
var v2s []V2
if err := v2db.Offset(i * size).Limit(size).Find(&v2s).Error; err != nil {
return name, fmt.Errorf("find v2 %s failed %w", name, err)
}
if len(v2s) == 0 {
return name, nil
}
v3s := make([]V3, 0, len(v2s))
for _, v := range v2s {
v3s = append(v3s, fn(v))
}
if err := v3db.Create(&v3s).Error; err != nil {
return name, fmt.Errorf("insert v3 %s failed %w", name, err)
}
}
}
@@ -0,0 +1,140 @@
package conversion
import (
v2 "github.com/openimsdk/open-im-server/v3/tools/data-conversion/chat/v2"
"github.com/openimsdk/open-im-server/v3/tools/data-conversion/chat/v3/admin"
"github.com/openimsdk/open-im-server/v3/tools/data-conversion/chat/v3/chat"
)
// ########## chat ##########
func Account(v v2.Account) chat.Account {
return chat.Account{
UserID: v.UserID,
Password: v.Password,
CreateTime: v.CreateTime,
ChangeTime: v.ChangeTime,
OperatorUserID: v.OperatorUserID,
}
}
func Attribute(v v2.Attribute) chat.Attribute {
return chat.Attribute{
UserID: v.UserID,
Account: v.Account,
PhoneNumber: v.PhoneNumber,
AreaCode: v.AreaCode,
Email: v.Email,
Nickname: v.Nickname,
FaceURL: v.FaceURL,
Gender: v.Gender,
CreateTime: v.CreateTime,
ChangeTime: v.ChangeTime,
BirthTime: v.BirthTime,
Level: v.Level,
AllowVibration: v.AllowVibration,
AllowBeep: v.AllowBeep,
AllowAddFriend: v.AllowAddFriend,
GlobalRecvMsgOpt: 0,
}
}
func Register(v v2.Register) chat.Register {
return chat.Register{
UserID: v.UserID,
DeviceID: v.DeviceID,
IP: v.IP,
Platform: v.Platform,
AccountType: v.AccountType,
Mode: v.Mode,
CreateTime: v.CreateTime,
}
}
func UserLoginRecord(v v2.UserLoginRecord) chat.UserLoginRecord {
return chat.UserLoginRecord{
UserID: v.UserID,
LoginTime: v.LoginTime,
IP: v.IP,
DeviceID: v.DeviceID,
Platform: v.Platform,
}
}
// ########## admin ##########
func Admin(v v2.Admin) admin.Admin {
return admin.Admin{
Account: v.Account,
Password: v.Password,
FaceURL: v.FaceURL,
Nickname: v.Nickname,
UserID: v.UserID,
Level: v.Level,
CreateTime: v.CreateTime,
}
}
func Applet(v v2.Applet) admin.Applet {
return admin.Applet{
ID: v.ID,
Name: v.Name,
AppID: v.AppID,
Icon: v.Icon,
URL: v.URL,
MD5: v.MD5,
Size: v.Size,
Version: v.Version,
Priority: v.Priority,
Status: v.Status,
CreateTime: v.CreateTime,
}
}
func ForbiddenAccount(v v2.ForbiddenAccount) admin.ForbiddenAccount {
return admin.ForbiddenAccount{
UserID: v.UserID,
Reason: v.Reason,
OperatorUserID: v.OperatorUserID,
CreateTime: v.CreateTime,
}
}
func InvitationRegister(v v2.InvitationRegister) admin.InvitationRegister {
return admin.InvitationRegister{
InvitationCode: v.InvitationCode,
UsedByUserID: v.UsedByUserID,
CreateTime: v.CreateTime,
}
}
func IPForbidden(v v2.IPForbidden) admin.IPForbidden {
return admin.IPForbidden{
IP: v.IP,
LimitRegister: v.LimitRegister > 0,
LimitLogin: v.LimitLogin > 0,
CreateTime: v.CreateTime,
}
}
func LimitUserLoginIP(v v2.LimitUserLoginIP) admin.LimitUserLoginIP {
return admin.LimitUserLoginIP{
UserID: v.UserID,
IP: v.IP,
CreateTime: v.CreateTime,
}
}
func RegisterAddFriend(v v2.RegisterAddFriend) admin.RegisterAddFriend {
return admin.RegisterAddFriend{
UserID: v.UserID,
CreateTime: v.CreateTime,
}
}
func RegisterAddGroup(v v2.RegisterAddGroup) admin.RegisterAddGroup {
return admin.RegisterAddGroup{
GroupID: v.GroupID,
CreateTime: v.CreateTime,
}
}
+67
View File
@@ -0,0 +1,67 @@
package main
import (
"fmt"
"github.com/openimsdk/open-im-server/v3/tools/data-conversion/chat/conversion"
"gorm.io/driver/mysql"
"gorm.io/gorm"
"log"
)
func main() {
var (
usernameV2 = "root"
passwordV2 = "openIM123"
addrV2 = "127.0.0.1:13306"
databaseV2 = "admin_chat"
)
var (
usernameV3 = "root"
passwordV3 = "openIM123"
addrV3 = "127.0.0.1:13306"
databaseV3 = "openim_enterprise"
)
dsnV2 := fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8mb4&parseTime=True&loc=Local", usernameV2, passwordV2, addrV2, databaseV2)
dsnV3 := fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8mb4&parseTime=True&loc=Local", usernameV3, passwordV3, addrV3, databaseV3)
dbV2, err := gorm.Open(mysql.Open(dsnV2), &gorm.Config{})
if err != nil {
log.Println("open v2 db failed", err)
return
}
dbV3, err := gorm.Open(mysql.Open(dsnV3), &gorm.Config{})
if err != nil {
log.Println("open v3 db failed", err)
return
}
var fns []func() (string, error)
Append := func(fn func() (string, error)) {
fns = append(fns, fn)
}
Append(func() (string, error) { return conversion.FindAndInsert(dbV2, dbV3, conversion.Account) })
Append(func() (string, error) { return conversion.FindAndInsert(dbV2, dbV3, conversion.Attribute) })
Append(func() (string, error) { return conversion.FindAndInsert(dbV2, dbV3, conversion.Register) })
Append(func() (string, error) { return conversion.FindAndInsert(dbV2, dbV3, conversion.UserLoginRecord) })
Append(func() (string, error) { return conversion.FindAndInsert(dbV2, dbV3, conversion.Admin) })
Append(func() (string, error) { return conversion.FindAndInsert(dbV2, dbV3, conversion.Applet) })
Append(func() (string, error) { return conversion.FindAndInsert(dbV2, dbV3, conversion.ForbiddenAccount) })
Append(func() (string, error) { return conversion.FindAndInsert(dbV2, dbV3, conversion.InvitationRegister) })
Append(func() (string, error) { return conversion.FindAndInsert(dbV2, dbV3, conversion.IPForbidden) })
Append(func() (string, error) { return conversion.FindAndInsert(dbV2, dbV3, conversion.LimitUserLoginIP) })
Append(func() (string, error) { return conversion.FindAndInsert(dbV2, dbV3, conversion.RegisterAddFriend) })
Append(func() (string, error) { return conversion.FindAndInsert(dbV2, dbV3, conversion.RegisterAddGroup) })
for i := range fns {
name, err := fns[i]()
if err == nil {
log.Printf("[%d/%d] %s success\n", i+1, len(fns), name)
} else {
log.Printf("[%d/%d] %s failed %s\n", i+1, len(fns), name, err)
return
}
}
}
+63
View File
@@ -0,0 +1,63 @@
package v2
import (
"time"
)
// AppVersion pc端版本管理
type AppVersion struct {
Version string `gorm:"column:version;size:64" json:"version"`
Type int `gorm:"column:type;primary_key" json:"type"`
UpdateTime int `gorm:"column:update_time" json:"update_time"`
ForceUpdate bool `gorm:"column:force_update" json:"force_update"`
FileName string `gorm:"column:file_name" json:"file_name"`
YamlName string `gorm:"column:yaml_name" json:"yaml_name"`
UpdateLog string `gorm:"column:update_log" json:"update_log"`
}
// Admin 后台管理员
type Admin struct {
Account string `gorm:"column:account;primary_key;type:char(64)" json:"account"`
Password string `gorm:"column:Password;type:char(64)" json:"password"`
FaceURL string `gorm:"column:FaceURL;type:char(64)" json:"faceURL"`
Nickname string `gorm:"column:Nickname;type:char(64)" json:"nickname"`
UserID string `gorm:"column:UserID;type:char(64)" json:"userID"` //openIM userID
Level int32 `gorm:"column:level;default:1" json:"level"`
CreateTime time.Time `gorm:"column:create_time" json:"createTime"`
}
// RegisterAddFriend 注册时默认好友
type RegisterAddFriend struct {
UserID string `gorm:"column:user_id;primary_key;type:char(64)" json:"userID"`
CreateTime time.Time `gorm:"column:create_time" json:"createTime"`
}
// RegisterAddGroup 注册时默认群组
type RegisterAddGroup struct {
GroupID string `gorm:"column:group_id;primary_key;type:char(64)" json:"userID"`
CreateTime time.Time `gorm:"column:create_time" json:"createTime"`
}
// ClientInitConfig 系统相关配置项
type ClientInitConfig struct {
DiscoverPageURL string `gorm:"column:discover_page_url;size:128" json:"discoverPageURL"`
OrdinaryUserAddFriend int32 `gorm:"column:ordinary_user_add_friend; default:1" json:"ordinaryUserAddFriend"`
BossUserID string `gorm:"column:boss_user_id;type:char(64)" json:"bossUserID"`
AdminURL string `gorm:"column:admin_url;type:char(128)" json:"adminURL"`
AllowSendMsgNotFriend int32 `gorm:"column:allow_send_msg_not_friend;default:1" json:"allowSendMsgNotFriend"`
NeedInvitationCodeRegister int32 `gorm:"column:need_invitation_code_register;default:0" json:"needInvitationCodeRegister"`
}
type Applet struct {
ID string `gorm:"column:id;primary_key;size:64"`
Name string `gorm:"column:name;uniqueIndex;size:64"`
AppID string `gorm:"column:app_id;uniqueIndex;size:255"`
Icon string `gorm:"column:icon;size:255"`
URL string `gorm:"column:url;size:255"`
MD5 string `gorm:"column:md5;size:255"`
Size int64 `gorm:"column:size"`
Version string `gorm:"column:version;size:64"`
Priority uint32 `gorm:"column:priority;size:64"`
Status uint8 `gorm:"column:status"`
CreateTime time.Time `gorm:"column:create_time;autoCreateTime;size:64"`
}
+95
View File
@@ -0,0 +1,95 @@
package v2
import (
"time"
)
// Register 注册信息表
type Register struct {
UserID string `gorm:"column:user_id;primary_key;type:char(64)" json:"userID"`
DeviceID string `gorm:"column:device_id;type:varchar(255)" json:"deviceID"`
IP string `gorm:"column:ip;type:varchar(32)" json:"ip"`
Platform string `gorm:"column:platform;type:varchar(32)" json:"platform"`
AccountType string `gorm:"column:account_type;type:varchar(32)" json:"accountType"` //email phone account
Mode string `gorm:"column:mode;type:varchar(32)"` //user admin
CreateTime time.Time `gorm:"column:create_time" json:"createTime"`
}
// Account 账号密码表
type Account struct {
UserID string `gorm:"column:user_id;primary_key;type:char(64)" json:"userID"`
Password string `gorm:"column:password;type:varchar(255)" json:"password"`
CreateTime time.Time `gorm:"column:create_time" json:"createTime"`
ChangeTime time.Time `gorm:"column:change_time" json:"changeTime"`
OperatorUserID string `gorm:"column:operator_user_id;type:varchar(64)" json:"operatorUserID"`
}
// Attribute 用户属性表
type Attribute struct {
UserID string `gorm:"column:user_id;primary_key;type:char(64)" json:"userID"`
Account string `gorm:"column:account;type:char(64)" json:"account"`
PhoneNumber string `gorm:"column:phone_number;type:varchar(32)" json:"phoneNumber"`
AreaCode string `gorm:"column:area_code;type:varchar(8)" json:"areaCode"`
Email string `gorm:"column:email;type:varchar(64)" json:"email"`
Nickname string `gorm:"column:nickname;type:varchar(64)" json:"nickname"`
FaceURL string `gorm:"column:face_url;type:varchar(255)" json:"faceURL"`
Gender int32 `gorm:"column:gender" json:"gender"`
Birth uint32 `gorm:"column:birth" json:"birth"`
CreateTime time.Time `gorm:"column:create_time" json:"createTime"`
ChangeTime time.Time `gorm:"column:change_time" json:"changeTime"`
BirthTime time.Time `gorm:"column:birth_time" json:"birthTime"`
Level int32 `gorm:"column:level;default:1" json:"level"`
AllowVibration int32 `gorm:"column:allow_vibration;default:1" json:"allowVibration"`
AllowBeep int32 `gorm:"column:allow_beep;default:1" json:"allowBeep"`
AllowAddFriend int32 `gorm:"column:allow_add_friend;default:1" json:"allowAddFriend"`
}
// 封号表
type ForbiddenAccount struct {
UserID string `gorm:"column:user_id;index:userID;primary_key;type:char(64)" json:"userID"`
CreateTime time.Time `gorm:"column:create_time" json:"createTime"`
Reason string `gorm:"column:reason;type:varchar(255)" json:"reason"`
OperatorUserID string `gorm:"column:operator_user_id;type:varchar(255)" json:"operatorUserID"`
}
// 用户登录信息表
type UserLoginRecord struct {
UserID string `gorm:"column:user_id;size:64" json:"userID"`
LoginTime time.Time `gorm:"column:login_time" json:"loginTime"`
IP string `gorm:"column:ip;type:varchar(32)" json:"ip"`
DeviceID string `gorm:"column:device_id;type:varchar(255)" json:"deviceID"`
Platform string `gorm:"column:platform;type:varchar(32)" json:"platform"`
}
// 禁止ip登录 注册
type IPForbidden struct {
IP string `gorm:"column:ip;primary_key;type:char(32)" json:"ip"`
LimitRegister int32 `gorm:"column:limit_register" json:"limitRegister"`
LimitLogin int32 `gorm:"column:limit_login" json:"limitLogin"`
CreateTime time.Time `gorm:"column:create_time" json:"createTime"`
}
// 限制userID只能在某些ip登录
type LimitUserLoginIP struct {
UserID string `gorm:"column:user_id;primary_key;type:char(64)" json:"userID"`
IP string `gorm:"column:ip;primary_key;type:char(32)" json:"ip"`
CreateTime time.Time `gorm:"column:create_time" json:"createTime"`
}
// 邀请码被注册使用
type InvitationRegister struct {
InvitationCode string `gorm:"column:invitation_code;primary_key;type:char(32)" json:"invitationCode"`
CreateTime time.Time `gorm:"column:create_time" json:"createTime"`
UsedByUserID string `gorm:"column:user_id;index:userID;type:char(64)" json:"usedByUserID"`
}
type SignalRecord struct {
FileName string `gorm:"column:file_name;primary_key;type:char(128)" json:"fileName"`
MediaType string `gorm:"column:media_type;type:char(64);index:media_type_index" json:"mediaType"`
RoomType string `gorm:"column:room_type;type:char(20)" json:"roomType"`
SenderID string `gorm:"column:sender_id;type:char(64);index:sender_id_index" json:"senderID"`
RecvID string `gorm:"column:recv_id;type:char(64);index:recv_id_index" json:"recvID"`
GroupID string `gorm:"column:group_id;type:char(64)" json:"groupID"`
DownloadURL string `gorm:"column:download_url;type:text" json:"downloadURL"`
CreateTime time.Time `gorm:"create_time;index:create_time_index" json:"createTime"`
}
@@ -0,0 +1,34 @@
// Copyright © 2023 OpenIM open source community. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package admin
import (
"time"
)
// Admin 后台管理员.
type Admin struct {
Account string `gorm:"column:account;primary_key;type:varchar(64)"`
Password string `gorm:"column:password;type:varchar(64)"`
FaceURL string `gorm:"column:face_url;type:varchar(255)"`
Nickname string `gorm:"column:nickname;type:varchar(64)"`
UserID string `gorm:"column:user_id;type:varchar(64)"` // openIM userID
Level int32 `gorm:"column:level;default:1" `
CreateTime time.Time `gorm:"column:create_time"`
}
func (Admin) TableName() string {
return "admins"
}
@@ -0,0 +1,37 @@
// Copyright © 2023 OpenIM open source community. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package admin
import (
"time"
)
type Applet struct {
ID string `gorm:"column:id;primary_key;size:64"`
Name string `gorm:"column:name;size:64"`
AppID string `gorm:"column:app_id;uniqueIndex;size:255"`
Icon string `gorm:"column:icon;size:255"`
URL string `gorm:"column:url;size:255"`
MD5 string `gorm:"column:md5;size:255"`
Size int64 `gorm:"column:size"`
Version string `gorm:"column:version;size:64"`
Priority uint32 `gorm:"column:priority;size:64"`
Status uint8 `gorm:"column:status"`
CreateTime time.Time `gorm:"column:create_time;autoCreateTime;size:64"`
}
func (Applet) TableName() string {
return "applets"
}
@@ -0,0 +1,25 @@
// Copyright © 2023 OpenIM open source community. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package admin
// ClientConfig 客户端相关配置项.
type ClientConfig struct {
Key string `gorm:"column:key;primary_key;type:varchar(255)"`
Value string `gorm:"column:value;not null;type:text"`
}
func (ClientConfig) TableName() string {
return "client_config"
}
@@ -0,0 +1,31 @@
// Copyright © 2023 OpenIM open source community. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package admin
import (
"time"
)
// ForbiddenAccount 封号表.
type ForbiddenAccount struct {
UserID string `gorm:"column:user_id;index:userID;primary_key;type:char(64)"`
Reason string `gorm:"column:reason;type:varchar(255)" `
OperatorUserID string `gorm:"column:operator_user_id;type:varchar(255)"`
CreateTime time.Time `gorm:"column:create_time" `
}
func (ForbiddenAccount) TableName() string {
return "forbidden_accounts"
}
@@ -0,0 +1,30 @@
// Copyright © 2023 OpenIM open source community. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package admin
import (
"time"
)
// 邀请码被注册使用.
type InvitationRegister struct {
InvitationCode string `gorm:"column:invitation_code;primary_key;type:char(32)"`
UsedByUserID string `gorm:"column:user_id;index:userID;type:char(64)"`
CreateTime time.Time `gorm:"column:create_time"`
}
func (InvitationRegister) TableName() string {
return "invitation_registers"
}
@@ -0,0 +1,31 @@
// Copyright © 2023 OpenIM open source community. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package admin
import (
"time"
)
// 禁止ip登录 注册.
type IPForbidden struct {
IP string `gorm:"column:ip;primary_key;type:char(32)"`
LimitRegister bool `gorm:"column:limit_register"`
LimitLogin bool `gorm:"column:limit_login"`
CreateTime time.Time `gorm:"column:create_time"`
}
func (IPForbidden) TableName() string {
return "ip_forbiddens"
}
@@ -0,0 +1,30 @@
// Copyright © 2023 OpenIM open source community. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package admin
import (
"time"
)
// 限制userID只能在某些ip登录.
type LimitUserLoginIP struct {
UserID string `gorm:"column:user_id;primary_key;type:char(64)"`
IP string `gorm:"column:ip;primary_key;type:char(32)"`
CreateTime time.Time `gorm:"column:create_time" `
}
func (LimitUserLoginIP) TableName() string {
return "limit_user_login_ips"
}
@@ -0,0 +1,29 @@
// Copyright © 2023 OpenIM open source community. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package admin
import (
"time"
)
// RegisterAddFriend 注册时默认好友.
type RegisterAddFriend struct {
UserID string `gorm:"column:user_id;primary_key;type:char(64)"`
CreateTime time.Time `gorm:"column:create_time"`
}
func (RegisterAddFriend) TableName() string {
return "register_add_friends"
}
@@ -0,0 +1,29 @@
// Copyright © 2023 OpenIM open source community. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package admin
import (
"time"
)
// RegisterAddGroup 注册时默认群组.
type RegisterAddGroup struct {
GroupID string `gorm:"column:group_id;primary_key;type:char(64)"`
CreateTime time.Time `gorm:"column:create_time"`
}
func (RegisterAddGroup) TableName() string {
return "register_add_groups"
}
@@ -0,0 +1,32 @@
// Copyright © 2023 OpenIM open source community. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package chat
import (
"time"
)
// Account 账号密码表.
type Account struct {
UserID string `gorm:"column:user_id;primary_key;type:char(64)"`
Password string `gorm:"column:password;type:varchar(32)"`
CreateTime time.Time `gorm:"column:create_time;autoCreateTime"`
ChangeTime time.Time `gorm:"column:change_time;autoUpdateTime"`
OperatorUserID string `gorm:"column:operator_user_id;type:varchar(64)"`
}
func (Account) TableName() string {
return "accounts"
}
@@ -0,0 +1,43 @@
// Copyright © 2023 OpenIM open source community. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package chat
import (
"time"
)
// Attribute 用户属性表.
type Attribute struct {
UserID string `gorm:"column:user_id;primary_key;type:char(64)"`
Account string `gorm:"column:account;type:char(64)"`
PhoneNumber string `gorm:"column:phone_number;type:varchar(32)"`
AreaCode string `gorm:"column:area_code;type:varchar(8)"`
Email string `gorm:"column:email;type:varchar(64)" `
Nickname string `gorm:"column:nickname;type:varchar(64)" `
FaceURL string `gorm:"column:face_url;type:varchar(255)" `
Gender int32 `gorm:"column:gender"`
CreateTime time.Time `gorm:"column:create_time"`
ChangeTime time.Time `gorm:"column:change_time"`
BirthTime time.Time `gorm:"column:birth_time"`
Level int32 `gorm:"column:level;default:1"`
AllowVibration int32 `gorm:"column:allow_vibration;default:1"`
AllowBeep int32 `gorm:"column:allow_beep;default:1"`
AllowAddFriend int32 `gorm:"column:allow_add_friend;default:1"`
GlobalRecvMsgOpt int32 `gorm:"column:global_recv_msg_opt;default:0"`
}
func (Attribute) TableName() string {
return "attributes"
}
@@ -0,0 +1,34 @@
// Copyright © 2023 OpenIM open source community. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package chat
import (
"time"
)
// Register 注册信息表.
type Register struct {
UserID string `gorm:"column:user_id;primary_key;type:char(64)"`
DeviceID string `gorm:"column:device_id;type:varchar(255)"`
IP string `gorm:"column:ip;type:varchar(64)"`
Platform string `gorm:"column:platform;type:varchar(32)"`
AccountType string `gorm:"column:account_type;type:varchar(32)"` // email phone account
Mode string `gorm:"column:mode;type:varchar(32)"` // user admin
CreateTime time.Time `gorm:"column:create_time"`
}
func (Register) TableName() string {
return "registers"
}
@@ -0,0 +1,32 @@
// Copyright © 2023 OpenIM open source community. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
package chat
import (
"time"
)
// 用户登录信息表.
type UserLoginRecord struct {
UserID string `gorm:"column:user_id;size:64"`
LoginTime time.Time `gorm:"column:login_time"`
IP string `gorm:"column:ip;type:varchar(32)"`
DeviceID string `gorm:"column:device_id;type:varchar(255)"`
Platform string `gorm:"column:platform;type:varchar(32)"`
}
func (UserLoginRecord) TableName() string {
return "user_login_records"
}