mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-12-07 14:09:47 +00:00
To make sure that the code stays maintainable, I added the `importas` linter to ensure that the imports for models and services stay consistent. I realised that this might be needed after finding some discrepancies between singular/plural naming, and, especially in the case of the `forgejo.org/services/context` package, multiple different aliases like `gitea_ctx`, `app_context` and `forgejo_context`. I decided for `app_context`, as that seems to be the most commonly used naming. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/10253 Reviewed-by: Gusted <gusted@noreply.codeberg.org> Co-authored-by: nachtjasmin <nachtjasmin@posteo.de> Co-committed-by: nachtjasmin <nachtjasmin@posteo.de>
65 lines
1.7 KiB
Go
65 lines
1.7 KiB
Go
// Copyright 2025 The Forgejo Authors. All rights reserved.
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
package forgejo_migrations
|
|
|
|
import (
|
|
activities_model "forgejo.org/models/activities"
|
|
"forgejo.org/modules/setting"
|
|
|
|
"xorm.io/xorm"
|
|
)
|
|
|
|
func init() {
|
|
registerMigration(&Migration{
|
|
Description: "remove columns and rework indexes for notification table",
|
|
Upgrade: reworkNotification,
|
|
})
|
|
}
|
|
|
|
func reworkNotification(x *xorm.Engine) error {
|
|
type Notification struct {
|
|
UserID int64 `xorm:"NOT NULL INDEX(s)"`
|
|
Status activities_model.NotificationStatus `xorm:"SMALLINT NOT NULL INDEX(s)"`
|
|
}
|
|
|
|
if err := dropIndexIfExists(x, "notification", "IDX_notification_user_id"); err != nil {
|
|
return err
|
|
}
|
|
|
|
if err := dropIndexIfExists(x, "notification", "IDX_notification_created_unix"); err != nil {
|
|
return err
|
|
}
|
|
|
|
if err := dropIndexIfExists(x, "notification", "IDX_notification_updated_by"); err != nil {
|
|
return err
|
|
}
|
|
|
|
if err := dropIndexIfExists(x, "notification", "IDX_notification_commit_id"); err != nil {
|
|
return err
|
|
}
|
|
|
|
if err := dropIndexIfExists(x, "notification", "IDX_notification_status"); err != nil {
|
|
return err
|
|
}
|
|
|
|
switch {
|
|
case setting.Database.Type.IsSQLite3():
|
|
|
|
if _, err := x.Exec("ALTER TABLE `notification` DROP COLUMN `updated_by`"); err != nil {
|
|
return err
|
|
}
|
|
|
|
if _, err := x.Exec("ALTER TABLE `notification` DROP COLUMN `commit_id`"); err != nil {
|
|
return err
|
|
}
|
|
|
|
case setting.Database.Type.IsMySQL(), setting.Database.Type.IsPostgreSQL():
|
|
if _, err := x.Exec("ALTER TABLE `notification` DROP COLUMN `updated_by`, DROP COLUMN `commit_id`"); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
|
|
_, err := x.SyncWithOptions(xorm.SyncOptions{IgnoreDropIndices: true}, new(Notification))
|
|
return err
|
|
}
|