squawk icon indicating copy to clipboard operation
squawk copied to clipboard

`adding-foreign-key-constraint` shouldn't warn about foreign keys when creating table

Open cdignam-segment opened this issue 2 years ago • 1 comments

I think Squawk shouldn't complain here because there won't be any rows in our table so the lock will be short.

stdin:1:0: warning: adding-foreign-key-constraint

   1 | CREATE TABLE IF NOT EXISTS my.table
   2 | (
   3 |     username                text            primary key,
   4 |     nickname  text            not null,
   5 |     --
   6 |     --
   7 |     --
   8 |     --
   9 |     --
  10 | 
  11 |     CONSTRAINT nickname_fkey
  12 |         FOREIGN KEY (nickname) REFERENCES some.nickname_table (id)
  13 | );

  note: Requires a table scan of the table you're altering and a SHARE ROW EXCLUSIVE lock on both tables, which blocks writes to both tables while your table is scanned.
  help: Add NOT VALID to the constraint in one transaction and then VALIDATE the constraint in a separate transaction.

find detailed examples and solutions for each rule at https://squawkhq.com/docs/rules     

cdignam-segment avatar Jun 22 '22 20:06 cdignam-segment

+1

maximus1108 avatar May 10 '23 16:05 maximus1108