🐛(docs) run migration 0027 without superuser role#2284
Conversation
|
@CodeRabbit review |
✅ Actions performedReview triggered.
|
WalkthroughThis pull request replaces a PostgreSQL C-language function with a SQL-based equivalent to enable deployments on managed databases without superuser privileges. The migration changes Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 inconclusive)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 5
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docker/files/docker-entrypoint-initdb.d/01_create_app_user.sh`:
- Around line 15-16: The SQL here interpolates DB_USER, DB_PASSWORD and
POSTGRES_DB directly into the CREATE USER and ALTER DATABASE statements; replace
the direct bash interpolation with psql variable substitution (use the psql -v
mechanism and reference variables inside SQL with :'VAR' or :VAR as appropriate)
so the script passes DB_USER, DB_PASSWORD and POSTGRES_DB into the SQL safely
rather than expanding them in the shell; update the CREATE USER and ALTER
DATABASE statements to use those psql variables (and keep proper
quoting/escaping) instead of ${DB_USER}/${DB_PASSWORD}/${POSTGRES_DB}.
- Around line 9-12: The script assumes environment variables POSTGRES_USER,
POSTGRES_DB, DB_USER and DB_PASSWORD are present; add explicit validation at the
top that each required var is set and non-empty (check POSTGRES_USER and
POSTGRES_DB always, and if DB_USER != POSTGRES_USER then require DB_USER and
DB_PASSWORD), and on missing values print a clear error naming the missing
variable(s) and exit with a non-zero status so psql isn't invoked with unclear
errors.
- Around line 14-17: Replace the non-idempotent CREATE USER line with an
idempotent CREATE ROLE ... LOGIN so the script won't fail if the role already
exists: use CREATE ROLE "${DB_USER}" WITH LOGIN PASSWORD '${DB_PASSWORD}'; keep
the existing ALTER DATABASE "${POSTGRES_DB}" OWNER TO "${DB_USER}"; (use the
same DB_USER, DB_PASSWORD and POSTGRES_DB variables) so the role is created as a
login role and the database ownership is still transferred without error on
repeated runs.
In `@env.d/development/postgresql`:
- Line 14: Fix the typo in the comment "# The database must be deleted in roder
to be recreated." by changing "roder" to "order" so it reads "# The database
must be deleted in order to be recreated."; locate and update that exact comment
in the postgresql environment config (the comment near the database recreate
instruction).
In `@src/backend/core/migrations/0027_auto_20251120_0956.py`:
- Around line 16-17: The SQL function in migration 0027_auto_20251120_0956.py is
using an invalid `return` line for a LANGUAGE sql function; update the function
definition to include the required AS clause and dollar-quoted body and end with
a semicolon (e.g., change the fragment after `LANGUAGE sql IMMUTABLE PARALLEL
SAFE STRICT` to use `AS $$ RETURN unaccent($1) $$;` or `AS $$ SELECT
unaccent($1) $$;`). Ensure you replace the lone `return unaccent($1);` line with
the proper AS $$ ... $$; block so the migration executes under PostgreSQL.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: ba18b8fd-829e-464b-b2c1-da82a31b6931
📒 Files selected for processing (4)
compose.ymldocker/files/docker-entrypoint-initdb.d/01_create_app_user.shenv.d/development/postgresqlsrc/backend/core/migrations/0027_auto_20251120_0956.py
e61c67a to
d4d5967
Compare
In development environment we wanto tu use the application with a postgres user not having superuser role. The migration 0027 needs superuser role to be executed, so we want to be able to test migrations and other scenarios with a normal user. In order to create this user, the compose service must be deleted first and then recreated with DB_USER and DB_PASSWORD environment variable values different with POSTGRES_USER and POSTGRES_PASSWORD
The migration 00227 must be run with a postgres superuser, most af managed postgresql database can not be run using this kind of user. Ti fix this, we use postgresql unnacent function instead of accessing C function.
d4d5967 to
abd03d1
Compare
Purpose
In development environment, we want to use the application with a
postgres user not having superuser role. The migration 0027 needs
superuser role to be executed, so we want to be able to test migrations
and other scenarios with a normal user. In order to create this user,
the compose service must be deleted first and then recreated with
DB_USER and DB_PASSWORD environment variable values different with
POSTGRES_USER and POSTGRES_PASSWORD.
Once with user without superuser role, we modified the migration 0027 to make it runnable with a user without superuser role.
Proposal
Fix #1895