quintodrome/db/migrations/20201010162350_add_album_size.go

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

35 lines
646 B
Go
Raw Normal View History

package migrations
import (
2023-11-27 10:46:44 -09:00
"context"
"database/sql"
2023-04-04 05:57:00 -08:00
"github.com/pressly/goose/v3"
)
func init() {
2023-11-27 10:46:44 -09:00
goose.AddMigrationContext(Up20201010162350, Down20201010162350)
}
2023-11-27 10:46:44 -09:00
func Up20201010162350(_ context.Context, tx *sql.Tx) error {
_, err := tx.Exec(`
alter table album
add size integer default 0 not null;
create index if not exists album_size
on album(size);
update album set size = ifnull((
select sum(f.size)
from media_file f
where f.album_id = album.id
), 0)
where id not null;`)
return err
}
2023-11-27 10:46:44 -09:00
func Down20201010162350(_ context.Context, tx *sql.Tx) error {
// This code is executed when the migration is rolled back.
return nil
}