Skip to content

Commit

Permalink
More code moved to SQL functions from Ruby.
Browse files Browse the repository at this point in the history
  • Loading branch information
ppawel committed Sep 20, 2012
1 parent 34a3d16 commit 9328ce0
Show file tree
Hide file tree
Showing 6 changed files with 136 additions and 67 deletions.
4 changes: 2 additions & 2 deletions sql/osmonitor_data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ INSERT INTO osmonitor_config_options (option_key, geom_value) VALUES ('boundary_
INSERT INTO osmonitor_config_options (option_key, geom_value) VALUES ('boundary_CR', ST_PolygonFromText('POLYGON((14.700280 48.581379,14.656387 48.607498,14.652498 48.609444,14.615000 48.628052,14.608889 48.628883,14.505554 48.628326,14.446388 48.618889,14.390276 48.592499,14.278332 48.582497,14.184166 48.596107,14.052500 48.664162,14.052500 48.668327,14.051388 48.671944,14.049166 48.674721,14.007221 48.710274,13.990000 48.717773,13.883610 48.763611,13.858055 48.770554,13.833611 48.773605,13.832499 48.774994,13.815554 48.778328,13.812222 48.780830,13.812777 48.785271,13.815832 48.792770,13.815554 48.796944,13.813889 48.800278,13.802776 48.810829,13.785831 48.830826,13.779444 48.835831,13.769444 48.838608,13.765554 48.840828,13.763054 48.843605,13.761389 48.846939,13.756666 48.852493,13.753332 48.859161,13.745832 48.867775,13.742498 48.874443,13.740833 48.881660,13.736666 48.883888,13.731943 48.883606,13.724443 48.879440,13.719444 48.878326,13.707777 48.880272,13.691111 48.878326,13.677776 48.884163,13.666666 48.894722,13.661943 48.896385,13.655554 48.901108,13.649166 48.906105,13.641109 48.914162,13.625555 48.939163,13.624998 48.947495,13.627499 48.950554,13.626389 48.953331,13.605276 48.950829,13.599722 48.951942,13.593332 48.956940,13.591110 48.959717,13.587776 48.966385,13.580555 48.970833,13.564826 48.973667,13.509722 48.972496,13.402542 49.006187,13.396944 49.048050,13.395277 49.050278,13.322777 49.098328,13.314165 49.103333,13.173054 49.167221,13.031111 49.287773,12.966665 49.331940,12.957222 49.336388,12.945555 49.339439,12.890833 49.346939,12.886110 49.346939,12.884165 49.345276,12.884165 49.342216,12.885277 49.339722,12.893055 49.331108,12.891109 49.328888,12.887777 49.327774,12.883333 49.327499,12.878611 49.328049,12.803610 49.337776,12.795555 49.339722,12.786110 49.344162,12.674444 49.424995,12.597776 49.527496,12.578609 49.560555,12.554722 49.616661,12.524443 49.665550,12.515554 49.679443,12.513054 49.681389,12.508888 49.682495,12.476110 49.690826,12.455555 49.695549,12.467499 49.782219,12.469444 49.784721,12.546944 49.897499,12.547222 49.907219,12.545555 49.915550,12.544167 49.918053,12.492777 49.974998,12.490000 49.976662,12.471109 49.985832,12.429443 49.993889,12.307499 50.047493,12.265554 50.066109,12.206142 50.106209,12.192499 50.131660,12.193888 50.138054,12.196388 50.143883,12.209166 50.160553,12.209721 50.163887,12.208611 50.169441,12.123333 50.307495,12.120832 50.309441,12.093704 50.322533,12.177221 50.318054,12.180277 50.316383,12.195833 50.305832,12.278055 50.221664,12.284166 50.215271,12.323055 50.206665,12.325554 50.236107,12.398611 50.309166,12.486111 50.373055,12.512220 50.391106,12.518610 50.393883,12.618610 50.411942,12.623333 50.411942,12.671389 50.411942,12.734722 50.428329,12.746111 50.434715,12.768332 50.444160,12.776110 50.445831,12.818888 50.454437,12.831388 50.451660,12.855833 50.442215,12.896944 50.426109,12.899721 50.424438,12.917221 50.414719,12.938889 50.408882,12.950554 50.411110,12.985558 50.418327,12.991943 50.421104,13.011665 50.436386,13.018888 50.442215,13.079443 50.498055,13.183332 50.501938,13.191111 50.503609,13.203333 50.516937,13.208887 50.523888,13.222776 50.544167,13.223888 50.546944,13.223888 50.550278,13.222221 50.555550,13.222221 50.558609,13.224165 50.564720,13.248055 50.588333,13.251110 50.589996,13.378332 50.629440,13.413332 50.612221,13.416388 50.610550,13.436666 50.605270,13.458611 50.600555,13.463888 50.600273,13.472500 50.605270,13.518332 50.637772,13.520277 50.639999,13.519722 50.642776,13.515554 50.646942,13.510832 50.650551,13.541111 50.689720,13.582222 50.709442,13.634722 50.722221,13.669443 50.725830,13.734165 50.730827,13.891109 50.768883,13.902777 50.786942,13.904444 50.789444,13.986666 50.813606,13.994720 50.815277,14.155554 50.843048,14.311388 50.882217,14.368332 50.934998,14.322777 50.945274,14.319721 50.946938,14.256109 50.987778,14.254999 50.990273,14.255554 50.993050,14.265554 51.009438,14.285555 51.037498,14.302776 51.051384,14.309721 51.053604,14.491665 51.036659,14.569166 51.005554,14.597221 50.982498,14.628332 50.923607,14.631388 50.881104,14.618055 50.859993,14.619165 50.857498,14.621666 50.855553,14.651667 50.847221,14.717777 50.829163,14.739721 50.823883,14.766666 50.818329,14.776388 50.818329,14.801666 50.818886,14.804165 50.820549,14.824999 50.856384,14.828333 50.865829,14.966665 50.859161,15.001665 50.866386,15.005278 50.867218,15.006943 50.869995,15.019165 50.950554,15.020555 50.964722,15.020555 50.967773,15.013887 50.979721,15.010555 50.984161,15.176943 51.014717,15.239443 50.991943,15.275276 50.974998,15.295277 50.954163,15.294167 50.948608,15.276943 50.938889,15.272778 50.934441,15.271944 50.931107,15.270832 50.921387,15.274443 50.911110,15.282221 50.893326,15.283333 50.890831,15.303610 50.864166,15.310555 50.858330,15.328888 50.854721,15.355555 50.846107,15.361944 50.843330,15.364166 50.841385,15.369720 50.831665,15.379720 50.779442,15.488333 50.786659,15.606667 50.772774,15.787498 50.744164,15.946943 50.689438,16.024441 50.629997,16.071388 50.635551,16.118053 50.657799,16.137497 50.656105,16.237499 50.670555,16.325554 50.665550,16.334999 50.663887,16.341942 50.661110,16.369999 50.644165,16.429165 50.602493,16.431389 50.600555,16.444443 50.585548,16.447777 50.581108,16.449165 50.575829,16.448055 50.572777,16.406666 50.523048,16.368332 50.498604,16.361111 50.496384,16.351944 50.496384,16.346664 50.496941,16.338333 50.499161,16.319164 50.505272,16.310833 50.504166,16.213886 50.449715,16.209164 50.445549,16.203888 50.437775,16.202774 50.431389,16.203331 50.428604,16.205830 50.423882,16.217499 50.411110,16.220554 50.409439,16.266109 50.389717,16.303055 50.378052,16.371944 50.361107,16.441387 50.316666,16.458611 50.303604,16.546108 50.229164,16.549999 50.224998,16.559166 50.214165,16.565277 50.202217,16.566387 50.178055,16.563610 50.164719,16.567497 50.160553,16.587776 50.139999,16.614441 50.119720,16.638054 50.109444,16.641941 50.108330,16.703888 50.098328,16.713886 50.097496,16.718330 50.097771,16.725277 50.099716,16.786663 50.140549,16.802935 50.169651,16.806942 50.174995,16.815552 50.183884,16.843887 50.200272,16.849998 50.203331,16.909164 50.222221,16.913609 50.222496,16.968609 50.222771,17.002220 50.216942,16.972775 50.309998,16.937496 50.340553,16.869442 50.405273,16.867496 50.410553,16.868053 50.413055,16.869999 50.415833,16.887497 50.437492,16.890274 50.439438,16.898609 50.440277,16.910831 50.440132,16.941387 50.434998,17.057777 50.410553,17.118053 50.396660,17.201942 50.363884,17.208611 50.358055,17.226944 50.345276,17.283607 50.320274,17.378330 50.279442,17.433052 50.270271,17.619999 50.265549,17.633610 50.265549,17.656666 50.269997,17.665554 50.274719,17.692219 50.296661,17.694443 50.298882,17.695000 50.307777,17.693886 50.316383,17.694164 50.319443,17.696110 50.321938,17.703888 50.323326,17.722775 50.319717,17.726109 50.318329,17.753052 50.297775,17.762775 50.234718,17.763054 50.231941,17.764164 50.211662,17.763885 50.208611,17.762497 50.205551,17.698887 50.179993,17.691666 50.178055,17.651943 50.171944,17.633610 50.171944,17.623333 50.172775,17.614719 50.172493,17.607498 50.170555,17.600555 50.164162,17.598610 50.161659,17.597775 50.158333,17.600830 50.153885,17.607220 50.147774,17.657776 50.108055,17.836388 49.990829,17.843887 49.988327,17.867222 49.981110,17.882774 49.976944,17.887775 49.976662,17.913609 49.976387,17.922497 49.976944,17.933052 49.979721,18.009441 50.011108,18.053162 50.055931,18.094166 50.038055,18.270275 49.957771,18.350277 49.938889,18.549721 49.922493,18.553608 49.923050,18.557777 49.921661,18.577221 49.914444,18.579441 49.912498,18.581108 49.907494,18.579350 49.814995,18.634163 49.737778,18.786942 49.681938,18.809998 49.674438,18.811665 49.672218,18.839443 49.594994,18.847775 49.554161,18.852219 49.527771,18.851246 49.517357,18.792774 49.513885,18.655552 49.504166,18.581108 49.497772,18.568886 49.496109,18.562222 49.493889,18.551388 49.486938,18.548332 49.481667,18.547775 49.478333,18.548332 49.463608,18.546108 49.457497,18.541111 49.453331,18.386944 49.335831,18.379444 49.330276,18.317776 49.307495,18.307220 49.303886,18.281387 49.301941,18.269997 49.299995,18.216389 49.289162,18.212776 49.288055,18.208054 49.284164,18.179722 49.249443,18.175831 49.244438,18.174721 49.241661,18.174164 49.210274,18.161942 49.174164,18.158886 49.165276,18.155830 49.159721,18.145277 49.145000,18.150833 49.129997,18.151386 49.124443,18.147778 49.115555,18.121944 49.082771,18.075279 49.041943,17.911110 48.984993,17.841942 48.928329,17.763054 48.879715,17.757500 48.876663,17.712219 48.856110,17.677498 48.851944,17.654999 48.851944,17.645554 48.851944,17.502777 48.838882,17.418610 48.826660,17.403889 48.822777,17.390274 48.822777,17.385830 48.823326,17.376389 48.827499,17.330830 48.850273,17.252777 48.870827,17.239998 48.872772,17.230274 48.873055,17.187908 48.869446,17.113888 48.833054,17.110554 48.830551,17.044167 48.771385,17.038887 48.765274,17.022499 48.743607,16.988331 48.681664,16.946182 48.619064,16.919998 48.700272,16.918610 48.703331,16.913055 48.708885,16.899719 48.722221,16.885277 48.729439,16.875832 48.727219,16.871944 48.724998,16.863052 48.722221,16.838608 48.716660,16.827221 48.715828,16.788330 48.719162,16.782776 48.720551,16.711666 48.746384,16.667221 48.781387,16.655830 48.787773,16.644997 48.790550,16.543610 48.811943,16.537498 48.812775,16.461941 48.813332,16.457497 48.811943,16.451664 48.806389,16.430832 48.782219,16.417774 48.756943,16.413055 48.750549,16.403332 48.743050,16.395275 48.739441,16.386387 48.736382,16.376389 48.734444,16.370552 48.733887,16.333054 48.733055,16.103333 48.750000,16.081108 48.754715,16.060555 48.760277,16.021664 48.777222,15.964167 48.804718,15.849432 48.859703,15.746387 48.858604,15.688610 48.863327,15.683332 48.864716,15.584999 48.899162,15.564439 48.909164,15.546665 48.912216,15.519165 48.918327,15.509722 48.921661,15.451666 48.951111,15.392500 48.973610,15.364721 48.983604,15.353333 48.985832,15.301388 48.987778,15.156666 48.999718,15.065554 49.014717,15.031387 49.018608,15.025833 49.018883,15.011389 49.015274,14.996944 49.007500,14.981110 48.984718,14.978054 48.977219,14.978054 48.973053,14.984999 48.939163,14.958887 48.794716,14.885555 48.782776,14.849443 48.786385,14.836388 48.787498,14.830276 48.787498,14.815832 48.783882,14.812498 48.781387,14.730276 48.698608,14.726110 48.691940,14.722221 48.684715,14.714722 48.660553,14.715832 48.652771,14.721388 48.643326,14.720276 48.605827,14.718611 48.602219,14.706665 48.586662,14.704166 48.583611,14.700280 48.581379))', 4326));

-- Timestamp of last OSM_Preprocess() invocation.
INSERT INTO osmonitor_config_options (option_key, date_value) VALUES ('last_preprocessing', NULL);
INSERT INTO osmonitor_config_options (option_key, date_value) VALUES ('last_preprocessing', '1990-01-01');

-- Data timestamp during last OSM_Preprocess() invocation.
INSERT INTO osmonitor_config_options (option_key, date_value) VALUES ('last_preprocessing_data_timestamp', NULL);
INSERT INTO osmonitor_config_options (option_key, date_value) VALUES ('last_preprocessing_data_timestamp', '1990-01-01');
27 changes: 23 additions & 4 deletions sql/osmonitor_ddl.sql
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,33 @@ CREATE TABLE osmonitor_roads (
id text PRIMARY KEY,
data_timestamp timestamp without time zone,
report_timestamp timestamp without time zone,
country character varying(5),
ref character varying(20),
status bytea,
UNIQUE (country, ref)
country character varying(5) NOT NULL,
ref character varying(20) NOT NULL,
report_color character varying(20),
needs_refresh boolean NOT NULL DEFAULT true,
status bytea
);

ALTER TABLE osmonitor_road_data ADD CONSTRAINT fk_osmonitor_road_data_road_id FOREIGN KEY (road_id) REFERENCES osmonitor_roads (id)
ON UPDATE CASCADE ON DELETE CASCADE;

ALTER TABLE osmonitor_road_relations ADD CONSTRAINT fk_osmonitor_road_relations_road_id FOREIGN KEY (road_id) REFERENCES osmonitor_roads (id)
ON UPDATE CASCADE ON DELETE CASCADE;

DROP TABLE IF EXISTS osmonitor_actions;
CREATE TABLE osmonitor_actions (
data_type character(1) NOT NULL,
action character(1) NOT NULL,
id bigint NOT NULL
);

-- Create customisable hook function that is called within the replication update transaction.
DROP FUNCTION IF EXISTS osmosisUpdate();
CREATE FUNCTION osmosisUpdate() RETURNS void AS $$
DECLARE
BEGIN
-- Simply transfer actions to our own table so we don't disturb any replication transactions.
-- Also our own processing allows for getting some logging output while osmosisUpdate output is logged nowhere.
INSERT INTO osmonitor_actions SELECT * FROM actions;
END;
$$ LANGUAGE plpgsql;
Loading

0 comments on commit 9328ce0

Please sign in to comment.