feat: implement license platform business flows and delivery tooling
Add admin and customer interfaces, orders, signed activation and leases, protected package delivery, keyring verification, migrations, security controls, tests and deployment documentation. Co-Authored-By: Craft Agent <agents-noreply@craft.do>
This commit is contained in:
47
backend/internal/httpapi/readiness.go
Normal file
47
backend/internal/httpapi/readiness.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package httpapi
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"net/http"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
const RequiredSchemaVersion = 10
|
||||
|
||||
func RegisterReadiness(r *gin.Engine, db *sql.DB) {
|
||||
r.GET("/api/v1/health/ready", func(c *gin.Context) {
|
||||
ctx, cancel := context.WithTimeout(c.Request.Context(), 2*time.Second)
|
||||
defer cancel()
|
||||
if err := CheckSchema(ctx, db); err != nil {
|
||||
c.JSON(http.StatusServiceUnavailable, gin.H{"status": "not_ready"})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"status": "ready"})
|
||||
})
|
||||
}
|
||||
|
||||
func CheckSchema(ctx context.Context, db *sql.DB) error {
|
||||
if db == nil {
|
||||
return sql.ErrConnDone
|
||||
}
|
||||
var version uint64
|
||||
var dirty bool
|
||||
rows, err := db.QueryContext(ctx, "SELECT version, dirty FROM schema_migrations")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer rows.Close()
|
||||
if !rows.Next() {
|
||||
return sql.ErrNoRows
|
||||
}
|
||||
if err := rows.Scan(&version, &dirty); err != nil {
|
||||
return err
|
||||
}
|
||||
if rows.Next() || rows.Err() != nil || version != RequiredSchemaVersion || dirty {
|
||||
return sql.ErrNoRows
|
||||
}
|
||||
return nil
|
||||
}
|
||||
Reference in New Issue
Block a user