refactor(db): thread context.Context through all Store methods
Enables request-scoped cancellation, timeouts, and graceful shutdown for all database operations across API handlers, CLI commands, and TUI.
This commit is contained in:
+4
-4
@@ -20,14 +20,14 @@ func init() {
|
||||
rootCmd.AddCommand(promoteCmd)
|
||||
}
|
||||
|
||||
func runPromote(_ *cobra.Command, args []string) error {
|
||||
func runPromote(cmd *cobra.Command, args []string) error {
|
||||
store, err := openStore()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer store.Close()
|
||||
|
||||
id, err := store.Resolve(args[0])
|
||||
id, err := store.Resolve(cmd.Context(), args[0])
|
||||
if err != nil {
|
||||
return fmt.Errorf("not_found — no entity with id %s", args[0])
|
||||
}
|
||||
@@ -40,14 +40,14 @@ func runPromote(_ *cobra.Command, args []string) error {
|
||||
cardType = db.CardType(args[1])
|
||||
}
|
||||
|
||||
e, err := store.Get(id)
|
||||
e, err := store.Get(cmd.Context(), id)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
cd := carddata.GenerateCardData(cardType, e.Body)
|
||||
|
||||
if err := store.Promote(id, cardType, cd); err != nil {
|
||||
if err := store.Promote(cmd.Context(), id, cardType, cd); err != nil {
|
||||
if err == db.ErrAlreadyPromoted {
|
||||
return fmt.Errorf("invalid_promote — entity %s is already a %s",
|
||||
display.FormatID(id), *e.CardType)
|
||||
|
||||
Reference in New Issue
Block a user