@@ -53,48 +53,48 @@ impl Rule for AddingForeignKeyConstraint {
53
53
if let Some ( pgt_query:: NodeEnum :: AlterTableCmd ( cmd) ) = & cmd. node {
54
54
match cmd. subtype ( ) {
55
55
pgt_query:: protobuf:: AlterTableType :: AtAddConstraint => {
56
- if let Some ( def ) = cmd . def . as_ref ( ) . and_then ( |d| d . node . as_ref ( ) ) {
57
- if let pgt_query :: NodeEnum :: Constraint ( constraint ) = def {
58
- // check if it's a foreign key constraint
59
- if constraint. contype ( )
60
- == pgt_query :: protobuf :: ConstrType :: ConstrForeign
61
- {
62
- // it is okay if NOT VALID is specified (skip_validation = true)
63
- if !constraint . skip_validation {
64
- diagnostics . push ( RuleDiagnostic :: new (
65
- rule_category ! ( ) ,
66
- None ,
67
- markup ! {
68
- "Adding a foreign key constraint requires a table scan and locks on both tables."
69
- } ,
70
- ) . detail ( None , "This will block writes to both the referencing and referenced tables while PostgreSQL verifies the constraint." )
71
- . note ( "Add the constraint as NOT VALID first, then VALIDATE it in a separate transaction .") ) ;
72
- }
56
+ if let Some ( pgt_query :: NodeEnum :: Constraint ( constraint ) ) =
57
+ cmd . def . as_ref ( ) . and_then ( |d| d . node . as_ref ( ) )
58
+ {
59
+ // check if it's a foreign key constraint
60
+ if constraint . contype ( )
61
+ == pgt_query :: protobuf :: ConstrType :: ConstrForeign
62
+ {
63
+ // it is okay if NOT VALID is specified ( skip_validation = true)
64
+ if !constraint . skip_validation {
65
+ diagnostics . push ( RuleDiagnostic :: new (
66
+ rule_category ! ( ) ,
67
+ None ,
68
+ markup ! {
69
+ "Adding a foreign key constraint requires a table scan and locks on both tables."
70
+ } ,
71
+ ) . detail ( None , "This will block writes to both the referencing and referenced tables while PostgreSQL verifies the constraint .")
72
+ . note ( "Add the constraint as NOT VALID first, then VALIDATE it in a separate transaction." ) ) ;
73
73
}
74
74
}
75
75
}
76
76
}
77
77
pgt_query:: protobuf:: AlterTableType :: AtAddColumn => {
78
- if let Some ( def) = cmd. def . as_ref ( ) . and_then ( |d| d. node . as_ref ( ) ) {
79
- if let pgt_query:: NodeEnum :: ColumnDef ( col_def) = def {
80
- // check constraints on the column
81
- for constraint in & col_def. constraints {
82
- if let Some ( pgt_query:: NodeEnum :: Constraint ( constr) ) =
83
- & constraint. node
78
+ if let Some ( pgt_query:: NodeEnum :: ColumnDef ( col_def) ) =
79
+ cmd. def . as_ref ( ) . and_then ( |d| d. node . as_ref ( ) )
80
+ {
81
+ // check constraints on the column
82
+ for constraint in & col_def. constraints {
83
+ if let Some ( pgt_query:: NodeEnum :: Constraint ( constr) ) =
84
+ & constraint. node
85
+ {
86
+ if constr. contype ( )
87
+ == pgt_query:: protobuf:: ConstrType :: ConstrForeign
88
+ && !constr. skip_validation
84
89
{
85
- if constr. contype ( )
86
- == pgt_query:: protobuf:: ConstrType :: ConstrForeign
87
- && !constr. skip_validation
88
- {
89
- diagnostics. push ( RuleDiagnostic :: new (
90
- rule_category ! ( ) ,
91
- None ,
92
- markup ! {
93
- "Adding a column with a foreign key constraint requires a table scan and locks."
94
- } ,
95
- ) . detail ( None , "Using REFERENCES when adding a column will block writes while verifying the constraint." )
96
- . note ( "Add the column without the constraint first, then add the constraint as NOT VALID and VALIDATE it separately." ) ) ;
97
- }
90
+ diagnostics. push ( RuleDiagnostic :: new (
91
+ rule_category ! ( ) ,
92
+ None ,
93
+ markup ! {
94
+ "Adding a column with a foreign key constraint requires a table scan and locks."
95
+ } ,
96
+ ) . detail ( None , "Using REFERENCES when adding a column will block writes while verifying the constraint." )
97
+ . note ( "Add the column without the constraint first, then add the constraint as NOT VALID and VALIDATE it separately." ) ) ;
98
98
}
99
99
}
100
100
}
0 commit comments