You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
PostgresAgentStateStore executes ALTER TABLE even when createIfNotExist=false #3213
ALTERTABLE<table>
ADD COLUMN IF NOT EXISTS version BIGINTNOT NULL DEFAULT 0;
This causes initialization to fail in production environments where the application database account only has DML permissions (SELECT, INSERT, UPDATE, DELETE) and schema changes are managed separately by DBA/Flyway/Liquibase.
Category: bug | Status: Confirmed | Severity: high
Verified against main @ 7854f0de. The report is accurate: the version-column migration runs on the path that is supposed to be DDL-free.
Root cause
PostgresAgentStateStore.java:127-134 — ensureVersionColumn() is called after the createIfNotExist branch, so it is unconditional:
if (createIfNotExist) {
createSchemaIfNotExist();
createTableIfNotExist();
} else {
verifySchemaExists();
verifyTableExists();
}
ensureVersionColumn(); // <-- runs in both cases
and ensureVersionColumn() (:137-146) emits DDL directly:
ALTERTABLE<schema>.<table> ADD COLUMN IF NOT EXISTS version BIGINTNOT NULL DEFAULT 1
There is no read-only counterpart (verifySchemaExists:188 and verifyTableExists:208 are SELECTs against INFORMATION_SCHEMA; nothing equivalent exists for the column).
Why IF NOT EXISTS does not save it
PostgreSQL checks table ownership before honoring ADD COLUMN IF NOT EXISTS, so a DML-only account gets ERROR: must be owner of table … (SQLSTATE 42501) on every startup, even when the column already exists. createIfNotExist(false) therefore does not deliver the least-privilege deployment it advertises; the only workarounds today are granting DDL/ownership to the app role or forking the class.
Not consistent with the sibling stores
Store
createIfNotExist=false behavior
PostgresAgentStateStore.java:134
unconditional ALTER TABLE — broken for DML-only roles
MysqlAgentStateStore.java:178-209
SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS … first (:183); ALTER only when the column is genuinely missing (:197)
JdbcAgentStateStore.java:76-85
no DDL at all on the verify path
So MySQL already implements exactly the shape this issue proposes; Postgres just never got the same guard.
One correction to the report: the ALTER now defaults to 1, not 0. That was ensureVersionColumn()'s sentinel-value bug (#3162, fixed by #3165) and is separate from this DDL-permission issue — the unconditional execution is unchanged.
Fix direction
On the createIfNotExist=false path, replace ensureVersionColumn() with a read-only verifyVersionColumnExists() mirroring MysqlAgentStateStore.java:183-190, and fail with an IllegalStateException that quotes the exact migration DDL to run.
Keep createSchemaIfNotExist() / createTableIfNotExist() / ensureVersionColumn() together under createIfNotExist=true.
Backward compatibility: users who relied on the silent migration with createIfNotExist=false get an explicit opt-in (e.g. autoMigrateSchema) rather than the implicit DDL; DEFAULT 1 from fix(state): resolve phantom CAS conflicts on version-0 migrated rows … #3165 is preserved on that migration path. Worth noting PostgresDistributedStore uses createIfNotExist=true and is unaffected.
Test gap: PostgresAgentStateStoreTest.java:128-131 asserts only that createStatement() is never called, while ensureVersionColumn() goes through prepareStatement() — that is why the existing "no auto-create" test passes despite the DDL. A regression test should assert never()).prepareStatement(startsWith("ALTER")) on the false path, plus a missing-column case expecting the new exception.
Next step: reply /approve on this issue and a fix PR implementing items 1-4 will be generated; /revise <notes> to steer the scope, or /reject to stop. Not proposing a PR unprompted this tick: item 3 changes startup behavior for existing Postgres deployments, so the opt-in flag name is a maintainer call.
Hi, I'd like to work on this issue. Following the fix direction above, I'll scope the PR to items 1, 2 and 4, and leave item 3 (the autoMigrateSchema opt-in flag) for maintainers to decide since the flag name is a design call:
On the createIfNotExist=false path, replace the unconditional ensureVersionColumn() with a read-only verifyVersionColumnExists() mirroring the MySQL store's INFORMATION_SCHEMA check, failing with an IllegalStateException that quotes the exact migration DDL to run.
Keep createSchemaIfNotExist() / createTableIfNotExist() / ensureVersionColumn() together under createIfNotExist=true (the DEFAULT 1 backfill value preserved).
Regression tests: assert prepareStatement(startsWith("ALTER")) is never invoked on the false path, plus a missing-column case expecting the new exception (the existing test only asserted createStatement() is never called, which the prepareStatement-based DDL bypassed).
Status: 72 h feedback window expired — no automated PR will be generated, the proposal window here is closed
The evaluation CTA above (5749751099, posted 2026-09-20T12:18:59Z) reached its 72-hour feedback
limit at 2026-09-23T12:18:59Z with no own-line /approve, /revise, or /reject command in the
thread, so per our workflow we skip PR generation and no competing PR will be filed from this
proposal window. No action is needed from anyone.
This is a timing stand-down, not a verdict on the report — and in this case the fix is already
being shipped by the community:
@aiyili claimed the work here on 2026-09-21T05:52:49Z (5756001694), scoping the change to the
read-only verifyVersionColumnExists() guard on the createIfNotExist=false path, keeping ensureVersionColumn() under createIfNotExist=true, and adding the prepareStatement("ALTER …")
regression test.
That claim became PR fix(postgresql): no ALTER TABLE on the createIfNotExist=false path #3227 (fix(postgresql): no ALTER TABLE on the createIfNotExist=false
path). As of this check it is still OPEN and unmerged at head 5aa82149782b (last updated
2026-09-21T07:41:27Z), so it remains the active carrier for this issue and the fix lands through
it rather than through a bot-generated PR.
Measured on the thread at 2026-09-23T12:36Z: 1 non-bot reply after the CTA, 0 own-line directive
tokens in it (the slash tokens in the evaluation text itself are ours, not a reply), and 0 reactions
on the CTA — so there was nothing to act on.
The evaluation itself stands as recorded: PostgresAgentStateStore.java:127-134 calls ensureVersionColumn() unconditionally after the createIfNotExist branch, so the ALTER TABLE … ADD COLUMN IF NOT EXISTS version DDL still runs on the path that is supposed to be
DDL-free, and a DML-only role hits SQLSTATE 42501 at startup. The createIfNotExist=false shape
MySQL already implements (INFORMATION_SCHEMA.COLUMNS check before any ALTER) is the reference.
If a maintainer would still prefer an independent, bot-generated PR for this fix despite #3227,
leave a one-line approve on this issue and the spec will be regenerated.
Following up on the 72 h stand-down: the fix is already in flight as #3227 (#3227), still open and ready for review when a maintainer has a moment.
Scope, matching the evaluation:
createIfNotExist=false path: the unconditional ensureVersionColumn() is replaced by a read-only verifyVersionColumnExists() -- an INFORMATION_SCHEMA.COLUMNS check mirroring MysqlAgentStateStore, throwing IllegalStateException that quotes the exact ALTER TABLE ... ADD COLUMN IF NOT EXISTS version DDL to run via the user's own migration process.
ensureVersionColumn() stays under createIfNotExist=true (the DEFAULT 1 backfill value is preserved).
Regression: the false path asserts prepareStatement(startsWith("ALTER")) is never invoked (the previous test only guarded createStatement(), which the prepareStatement-based DDL bypassed).
Happy to rebase onto current main before merge if needed.
Activity
oss-maintainer commentedon Sep 20, 2026
Issue Evaluation
Category:
bug| Status: Confirmed | Severity: highVerified against
main@7854f0de. The report is accurate: theversion-column migration runs on the path that is supposed to be DDL-free.Root cause
PostgresAgentStateStore.java:127-134—ensureVersionColumn()is called after thecreateIfNotExistbranch, so it is unconditional:and
ensureVersionColumn()(:137-146) emits DDL directly:There is no read-only counterpart (
verifySchemaExists:188andverifyTableExists:208areSELECTs againstINFORMATION_SCHEMA; nothing equivalent exists for the column).Why
IF NOT EXISTSdoes not save itPostgreSQL checks table ownership before honoring
ADD COLUMN IF NOT EXISTS, so a DML-only account getsERROR: must be owner of table …(SQLSTATE 42501) on every startup, even when the column already exists.createIfNotExist(false)therefore does not deliver the least-privilege deployment it advertises; the only workarounds today are granting DDL/ownership to the app role or forking the class.Not consistent with the sibling stores
createIfNotExist=falsebehaviorPostgresAgentStateStore.java:134ALTER TABLE— broken for DML-only rolesMysqlAgentStateStore.java:178-209SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS …first (:183);ALTERonly when the column is genuinely missing (:197)JdbcAgentStateStore.java:76-85So MySQL already implements exactly the shape this issue proposes; Postgres just never got the same guard.
One correction to the report: the
ALTERnow defaults to1, not0. That wasensureVersionColumn()'s sentinel-value bug (#3162, fixed by #3165) and is separate from this DDL-permission issue — the unconditional execution is unchanged.Fix direction
createIfNotExist=falsepath, replaceensureVersionColumn()with a read-onlyverifyVersionColumnExists()mirroringMysqlAgentStateStore.java:183-190, and fail with anIllegalStateExceptionthat quotes the exact migration DDL to run.createSchemaIfNotExist()/createTableIfNotExist()/ensureVersionColumn()together undercreateIfNotExist=true.createIfNotExist=falseget an explicit opt-in (e.g.autoMigrateSchema) rather than the implicit DDL;DEFAULT 1from fix(state): resolve phantom CAS conflicts on version-0 migrated rows … #3165 is preserved on that migration path. Worth notingPostgresDistributedStoreusescreateIfNotExist=trueand is unaffected.PostgresAgentStateStoreTest.java:128-131asserts only thatcreateStatement()is never called, whileensureVersionColumn()goes throughprepareStatement()— that is why the existing "no auto-create" test passes despite the DDL. A regression test should assertnever()).prepareStatement(startsWith("ALTER"))on thefalsepath, plus a missing-column case expecting the new exception.Next step: reply
/approveon this issue and a fix PR implementing items 1-4 will be generated;/revise <notes>to steer the scope, or/rejectto stop. Not proposing a PR unprompted this tick: item 3 changes startup behavior for existing Postgres deployments, so the opt-in flag name is a maintainer call.Automated evaluation by github-manager-bot
aiyili commentedon Sep 21, 2026
Hi, I'd like to work on this issue. Following the fix direction above, I'll scope the PR to items 1, 2 and 4, and leave item 3 (the
autoMigrateSchemaopt-in flag) for maintainers to decide since the flag name is a design call:createIfNotExist=falsepath, replace the unconditionalensureVersionColumn()with a read-onlyverifyVersionColumnExists()mirroring the MySQL store's INFORMATION_SCHEMA check, failing with anIllegalStateExceptionthat quotes the exact migration DDL to run.createSchemaIfNotExist()/createTableIfNotExist()/ensureVersionColumn()together undercreateIfNotExist=true(theDEFAULT 1backfill value preserved).prepareStatement(startsWith("ALTER"))is never invoked on thefalsepath, plus a missing-column case expecting the new exception (the existing test only assertedcreateStatement()is never called, which theprepareStatement-based DDL bypassed).PR coming shortly.
fix(jdbc): 补齐 version 列迁移,从废弃 mysql/postgresql 模块迁入不再报 Unknown column
oss-maintainer commentedon Sep 23, 2026
Status: 72 h feedback window expired — no automated PR will be generated, the proposal window here is closed
The evaluation CTA above (
5749751099, posted 2026-09-20T12:18:59Z) reached its 72-hour feedbacklimit at 2026-09-23T12:18:59Z with no own-line
/approve,/revise, or/rejectcommand in thethread, so per our workflow we skip PR generation and no competing PR will be filed from this
proposal window. No action is needed from anyone.
This is a timing stand-down, not a verdict on the report — and in this case the fix is already
being shipped by the community:
5756001694), scoping the change to theread-only
verifyVersionColumnExists()guard on thecreateIfNotExist=falsepath, keepingensureVersionColumn()undercreateIfNotExist=true, and adding theprepareStatement("ALTER …")regression test.
path). As of this check it is still
OPENand unmerged at head5aa82149782b(last updated2026-09-21T07:41:27Z), so it remains the active carrier for this issue and the fix lands through
it rather than through a bot-generated PR.
Measured on the thread at 2026-09-23T12:36Z: 1 non-bot reply after the CTA, 0 own-line directive
tokens in it (the slash tokens in the evaluation text itself are ours, not a reply), and 0 reactions
on the CTA — so there was nothing to act on.
The evaluation itself stands as recorded:
PostgresAgentStateStore.java:127-134callsensureVersionColumn()unconditionally after thecreateIfNotExistbranch, so theALTER TABLE … ADD COLUMN IF NOT EXISTS versionDDL still runs on the path that is supposed to beDDL-free, and a DML-only role hits SQLSTATE 42501 at startup. The
createIfNotExist=falseshapeMySQL already implements (
INFORMATION_SCHEMA.COLUMNScheck before anyALTER) is the reference.If a maintainer would still prefer an independent, bot-generated PR for this fix despite #3227,
leave a one-line
approveon this issue and the spec will be regenerated.Automated by github-manager-bot
aiyili commentedon Sep 24, 2026
Following up on the 72 h stand-down: the fix is already in flight as #3227 (#3227), still open and ready for review when a maintainer has a moment.
Scope, matching the evaluation:
createIfNotExist=falsepath: the unconditionalensureVersionColumn()is replaced by a read-onlyverifyVersionColumnExists()-- anINFORMATION_SCHEMA.COLUMNScheck mirroringMysqlAgentStateStore, throwingIllegalStateExceptionthat quotes the exactALTER TABLE ... ADD COLUMN IF NOT EXISTS versionDDL to run via the user's own migration process.ensureVersionColumn()stays undercreateIfNotExist=true(theDEFAULT 1backfill value is preserved).prepareStatement(startsWith("ALTER"))is never invoked (the previous test only guardedcreateStatement(), which theprepareStatement-based DDL bypassed).Happy to rebase onto current
mainbefore merge if needed.