refactor: shorten model and table prefixes
This commit is contained in:
@@ -17,8 +17,8 @@ type DemoOptions struct {
|
||||
}
|
||||
|
||||
type DemoResult struct {
|
||||
User models.SenlinAgentUser
|
||||
Projects []models.SenlinAgentProject
|
||||
User models.SaUser
|
||||
Projects []models.SaProject
|
||||
}
|
||||
|
||||
func Demo(database *gorm.DB, options DemoOptions) (DemoResult, error) {
|
||||
@@ -53,8 +53,8 @@ func Demo(database *gorm.DB, options DemoOptions) (DemoResult, error) {
|
||||
return result, err
|
||||
}
|
||||
|
||||
func upsertUser(tx *gorm.DB, email string, displayName string, password string) (models.SenlinAgentUser, error) {
|
||||
var user models.SenlinAgentUser
|
||||
func upsertUser(tx *gorm.DB, email string, displayName string, password string) (models.SaUser, error) {
|
||||
var user models.SaUser
|
||||
err := tx.Where("email = ?", email).First(&user).Error
|
||||
if err == nil {
|
||||
return user, nil
|
||||
@@ -66,7 +66,7 @@ func upsertUser(tx *gorm.DB, email string, displayName string, password string)
|
||||
if err != nil {
|
||||
return user, err
|
||||
}
|
||||
user = models.SenlinAgentUser{
|
||||
user = models.SaUser{
|
||||
Email: email,
|
||||
DisplayName: displayName,
|
||||
PasswordHash: string(hash),
|
||||
@@ -75,7 +75,7 @@ func upsertUser(tx *gorm.DB, email string, displayName string, password string)
|
||||
return user, tx.Create(&user).Error
|
||||
}
|
||||
|
||||
func seedProjects(tx *gorm.DB, ownerID uint) ([]models.SenlinAgentProject, error) {
|
||||
func seedProjects(tx *gorm.DB, ownerID uint) ([]models.SaProject, error) {
|
||||
definitions := []struct {
|
||||
Name string
|
||||
Identifier string
|
||||
@@ -87,7 +87,7 @@ func seedProjects(tx *gorm.DB, ownerID uint) ([]models.SenlinAgentProject, error
|
||||
{Name: "运营自动化", Identifier: "AUTO", Description: "定时任务和业务流程自动化"},
|
||||
}
|
||||
|
||||
projects := make([]models.SenlinAgentProject, 0, len(definitions))
|
||||
projects := make([]models.SaProject, 0, len(definitions))
|
||||
for _, definition := range definitions {
|
||||
project, err := firstOrCreateProject(tx, ownerID, definition.Name, definition.Identifier, definition.Description)
|
||||
if err != nil {
|
||||
@@ -109,8 +109,8 @@ func seedProjects(tx *gorm.DB, ownerID uint) ([]models.SenlinAgentProject, error
|
||||
return projects, nil
|
||||
}
|
||||
|
||||
func firstOrCreateProject(tx *gorm.DB, ownerID uint, name string, identifier string, description string) (models.SenlinAgentProject, error) {
|
||||
var project models.SenlinAgentProject
|
||||
func firstOrCreateProject(tx *gorm.DB, ownerID uint, name string, identifier string, description string) (models.SaProject, error) {
|
||||
var project models.SaProject
|
||||
err := tx.Where("owner_id = ? AND name = ?", ownerID, name).First(&project).Error
|
||||
if err == nil {
|
||||
return project, nil
|
||||
@@ -118,7 +118,7 @@ func firstOrCreateProject(tx *gorm.DB, ownerID uint, name string, identifier str
|
||||
if err != gorm.ErrRecordNotFound {
|
||||
return project, err
|
||||
}
|
||||
project = models.SenlinAgentProject{OwnerID: ownerID, Name: name, Identifier: identifier, Description: description}
|
||||
project = models.SaProject{OwnerID: ownerID, Name: name, Identifier: identifier, Description: description}
|
||||
return project, tx.Create(&project).Error
|
||||
}
|
||||
|
||||
@@ -145,7 +145,7 @@ func seedProjectA1(tx *gorm.DB, userID uint, projectID uint) error {
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
for _, item := range []models.SenlinAgentInboxItem{
|
||||
for _, item := range []models.SaInboxItem{
|
||||
{ProjectID: projectID, CreatedBy: userID, SourceType: "产品研究", Title: "竞争对手定价更新监控", Body: "跟进企业版价格调整和功能组合变化。", Status: "open"},
|
||||
{ProjectID: projectID, CreatedBy: userID, SourceType: "客户支持", Title: "客户反馈:导出功能报错", Body: "客户在导出智能报表时遇到权限校验异常。", Status: "open"},
|
||||
{ProjectID: projectID, CreatedBy: userID, SourceType: "架构讨论", Title: "API 调用策略评估建议", Body: "评估批量任务调度和 AI 限流策略。", Status: "open"},
|
||||
@@ -155,7 +155,7 @@ func seedProjectA1(tx *gorm.DB, userID uint, projectID uint) error {
|
||||
return err
|
||||
}
|
||||
}
|
||||
for _, task := range []models.SenlinAgentTask{
|
||||
for _, task := range []models.SaTask{
|
||||
{ProjectID: projectID, CreatedBy: userID, TagID: &uiTagID, Title: "智能报表导出功能", Description: "修复权限校验并补充导出失败提示。", Status: "open", DueAt: &dueSoon, SortOrder: 1},
|
||||
{ProjectID: projectID, CreatedBy: userID, TagID: &automationTagID, Title: "企业版权限体系梳理", Description: "整理角色、项目和任务分享边界。", Status: "open", DueAt: &dueLater, SortOrder: 2},
|
||||
{ProjectID: projectID, CreatedBy: userID, TagID: &feedbackTagID, Title: "Q3 营销策略制定", Description: "汇总竞品情报和客户反馈,生成策略草案。", Status: "open", DueAt: &dueLater, SortOrder: 3},
|
||||
@@ -164,7 +164,7 @@ func seedProjectA1(tx *gorm.DB, userID uint, projectID uint) error {
|
||||
return err
|
||||
}
|
||||
}
|
||||
for _, session := range []models.SenlinAgentAISession{
|
||||
for _, session := range []models.SaAISession{
|
||||
{ProjectID: projectID, CreatedBy: userID, Title: "生成 Q3 营销策略初稿", Context: "基于市场分析和竞品数据,输出 Q3 营销策略重点。"},
|
||||
{ProjectID: projectID, CreatedBy: userID, Title: "产品定价模型讨论", Context: "对企业版与标准版定价模型进行对比分析。"},
|
||||
{ProjectID: projectID, CreatedBy: userID, Title: "客户流失原因分析", Context: "分析近三个月客户流失数据与反馈原因。"},
|
||||
@@ -174,7 +174,7 @@ func seedProjectA1(tx *gorm.DB, userID uint, projectID uint) error {
|
||||
return err
|
||||
}
|
||||
}
|
||||
for _, note := range []models.SenlinAgentNote{
|
||||
for _, note := range []models.SaNote{
|
||||
{ProjectID: projectID, CreatedBy: userID, Title: "用户权限体系设计文档 v2.1", Markdown: "# 权限体系\n\n围绕项目、任务和资料分享做保守授权。"},
|
||||
{ProjectID: projectID, CreatedBy: userID, Title: "导出功能技术方案评审", Markdown: "# 导出功能\n\n记录权限校验和任务队列方案。"},
|
||||
} {
|
||||
@@ -182,7 +182,7 @@ func seedProjectA1(tx *gorm.DB, userID uint, projectID uint) error {
|
||||
return err
|
||||
}
|
||||
}
|
||||
for _, source := range []models.SenlinAgentSource{
|
||||
for _, source := range []models.SaSource{
|
||||
{ProjectID: projectID, CreatedBy: userID, Kind: "file", Title: "2026 Q3 竞品功能对比表", FilePath: "projects/a1/competitors.xlsx", ContentText: "竞品功能矩阵和价格摘要"},
|
||||
{ProjectID: projectID, CreatedBy: userID, Kind: "link", Title: "客户访谈记录索引", URL: "https://example.com/interviews", ContentText: "客户访谈和问题归类"},
|
||||
} {
|
||||
@@ -190,7 +190,7 @@ func seedProjectA1(tx *gorm.DB, userID uint, projectID uint) error {
|
||||
return err
|
||||
}
|
||||
}
|
||||
for _, plan := range []models.SenlinAgentCronPlan{
|
||||
for _, plan := range []models.SaCronPlan{
|
||||
{ProjectID: projectID, CreatedBy: userID, Title: "每日 Inbox 摘要", Schedule: "0 9 * * *", NextRunAt: &nextRun, Enabled: true},
|
||||
{ProjectID: projectID, CreatedBy: userID, Title: "每周任务风险扫描", Schedule: "0 10 * * 1", NextRunAt: &dueSoon, Enabled: true},
|
||||
{ProjectID: projectID, CreatedBy: userID, Title: "月底知识归档提醒", Schedule: "0 18 28 * *", NextRunAt: &dueLater, Enabled: false},
|
||||
@@ -199,7 +199,7 @@ func seedProjectA1(tx *gorm.DB, userID uint, projectID uint) error {
|
||||
return err
|
||||
}
|
||||
}
|
||||
for _, channel := range []models.SenlinAgentProjectChannel{
|
||||
for _, channel := range []models.SaProjectChannel{
|
||||
{ProjectID: projectID, Title: "客户研究频道", Icon: "user", URL: "https://example.com/research", SortOrder: 7},
|
||||
{ProjectID: projectID, Title: "产品设计频道", Icon: "link", URL: "https://example.com/design", SortOrder: 8},
|
||||
} {
|
||||
@@ -211,39 +211,39 @@ func seedProjectA1(tx *gorm.DB, userID uint, projectID uint) error {
|
||||
}
|
||||
|
||||
func seedCompactProject(tx *gorm.DB, userID uint, projectID uint) error {
|
||||
item := models.SenlinAgentInboxItem{ProjectID: projectID, CreatedBy: userID, SourceType: "手动收集", Title: "待处理事项", Body: "项目启动资料待整理。", Status: "open"}
|
||||
item := models.SaInboxItem{ProjectID: projectID, CreatedBy: userID, SourceType: "手动收集", Title: "待处理事项", Body: "项目启动资料待整理。", Status: "open"}
|
||||
if err := firstOrCreateInbox(tx, item); err != nil {
|
||||
return err
|
||||
}
|
||||
task := models.SenlinAgentTask{ProjectID: projectID, CreatedBy: userID, Title: "项目例会纪要整理", Description: "归档本周同步内容。", Status: "open"}
|
||||
task := models.SaTask{ProjectID: projectID, CreatedBy: userID, Title: "项目例会纪要整理", Description: "归档本周同步内容。", Status: "open"}
|
||||
return firstOrCreateTask(tx, task)
|
||||
}
|
||||
|
||||
func firstOrCreateTag(tx *gorm.DB, projectID uint, name string) error {
|
||||
candidate := models.SenlinAgentTag{ProjectID: projectID, Name: name}
|
||||
candidate := models.SaTag{ProjectID: projectID, Name: name}
|
||||
if err := tx.Clauses(clause.OnConflict{
|
||||
Columns: []clause.Column{{Name: "project_id"}, {Name: "name"}},
|
||||
DoNothing: true,
|
||||
}).Create(&candidate).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
return tx.Where("project_id = ? AND name = ?", projectID, name).First(&models.SenlinAgentTag{}).Error
|
||||
return tx.Where("project_id = ? AND name = ?", projectID, name).First(&models.SaTag{}).Error
|
||||
}
|
||||
|
||||
func tagID(tx *gorm.DB, projectID uint, name string) (uint, error) {
|
||||
var tag models.SenlinAgentTag
|
||||
var tag models.SaTag
|
||||
if err := tx.Where("project_id = ? AND name = ?", projectID, name).First(&tag).Error; err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return tag.ID, nil
|
||||
}
|
||||
|
||||
func firstOrCreateInbox(tx *gorm.DB, item models.SenlinAgentInboxItem) error {
|
||||
return firstOrCreate(tx, &models.SenlinAgentInboxItem{}, "project_id = ? AND title = ?", []any{item.ProjectID, item.Title}, item)
|
||||
func firstOrCreateInbox(tx *gorm.DB, item models.SaInboxItem) error {
|
||||
return firstOrCreate(tx, &models.SaInboxItem{}, "project_id = ? AND title = ?", []any{item.ProjectID, item.Title}, item)
|
||||
}
|
||||
|
||||
func firstOrCreateTask(tx *gorm.DB, task models.SenlinAgentTask) error {
|
||||
var existing models.SenlinAgentTask
|
||||
func firstOrCreateTask(tx *gorm.DB, task models.SaTask) error {
|
||||
var existing models.SaTask
|
||||
err := tx.Where("project_id = ? AND title = ?", task.ProjectID, task.Title).First(&existing).Error
|
||||
if err == nil {
|
||||
if task.TagID != nil && existing.TagID == nil {
|
||||
@@ -257,24 +257,24 @@ func firstOrCreateTask(tx *gorm.DB, task models.SenlinAgentTask) error {
|
||||
return tx.Create(&task).Error
|
||||
}
|
||||
|
||||
func firstOrCreateAISession(tx *gorm.DB, session models.SenlinAgentAISession) error {
|
||||
return firstOrCreate(tx, &models.SenlinAgentAISession{}, "project_id = ? AND title = ?", []any{session.ProjectID, session.Title}, session)
|
||||
func firstOrCreateAISession(tx *gorm.DB, session models.SaAISession) error {
|
||||
return firstOrCreate(tx, &models.SaAISession{}, "project_id = ? AND title = ?", []any{session.ProjectID, session.Title}, session)
|
||||
}
|
||||
|
||||
func firstOrCreateNote(tx *gorm.DB, note models.SenlinAgentNote) error {
|
||||
return firstOrCreate(tx, &models.SenlinAgentNote{}, "project_id = ? AND title = ?", []any{note.ProjectID, note.Title}, note)
|
||||
func firstOrCreateNote(tx *gorm.DB, note models.SaNote) error {
|
||||
return firstOrCreate(tx, &models.SaNote{}, "project_id = ? AND title = ?", []any{note.ProjectID, note.Title}, note)
|
||||
}
|
||||
|
||||
func firstOrCreateSource(tx *gorm.DB, source models.SenlinAgentSource) error {
|
||||
return firstOrCreate(tx, &models.SenlinAgentSource{}, "project_id = ? AND title = ?", []any{source.ProjectID, source.Title}, source)
|
||||
func firstOrCreateSource(tx *gorm.DB, source models.SaSource) error {
|
||||
return firstOrCreate(tx, &models.SaSource{}, "project_id = ? AND title = ?", []any{source.ProjectID, source.Title}, source)
|
||||
}
|
||||
|
||||
func firstOrCreateCronPlan(tx *gorm.DB, plan models.SenlinAgentCronPlan) error {
|
||||
return firstOrCreate(tx, &models.SenlinAgentCronPlan{}, "project_id = ? AND title = ?", []any{plan.ProjectID, plan.Title}, plan)
|
||||
func firstOrCreateCronPlan(tx *gorm.DB, plan models.SaCronPlan) error {
|
||||
return firstOrCreate(tx, &models.SaCronPlan{}, "project_id = ? AND title = ?", []any{plan.ProjectID, plan.Title}, plan)
|
||||
}
|
||||
|
||||
func firstOrCreateChannel(tx *gorm.DB, channel models.SenlinAgentProjectChannel) error {
|
||||
return firstOrCreate(tx, &models.SenlinAgentProjectChannel{}, "project_id = ? AND title = ?", []any{channel.ProjectID, channel.Title}, channel)
|
||||
func firstOrCreateChannel(tx *gorm.DB, channel models.SaProjectChannel) error {
|
||||
return firstOrCreate(tx, &models.SaProjectChannel{}, "project_id = ? AND title = ?", []any{channel.ProjectID, channel.Title}, channel)
|
||||
}
|
||||
|
||||
func firstOrCreate[T any](tx *gorm.DB, model *T, where string, args []any, create T) error {
|
||||
|
||||
@@ -41,9 +41,9 @@ func TestPostgresDemoSeedSerializesConcurrentRunsForSameOwner(t *testing.T) {
|
||||
email := "postgres-seed-" + suffix + "@example.com"
|
||||
passwordHash, err := bcrypt.GenerateFromPassword([]byte("original-password"), bcrypt.MinCost)
|
||||
require.NoError(t, err)
|
||||
user := models.SenlinAgentUser{Email: email, DisplayName: "保留用户名称", PasswordHash: string(passwordHash), Role: "user"}
|
||||
user := models.SaUser{Email: email, DisplayName: "保留用户名称", PasswordHash: string(passwordHash), Role: "user"}
|
||||
require.NoError(t, database.Create(&user).Error)
|
||||
projects := []models.SenlinAgentProject{
|
||||
projects := []models.SaProject{
|
||||
{OwnerID: user.ID, Name: "项目 A1", Identifier: "A1"},
|
||||
{OwnerID: user.ID, Name: "项目 A2", Identifier: "A2"},
|
||||
{OwnerID: user.ID, Name: "数据中台", Identifier: "DATA"},
|
||||
@@ -52,9 +52,9 @@ func TestPostgresDemoSeedSerializesConcurrentRunsForSameOwner(t *testing.T) {
|
||||
for index := range projects {
|
||||
require.NoError(t, database.Create(&projects[index]).Error)
|
||||
}
|
||||
uiTag := models.SenlinAgentTag{ProjectID: projects[0].ID, Name: "UI"}
|
||||
uiTag := models.SaTag{ProjectID: projects[0].ID, Name: "UI"}
|
||||
require.NoError(t, database.Create(&uiTag).Error)
|
||||
require.NoError(t, database.Create(&models.SenlinAgentTask{
|
||||
require.NoError(t, database.Create(&models.SaTask{
|
||||
ProjectID: projects[0].ID, CreatedBy: user.ID, TagID: &uiTag.ID,
|
||||
Title: "智能报表导出功能", Status: "open",
|
||||
}).Error)
|
||||
@@ -76,7 +76,7 @@ func TestPostgresDemoSeedSerializesConcurrentRunsForSameOwner(t *testing.T) {
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
if tx.Statement.Schema.Table == (models.SenlinAgentUser{}).TableName() {
|
||||
if tx.Statement.Schema.Table == (models.SaUser{}).TableName() {
|
||||
if _, locking := tx.Statement.Clauses["FOR"]; locking && marker == secondDemoSeedRun {
|
||||
signalDemoSeedStage(secondOwnerQueryAttempted)
|
||||
}
|
||||
@@ -135,22 +135,22 @@ func TestPostgresDemoSeedSerializesConcurrentRunsForSameOwner(t *testing.T) {
|
||||
require.NoError(t, waitForDemoSeedResult(t, ctx, firstResult, "first Demo result"))
|
||||
require.NoError(t, waitForDemoSeedResult(t, ctx, secondResult, "second Demo result"))
|
||||
|
||||
var storedUser models.SenlinAgentUser
|
||||
var storedUser models.SaUser
|
||||
require.NoError(t, database.Where("email = ?", email).First(&storedUser).Error)
|
||||
require.Equal(t, "保留用户名称", storedUser.DisplayName)
|
||||
require.NoError(t, bcrypt.CompareHashAndPassword([]byte(storedUser.PasswordHash), []byte("original-password")))
|
||||
require.Error(t, bcrypt.CompareHashAndPassword([]byte(storedUser.PasswordHash), []byte("new-password")))
|
||||
|
||||
projectIDs := []uint{projects[0].ID, projects[1].ID, projects[2].ID, projects[3].ID}
|
||||
assertPostgresDemoCount(t, database, &models.SenlinAgentProject{}, "owner_id = ?", []any{user.ID}, 4)
|
||||
assertPostgresDemoCount(t, database, &models.SenlinAgentTag{}, "project_id = ?", []any{projects[0].ID}, 4)
|
||||
assertPostgresDemoCount(t, database, &models.SenlinAgentTask{}, "project_id IN ?", []any{projectIDs}, 6)
|
||||
assertPostgresDemoCount(t, database, &models.SenlinAgentInboxItem{}, "project_id IN ?", []any{projectIDs}, 7)
|
||||
assertPostgresDemoCount(t, database, &models.SenlinAgentAISession{}, "project_id = ?", []any{projects[0].ID}, 4)
|
||||
assertPostgresDemoCount(t, database, &models.SenlinAgentNote{}, "project_id = ?", []any{projects[0].ID}, 2)
|
||||
assertPostgresDemoCount(t, database, &models.SenlinAgentSource{}, "project_id = ?", []any{projects[0].ID}, 2)
|
||||
assertPostgresDemoCount(t, database, &models.SenlinAgentCronPlan{}, "project_id = ?", []any{projects[0].ID}, 3)
|
||||
assertPostgresDemoCount(t, database, &models.SenlinAgentProjectChannel{}, "project_id = ?", []any{projects[0].ID}, 2)
|
||||
assertPostgresDemoCount(t, database, &models.SaProject{}, "owner_id = ?", []any{user.ID}, 4)
|
||||
assertPostgresDemoCount(t, database, &models.SaTag{}, "project_id = ?", []any{projects[0].ID}, 4)
|
||||
assertPostgresDemoCount(t, database, &models.SaTask{}, "project_id IN ?", []any{projectIDs}, 6)
|
||||
assertPostgresDemoCount(t, database, &models.SaInboxItem{}, "project_id IN ?", []any{projectIDs}, 7)
|
||||
assertPostgresDemoCount(t, database, &models.SaAISession{}, "project_id = ?", []any{projects[0].ID}, 4)
|
||||
assertPostgresDemoCount(t, database, &models.SaNote{}, "project_id = ?", []any{projects[0].ID}, 2)
|
||||
assertPostgresDemoCount(t, database, &models.SaSource{}, "project_id = ?", []any{projects[0].ID}, 2)
|
||||
assertPostgresDemoCount(t, database, &models.SaCronPlan{}, "project_id = ?", []any{projects[0].ID}, 3)
|
||||
assertPostgresDemoCount(t, database, &models.SaProjectChannel{}, "project_id = ?", []any{projects[0].ID}, 2)
|
||||
}
|
||||
|
||||
func signalDemoSeedStage(stage chan<- struct{}) {
|
||||
@@ -188,7 +188,7 @@ func assertPostgresDemoCount(t *testing.T, database *gorm.DB, model any, where s
|
||||
}
|
||||
|
||||
func cleanupPostgresDemoSeed(database *gorm.DB, userID uint) {
|
||||
var projects []models.SenlinAgentProject
|
||||
var projects []models.SaProject
|
||||
if database.Where("owner_id = ?", userID).Find(&projects).Error != nil {
|
||||
return
|
||||
}
|
||||
@@ -197,34 +197,34 @@ func cleanupPostgresDemoSeed(database *gorm.DB, userID uint) {
|
||||
projectIDs = append(projectIDs, project.ID)
|
||||
}
|
||||
if len(projectIDs) != 0 {
|
||||
var tasks []models.SenlinAgentTask
|
||||
var tasks []models.SaTask
|
||||
database.Where("project_id IN ?", projectIDs).Find(&tasks)
|
||||
taskIDs := make([]uint, 0, len(tasks))
|
||||
for _, task := range tasks {
|
||||
taskIDs = append(taskIDs, task.ID)
|
||||
}
|
||||
if len(taskIDs) != 0 {
|
||||
database.Where("task_id IN ?", taskIDs).Delete(&models.SenlinAgentTaskShare{})
|
||||
database.Where("task_id IN ?", taskIDs).Delete(&models.SaTaskShare{})
|
||||
}
|
||||
var inboxItems []models.SenlinAgentInboxItem
|
||||
var inboxItems []models.SaInboxItem
|
||||
database.Where("project_id IN ?", projectIDs).Find(&inboxItems)
|
||||
inboxIDs := make([]uint, 0, len(inboxItems))
|
||||
for _, item := range inboxItems {
|
||||
inboxIDs = append(inboxIDs, item.ID)
|
||||
}
|
||||
if len(inboxIDs) != 0 {
|
||||
database.Where("inbox_item_id IN ?", inboxIDs).Delete(&models.SenlinAgentInboxSuggestion{})
|
||||
database.Where("inbox_item_id IN ?", inboxIDs).Delete(&models.SaInboxSuggestion{})
|
||||
}
|
||||
database.Where("project_id IN ?", projectIDs).Delete(&models.SenlinAgentProjectEvent{})
|
||||
database.Where("project_id IN ?", projectIDs).Delete(&models.SenlinAgentTask{})
|
||||
database.Where("project_id IN ?", projectIDs).Delete(&models.SenlinAgentNote{})
|
||||
database.Where("project_id IN ?", projectIDs).Delete(&models.SenlinAgentSource{})
|
||||
database.Where("project_id IN ?", projectIDs).Delete(&models.SenlinAgentAISession{})
|
||||
database.Where("project_id IN ?", projectIDs).Delete(&models.SenlinAgentTag{})
|
||||
database.Where("project_id IN ?", projectIDs).Delete(&models.SenlinAgentProjectChannel{})
|
||||
database.Where("project_id IN ?", projectIDs).Delete(&models.SenlinAgentCronPlan{})
|
||||
database.Where("project_id IN ?", projectIDs).Delete(&models.SenlinAgentInboxItem{})
|
||||
database.Where("id IN ?", projectIDs).Delete(&models.SenlinAgentProject{})
|
||||
database.Where("project_id IN ?", projectIDs).Delete(&models.SaProjectEvent{})
|
||||
database.Where("project_id IN ?", projectIDs).Delete(&models.SaTask{})
|
||||
database.Where("project_id IN ?", projectIDs).Delete(&models.SaNote{})
|
||||
database.Where("project_id IN ?", projectIDs).Delete(&models.SaSource{})
|
||||
database.Where("project_id IN ?", projectIDs).Delete(&models.SaAISession{})
|
||||
database.Where("project_id IN ?", projectIDs).Delete(&models.SaTag{})
|
||||
database.Where("project_id IN ?", projectIDs).Delete(&models.SaProjectChannel{})
|
||||
database.Where("project_id IN ?", projectIDs).Delete(&models.SaCronPlan{})
|
||||
database.Where("project_id IN ?", projectIDs).Delete(&models.SaInboxItem{})
|
||||
database.Where("id IN ?", projectIDs).Delete(&models.SaProject{})
|
||||
}
|
||||
database.Delete(&models.SenlinAgentUser{}, userID)
|
||||
database.Delete(&models.SaUser{}, userID)
|
||||
}
|
||||
|
||||
@@ -54,7 +54,7 @@ func TestDemoSeedIsIdempotent(t *testing.T) {
|
||||
require.Equal(t, first.User.ID, second.User.ID)
|
||||
require.Len(t, second.Projects, 4)
|
||||
var userCount int64
|
||||
require.NoError(t, database.Model(&models.SenlinAgentUser{}).Where("email = ?", "demo@senlin.ai").Count(&userCount).Error)
|
||||
require.NoError(t, database.Model(&models.SaUser{}).Where("email = ?", "demo@senlin.ai").Count(&userCount).Error)
|
||||
require.Equal(t, int64(1), userCount)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user