Repository navigation
h5i-app-pg: refuse mixed-case schema names in with_schema - #765
Open
hiroki-abe-58 wants to merge 1 commit into
Open
hiroki-abe-58 wants to merge 1 commit into
hiroki-abe-58 wants to merge 1 commit into
Conversation
`with_schema` puts the name into `search_path` unquoted, where PostgreSQL folds it to lowercase, but `install_schema` creates the schema quoted, as written. With `with_schema(url, "Board")`, `install_schema` creates "Board", the search path names `board`, and the next CREATE TABLE fails with "no schema has been selected to create in". Refuse names with uppercase letters up front; every caller in the repository already uses lowercase. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What.
with_schemanow refuses schema names containing anything other than[a-z0-9_]; before, it accepted any[A-Za-z0-9_]+. There is one check with one error message, and three unit tests.Why.
with_schemaputs the name intosearch_pathunquoted, and PostgreSQL folds it to lowercase.install_schemareadscurrent_setting('search_path')and runsCREATE SCHEMA IF NOT EXISTS "<name>", quoted and as written.With
with_schema(url, "Board"):install_schemacreates the schema"Board".board, which doesn't exist.CREATE TABLEfails with3F000: no schema has been selected to create in.Every caller in the repository already uses a lowercase name, so
with_schemanow refuses names it cannot install, instead of lettinginstall_schemafail later. I did not fold the name to lowercase, because"Board"and"board"would then silently share a schema. I did not quote it insearch_patheither, because that would change every existing caller's URL and introduce case-sensitive schema names.Behavior change. A name with uppercase letters now fails in
with_schemainstead of ininstall_schema.One setup used to work by accident. If a lowercase schema such as
boardalready existed,install_schemasucceeded, put the tables inboard, and left an empty"Board"schema behind. That setup now gets an error and must use the lowercase name.install_schemastill reads an unquoted mixed-case search path that is set by other means (rawoptions=,ALTER ROLE ... SET search_path) the same way as before. I can also fold unquoted names there, if you prefer.Reproduction (PostgreSQL 17).
Engineonpool(&with_schema(url, "Board")?, ..)and callinstall_schema(). It fails with3F000: no schema has been selected to create in, andcurrent_schema()is NULL. With"board"it succeeds.with_schema(url, "Board")returnsErr(Decode("schema name \"Board\" must be [a-z0-9_]+")).Tests
cargo test --locked -p h5i-app-pg, with and without--all-features, run against a local PostgreSQL 17 throughH5I_APP_TEST_DATABASE_URL: 8 passed, 0 skipped. That includes the 3reads_testDB tests.cargo clippy --locked -p h5i-app-pg --all-targets --all-features -- -D warnings: clean.with_schema_refuses_names_postgres_would_foldfails on"Board".cargo appchecks. No proof or trust assumption changes.This change was written with Claude Code (Claude Opus 5.5). It has been reviewed only by AI, in a separate session; no human has reviewed it.
🤖 Generated with Claude Code