-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcheck.rb
executable file
·43 lines (35 loc) · 1.09 KB
/
check.rb
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
#!/usr/bin/env ruby
# {
# "source": {
# "host": "...",
# "user": "...",
# "password": "..."
# "database": "..."
# "table": "..."
# },
# "version": { "id": 1423 }
# }
require 'mysql2'
require 'json'
# Parse the parameters passed to the script over STDIN
sSource = ARGF.read
source = JSON.parse(sSource)
host = source["source"]["host"]
user = source["source"]["user"]
password = source["source"]["password"]
database = source["source"]["database"]
# For the first build, the version field will be null, so let's handle that edge case
previous_version = 0
if source.has_key?("version") and not source["version"].nil?
previous_version = source["version"]["id"]
end
# Pull down all new rows, determined by the 'id' primary key
client = Mysql2::Client.new(:host => host, :username => user, :password => password, :database => database)
# Build the result and send to STDOUT
ret = []
results = client.query("SELECT id FROM concourseresource WHERE id > #{previous_version};")
results.each do |r|
ret << { "id": "#{r["id"]}"}
end
# Return the expected JSON to STDOUT
puts ret.to_json