Add a sort field to subforums
This commit is contained in:
parent
4b13f99df8
commit
9c7acd7dbb
|
@ -0,0 +1,52 @@
|
|||
package migrations
|
||||
|
||||
import (
|
||||
"context"
|
||||
"time"
|
||||
|
||||
"git.handmade.network/hmn/hmn/src/migration/types"
|
||||
"git.handmade.network/hmn/hmn/src/oops"
|
||||
"github.com/jackc/pgx/v4"
|
||||
)
|
||||
|
||||
func init() {
|
||||
registerMigration(AddSubforumSort{})
|
||||
}
|
||||
|
||||
type AddSubforumSort struct{}
|
||||
|
||||
func (m AddSubforumSort) Version() types.MigrationVersion {
|
||||
return types.MigrationVersion(time.Date(2021, 9, 23, 6, 12, 11, 0, time.UTC))
|
||||
}
|
||||
|
||||
func (m AddSubforumSort) Name() string {
|
||||
return "AddSubforumSort"
|
||||
}
|
||||
|
||||
func (m AddSubforumSort) Description() string {
|
||||
return "Adds a sort field to subforums."
|
||||
}
|
||||
|
||||
func (m AddSubforumSort) Up(ctx context.Context, tx pgx.Tx) error {
|
||||
_, err := tx.Exec(ctx, `
|
||||
ALTER TABLE handmade_subforum
|
||||
ADD sort INTEGER NOT NULL DEFAULT 10;
|
||||
`)
|
||||
if err != nil {
|
||||
return oops.New(err, "failed to add sort key")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (m AddSubforumSort) Down(ctx context.Context, tx pgx.Tx) error {
|
||||
_, err := tx.Exec(ctx, `
|
||||
ALTER TABLE handmade_subforum
|
||||
DROP sort;
|
||||
`)
|
||||
if err != nil {
|
||||
return oops.New(err, "failed to drop sort key")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
|
@ -52,7 +52,7 @@ func GetFullSubforumTree(ctx context.Context, conn *pgxpool.Pool) SubforumTree {
|
|||
SELECT $columns
|
||||
FROM
|
||||
handmade_subforum as sf
|
||||
ORDER BY id ASC
|
||||
ORDER BY sort, id ASC
|
||||
`,
|
||||
)
|
||||
if err != nil {
|
||||
|
|
Loading…
Reference in New Issue