Files
xinfra/server/internal/database/database.go
T
Hungerdream f0c1b38c5b feat(delivery): add automatic rollback state machine for failed deployments
Introduce a compensating workflow that launches the dedicated AWX
rollback template when a deployment cannot be started or fails midway.

- add task states: rollback_pending, rolling_back, rolled_back,
  rollback_failed, rollback_acknowledged
- add RollbackJob model to track the compensating AWX run separately
  from the deploy run, preserving both job IDs for audit
- hold resource reservations in 'rollback' status until cleanup
  succeeds so a failed cleanup cannot be masked by a later delivery
- poll rollback jobs with a 2-minute launch timeout; an unknown launch
  result surfaces as a recoverable failure instead of re-launching
- protect finished/register_failed/rolled-back tasks from rollback;
  register_failed keeps the healthy instance and its resource usage
- add DELIVERY_ROLLBACK_TEMPLATE_ID config; without it, failures are
  marked rollback_failed and require manual cleanup
- use unique pending-<task_id> placeholder for executor job IDs
2026-07-28 14:29:09 +08:00

34 lines
703 B
Go

package database
import (
"github.com/1024XEngineer/xinfra/server/internal/model"
"gorm.io/driver/mysql"
"gorm.io/gorm"
)
func Open(dsn string) (*gorm.DB, error) {
return gorm.Open(mysql.Open(dsn), &gorm.Config{})
}
func AutoMigrate(db *gorm.DB) error {
return db.AutoMigrate(
&model.User{},
&model.WayenCredential{},
&model.BusinessLine{},
&model.BusinessLineUser{},
&model.BusinessLineWayneNamespace{},
&model.AccessToken{},
&model.WayneToken{},
&model.AuditLog{},
&model.ResourceQuota{},
&model.DeliveryTask{},
&model.ResourceReservation{},
&model.MySQLInstance{},
&model.ResourceUsage{},
&model.ExecutionJob{},
&model.RollbackJob{},
&model.TaskEvent{},
)
}