From 959a0cbeebca16aefb40bbccb4d3073ee8b65918 Mon Sep 17 00:00:00 2001 From: MickLesk Date: Sun, 22 Feb 2026 14:23:29 +0100 Subject: [PATCH] fix: quote PostgreSQL identifiers in setup_postgresql_db - Rename Twenty DB from 'default' to 'twenty_db' (reserved keyword) - Quote all identifiers in setup_postgresql_db with double quotes to prevent SQL syntax errors with reserved words --- install/twenty-install.sh | 2 +- misc/tools.func | 26 +++++++++++++------------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/install/twenty-install.sh b/install/twenty-install.sh index dbe51c724..f0c057b32 100644 --- a/install/twenty-install.sh +++ b/install/twenty-install.sh @@ -20,7 +20,7 @@ $STD apt install -y \ msg_ok "Installed Dependencies" PG_VERSION="16" setup_postgresql -PG_DB_NAME="default" PG_DB_USER="twenty" setup_postgresql_db +PG_DB_NAME="twenty_db" PG_DB_USER="twenty" setup_postgresql_db NODE_VERSION="24" setup_nodejs fetch_and_deploy_gh_release "twenty" "twentyhq/twenty" "tarball" diff --git a/misc/tools.func b/misc/tools.func index a89fec2f7..b85a05479 100644 --- a/misc/tools.func +++ b/misc/tools.func @@ -5540,8 +5540,8 @@ function setup_postgresql_db() { fi msg_info "Setting up PostgreSQL Database" - $STD sudo -u postgres psql -c "CREATE ROLE $PG_DB_USER WITH LOGIN PASSWORD '$PG_DB_PASS';" - $STD sudo -u postgres psql -c "CREATE DATABASE $PG_DB_NAME WITH OWNER $PG_DB_USER ENCODING 'UTF8' TEMPLATE template0;" + $STD sudo -u postgres psql -c "CREATE ROLE \"$PG_DB_USER\" WITH LOGIN PASSWORD '$PG_DB_PASS';" + $STD sudo -u postgres psql -c "CREATE DATABASE \"$PG_DB_NAME\" WITH OWNER \"$PG_DB_USER\" ENCODING 'UTF8' TEMPLATE template0;" # Install extensions (comma-separated) if [[ -n "${PG_DB_EXTENSIONS:-}" ]]; then @@ -5554,26 +5554,26 @@ function setup_postgresql_db() { # ALTER ROLE settings for Django/Rails compatibility (unless skipped) if [[ "${PG_DB_SKIP_ALTER_ROLE:-}" != "true" ]]; then - $STD sudo -u postgres psql -c "ALTER ROLE $PG_DB_USER SET client_encoding TO 'utf8';" - $STD sudo -u postgres psql -c "ALTER ROLE $PG_DB_USER SET default_transaction_isolation TO 'read committed';" - $STD sudo -u postgres psql -c "ALTER ROLE $PG_DB_USER SET timezone TO 'UTC';" + $STD sudo -u postgres psql -c "ALTER ROLE \"$PG_DB_USER\" SET client_encoding TO 'utf8';" + $STD sudo -u postgres psql -c "ALTER ROLE \"$PG_DB_USER\" SET default_transaction_isolation TO 'read committed';" + $STD sudo -u postgres psql -c "ALTER ROLE \"$PG_DB_USER\" SET timezone TO 'UTC';" fi # Schema permissions (if requested) if [[ "${PG_DB_SCHEMA_PERMS:-}" == "true" ]]; then - $STD sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE $PG_DB_NAME TO $PG_DB_USER;" - $STD sudo -u postgres psql -c "ALTER USER $PG_DB_USER CREATEDB;" - $STD sudo -u postgres psql -d "$PG_DB_NAME" -c "GRANT ALL ON SCHEMA public TO $PG_DB_USER;" - $STD sudo -u postgres psql -d "$PG_DB_NAME" -c "GRANT CREATE ON SCHEMA public TO $PG_DB_USER;" - $STD sudo -u postgres psql -d "$PG_DB_NAME" -c "ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON TABLES TO $PG_DB_USER;" - $STD sudo -u postgres psql -d "$PG_DB_NAME" -c "ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON SEQUENCES TO $PG_DB_USER;" + $STD sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE \"$PG_DB_NAME\" TO \"$PG_DB_USER\";" + $STD sudo -u postgres psql -c "ALTER USER \"$PG_DB_USER\" CREATEDB;" + $STD sudo -u postgres psql -d "$PG_DB_NAME" -c "GRANT ALL ON SCHEMA public TO \"$PG_DB_USER\";" + $STD sudo -u postgres psql -d "$PG_DB_NAME" -c "GRANT CREATE ON SCHEMA public TO \"$PG_DB_USER\";" + $STD sudo -u postgres psql -d "$PG_DB_NAME" -c "ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON TABLES TO \"$PG_DB_USER\";" + $STD sudo -u postgres psql -d "$PG_DB_NAME" -c "ALTER DEFAULT PRIVILEGES IN SCHEMA public GRANT ALL ON SEQUENCES TO \"$PG_DB_USER\";" fi # Superuser grant (if requested - WARNING!) if [[ "${PG_DB_GRANT_SUPERUSER:-}" == "true" ]]; then msg_warn "Granting SUPERUSER privilege (security risk!)" - $STD sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE $PG_DB_NAME to $PG_DB_USER;" - $STD sudo -u postgres psql -c "ALTER USER $PG_DB_USER WITH SUPERUSER;" + $STD sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE \"$PG_DB_NAME\" TO \"$PG_DB_USER\";" + $STD sudo -u postgres psql -c "ALTER USER \"$PG_DB_USER\" WITH SUPERUSER;" fi # Save credentials