feat(documents): rebuild project document workbench

This commit is contained in:
2026-07-24 12:16:02 +08:00
parent 366136cee9
commit 77beaebb30
73 changed files with 5867 additions and 1264 deletions

View File

@@ -31,6 +31,7 @@ func runVersionedMigrations(database *gorm.DB) error {
migrations := []versionedMigration{
{version: 1, name: "normalize_project_identifiers", run: normalizeLegacyProjectIdentifiers},
{version: 2, name: "deduplicate_project_tags", run: deduplicateLegacyProjectTags},
{version: 3, name: "replace_notes_sources_with_documents", run: replaceNotesSourcesWithDocuments},
}
for _, migration := range migrations {
// Connection callbacks can provide an initialized Gorm session. Start each
@@ -63,6 +64,28 @@ func runVersionedMigrations(database *gorm.DB) error {
return nil
}
func replaceNotesSourcesWithDocuments(tx *gorm.DB) (map[string]int, error) {
deletedShares := int64(0)
if tx.Migrator().HasTable(&SaTaskShare{}) {
result := tx.Where("object_type IN ?", []string{"note", "source"}).Delete(&SaTaskShare{})
if result.Error != nil {
return nil, result.Error
}
deletedShares = result.RowsAffected
}
dropped := 0
for _, table := range []string{"sa_notes", "sa_sources"} {
if !tx.Migrator().HasTable(table) {
continue
}
if err := tx.Migrator().DropTable(table); err != nil {
return nil, err
}
dropped++
}
return map[string]int{"dropped_tables": dropped, "deleted_task_shares": int(deletedShares)}, nil
}
func normalizeLegacyProjectIdentifiers(tx *gorm.DB) (map[string]int, error) {
var projects []SaProject
if err := tx.Model(&SaProject{}).Select("id", "owner_id", "identifier").Order("owner_id asc, id asc").Find(&projects).Error; err != nil {