mirror of
https://github.com/marcusDenslow/terminalShop.git
synced 2026-10-25 10:02:21 +01:00
feat: implement server-side cart persistence with Stripe PaymentIntents Replaced the client-only in-mem cart with a database-backed cart system - Add Cart and CartItem GORM models (two-table design) - Add 6 cart API endpoints (get, set item, set address, set card, clear, conver) - Switch from Stripe Charge API to PaymentIntents with confirm:true - Add 9 API client methods for cart and card operations - Refactor TUI cart from map[int] (slice index) to map[uint] (CoffeeID) - Replace single-shot checkout with saveCardAndConvert multi-step flow - Add CheckingOut state with "submitting order..." processing indicator - Fix Stripe tokenization to use secret key for server-side SSH apps - Remove admin product CRUD endpoints and old checkout handler
33 lines
856 B
Go
33 lines
856 B
Go
package database
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
|
|
"gorm.io/gorm"
|
|
"terminalShop/pkg/models"
|
|
)
|
|
|
|
// Migrate runs database migrations
|
|
func Migrate(db *gorm.DB) error {
|
|
log.Println("Running database migrations...")
|
|
|
|
// AutoMigrate will create tables, missing columns, and indexes
|
|
// It will NOT delete unused columns or change column types
|
|
if err := db.AutoMigrate(
|
|
&models.Cart{}, // Server-side shipping cart
|
|
&models.CartItem{}, // Cart line items
|
|
&models.Coffee{},
|
|
&models.User{}, // SSH key-based authentication
|
|
&models.Card{}, // Saved payment methods
|
|
&models.Order{}, // Completed purchases
|
|
&models.OrderItem{}, // Line items within orders
|
|
&models.Address{}, // Saved addresses
|
|
); err != nil {
|
|
return fmt.Errorf("migration failed: %w", err)
|
|
}
|
|
|
|
log.Println("Database migrations completed successfully")
|
|
return nil
|
|
}
|