Skip to content

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

Fix bugs with postgresql. Closes #837, Closes #838

Acho Arnoldf4a634df45a8
diff --git a/api/Dockerfile b/api/Dockerfile
index 34d82403..8e0206a2 100644
--- a/api/Dockerfile
+++ b/api/Dockerfile
@@ -1,4 +1,4 @@
-FROM golang as builder
+FROM golang AS builder
ARG GIT_COMMIT
ENV GIT_COMMIT=$GIT_COMMIT
diff --git a/api/pkg/di/container.go b/api/pkg/di/container.go
index 02d37738..14fc9ea4 100644
--- a/api/pkg/di/container.go
+++ b/api/pkg/di/container.go
@@ -231,13 +231,13 @@ func (container *Container) GormLogger() gormLogger.Interface {
}
func (container *Container) connect(dsn string, config *gorm.Config) (db *gorm.DB, err error) {
- if strings.HasPrefix(dsn, "postgres://") {
- return gorm.Open(postgres.Open(dsn), config)
+ if strings.HasPrefix(dsn, "libsql://") {
+ return gorm.Open(sqlite.New(sqlite.Config{
+ DriverName: "libsql",
+ DSN: dsn,
+ }), config)
}
- return gorm.Open(sqlite.New(sqlite.Config{
- DriverName: "libsql",
- DSN: dsn,
- }), config)
+ return gorm.Open(postgres.Open(dsn), config)
}
// DedicatedDB creates an instance of gorm.DB if it has not been created already
@@ -339,11 +339,15 @@ 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(`
+ // This is only applicable to PROD on cockroachDB
+ if os.Getenv("DATABASE_MIGRATION_CONSTRAINT_FIX") == "1" {
+ 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{})))
diff --git a/docker-compose.yml b/docker-compose.yml
index 16e885e9..ef63287d 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -1,5 +1,3 @@
-version: "3.8"
-
services:
postgres:
image: postgres:alpine
@@ -13,7 +11,7 @@ services:
- "5435:5432"
restart: on-failure
healthcheck:
- test: ["CMD-SHELL", "pg_isready", "-U", "dbusername", "-d", "httpsms"]
+ test: ["CMD-SHELL", "pg_isready -U $${POSTGRES_USER} -d $${POSTGRES_DB}"]
interval: 30s
timeout: 60s
retries: 5
diff --git a/web/Dockerfile b/web/Dockerfile
index 169f78cc..813399ea 100644
--- a/web/Dockerfile
+++ b/web/Dockerfile
@@ -1,5 +1,5 @@
# build stage
-FROM node:lts-alpine as build
+FROM node:lts-alpine AS build
WORKDIR /app