fix: table 'overnight_bot.system_state_history' doesn't exist
Deploy / Test, build and deploy (push) Successful in 1m49s
Deploy / Test, build and deploy (push) Successful in 1m49s
This commit is contained in:
@@ -7,7 +7,7 @@ import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
mysql "github.com/go-sql-driver/mysql"
|
||||
"github.com/jmoiron/sqlx"
|
||||
"github.com/shopspring/decimal"
|
||||
|
||||
@@ -699,9 +699,17 @@ func (r *Repository) insertSystemStateHistory(ctx context.Context, state domain.
|
||||
_, err := r.execer().ExecContext(ctx, `
|
||||
INSERT INTO system_state_history (ts, state, mode, halted, halt_reason, context_json)
|
||||
VALUES (UTC_TIMESTAMP(3), ?, ?, ?, ?, ?)`, state, mode, halted, nullableString(reason), contextJSON)
|
||||
if isMissingTableError(err) {
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func isMissingTableError(err error) bool {
|
||||
var mysqlErr *mysql.MySQLError
|
||||
return errors.As(err, &mysqlErr) && mysqlErr.Number == 1146
|
||||
}
|
||||
|
||||
func (r *Repository) Unhalt(ctx context.Context, reason string) error {
|
||||
return r.RunInTx(ctx, func(ctx context.Context, repo repository.Repository) error {
|
||||
state, halted, haltReason, err := repo.GetSystemState(ctx)
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
package mysql
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
mysql "github.com/go-sql-driver/mysql"
|
||||
"github.com/shopspring/decimal"
|
||||
|
||||
"overnight-trading-bot/internal/domain"
|
||||
@@ -25,3 +28,15 @@ func TestMinuteCandleRowPreservesTimestamp(t *testing.T) {
|
||||
t.Fatalf("daily timestamp was not truncated to date: %s", daily.TradeDate)
|
||||
}
|
||||
}
|
||||
|
||||
func TestIsMissingTableError(t *testing.T) {
|
||||
if !isMissingTableError(&mysql.MySQLError{Number: 1146}) {
|
||||
t.Fatal("expected MySQL 1146 to be treated as missing table")
|
||||
}
|
||||
if !isMissingTableError(fmt.Errorf("wrap: %w", &mysql.MySQLError{Number: 1146})) {
|
||||
t.Fatal("expected wrapped MySQL 1146 to be treated as missing table")
|
||||
}
|
||||
if isMissingTableError(errors.New("not mysql")) {
|
||||
t.Fatal("plain errors must not be treated as missing table")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user