mirror of
https://github.com/hanzoai/forge.git
synced 2026-10-30 15:00:39 +00:00
Source files keep their SPDX-License-Identifier and Hanzo copyright line; the Gitea, Gogs and LFS Test Server copyrights they used to repeat now live once in NOTICE, alongside LICENSE. The header lint accepts any copyright line above the SPDX line, so it no longer demands an upstream one. Co-authored-by: Hanzo Dev <[email protected]>
41 lines
1.2 KiB
Go
41 lines
1.2 KiB
Go
// Copyright 2026 Hanzo AI, Inc. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package v1_27
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/hanzoai/git/models/db"
|
|
|
|
"github.com/hanzoai/xorm/schemas"
|
|
)
|
|
|
|
// AddCreatedUnixToActionUserIsDeletedIndex extends the c_u composite index on
|
|
// the action table to include created_unix, enabling efficient ORDER BY on the
|
|
// dashboard feed query without a full sort of all matching rows.
|
|
func AddCreatedUnixToActionUserIsDeletedIndex(x db.EngineMigration) error {
|
|
// xorm Sync cannot reliably update an index when another index already
|
|
// covers the same columns in a different order (Equal() is order-insensitive).
|
|
// Drop the old c_u index explicitly, then recreate it with the new column set.
|
|
indexes, err := x.Dialect().GetIndexes(x.DB(), context.Background(), "action")
|
|
if err != nil {
|
|
return err
|
|
}
|
|
for _, idx := range indexes {
|
|
if idx.Name == "c_u" {
|
|
if _, err := x.Exec(x.Dialect().DropIndexSQL("action", idx)); err != nil {
|
|
return err
|
|
}
|
|
break
|
|
}
|
|
}
|
|
|
|
newIndex := schemas.NewIndex("c_u", schemas.IndexType)
|
|
newIndex.AddColumn("user_id", "is_deleted", "created_unix")
|
|
if _, err := x.Exec(x.Dialect().CreateIndexSQL("action", newIndex)); err != nil {
|
|
return err
|
|
}
|
|
return nil
|
|
}
|