Quantcast
Channel: Issues for Drupal core
Viewing all articles
Browse latest Browse all 299620

New serial columns do not own sequences

$
0
0

Problem/Motivation

Follow-up from reviewing #3026290: PostgreSQL constraints are still not renamed properly on table renames.

The pgsql driver does not set the ownership of sequences it creates when changeField method is called. This happens if you specify a table without a serial field, then later change an integer field into one. This means that the preferred pg_get_serial_sequence function will not return the newly created sequence.

Sequences created automagically with CREATE TABLE are "owned" by the relation, but those created with CREATE SEQUENCE need the OWNED BY statement appended with the relation and the column.

Drupal 8 and 7 core currently do not have any database updates that change fields into serial columns, but contrib. or custom code might.

Proposed resolution

  1. Add OWNED BY {table}.field to the create sequence statements.
  2. Add a database update to check serial fields to make sure they exist via pg_get_serial_sequence, and if not, alter the sequence with the same statement above.
  3. Potentially refactor as a protected (or public?) function for ease-of-use?
  4. Write a test to assert that sequence ownership exists on change field.
  5. Write a test to assert that the database update works.

Remaining tasks

  • Write a patch.
  • Review
  • Commit and unpostpone the 7.x issue

API changes

None

Release notes snippet


Viewing all articles
Browse latest Browse all 299620

Latest Images

Trending Articles



Latest Images