Skip to content

Commit a004678

Browse files
authored
Reset topic ID starting value during import #265 (#268)
2 parents 9bad325 + fc0bb44 commit a004678

File tree

4 files changed

+65
-1
lines changed

4 files changed

+65
-1
lines changed

Gemfile.lock

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ GEM
123123
bindex (0.8.1)
124124
bootsnap (1.18.6)
125125
msgpack (~> 1.2)
126-
brakeman (7.0.2)
126+
brakeman (7.1.0)
127127
racc
128128
builder (3.3.0)
129129
bullet (8.0.8)

brakeman

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"ignored_warnings": [
3+
{
4+
"warning_type": "SQL Injection",
5+
"warning_code": 0,
6+
"fingerprint": "05636d40d833157e028a2fd9aecd6f263d7f3915f8ed3334a502e18763f1841d",
7+
"check_name": "SQL",
8+
"message": "Possible SQL injection",
9+
"file": "lib/autorequire/data_import.rb",
10+
"line": 148,
11+
"link": "https://brakemanscanner.org/docs/warning_types/sql_injection/",
12+
"code": "ActiveRecord::Base.connection.execute(\"SELECT setval('topics_id_seq', #{((Topic.maximum(:id) or 0) + 1)}, ?)\", false)",
13+
"render_path": null,
14+
"location": {
15+
"type": "method",
16+
"class": "DataImport",
17+
"method": "s(:self).reset_topic_id_starting_value"
18+
},
19+
"user_input": "Topic.maximum(:id)",
20+
"confidence": "High",
21+
"cwe_id": [
22+
89
23+
],
24+
"note": ""
25+
}
26+
],
27+
"brakeman_version": "7.0.2"
28+
}

config/brakeman.ignore

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"ignored_warnings": [
3+
{
4+
"warning_type": "SQL Injection",
5+
"warning_code": 0,
6+
"fingerprint": "05636d40d833157e028a2fd9aecd6f263d7f3915f8ed3334a502e18763f1841d",
7+
"check_name": "SQL",
8+
"message": "Possible SQL injection",
9+
"file": "lib/autorequire/data_import.rb",
10+
"line": 148,
11+
"link": "https://brakemanscanner.org/docs/warning_types/sql_injection/",
12+
"code": "ActiveRecord::Base.connection.execute(\"SELECT setval('topics_id_seq', #{((Topic.maximum(:id) or 0) + 1)}, ?)\", false)",
13+
"render_path": null,
14+
"location": {
15+
"type": "method",
16+
"class": "DataImport",
17+
"method": "s(:self).reset_topic_id_starting_value"
18+
},
19+
"user_input": "Topic.maximum(:id)",
20+
"confidence": "High",
21+
"cwe_id": [
22+
89
23+
],
24+
"note": ""
25+
}
26+
],
27+
"brakeman_version": "7.0.2"
28+
}

lib/autorequire/data_import.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,14 @@ def self.import_topics
139139
puts "#{topic.title} #{topic.new_record? ? "created" : "already exists"}"
140140
topic.save!
141141
end
142+
reset_topic_id_starting_value
143+
end
144+
145+
def self.reset_topic_id_starting_value
146+
max_id = Topic.maximum(:id) || 0
147+
new_start_value = max_id + 1
148+
ActiveRecord::Base.connection.execute("SELECT setval('topics_id_seq', #{new_start_value}, ?)", false)
149+
puts "Reset topics ID starting value to #{new_start_value}"
142150
end
143151

144152
def self.import_tags

0 commit comments

Comments
 (0)