Explorar el Código

调整label表

lichangdong hace 1 semana
padre
commit
83d04ae52e

+ 5 - 10
ent/migrate/schema.go

@@ -556,9 +556,9 @@ var (
 		PrimaryKey: []*schema.Column{LabelColumns[0]},
 		Indexes: []*schema.Index{
 			{
-				Name:    "label_name_from_mode",
+				Name:    "label_name_organization_id",
 				Unique:  true,
-				Columns: []*schema.Column{LabelColumns[5], LabelColumns[6], LabelColumns[7]},
+				Columns: []*schema.Column{LabelColumns[5], LabelColumns[9]},
 			},
 		},
 	}
@@ -621,14 +621,9 @@ var (
 		},
 		Indexes: []*schema.Index{
 			{
-				Name:    "labelrelationship_label_id",
-				Unique:  false,
-				Columns: []*schema.Column{LabelRelationshipColumns[6]},
-			},
-			{
-				Name:    "labelrelationship_contact_id",
-				Unique:  false,
-				Columns: []*schema.Column{LabelRelationshipColumns[5]},
+				Name:    "u_label_contact",
+				Unique:  true,
+				Columns: []*schema.Column{LabelRelationshipColumns[6], LabelRelationshipColumns[5]},
 			},
 		},
 	}

+ 1 - 1
ent/schema/label.go

@@ -46,7 +46,7 @@ func (Label) Mixin() []ent.Mixin {
 
 func (Label) Indexes() []ent.Index {
 	return []ent.Index{
-		index.Fields("name", "from", "mode").Unique(),
+		index.Fields("name", "organization_id").Unique(),
 	}
 }
 

+ 3 - 2
ent/schema/label_relationship.go

@@ -37,8 +37,9 @@ func (LabelRelationship) Mixin() []ent.Mixin {
 
 func (LabelRelationship) Indexes() []ent.Index {
 	return []ent.Index{
-		index.Fields("label_id"),
-		index.Fields("contact_id"),
+		//index.Fields("label_id"),
+		//index.Fields("contact_id"),
+		index.Fields("label_id", "contact_id").Unique().StorageKey("u_label_contact"),
 	}
 }
 

+ 1 - 2
internal/service/MessageHandlers/contact_Label_info_notice.go

@@ -87,7 +87,6 @@ func (f *ContactLabelInfoNotice) Handle(ctx context.Context, msg *wechat_ws.MsgJ
 				SetCreatedAt(time.Now()).
 				SetUpdatedAt(time.Now()),
 		)
-
 		logx.Info("数据:", label.LabelName+"-----", label.LabelId, wxInfo.OrganizationID, message.WeChatId, time.Unix(tsInt/1000, 0))
 	}
 	//批量插入labelLog
@@ -107,7 +106,7 @@ func (f *ContactLabelInfoNotice) Handle(ctx context.Context, msg *wechat_ws.MsgJ
 	if len(labelCreates) > 0 {
 		err := svcCtx.DB.Label.CreateBulk(labelCreates...).
 			OnConflict(
-				sql.ConflictColumns("name", "from", "organization_id"),
+				sql.ConflictColumns("name", "organization_id"),
 			).
 			DoNothing().
 			Exec(ctx)