hotdog 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/hotdog/application.rb +1 -1
- data/lib/hotdog/commands/hosts.rb +2 -2
- data/lib/hotdog/commands/search.rb +54 -56
- data/lib/hotdog/commands.rb +80 -84
- data/lib/hotdog/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 12b1b97f8c77f181a665ba52db0725c613d638a7
|
4
|
+
data.tar.gz: 73be8bb8526df6c4bb95811e6e56de196fae0a73
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 602156cf61f52c8f8c14937dcf324b93516ac16b6f0e61c971bcccb124a7827902e313c400fdcb98eb54d83f8ae2cf7a21783d4f1937df18899c20782380224a
|
7
|
+
data.tar.gz: eb9ab65fad8b6b25e59eec751cc02b4a99cc0d69fc5f2fc61a7c6df2c9fbce5055928ed2ab8f2c85b7af2a8580f9db51e5534c277fac89a100ab7e9b7064eb27
|
data/lib/hotdog/application.rb
CHANGED
@@ -155,7 +155,7 @@ module Hotdog
|
|
155
155
|
|
156
156
|
def find_library(dirname, name)
|
157
157
|
load_path = $LOAD_PATH.map { |path| File.join(path, dirname) }.select { |path| File.directory?(path) }
|
158
|
-
libraries = load_path.
|
158
|
+
libraries = load_path.flat_map { |path| Dir.glob(File.join(path, "*.rb")) }.select { |file| File.file?(file) }
|
159
159
|
rbname = "#{name}.rb"
|
160
160
|
if library = libraries.find { |file| File.basename(file) == rbname }
|
161
161
|
library
|
@@ -8,13 +8,13 @@ module Hotdog
|
|
8
8
|
if args.empty?
|
9
9
|
result = execute("SELECT id FROM hosts").to_a.reduce(:+)
|
10
10
|
else
|
11
|
-
result = args.
|
11
|
+
result = args.flat_map { |host_name|
|
12
12
|
if glob?(host_name)
|
13
13
|
execute("SELECT id FROM hosts WHERE name GLOB ?", [host_name]).to_a.reduce(:+)
|
14
14
|
else
|
15
15
|
execute("SELECT id FROM hosts WHERE name = ?", [host_name]).to_a.reduce(:+)
|
16
16
|
end
|
17
|
-
}
|
17
|
+
}
|
18
18
|
end
|
19
19
|
if result && (0 < result.length)
|
20
20
|
result, fields = get_hosts(result)
|
@@ -305,12 +305,13 @@ module Hotdog
|
|
305
305
|
else
|
306
306
|
# workaround for "too many terms in compound SELECT"
|
307
307
|
min, max = environment.execute("SELECT MIN(id), MAX(id) FROM hosts ORDER BY id LIMIT 1").first.to_a
|
308
|
-
|
309
|
-
|
310
|
-
range = (slice*i)...(slice*(i+1))
|
308
|
+
(min / SQLITE_LIMIT_COMPOUND_SELECT).upto(max / SQLITE_LIMIT_COMPOUND_SELECT).flat_map { |i|
|
309
|
+
range = (SQLITE_LIMIT_COMPOUND_SELECT*i)...(SQLITE_LIMIT_COMPOUND_SELECT*(i+1))
|
311
310
|
selected = values.select { |n| range === n }
|
312
|
-
|
313
|
-
|
311
|
+
q = "SELECT id FROM hosts " \
|
312
|
+
"WHERE ? <= id AND id < ? AND id NOT IN (%s);"
|
313
|
+
environment.execute(q % selected.map { "?" }.join(", "), [range.first, range.last] + selected).map { |row| row.first }
|
314
|
+
}.tap do |values|
|
314
315
|
environment.logger.debug("NOT expr: #{values.length} value(s)")
|
315
316
|
end
|
316
317
|
end
|
@@ -354,33 +355,32 @@ module Hotdog
|
|
354
355
|
end
|
355
356
|
|
356
357
|
def evaluate(environment, options={})
|
357
|
-
q = []
|
358
358
|
if identifier?
|
359
359
|
if attribute?
|
360
360
|
case identifier
|
361
361
|
when /\Ahost\z/i
|
362
|
-
q
|
363
|
-
|
364
|
-
values = environment.execute(q
|
362
|
+
q = "SELECT hosts.id FROM hosts " \
|
363
|
+
"WHERE hosts.name = ?;"
|
364
|
+
values = environment.execute(q, [attribute]).map { |row| row.first }
|
365
365
|
else
|
366
|
-
q
|
367
|
-
|
368
|
-
|
369
|
-
values = environment.execute(q
|
366
|
+
q = "SELECT DISTINCT hosts_tags.host_id FROM hosts_tags " \
|
367
|
+
"INNER JOIN tags ON hosts_tags.tag_id = tags.id " \
|
368
|
+
"WHERE tags.name = ? AND tags.value = ?;"
|
369
|
+
values = environment.execute(q, [identifier, attribute]).map { |row| row.first }
|
370
370
|
end
|
371
371
|
else
|
372
|
-
q
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
values = environment.execute(q
|
372
|
+
q = "SELECT DISTINCT hosts_tags.host_id FROM hosts_tags " \
|
373
|
+
"INNER JOIN hosts ON hosts_tags.host_id = hosts.id " \
|
374
|
+
"INNER JOIN tags ON hosts_tags.tag_id = tags.id " \
|
375
|
+
"WHERE hosts.name = ? OR tags.name = ? OR tags.value = ?;"
|
376
|
+
values = environment.execute(q, [identifier, identifier, identifier]).map { |row| row.first }
|
377
377
|
end
|
378
378
|
else
|
379
379
|
if attribute?
|
380
|
-
q
|
381
|
-
|
382
|
-
|
383
|
-
values = environment.execute(q
|
380
|
+
q = "SELECT DISTINCT hosts_tags.host_id FROM hosts_tags " \
|
381
|
+
"INNER JOIN tags ON hosts_tags.tag_id = tags.id " \
|
382
|
+
"WHERE tags.value = ?;"
|
383
|
+
values = environment.execute(q, [attribute]).map { |row| row.first }
|
384
384
|
else
|
385
385
|
return []
|
386
386
|
end
|
@@ -431,33 +431,32 @@ module Hotdog
|
|
431
431
|
|
432
432
|
class TagGlobExpressionNode < TagExpressionNode
|
433
433
|
def evaluate(environment, options={})
|
434
|
-
q = []
|
435
434
|
if identifier?
|
436
435
|
if attribute?
|
437
436
|
case identifier
|
438
437
|
when /\Ahost\z/i
|
439
|
-
q
|
440
|
-
|
441
|
-
values = environment.execute(q
|
438
|
+
q = "SELECT hosts.id FROM hosts " \
|
439
|
+
"WHERE hosts.name GLOB ?;"
|
440
|
+
values = environment.execute(q, [attribute]).map { |row| row.first }
|
442
441
|
else
|
443
|
-
q
|
444
|
-
|
445
|
-
|
446
|
-
values = environment.execute(q
|
442
|
+
q = "SELECT DISTINCT hosts_tags.host_id FROM hosts_tags " \
|
443
|
+
"INNER JOIN tags ON hosts_tags.tag_id = tags.id " \
|
444
|
+
"WHERE tags.name GLOB ? AND tags.value GLOB ?;"
|
445
|
+
values = environment.execute(q, [identifier, attribute]).map { |row| row.first }
|
447
446
|
end
|
448
447
|
else
|
449
|
-
q
|
450
|
-
|
451
|
-
|
452
|
-
|
453
|
-
values = environment.execute(q
|
448
|
+
q = "SELECT DISTINCT hosts_tags.host_id FROM hosts_tags " \
|
449
|
+
"INNER JOIN hosts ON hosts_tags.host_id = hosts.id " \
|
450
|
+
"INNER JOIN tags ON hosts_tags.tag_id = tags.id " \
|
451
|
+
"WHERE hosts.name GLOB ? OR tags.name GLOB ? OR tags.value GLOB ?;"
|
452
|
+
values = environment.execute(q, [identifier, identifier, identifier]).map { |row| row.first }
|
454
453
|
end
|
455
454
|
else
|
456
455
|
if attribute?
|
457
|
-
q
|
458
|
-
|
459
|
-
|
460
|
-
values = environment.execute(q
|
456
|
+
q = "SELECT DISTINCT hosts_tags.host_id FROM hosts_tags " \
|
457
|
+
"INNER JOIN tags ON hosts_tags.tag_id = tags.id " \
|
458
|
+
"WHERE tags.value GLOB ?;"
|
459
|
+
values = environment.execute(q, [attribute]).map { |row| row.first }
|
461
460
|
else
|
462
461
|
return []
|
463
462
|
end
|
@@ -478,33 +477,32 @@ module Hotdog
|
|
478
477
|
end
|
479
478
|
|
480
479
|
def evaluate(environment, options={})
|
481
|
-
q = []
|
482
480
|
if identifier?
|
483
481
|
if attribute?
|
484
482
|
case identifier
|
485
483
|
when /\Ahost\z/i
|
486
|
-
q
|
487
|
-
|
488
|
-
values = environment.execute(q
|
484
|
+
q = "SELECT hosts.id FROM hosts " \
|
485
|
+
"WHERE hosts.name REGEXP ?;"
|
486
|
+
values = environment.execute(q, [attribute]).map { |row| row.first }
|
489
487
|
else
|
490
|
-
q
|
491
|
-
|
492
|
-
|
493
|
-
values = environment.execute(q
|
488
|
+
q = "SELECT DISTINCT hosts_tags.host_id FROM hosts_tags " \
|
489
|
+
"INNER JOIN tags ON hosts_tags.tag_id = tags.id " \
|
490
|
+
"WHERE tags.name REGEXP ? AND tags.value REGEXP ?;"
|
491
|
+
values = environment.execute(q, [identifier, attribute]).map { |row| row.first }
|
494
492
|
end
|
495
493
|
else
|
496
|
-
q
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
values = environment.execute(q
|
494
|
+
q = "SELECT DISTINCT hosts_tags.host_id FROM hosts_tags " \
|
495
|
+
"INNER JOIN hosts ON hosts_tags.host_id = hosts.id " \
|
496
|
+
"INNER JOIN tags ON hosts_tags.tag_id = tags.id " \
|
497
|
+
"WHERE hosts.name REGEXP ? OR tags.name REGEXP ? OR tags.value REGEXP ?;"
|
498
|
+
values = environment.execute(q, [identifier, identifier, identifier]).map { |row| row.first }
|
501
499
|
end
|
502
500
|
else
|
503
501
|
if attribute?
|
504
|
-
q
|
505
|
-
|
506
|
-
|
507
|
-
values = environment.execute(q
|
502
|
+
q = "SELECT DISTINCT hosts_tags.host_id FROM hosts_tags " \
|
503
|
+
"INNER JOIN tags ON hosts_tags.tag_id = tags.id " \
|
504
|
+
"WHERE tags.value REGEXP ?;"
|
505
|
+
values = environment.execute(q, [attribute]).map { |row| row.first }
|
508
506
|
else
|
509
507
|
return []
|
510
508
|
end
|
data/lib/hotdog/commands.rb
CHANGED
@@ -7,11 +7,12 @@ require "sqlite3"
|
|
7
7
|
|
8
8
|
module Hotdog
|
9
9
|
module Commands
|
10
|
+
SQLITE_LIMIT_COMPOUND_SELECT = 500 # TODO: get actual value from `sqlite3_limit()`?
|
11
|
+
|
10
12
|
class BaseCommand
|
11
13
|
PERSISTENT_DB = "persistent.db"
|
12
14
|
MASK_DATABASE = 0xffff0000
|
13
15
|
MASK_QUERY = 0x0000ffff
|
14
|
-
MAX_TERMS = 200
|
15
16
|
|
16
17
|
def initialize(application)
|
17
18
|
@application = application
|
@@ -84,22 +85,21 @@ module Hotdog
|
|
84
85
|
host_names = {}
|
85
86
|
else
|
86
87
|
host_names = Hash[
|
87
|
-
host_ids.each_slice(
|
88
|
+
host_ids.each_slice(SQLITE_LIMIT_COMPOUND_SELECT).flat_map { |host_ids|
|
88
89
|
execute("SELECT id, name FROM hosts WHERE id IN (%s)" % host_ids.map { "?" }.join(", "), host_ids).map { |row| row.to_a }
|
89
|
-
}
|
90
|
+
}
|
90
91
|
]
|
91
92
|
end
|
92
|
-
q1 =
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
q1 << "GROUP BY tags.name;"
|
93
|
+
q1 = "SELECT tags.name, GROUP_CONCAT(tags.value, ',') FROM hosts_tags " \
|
94
|
+
"INNER JOIN hosts ON hosts_tags.host_id = hosts.id " \
|
95
|
+
"INNER JOIN tags ON hosts_tags.tag_id = tags.id " \
|
96
|
+
"WHERE hosts_tags.host_id = ? AND tags.name IN (%s) " \
|
97
|
+
"GROUP BY tags.name;"
|
98
98
|
result = host_ids.map { |host_id|
|
99
99
|
tag_values = Hash[
|
100
|
-
fields_without_host.each_slice(
|
101
|
-
execute(q1
|
102
|
-
}
|
100
|
+
fields_without_host.each_slice(SQLITE_LIMIT_COMPOUND_SELECT - 1).flat_map { |fields_without_host|
|
101
|
+
execute(q1 % fields_without_host.map { "?" }.join(", "), [host_id] + fields_without_host).map { |row| row.to_a }
|
102
|
+
}
|
103
103
|
]
|
104
104
|
fields.map { |tag_name|
|
105
105
|
if tag_name == "host"
|
@@ -112,42 +112,40 @@ module Hotdog
|
|
112
112
|
[result, fields]
|
113
113
|
else
|
114
114
|
if @options[:listing]
|
115
|
-
q1 =
|
116
|
-
|
117
|
-
|
118
|
-
q1 << "WHERE hosts_tags.host_id IN (%s);"
|
115
|
+
q1 = "SELECT DISTINCT tags.name FROM hosts_tags " \
|
116
|
+
"INNER JOIN tags ON hosts_tags.tag_id = tags.id " \
|
117
|
+
"WHERE hosts_tags.host_id IN (%s);"
|
119
118
|
if @options[:primary_tag]
|
120
119
|
fields = [
|
121
120
|
@options[:primary_tag],
|
122
121
|
"host",
|
123
|
-
] + host_ids.each_slice(
|
124
|
-
execute(q1
|
122
|
+
] + host_ids.each_slice(SQLITE_LIMIT_COMPOUND_SELECT).flat_map { |host_ids|
|
123
|
+
execute(q1 % host_ids.map { "?" }.join(", "), host_ids).map { |row| row.first }.reject { |tag_name|
|
125
124
|
tag_name == @options[:primary_tag]
|
126
125
|
}
|
127
|
-
}
|
126
|
+
}
|
128
127
|
else
|
129
128
|
fields = [
|
130
129
|
"host",
|
131
|
-
] + host_ids.each_slice(
|
132
|
-
execute(q1
|
133
|
-
}
|
130
|
+
] + host_ids.each_slice(SQLITE_LIMIT_COMPOUND_SELECT).flat_map { |host_ids|
|
131
|
+
execute(q1 % host_ids.map { "?" }.join(", "), host_ids).map { |row| row.first }
|
132
|
+
}
|
134
133
|
end
|
135
134
|
host_names = Hash[
|
136
|
-
host_ids.each_slice(
|
135
|
+
host_ids.each_slice(SQLITE_LIMIT_COMPOUND_SELECT).flat_map { |host_ids|
|
137
136
|
execute("SELECT id, name FROM hosts WHERE id IN (%s)" % host_ids.map { "?" }.join(", "), host_ids).map { |row| row.to_a }
|
138
|
-
}
|
137
|
+
}
|
139
138
|
]
|
140
|
-
q2 =
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
q2 << "GROUP BY tags.name;"
|
139
|
+
q2 = "SELECT tags.name, GROUP_CONCAT(tags.value, ',') FROM hosts_tags " \
|
140
|
+
"INNER JOIN tags ON hosts_tags.tag_id = tags.id " \
|
141
|
+
"WHERE hosts_tags.host_id = ? AND tags.name IN (%s) " \
|
142
|
+
"GROUP BY tags.name;"
|
145
143
|
fields_without_host = fields.reject { |tag_name| tag_name == "host" }
|
146
144
|
result = host_ids.map { |host_id|
|
147
145
|
tag_values = Hash[
|
148
|
-
fields_without_host.each_slice(
|
149
|
-
execute(q2
|
150
|
-
}
|
146
|
+
fields_without_host.each_slice(SQLITE_LIMIT_COMPOUND_SELECT - 1).flat_map { |fields_without_host|
|
147
|
+
execute(q2 % fields_without_host.map { "?" }.join(", "), [host_id] + fields_without_host).map { |row| row.to_a }
|
148
|
+
}
|
151
149
|
]
|
152
150
|
fields.map { |tag_name|
|
153
151
|
if tag_name == "host"
|
@@ -161,20 +159,19 @@ module Hotdog
|
|
161
159
|
else
|
162
160
|
if @options[:primary_tag]
|
163
161
|
fields = [@options[:primary_tag]]
|
164
|
-
q1 =
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
}.reduce(:+)
|
162
|
+
q1 = "SELECT tags.value FROM hosts_tags " \
|
163
|
+
"INNER JOIN hosts ON hosts_tags.host_id = hosts.id " \
|
164
|
+
"INNER JOIN tags ON hosts_tags.tag_id = tags.id " \
|
165
|
+
"WHERE hosts_tags.host_id IN (%s) AND tags.name = ?;"
|
166
|
+
result = host_ids.each_slice(SQLITE_LIMIT_COMPOUND_SELECT - 1).flat_map { |host_ids|
|
167
|
+
execute(q1 % host_ids.map { "?" }.join(", "), host_ids + [@options[:primary_tag]]).map { |row| row.to_a }
|
168
|
+
}
|
172
169
|
[result, fields]
|
173
170
|
else
|
174
171
|
fields = ["host"]
|
175
|
-
result = host_ids.each_slice(
|
172
|
+
result = host_ids.each_slice(SQLITE_LIMIT_COMPOUND_SELECT).flat_map { |host_ids|
|
176
173
|
execute("SELECT name FROM hosts WHERE id IN (%s)" % host_ids.map { "?" }.join(", "), host_ids).map { |row| row.to_a }
|
177
|
-
}
|
174
|
+
}
|
178
175
|
[result, fields]
|
179
176
|
end
|
180
177
|
end
|
@@ -222,23 +219,22 @@ module Hotdog
|
|
222
219
|
|
223
220
|
memory_db.transaction do
|
224
221
|
known_tags = all_tags.keys.map { |tag| split_tag(tag) }.uniq
|
225
|
-
known_tags.each_slice(
|
222
|
+
known_tags.each_slice(SQLITE_LIMIT_COMPOUND_SELECT / 2) do |known_tags|
|
226
223
|
prepare(memory_db, "INSERT OR IGNORE INTO tags (name, value) VALUES %s" % known_tags.map { "(?, ?)" }.join(", ")).execute(known_tags)
|
227
224
|
end
|
228
225
|
|
229
226
|
known_hosts = all_tags.values.reduce(:+).uniq
|
230
|
-
known_hosts.each_slice(
|
227
|
+
known_hosts.each_slice(SQLITE_LIMIT_COMPOUND_SELECT) do |known_hosts|
|
231
228
|
prepare(memory_db, "INSERT OR IGNORE INTO hosts (name) VALUES %s" % known_hosts.map { "(?)" }.join(", ")).execute(known_hosts)
|
232
229
|
end
|
233
230
|
|
234
231
|
all_tags.each do |tag, hosts|
|
235
|
-
q =
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
prepare(memory_db, q.join(" ") % hosts.map { "?" }.join(", ")).execute(hosts + split_tag(tag))
|
232
|
+
q = "INSERT OR REPLACE INTO hosts_tags (host_id, tag_id) " \
|
233
|
+
"SELECT host.id, tag.id FROM " \
|
234
|
+
"( SELECT id FROM hosts WHERE name IN (%s) ) AS host, " \
|
235
|
+
"( SELECT id FROM tags WHERE name = ? AND value = ? LIMIT 1 ) AS tag;"
|
236
|
+
hosts.each_slice(SQLITE_LIMIT_COMPOUND_SELECT - 2) do |hosts|
|
237
|
+
prepare(memory_db, q % hosts.map { "?" }.join(", ")).execute(hosts + split_tag(tag))
|
242
238
|
end
|
243
239
|
end
|
244
240
|
end
|
@@ -269,10 +265,10 @@ module Hotdog
|
|
269
265
|
downtimes = all_downtimes.select { |downtime|
|
270
266
|
# active downtimes
|
271
267
|
downtime["active"] and ( downtime["start"].nil? or downtime["start"] < now ) and ( downtime["end"].nil? or now <= downtime["end"] )
|
272
|
-
}.
|
268
|
+
}.flat_map { |downtime|
|
273
269
|
# find host scopes
|
274
270
|
downtime["scope"].select { |scope| scope.start_with?("host:") }.map { |scope| scope.sub(/\Ahost:/, "") }
|
275
|
-
}
|
271
|
+
}
|
276
272
|
if not downtimes.empty?
|
277
273
|
logger.info("ignore host(s) with scheduled downtimes: #{downtimes.inspect}")
|
278
274
|
end
|
@@ -292,17 +288,17 @@ module Hotdog
|
|
292
288
|
create_table_hosts_tags(dst)
|
293
289
|
|
294
290
|
hosts = prepare(src, "SELECT id, name FROM hosts").execute().to_a
|
295
|
-
hosts.each_slice(
|
291
|
+
hosts.each_slice(SQLITE_LIMIT_COMPOUND_SELECT / 2) do |hosts|
|
296
292
|
prepare(dst, "INSERT INTO hosts (id, name) VALUES %s" % hosts.map { "(?, ?)" }.join(", ")).execute(hosts)
|
297
293
|
end
|
298
294
|
|
299
295
|
tags = prepare(src, "SELECT id, name, value FROM tags").execute().to_a
|
300
|
-
tags.each_slice(
|
296
|
+
tags.each_slice(SQLITE_LIMIT_COMPOUND_SELECT / 3) do |tags|
|
301
297
|
prepare(dst, "INSERT INTO tags (id, name, value) VALUES %s" % tags.map { "(?, ?, ?)" }.join(", ")).execute(tags)
|
302
298
|
end
|
303
299
|
|
304
300
|
hosts_tags = prepare(src, "SELECT host_id, tag_id FROM hosts_tags").to_a
|
305
|
-
hosts_tags.each_slice(
|
301
|
+
hosts_tags.each_slice(SQLITE_LIMIT_COMPOUND_SELECT / 2) do |hosts_tags|
|
306
302
|
prepare(dst, "INSERT INTO hosts_tags (host_id, tag_id) VALUES %s" % hosts_tags.map { "(?, ?)" }.join(", ")).execute(hosts_tags)
|
307
303
|
end
|
308
304
|
|
@@ -313,49 +309,49 @@ module Hotdog
|
|
313
309
|
end
|
314
310
|
|
315
311
|
def create_table_hosts(db)
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
q
|
321
|
-
q
|
322
|
-
db.execute(q.join(" "))
|
312
|
+
q = "CREATE TABLE IF NOT EXISTS hosts ( " \
|
313
|
+
"id INTEGER PRIMARY KEY AUTOINCREMENT, " \
|
314
|
+
"name VARCHAR(255) NOT NULL COLLATE NOCASE " \
|
315
|
+
");"
|
316
|
+
logger.debug(q)
|
317
|
+
db.execute(q)
|
323
318
|
end
|
324
319
|
|
325
320
|
def create_index_hosts(db)
|
326
|
-
|
327
|
-
|
321
|
+
q = "CREATE UNIQUE INDEX IF NOT EXISTS hosts_name ON hosts ( name );"
|
322
|
+
logger.debug(q)
|
323
|
+
db.execute(q)
|
328
324
|
end
|
329
325
|
|
330
326
|
def create_table_tags(db)
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
q
|
337
|
-
q
|
338
|
-
db.execute(q.join(" "))
|
327
|
+
q = "CREATE TABLE IF NOT EXISTS tags ( " \
|
328
|
+
"id INTEGER PRIMARY KEY AUTOINCREMENT, " \
|
329
|
+
"name VARCHAR(200) NOT NULL COLLATE NOCASE, " \
|
330
|
+
"value VARCHAR(200) NOT NULL COLLATE NOCASE " \
|
331
|
+
");"
|
332
|
+
logger.debug(q)
|
333
|
+
db.execute(q)
|
339
334
|
end
|
340
335
|
|
341
336
|
def create_index_tags(db)
|
342
|
-
|
343
|
-
|
337
|
+
q = "CREATE UNIQUE INDEX IF NOT EXISTS tags_name_value ON tags ( name, value );"
|
338
|
+
logger.debug(q)
|
339
|
+
db.execute(q)
|
344
340
|
end
|
345
341
|
|
346
342
|
def create_table_hosts_tags(db)
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
q
|
352
|
-
q
|
353
|
-
db.execute(q.join(" "))
|
343
|
+
q = "CREATE TABLE IF NOT EXISTS hosts_tags ( " \
|
344
|
+
"host_id INTEGER NOT NULL, " \
|
345
|
+
"tag_id INTEGER NOT NULL " \
|
346
|
+
");"
|
347
|
+
logger.debug(q)
|
348
|
+
db.execute(q)
|
354
349
|
end
|
355
350
|
|
356
351
|
def create_index_hosts_tags(db)
|
357
|
-
|
358
|
-
|
352
|
+
q = "CREATE UNIQUE INDEX IF NOT EXISTS hosts_tags_host_id_tag_id ON hosts_tags ( host_id, tag_id );"
|
353
|
+
logger.debug(q)
|
354
|
+
db.execute(q)
|
359
355
|
end
|
360
356
|
end
|
361
357
|
end
|
data/lib/hotdog/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hotdog
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yamashita Yuu
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-09-
|
11
|
+
date: 2015-09-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|