fix: resolve plan view crash from duplicate children and tiptap link conflict

Three fixes:

1. GetChildItems returned duplicate rows when an item was linked to a parent
   via multiple link types (e.g. both "parent" and "implements"), causing
   Svelte's {#each} to throw each_key_duplicate. Added SELECT DISTINCT.

2. StarterKit v3.20.4 now includes Link by default, conflicting with our
   custom SafeLink extension. Disabled StarterKit's built-in link.

3. Migration runner now tolerates "duplicate column name" errors on
   ALTER TABLE ADD COLUMN, making migrations idempotent when partially
   applied (e.g. server crash mid-migration).
This commit is contained in:
xarmian
2026-04-09 14:49:03 +00:00
parent 239ce19d1f
commit 9d90308e20
3 changed files with 11 additions and 2 deletions
+1 -1
View File
@@ -1317,7 +1317,7 @@ func (s *Store) GetAllItemProgress(workspaceID, collectionSlug string) ([]ItemPr
// via item_links. Returns children from any collection.
func (s *Store) GetChildItems(parentItemID string) ([]models.Item, error) {
rows, err := s.db.Query(s.q(fmt.Sprintf(`
SELECT i.id, i.workspace_id, i.collection_id, i.title, i.slug, i.content, i.fields, i.tags,
SELECT DISTINCT i.id, i.workspace_id, i.collection_id, i.title, i.slug, i.content, i.fields, i.tags,
i.pinned, i.sort_order, i.parent_id, i.assigned_user_id, i.agent_role_id, i.role_sort_order,
i.created_by, i.last_modified_by, i.source,
i.item_number, i.created_at, i.updated_at,
+9 -1
View File
@@ -255,7 +255,15 @@ func execMulti(db *sql.DB, sqlText string) error {
stmt := strings.TrimSpace(sqlText[:end+1])
if stmt != "" && stmt != ";" {
if _, err := db.Exec(stmt); err != nil {
return fmt.Errorf("exec migration statement: %w\nStatement: %.200s", err, stmt)
// Tolerate "duplicate column name" errors from ALTER TABLE ADD COLUMN.
// This makes migrations idempotent when partially applied (e.g. server
// crashed after adding a column but before recording the migration).
upper := strings.ToUpper(strings.TrimSpace(stmt))
isDupCol := strings.Contains(err.Error(), "duplicate column name")
isAddCol := strings.HasPrefix(upper, "ALTER TABLE") && strings.Contains(upper, "ADD COLUMN")
if !(isDupCol && isAddCol) {
return fmt.Errorf("exec migration statement: %w\nStatement: %.200s", err, stmt)
}
}
}
sqlText = sqlText[end+1:]
@@ -230,6 +230,7 @@
const extensions = [
StarterKit.configure({
codeBlock: false,
link: false, // We use our own SafeLink extension below
}),
MermaidCodeBlock.configure({
HTMLAttributes: { class: 'code-block' },