Skip to content

Commit

Permalink
migrations: fix migrations not being cancelable
Browse files Browse the repository at this point in the history
  • Loading branch information
Wessie committed Feb 22, 2024
1 parent f9b93de commit 89bb288
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
11 changes: 11 additions & 0 deletions cmd/hanyuu/migrations.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,17 @@ func (m migrateCmd) up(ctx context.Context, cfg config.Config) error {
return err
}

done := make(chan struct{})
defer close(done)

go func() {
select {
case <-ctx.Done():
m.migrate.GracefulStop <- true
case <-done:
}
}()

return m.migrate.Up()
}

Expand Down
2 changes: 1 addition & 1 deletion migrations/mysql/0007_eplay_dj.up.sql
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
ALTER TABLE eplay ADD COLUMN IF NOT EXISTS (djs_id INT DEFAULT NULL);

UPDATE eplay SET djs_id = (SELECT dj FROM listenlog WHERE eplay.dt <= listenlog.time ORDER BY listenlog.time ASC LIMIT 1);
UPDATE eplay SET djs_id = (SELECT dj FROM listenlog WHERE eplay.dt >= listenlog.time ORDER BY listenlog.time ASC LIMIT 1);

0 comments on commit 89bb288

Please sign in to comment.