From fc1b17b7a5f76372f010bf2025c869f13f503515 Mon Sep 17 00:00:00 2001 From: simon Date: Fri, 21 Jul 2017 12:18:42 +0100 Subject: [PATCH] #41 Updated ERD; added and tested migrations. --- .../entity-relationship-diagram.svg | 475 ++++++++++-------- .../20170721084900-dwellings.down.sql | 69 +++ .../20170721084900-dwellings.up.sql | 87 ++++ 3 files changed, 434 insertions(+), 197 deletions(-) create mode 100644 resources/migrations/20170721084900-dwellings.down.sql create mode 100644 resources/migrations/20170721084900-dwellings.up.sql diff --git a/doc/specification/entity-relationship-diagram.svg b/doc/specification/entity-relationship-diagram.svg index 0de6cf0..b20898a 100644 --- a/doc/specification/entity-relationship-diagram.svg +++ b/doc/specification/entity-relationship-diagram.svg @@ -25,16 +25,16 @@ borderopacity="1.0" inkscape:pageopacity="0.0" inkscape:pageshadow="2" - inkscape:zoom="1.979899" - inkscape:cx="833.70674" - inkscape:cy="324.89697" + inkscape:zoom="0.98994949" + inkscape:cx="455.50968" + inkscape:cy="346.1212" inkscape:document-units="px" inkscape:current-layer="layer1" showgrid="true" inkscape:window-width="1920" - inkscape:window-height="1058" - inkscape:window-x="1920" - inkscape:window-y="0" + inkscape:window-height="1031" + inkscape:window-x="0" + inkscape:window-y="27" inkscape:window-maximized="1"> + x="8.484766" + y="312.36221" + sodipodi:insensitive="true" /> + y="354.3468" /> YouYesYet: Entity Relationship Diagram + + + District + - District - Addresss + sodipodi:role="line">Dwelling + y="672.276" /> Elector Canvasser + y="553.07794" /> Authority + y="553.07794" /> Visit Intention @@ -236,26 +241,26 @@ width="100" height="60" x="732.33264" - y="775.31158" /> + y="794.50446" /> IssueExpertise Issue FollowupRequest @@ -303,27 +308,27 @@ width="100" height="60" x="220.18532" - y="896.52985" /> + y="915.72272" /> FollowupAction + transform="translate(170.18532,48.487322)"> + transform="translate(682.33266,290.92393)"> + id="g4369" + transform="translate(0,19.192898)"> @@ -402,7 +408,7 @@ + transform="translate(170.18532,48.487322)"> + id="g4402" + transform="translate(-168.69547,-222.23356)"> @@ -442,7 +449,7 @@ + transform="translate(169.17517,171.72593)"> + transform="translate(-170.71578,139.40105)"> @@ -604,146 +611,146 @@ xml:space="preserve" style="font-style:italic;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:20px;line-height:125%;font-family:'URW Chancery L';-inkscape-font-specification:'URW Chancery L Bold Italic';letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" x="472.0152" - y="394.48404" + y="413.67694" id="text4361" sodipodi:linespacing="125%">Version: 0.2Version: 0.3Date: 20170315Date: 20170401Author: Simon BrookeCopyright: (c) 2016 Simon Brooke for Radical Independence Campaign Introduced Visited Recorded + y="651.55505" + style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:10px;line-height:125%;font-family:Arial;-inkscape-font-specification:'Arial, Normal';text-align:start;writing-mode:lr-tb;text-anchor:start">Recorded Raised + x="49.187798" + y="391.35205" + style="font-style:italic;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:10px;line-height:125%;font-family:Arial;-inkscape-font-specification:'Arial, Bold Italic';text-align:start;writing-mode:lr-tb;text-anchor:start">Raised Authenticates + y="641.55505" + style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:10px;line-height:125%;font-family:Arial;-inkscape-font-specification:'Arial, Normal';text-align:start;writing-mode:lr-tb;text-anchor:start">Authenticates Has + y="761.55505" + style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:10px;line-height:125%;font-family:Arial;-inkscape-font-specification:'Arial, Normal';text-align:start;writing-mode:lr-tb;text-anchor:start">Has About + y="881.55505" + style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:10px;line-height:125%;font-family:Arial;-inkscape-font-specification:'Arial, Normal';text-align:start;writing-mode:lr-tb;text-anchor:start">About About @@ -751,89 +758,94 @@ xml:space="preserve" style="font-style:italic;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:20px;line-height:125%;font-family:'URW Chancery L';-inkscape-font-specification:'URW Chancery L Bold Italic';letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" x="280" - y="872.36218" + y="891.55505" id="text4417" sodipodi:linespacing="125%">Responded to + y="891.55505" + style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:10px;line-height:125%;font-family:Arial;-inkscape-font-specification:'Arial, Normal';text-align:start;writing-mode:lr-tb;text-anchor:start">Responded to Expressed + x="161.30452" + y="480.12863" + style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:10px;line-height:125%;font-family:Arial;-inkscape-font-specification:'Arial, Normal';text-align:start;writing-mode:lr-tb;text-anchor:start">Contains Contains + y="531.55505" + style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:10px;line-height:125%;font-family:Arial;-inkscape-font-specification:'Arial, Normal';text-align:start;writing-mode:lr-tb;text-anchor:start">Contains Resides at + y="651.55505" + style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:10px;line-height:125%;font-family:Arial;-inkscape-font-specification:'Arial, Normal';text-align:start;writing-mode:lr-tb;text-anchor:start">Resides at Requested + y="761.55505" + style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:10px;line-height:125%;font-family:Arial;-inkscape-font-specification:'Arial, Normal';text-align:start;writing-mode:lr-tb;text-anchor:start">Requested Performed + y="1021.5551" + style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:10px;line-height:125%;font-family:Arial;-inkscape-font-specification:'Arial, Normal';text-align:start;writing-mode:lr-tb;text-anchor:start">Performed To + y="571.55505" + style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:10px;line-height:125%;font-family:Arial;-inkscape-font-specification:'Arial, Normal';text-align:start;writing-mode:lr-tb;text-anchor:start">To + y="672.276" /> Team + y="792.48413" /> + y="581.55505" /> Organiser-ship TeamTeamMembership Has @@ -978,41 +990,41 @@ xml:space="preserve" style="font-style:italic;font-variant:normal;font-weight:bold;font-stretch:normal;font-size:20px;line-height:125%;font-family:'URW Chancery L';-inkscape-font-specification:'URW Chancery L Bold Italic';letter-spacing:0px;word-spacing:0px;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" x="879.90356" - y="621.14386" + y="640.33673" id="text4344" sodipodi:linespacing="125%">Has of of + transform="matrix(1,0,0,-1,171.72593,1625.9208)"> @@ -1037,13 +1049,13 @@ xml:space="preserve" style="font-style:normal;font-variant:normal;font-weight:normal;font-stretch:normal;font-size:15px;line-height:125%;font-family:Arial;-inkscape-font-specification:'Arial, Normal';text-align:start;letter-spacing:0px;word-spacing:0px;writing-mode:lr-tb;text-anchor:start;fill:#000000;fill-opacity:1;stroke:none;stroke-width:1px;stroke-linecap:butt;stroke-linejoin:miter;stroke-opacity:1" x="450" - y="742.36218" + y="761.55505" id="text4386" sodipodi:linespacing="125%">For + y="672.276" /> RoleRoleMembership + transform="translate(0,-222.73864)"> Role + id="g4338" + transform="translate(0,19.192898)"> Is Includes + transform="translate(341.43156,-222.73861)"> @@ -1159,5 +1172,73 @@ inkscape:connector-curvature="0" /> + + + FollowupMethod + + + + + + + Address diff --git a/resources/migrations/20170721084900-dwellings.down.sql b/resources/migrations/20170721084900-dwellings.down.sql new file mode 100644 index 0000000..674fb1b --- /dev/null +++ b/resources/migrations/20170721084900-dwellings.down.sql @@ -0,0 +1,69 @@ +-------------------------------------------------------------------------------- +---- +---- 20170721084900.up.sql: add dwellings table, to deal with flatted addresses. +---- +---- This program is free software; you can redistribute it and/or +---- modify it under the terms of the GNU General Public License +---- as published by the Free Software Foundation; either version 2 +---- of the License, or (at your option) any later version. +---- +---- This program is distributed in the hope that it will be useful, +---- but WITHOUT ANY WARRANTY; without even the implied warranty of +---- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +---- GNU General Public License for more details. +---- +---- You should have received a copy of the GNU General Public License +---- along with this program; if not, write to the Free Software +---- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +---- USA. +---- +---- Copyright (C) 2017 Simon Brooke for Radical Independence Campaign +---- +-------------------------------------------------------------------------------- +---- +---- NOTE +---- This file is essentially a Postgres schema dump of a database schema which was +---- created with the function initdb! in the file src/clj/youyesyet/db/schema.clj. +---- This file has then been mildly massaged to work with Migratus. +---- Either this file or src/clj/youyesyet/db/schema.clj is redundant; schema.clj +---- represents the older, Korma, way of doing things but does not readily allow +---- for migrations; this file represents the newer Migratus/HugSQL way. I'm not +---- certain which of these paths I'm going to go down. +---- +-------------------------------------------------------------------------------- + +alter table canvassers add column address_id integer references addresses(id); +--;; +alter table electors add column address_id integer references addresses(id); +--;; +alter table visits add column address_id integer references addresses(id); +--;; + +update canvassers set address_id = + (select address_id from dwellings where id = canvassers.dwelling_id); +--;; + +update electors set address_id = + (select address_id from dwellings where id = electors.dwelling_id); +--;; + +update visits set address_id = + (select address_id from dwellings where id = visits.dwelling_id); +--;; + +alter table canvassers alter column address_id set not null; +--;; +alter table electors alter column address_id set not null; +--;; +alter table visits alter column address_id set not null; +--;; + +alter table canvassers drop column dwelling_id; +--;; +alter table electors drop column dwelling_id; +--;; +alter table visits drop column dwelling_id; +--;; + +drop table if exists dwellings; +--;; diff --git a/resources/migrations/20170721084900-dwellings.up.sql b/resources/migrations/20170721084900-dwellings.up.sql new file mode 100644 index 0000000..da4a125 --- /dev/null +++ b/resources/migrations/20170721084900-dwellings.up.sql @@ -0,0 +1,87 @@ +-------------------------------------------------------------------------------- +---- +---- 20170721084900.up.sql: add dwellings table, to deal with flatted addresses. +---- +---- This program is free software; you can redistribute it and/or +---- modify it under the terms of the GNU General Public License +---- as published by the Free Software Foundation; either version 2 +---- of the License, or (at your option) any later version. +---- +---- This program is distributed in the hope that it will be useful, +---- but WITHOUT ANY WARRANTY; without even the implied warranty of +---- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +---- GNU General Public License for more details. +---- +---- You should have received a copy of the GNU General Public License +---- along with this program; if not, write to the Free Software +---- Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, +---- USA. +---- +---- Copyright (C) 2017 Simon Brooke for Radical Independence Campaign +---- +-------------------------------------------------------------------------------- +---- +---- NOTE +---- This file is essentially a Postgres schema dump of a database schema which was +---- created with the function initdb! in the file src/clj/youyesyet/db/schema.clj. +---- This file has then been mildly massaged to work with Migratus. +---- Either this file or src/clj/youyesyet/db/schema.clj is redundant; schema.clj +---- represents the older, Korma, way of doing things but does not readily allow +---- for migrations; this file represents the newer Migratus/HugSQL way. I'm not +---- certain which of these paths I'm going to go down. +---- +-------------------------------------------------------------------------------- + +CREATE TABLE IF NOT EXISTS dwellings ( + id serial NOT NULL primary key, + address_id integer NOT NULL, + sub_address varchar(16) +); +--;; + +ALTER TABLE public.dwellings OWNER TO youyesyet; +--;; + +INSERT INTO dwellings (address_id, sub_address) + SELECT DISTINCT id, '' FROM addresses; +--;; + +alter table canvassers add column dwelling_id integer references dwellings(id); +--;; +alter table electors add column dwelling_id integer references dwellings(id); +--;; +alter table visits add column dwelling_id integer references dwellings(id); +--;; + +update canvassers set dwelling_id = + (select id from dwellings where address_id = canvassers.address_id); +--;; + +update electors set dwelling_id = + (select id from dwellings where address_id = electors.address_id); +--;; + +update visits set dwelling_id = + (select id from dwellings where address_id = visits.address_id); +--;; + +alter table canvassers alter column dwelling_id set not null; +--;; +alter table electors alter column dwelling_id set not null; +--;; +alter table visits alter column dwelling_id set not null; +--;; + +alter table canvassers drop constraint canvassers_address_id_fkey; +--;; +alter table electors drop constraint electors_address_id_fkey; +--;; +alter table visits drop constraint visits_address_id_fkey; +--;; + +alter table canvassers drop column address_id; +--;; +alter table electors drop column address_id; +--;; +alter table visits drop column address_id; +--;;