Skip to content

Send and receive SMS messages using your Android phone programmatically via a simple HTTP API

Fix migration

Acho Arnold3b383eb61aca
diff --git a/api/pkg/di/container.go b/api/pkg/di/container.go
index c2788a21..bb70e330 100644
--- a/api/pkg/di/container.go
+++ b/api/pkg/di/container.go
@@ -271,6 +271,11 @@ func (container *Container) DB() (db *gorm.DB) {
container.logger.Debug(fmt.Sprintf("Running migrations for %T", db))
+ // This prevents a bug in the Gorm AutoMigrate where it tries to delete this no existent constraints
+ db.Exec(`
+ALTER TABLE users ADD CONSTRAINT uni_users_api_key CHECK (api_key IS NOT NULL);
+ALTER TABLE discords ADD CONSTRAINT uni_discords_server_id CHECK (server_id IS NOT NULL);`)
+
if err = db.AutoMigrate(&entities.Message{}); err != nil {
container.logger.Fatal(stacktrace.Propagate(err, fmt.Sprintf("cannot migrate %T", &entities.Message{})))
}