NewQuantStore creates a new QuantStore and auto-migrates. Uses a PostgreSQL advisory lock to prevent concurrent migration races when multiple instances (frontend + workers) start at the same time.
(db *gorm.DB)
| 45 | // Uses a PostgreSQL advisory lock to prevent concurrent migration races |
| 46 | // when multiple instances (frontend + workers) start at the same time. |
| 47 | func NewQuantStore(db *gorm.DB) (*QuantStore, error) { |
| 48 | if err := advisorylock.WithLockCtx(context.Background(), db, advisorylock.KeySchemaMigrate, func() error { |
| 49 | return db.AutoMigrate(&QuantJobRecord{}) |
| 50 | }); err != nil { |
| 51 | return nil, fmt.Errorf("migrating quantization_jobs: %w", err) |
| 52 | } |
| 53 | return &QuantStore{db: db}, nil |
| 54 | } |
| 55 | |
| 56 | // Create stores a new quantization job. |
| 57 | func (s *QuantStore) Create(job *QuantJobRecord) error { |
no test coverage detected