-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Detect CREATE TABLE statements without schema prefix (#236)
Previously, we would only detect `CREATE TABLE` statements where the table name is qualified by the `public.` schema prefix. This prefix will not always be present, even for PostgreSQL; it will certainly not be present for MySQL.
- Loading branch information
Showing
6 changed files
with
125 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
92 changes: 92 additions & 0 deletions
92
pkg/detectors/custom/.snapshots/TestSQLCreateTableMySQLJSON
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
[ | ||
{ | ||
"type": "custom", | ||
"detector_type": "detect_sql_create_table", | ||
"source": { | ||
"filename": "structure.sql", | ||
"language": "SQL", | ||
"language_type": "data", | ||
"line_number": 3, | ||
"column_number": 8, | ||
"text": null | ||
}, | ||
"value": { | ||
"object_name": "users", | ||
"field_name": "id", | ||
"field_type": "integer", | ||
"field_type_simple": "number" | ||
} | ||
}, | ||
{ | ||
"type": "custom", | ||
"detector_type": "detect_sql_create_table", | ||
"source": { | ||
"filename": "structure.sql", | ||
"language": "SQL", | ||
"language_type": "data", | ||
"line_number": 4, | ||
"column_number": 8, | ||
"text": null | ||
}, | ||
"value": { | ||
"object_name": "users", | ||
"field_name": "class_id", | ||
"field_type": "integer", | ||
"field_type_simple": "number" | ||
} | ||
}, | ||
{ | ||
"type": "custom", | ||
"detector_type": "detect_sql_create_table", | ||
"source": { | ||
"filename": "structure.sql", | ||
"language": "SQL", | ||
"language_type": "data", | ||
"line_number": 5, | ||
"column_number": 8, | ||
"text": null | ||
}, | ||
"value": { | ||
"object_name": "users", | ||
"field_name": "type", | ||
"field_type": "char", | ||
"field_type_simple": "string" | ||
} | ||
}, | ||
{ | ||
"type": "custom", | ||
"detector_type": "detect_sql_create_table", | ||
"source": { | ||
"filename": "structure.sql", | ||
"language": "SQL", | ||
"language_type": "data", | ||
"line_number": 6, | ||
"column_number": 8, | ||
"text": null | ||
}, | ||
"value": { | ||
"object_name": "users", | ||
"field_name": "created_at", | ||
"field_type": "timestamp", | ||
"field_type_simple": "date" | ||
} | ||
}, | ||
{ | ||
"type": "custom", | ||
"detector_type": "detect_sql_create_table", | ||
"source": { | ||
"filename": "structure.sql", | ||
"language": "SQL", | ||
"language_type": "data", | ||
"line_number": 7, | ||
"column_number": 8, | ||
"text": null | ||
}, | ||
"value": { | ||
"object_name": "users", | ||
"field_name": "updated_at", | ||
"field_type": "timestamp", | ||
"field_type_simple": "date" | ||
} | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
pkg/detectors/custom/testdata/config/sql_create_table_mysql.yml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
detect_sql_create_table: | ||
patterns: | ||
- | | ||
CREATE TABLE $TABLE_NAME ( | ||
<$COLUMN> | ||
) | ||
param_parenting: true | ||
languages: | ||
- sql |
8 changes: 8 additions & 0 deletions
8
pkg/detectors/custom/testdata/sql/create_table_mysql/structure.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
-- MySQL CREATE TABLE statement | ||
CREATE TABLE users ( | ||
id integer NOT NULL, | ||
class_id integer, | ||
type char(255) NOT NULL, | ||
created_at timestamp NOT NULL, | ||
updated_at timestamp NOT NULL | ||
); |