Repository navigation
fix: only qualify DROP/ALTER INDEX with an explicit schema, never CURRENT_SCHEMA() - #353
Merged
Merged
Conversation
This was referenced Sep 14, 2026
Member
Author
|
The red For reviewers comparing with #351: this PR deliberately leaves |
tr1v3r
force-pushed
the
fix/drop-index-current-schema
branch
2 times, most recently
from
September 14, 2026 15:47
3828a53 to
d46e218
Compare
tr1v3r
force-pushed
the
fix/drop-index-current-schema
branch
from
September 14, 2026 15:50
d46e218 to
e2d2a21
Compare
3 tasks done
oierxjn
added a commit
to YourTongji/YourTJ-Hub
that referenced
this pull request
Sep 17, 2026
v1.6.2 regressed Migrator().DropIndex/RenameIndex on PostgreSQL without an explicit schema (CURRENT_SCHEMA() rendered in identifier position, SQLSTATE 42601), failing the TestSchema* PG gate (go-gorm/postgres#350). v1.6.3 carries the fix (go-gorm/postgres#353). Dependabot's resolver still pins v1.6.2 after @dependabot recreate, so bump manually on this branch to unblock ci-backend-pg.
oierxjn
added a commit
to YourTongji/YourTJ-Hub
that referenced
this pull request
Sep 17, 2026
…s/gooseforum (#436) * chore(deps): bump gorm.io/driver/postgres in /apps/gooseforum Bumps [gorm.io/driver/postgres](https://github.com/go-gorm/postgres) from 1.6.0 to 1.6.2. - [Commits](go-gorm/postgres@v1.6.0...v1.6.2) --- updated-dependencies: - dependency-name: gorm.io/driver/postgres dependency-version: 1.6.2 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> * chore(deps): bump gorm.io/driver/postgres to v1.6.3 v1.6.2 regressed Migrator().DropIndex/RenameIndex on PostgreSQL without an explicit schema (CURRENT_SCHEMA() rendered in identifier position, SQLSTATE 42601), failing the TestSchema* PG gate (go-gorm/postgres#350). v1.6.3 carries the fix (go-gorm/postgres#353). Dependabot's resolver still pins v1.6.2 after @dependabot recreate, so bump manually on this branch to unblock ci-backend-pg. --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: oierxjn <1934672944@qq.com>
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.
Fixes #350.
Problem
Since v1.6.1 (PR #340),
Migrator().DropIndex()andMigrator().RenameIndex()fail in two ways:No explicit schema (the common default):
CurrentSchemareturnsclause.Expr{SQL: "CURRENT_SCHEMA()"}, and the newDROP INDEX ?.?/ALTER INDEX ?.? RENAME TO ?templates splice it into an identifier position:CURRENT_SCHEMA()is a function call; PostgreSQL cannot use it to qualify an identifier.Explicit schema (
TableName()likepublic.users): the schema is returned as a plain string, which?binding sends as a parameter:also invalid — identifiers must be quoted, not bound.
This breaks
AutoMigrateflows that drop/recreate indexes (e.g. gormigrate) and keeps the gorm core repo's postgres CI matrix red.Fix
Qualify the index only when the table has an explicit schema, using a quoted identifier:
CurrentSchemareturns astring(explicit schema fromschema.tableorTableExpr) →DROP INDEX "schema"."idx"/ALTER INDEX "schema"."idx" RENAME TO "idx_new"DROP INDEX "idx"/ALTER INDEX "idx" RENAME TO "idx_new"(pre-v1.6.1 behavior; the index resolves via the search_path)Tests
New
migrator_drop_index_test.gorecords the SQL through an injectedgorm.ConnPool(no live PostgreSQL needed) and asserts both scenarios forDropIndexandRenameIndex. Verified red → green: pre-fix the tests fail with exactly the two invalid statements above; post-fix all pass, full packagego test ./...green.