Skip to content

fix(db): skip orphaned sequences in resynchronizeDatabaseSequences#58762

Open
boris324 wants to merge 1 commit intonextcloud:masterfrom
boris324:fix/pgsql-orphaned-sequence-resync
Open

fix(db): skip orphaned sequences in resynchronizeDatabaseSequences#58762
boris324 wants to merge 1 commit intonextcloud:masterfrom
boris324:fix/pgsql-orphaned-sequence-resync

Conversation

@boris324
Copy link

@boris324 boris324 commented Mar 6, 2026

Fixes #58715

Orphaned PostgreSQL sequences (left behind after dropAutoincrementColumn in migrations like Version33000Date20251023110529) crash occ db:convert-type with:

SQLSTATE[42601]: Syntax error: ... SELECT setval('oc_preview_locations_id_seq', (SELECT MAX() FROM ))

The information_schema.columns lookup returns no row for these sequences, and the code accessed fields on the false result.

Changes:

  • Skip sequences where no column references them
  • Handle empty tables where MAX() returns NULL
  • Use schema-qualified table names for the MAX query
  • Added unit tests

When converting a database to PostgreSQL via `occ db:convert-type`,
the sequence resynchronization crashes on orphaned sequences that
no longer have an associated column (e.g. after autoincrement was
removed via dropAutoincrementColumn in a migration).

The query against information_schema.columns returns no row for
these sequences, and the code tried to access fields on a `false`
result, producing malformed SQL like:
  SELECT setval('...', (SELECT MAX() FROM ))

Skip sequences with no matching column. Also handle empty tables
where MAX returns NULL, and use schema-qualified table names.

Fixes nextcloud#58715
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant