Skip to content

Bug: SQL Syntax Error "IF NOT EXISTS" on PostgreSQL 16+ Migrations #837

@Ankitd013

Description

@Ankitd013

While attempting to run httpsms with a PostgreSQL 18.3 (Alpine) backend, the auto-migration fails during the schema initialization/update phase. The application attempts to use IF NOT EXISTS syntax for ALTER TABLE ... ADD CONSTRAINT, which is not supported in standard PostgreSQL.

Error Logs:
ERROR: syntax error at or near "EXISTS" at character 42
STATEMENT:
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);

Environment:
PostgreSQL Version: 18.3 (compiled by gcc Alpine 15.2.0)
Deployment: Docker Compose
Image: postgres:alpine

Steps to Reproduce:
Use a standard postgres:alpine image in a docker-compose setup.
Point the httpsms API service to this database.
Observe the logs during the initial container startup/migration phase.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions