Skip to content

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

Fix automigrate bug

Acho Arnolda3bbbfc31189
diff --git a/api/pkg/di/container.go b/api/pkg/di/container.go
index df7a0738..20bbc780 100644
--- a/api/pkg/di/container.go
+++ b/api/pkg/di/container.go
@@ -321,6 +321,12 @@ 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 IF NOT EXISTS uni_users_api_key CHECK (api_key IS NOT NULL);
+ALTER TABLE phone_api_keys ADD CONSTRAINT IF NOT EXISTS uni_phone_api_keys_api_key CHECK (api_key IS NOT NULL);
+ALTER TABLE discords ADD CONSTRAINT IF NOT EXISTS 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{})))
}