1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
---
source: crates/squawk/src/reporter.rs
expression: "check_sql(sql, filename, &[], None, false)"
---
CheckReport {
filename: "main.sql",
sql: "\n\n ALTER TABLE \"core_recipe\" ADD COLUMN \"foo\" integer NOT NULL;\nALTER TABLE \"core_foo\" ADD COLUMN \"bar\" integer NOT NULL;\nSELECT 1;\n",
violations: [
ReportViolation {
file: "main.sql",
line: 2,
column: 3,
range: 5..64,
level: Warning,
message: "Missing `set lock_timeout` before potentially slow operations",
help: Some(
"Configure a `lock_timeout` before this statement.",
),
rule_name: "require-timeout-settings",
column_end: 62,
line_end: 2,
fix: Some(
Fix {
title: "Add lock timeout",
edits: [
Edit {
text_range: 5..5,
text: Some(
"set lock_timeout = '1s';\n",
),
},
],
},
),
},
ReportViolation {
file: "main.sql",
line: 2,
column: 3,
range: 5..64,
level: Warning,
message: "Missing `set statement_timeout` before potentially slow operations",
help: Some(
"Configure a `statement_timeout` before this statement",
),
rule_name: "require-timeout-settings",
column_end: 62,
line_end: 2,
fix: Some(
Fix {
title: "Add statement timeout",
edits: [
Edit {
text_range: 5..5,
text: Some(
"set statement_timeout = '5s';\n",
),
},
],
},
),
},
ReportViolation {
file: "main.sql",
line: 2,
column: 29,
range: 31..64,
level: Warning,
message: "Adding a new column that is `NOT NULL` and has no default value to an existing table effectively makes it required.",
help: Some(
"Make the field nullable or add a non-VOLATILE DEFAULT",
),
rule_name: "adding-required-field",
column_end: 62,
line_end: 2,
fix: None,
},
ReportViolation {
file: "main.sql",
line: 2,
column: 29,
range: 31..64,
level: Warning,
message: "Missing `IF NOT EXISTS`, the migration can't be rerun if it fails part way through.",
help: None,
rule_name: "prefer-robust-stmts",
column_end: 62,
line_end: 2,
fix: Some(
Fix {
title: "Insert `if not exists`",
edits: [
Edit {
text_range: 41..41,
text: Some(
" if not exists",
),
},
],
},
),
},
ReportViolation {
file: "main.sql",
line: 2,
column: 46,
range: 48..55,
level: Warning,
message: "Using 32-bit integer fields can result in hitting the max `int` limit.",
help: Some(
"Use 64-bit integer values instead to prevent hitting this limit.",
),
rule_name: "prefer-bigint-over-int",
column_end: 53,
line_end: 2,
fix: Some(
Fix {
title: "Replace with a 64-bit integer type: `bigint`",
edits: [
Edit {
text_range: 48..55,
text: Some(
"bigint",
),
},
],
},
),
},
ReportViolation {
file: "main.sql",
line: 3,
column: 23,
range: 89..122,
level: Warning,
message: "Adding a new column that is `NOT NULL` and has no default value to an existing table effectively makes it required.",
help: Some(
"Make the field nullable or add a non-VOLATILE DEFAULT",
),
rule_name: "adding-required-field",
column_end: 56,
line_end: 3,
fix: None,
},
ReportViolation {
file: "main.sql",
line: 3,
column: 23,
range: 89..122,
level: Warning,
message: "Missing `IF NOT EXISTS`, the migration can't be rerun if it fails part way through.",
help: None,
rule_name: "prefer-robust-stmts",
column_end: 56,
line_end: 3,
fix: Some(
Fix {
title: "Insert `if not exists`",
edits: [
Edit {
text_range: 99..99,
text: Some(
" if not exists",
),
},
],
},
),
},
ReportViolation {
file: "main.sql",
line: 3,
column: 40,
range: 106..113,
level: Warning,
message: "Using 32-bit integer fields can result in hitting the max `int` limit.",
help: Some(
"Use 64-bit integer values instead to prevent hitting this limit.",
),
rule_name: "prefer-bigint-over-int",
column_end: 47,
line_end: 3,
fix: Some(
Fix {
title: "Replace with a 64-bit integer type: `bigint`",
edits: [
Edit {
text_range: 106..113,
text: Some(
"bigint",
),
},
],
},
),
},
],
}