|
|
@@ -26,16 +26,12 @@ require_relative "./db"
|
|
|
require_relative "./util"
|
|
|
require_relative "./geocode"
|
|
|
require_relative "./migrate"
|
|
|
+require_relative "./log"
|
|
|
|
|
|
# Ensure all da_* tables have the expected columns before enriching.
|
|
|
Migrate.run!
|
|
|
|
|
|
-LOOKUP_URL = ENV["LOOKUP_URL"] # e.g. http://web/list_lookup.php
|
|
|
-ENRICH_DEBUG = ENV["ENRICH_DEBUG"] == "1"
|
|
|
-
|
|
|
-def log_enrich(msg)
|
|
|
- puts msg if ENRICH_DEBUG
|
|
|
-end
|
|
|
+LOOKUP_URL = ENV["LOOKUP_URL"] # e.g. http://web/list_lookup.php
|
|
|
|
|
|
def ensure_extra_columns!(table)
|
|
|
DB.validate_table_name!(table)
|
|
|
@@ -53,7 +49,7 @@ def ensure_extra_columns!(table)
|
|
|
}.each do |col, defn|
|
|
|
DB.client.query("ALTER TABLE `#{esc}` ADD COLUMN IF NOT EXISTS `#{col}` #{defn}")
|
|
|
rescue Mysql2::Error => e
|
|
|
- warn "[enrich] schema migration skipped for #{table}.#{col}: #{e.message}"
|
|
|
+ Log.warn "enrich", "schema migration skipped for #{table}.#{col}: #{e.message}"
|
|
|
end
|
|
|
end
|
|
|
|
|
|
@@ -92,7 +88,7 @@ def enrich_after_upsert!(table:, council_reference:, address:)
|
|
|
orig_address: row["address"],
|
|
|
geo: geo
|
|
|
)
|
|
|
- log_enrich("enrich: geocoded #{table} #{council_reference}")
|
|
|
+ Log.debug "enrich", "geocoded #{table} #{council_reference}"
|
|
|
# refresh row to fetch lat/lng for next step
|
|
|
row = sel.execute(council_reference, address).first
|
|
|
rescue => e
|
|
|
@@ -111,12 +107,12 @@ def enrich_after_upsert!(table:, council_reference:, address:)
|
|
|
title = (resp["title_id"] || "").to_s
|
|
|
upd = DB.client.prepare("UPDATE `#{esc}` SET property_id = COALESCE(NULLIF(?,’’), property_id), title_reference = COALESCE(NULLIF(?,’’), title_reference) WHERE council_reference = ? AND address = ?")
|
|
|
upd.execute(pid, title, council_reference, address)
|
|
|
- log_enrich("enrich: lookup ok #{table} #{council_reference} pid=#{pid} title=#{title}")
|
|
|
+ Log.debug "enrich", "lookup ok #{table} #{council_reference} pid=#{pid} title=#{title}"
|
|
|
else
|
|
|
- warn "[enrich] lookup error #{table} #{council_reference}: #{resp["error"]}"
|
|
|
+ Log.warn "enrich", "lookup error #{table} #{council_reference}: #{resp["error"]}"
|
|
|
end
|
|
|
rescue => e
|
|
|
- warn "[enrich] lookup failed #{table} #{council_reference}: #{e.class} #{e.message}"
|
|
|
+ Log.warn "enrich", "lookup failed #{table} #{council_reference}: #{e.class} #{e.message}"
|
|
|
end
|
|
|
end
|
|
|
end
|