2021-03-22 09:38:04 -08:00
|
|
|
package migrations
|
2020-10-12 07:10:07 -08:00
|
|
|
|
|
|
|
|
import (
|
2023-11-27 10:46:44 -09:00
|
|
|
"context"
|
2020-10-12 07:10:07 -08:00
|
|
|
"database/sql"
|
|
|
|
|
|
2023-04-04 05:57:00 -08:00
|
|
|
"github.com/pressly/goose/v3"
|
2020-10-12 07:10:07 -08:00
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func init() {
|
2023-11-27 10:46:44 -09:00
|
|
|
goose.AddMigrationContext(Up20201010162350, Down20201010162350)
|
2020-10-12 07:10:07 -08:00
|
|
|
}
|
|
|
|
|
|
2023-11-27 10:46:44 -09:00
|
|
|
func Up20201010162350(_ context.Context, tx *sql.Tx) error {
|
2020-10-12 07:10:07 -08:00
|
|
|
_, err := tx.Exec(`
|
|
|
|
|
alter table album
|
|
|
|
|
add size integer default 0 not null;
|
|
|
|
|
create index if not exists album_size
|
|
|
|
|
on album(size);
|
2020-11-15 15:26:16 -09:00
|
|
|
|
|
|
|
|
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
|
2020-10-12 07:10:07 -08:00
|
|
|
}
|
|
|
|
|
|
2023-11-27 10:46:44 -09:00
|
|
|
func Down20201010162350(_ context.Context, tx *sql.Tx) error {
|
2020-10-12 07:10:07 -08:00
|
|
|
// This code is executed when the migration is rolled back.
|
|
|
|
|
return nil
|
|
|
|
|
}
|