dibi
dibi copied to clipboard
PostgreReflector: fix autoincrement column detection
- bug fix
- BC break? probably not
- versions affected: all
When an autoincrement column is not in the first position of primary key index, PostgreReflector is unable to detect it. This seems like a rather arbitrary check, which is also inconsistent with other drivers such as MySqlReflector; MySqlReflector doesn't require autoincrement columns to be part of a primary key at all to detect them.
My commit removes the primary key check from PostgreReflector autoincrement detection entirely, making it consistent with MySqlReflector and allowing PostgreReflector to detect autoincrement columns anywhere in the table.
This is potentially a BC break for someone who relies on PostgreReflector's failure to detect autoincrement columns outside the first position of primary key index.
Additionally, I've made the autoincrement check stricter in that the column's default value must start with nextval( instead of only nextval. This prevents potential false positives when a column's default value would be set to invoke some custom function like nextvalentine().
I've also noticed that IDENTITY autoincrement columns are not detected by dibi at all. This is actually the preferred, SQL-standard way of defining autoincrement columns since PostgreSQL 10. Reference: https://www.2ndquadrant.com/en/blog/postgresql-10-identity-columns/
I have added a second commit which fixes support for dibi detecting IDENTITY autoincrement columns.
Thank!