Tactical commit while I try to understand why the app doesn't rebuild

This commit is contained in:
Simon Brooke 2018-07-02 16:22:38 +01:00
parent f5afa67eed
commit 16af040537
45 changed files with 282 additions and 1973 deletions

View file

@ -1,50 +0,0 @@
--------------------------------------------------------------------------------
----
---- 20161014170335-basic-setup.down.sql: database schema for youyesyet.
----
---- 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) 2016 Simon Brooke for Radical Independence Campaign
----
--------------------------------------------------------------------------------
-- intended to reverse out the database changes made in
-- 20161014170335-basic-setup.up.sql
drop table addresses cascade;
--;;
drop table authorities cascade;
--;;
drop table canvassers cascade;
--;;
drop table districts cascade;
--;;
drop table electors cascade;
--;;
drop table followupactions cascade;
--;;
drop table followupmethods cascade;
--;;
drop table followuprequests cascade;
--;;
drop table issueexpertise cascade;
--;;
drop table issues cascade;
--;;
drop table options cascade;
--;;
drop table visits cascade;
--;;

View file

@ -1,669 +0,0 @@
--------------------------------------------------------------------------------
----
---- 20161014170335-basic-setup.up.sql: database schema for youyesyet.
----
---- 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) 2016 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.
----
--------------------------------------------------------------------------------
SET statement_timeout = 0;
--;;
SET lock_timeout = 0;
--;;
SET client_encoding = 'UTF8';
--;;
SET standard_conforming_strings = on;
--;;
SET check_function_bodies = false;
--;;
SET client_min_messages = warning;
--;;
--
-- Name: plpgsql; Type: EXTENSION; Schema: -; Owner:
--
-- CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog;
--;;
--
-- Name: EXTENSION plpgsql; Type: COMMENT; Schema: -; Owner:
--
-- COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language';
--;;
SET search_path = public, pg_catalog;
--;;
SET default_tablespace = '';
--;;
SET default_with_oids = false;
--;;
--
-- Name: addresses; Type: TABLE; Schema: public; Owner: youyesyet; Tablespace:
--
CREATE TABLE IF NOT EXISTS addresses (
id integer NOT NULL,
address character varying(256) NOT NULL,
postcode character varying(16),
phone character varying(16),
district_id integer,
latitude real,
longitude real
);
--;;
ALTER TABLE public.addresses OWNER TO youyesyet;
--;;
--
-- Name: addresses_id_seq; Type: SEQUENCE; Schema: public; Owner: youyesyet
--
CREATE SEQUENCE addresses_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--;;
ALTER TABLE public.addresses_id_seq OWNER TO youyesyet;
--;;
--
-- Name: addresses_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: youyesyet
--
ALTER SEQUENCE addresses_id_seq OWNED BY addresses.id;
--;;
--
-- Name: authorities; Type: TABLE; Schema: public; Owner: youyesyet; Tablespace:
--
CREATE TABLE IF NOT EXISTS authorities (
id character varying(32) NOT NULL
);
--;;
ALTER TABLE public.authorities OWNER TO youyesyet;
--;;
--
-- Name: canvassers; Type: TABLE; Schema: public; Owner: youyesyet; Tablespace:
--
CREATE TABLE IF NOT EXISTS canvassers (
id serial,
username character varying(32) NOT NULL,
fullname character varying(64) NOT NULL,
elector_id integer,
address_id integer NOT NULL,
phone character varying(16),
email character varying(128),
authority_id character varying(32) NOT NULL,
introduced_by int references canvassers(id),
authorised boolean
);
--;;
ALTER TABLE public.canvassers OWNER TO youyesyet;
--;;
--
-- Name: districts; Type: TABLE; Schema: public; Owner: youyesyet; Tablespace:
--
CREATE TABLE IF NOT EXISTS districts (
id integer NOT NULL,
name character varying(64) NOT NULL
);
--;;
ALTER TABLE public.districts OWNER TO youyesyet;
--;;
--
-- Name: electors; Type: TABLE; Schema: public; Owner: youyesyet; Tablespace:
--
CREATE TABLE IF NOT EXISTS electors (
id integer NOT NULL,
name character varying(64) NOT NULL,
address_id integer NOT NULL,
phone character varying(16),
email character varying(128)
);
--;;
ALTER TABLE public.electors OWNER TO youyesyet;
--;;
--
-- Name: followupactions; Type: TABLE; Schema: public; Owner: youyesyet; Tablespace:
--
CREATE TABLE IF NOT EXISTS followupactions (
id integer NOT NULL,
request_id integer NOT NULL,
actor integer NOT NULL,
date timestamp with time zone DEFAULT now() NOT NULL,
notes text,
closed boolean
);
--;;
ALTER TABLE public.followupactions OWNER TO youyesyet;
--
-- Name: followupactions_id_seq; Type: SEQUENCE; Schema: public; Owner: youyesyet
--
CREATE SEQUENCE followupactions_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--;;
ALTER TABLE public.followupactions_id_seq OWNER TO youyesyet;
--;;
--
-- Name: followupactions_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: youyesyet
--
ALTER SEQUENCE followupactions_id_seq OWNED BY followupactions.id;
--;;
--
-- Name: followupmethods; Type: TABLE; Schema: public; Owner: youyesyet; Tablespace:
--
CREATE TABLE IF NOT EXISTS followupmethods (
id character varying(32) NOT NULL
);
--;;
ALTER TABLE public.followupmethods OWNER TO youyesyet;
--;;
--
-- Name: followuprequests; Type: TABLE; Schema: public; Owner: youyesyet; Tablespace:
--
insert into followupmethods values ('Telephone');
--;;
insert into followupmethods values ('eMail');
--;;
insert into followupmethods values ('Post');
--;;
CREATE TABLE IF NOT EXISTS followuprequests (
id integer NOT NULL,
elector_id integer NOT NULL,
visit_id integer NOT NULL,
issue_id character varying(32) NOT NULL,
method_id character varying(32) NOT NULL
);
--;;
ALTER TABLE public.followuprequests OWNER TO youyesyet;
--;;
--
-- Name: followuprequests_id_seq; Type: SEQUENCE; Schema: public; Owner: youyesyet
--
CREATE SEQUENCE followuprequests_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--;;
ALTER TABLE public.followuprequests_id_seq OWNER TO youyesyet;
--;;
--
-- Name: followuprequests_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: youyesyet
--
ALTER SEQUENCE followuprequests_id_seq OWNED BY followuprequests.id;
--;;
--
-- Name: issueexpertise; Type: TABLE; Schema: public; Owner: youyesyet; Tablespace:
--
CREATE TABLE IF NOT EXISTS issueexpertise (
canvasser_id integer NOT NULL,
issue_id character varying(32) NOT NULL,
method_id character varying(32) NOT NULL
);
--;;
ALTER TABLE public.issueexpertise OWNER TO youyesyet;
--;;
--
-- Name: issues; Type: TABLE; Schema: public; Owner: youyesyet; Tablespace:
--
CREATE TABLE IF NOT EXISTS issues (
id character varying(32) NOT NULL,
url character varying(256)
);
--;;
ALTER TABLE public.issues OWNER TO youyesyet;
--;;
--
-- Name: options; Type: TABLE; Schema: public; Owner: youyesyet; Tablespace:
--
CREATE TABLE IF NOT EXISTS options (
id character varying(32) NOT NULL
);
--;;
ALTER TABLE public.options OWNER TO youyesyet;
--;;
--
-- Name: schema_migrations; Type: TABLE; Schema: public; Owner: youyesyet; Tablespace:
--
CREATE TABLE IF NOT EXISTS schema_migrations (
id bigint NOT NULL
);
--;;
ALTER TABLE public.schema_migrations OWNER TO youyesyet;
--;;
--
-- Name: visits; Type: TABLE; Schema: public; Owner: youyesyet; Tablespace:
--
CREATE TABLE IF NOT EXISTS visits (
id integer NOT NULL,
address_id integer NOT NULL,
canvasser_id integer NOT NULL,
date timestamp with time zone DEFAULT now() NOT NULL
);
--;;
ALTER TABLE public.visits OWNER TO youyesyet;
--;;
--
-- Name: visits_id_seq; Type: SEQUENCE; Schema: public; Owner: youyesyet
--
CREATE SEQUENCE visits_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
--;;
ALTER TABLE public.visits_id_seq OWNER TO youyesyet;
--;;
--
-- Name: visits_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: youyesyet
--
ALTER SEQUENCE visits_id_seq OWNED BY visits.id;
--;;
--
-- Name: id; Type: DEFAULT; Schema: public; Owner: youyesyet
--
ALTER TABLE ONLY addresses ALTER COLUMN id SET DEFAULT nextval('addresses_id_seq'::regclass);
--;;
--
-- Name: id; Type: DEFAULT; Schema: public; Owner: youyesyet
--
ALTER TABLE ONLY followupactions ALTER COLUMN id SET DEFAULT nextval('followupactions_id_seq'::regclass);
--;;
--
-- Name: id; Type: DEFAULT; Schema: public; Owner: youyesyet
--
ALTER TABLE ONLY followuprequests ALTER COLUMN id SET DEFAULT nextval('followuprequests_id_seq'::regclass);
--;;
--
-- Name: id; Type: DEFAULT; Schema: public; Owner: youyesyet
--
ALTER TABLE ONLY visits ALTER COLUMN id SET DEFAULT nextval('visits_id_seq'::regclass);
--;;
--
-- Name: addresses_address_key; Type: CONSTRAINT; Schema: public; Owner: youyesyet; Tablespace:
--
ALTER TABLE ONLY addresses
ADD CONSTRAINT addresses_address_key UNIQUE (address);
--;;
--
-- Name: addresses_pkey; Type: CONSTRAINT; Schema: public; Owner: youyesyet; Tablespace:
--
ALTER TABLE ONLY addresses
ADD CONSTRAINT addresses_pkey PRIMARY KEY (id);
--;;
--
-- Name: authorities_pkey; Type: CONSTRAINT; Schema: public; Owner: youyesyet; Tablespace:
--
ALTER TABLE ONLY authorities
ADD CONSTRAINT authorities_pkey PRIMARY KEY (id);
--;;
--
-- Name: canvassers_pkey; Type: CONSTRAINT; Schema: public; Owner: youyesyet; Tablespace:
--
ALTER TABLE ONLY canvassers
ADD CONSTRAINT canvassers_pkey PRIMARY KEY (id);
--;;
--
-- Name: districts_pkey; Type: CONSTRAINT; Schema: public; Owner: youyesyet; Tablespace:
--
ALTER TABLE ONLY districts
ADD CONSTRAINT districts_pkey PRIMARY KEY (id);
--;;
--
-- Name: electors_pkey; Type: CONSTRAINT; Schema: public; Owner: youyesyet; Tablespace:
--
ALTER TABLE ONLY electors
ADD CONSTRAINT electors_pkey PRIMARY KEY (id);
--;;
--
-- Name: followupactions_pkey; Type: CONSTRAINT; Schema: public; Owner: youyesyet; Tablespace:
--
ALTER TABLE ONLY followupactions
ADD CONSTRAINT followupactions_pkey PRIMARY KEY (id);
--;;
--
-- Name: followupmethods_pkey; Type: CONSTRAINT; Schema: public; Owner: youyesyet; Tablespace:
--
ALTER TABLE ONLY followupmethods
ADD CONSTRAINT followupmethods_pkey PRIMARY KEY (id);
--;;
--
-- Name: followuprequests_pkey; Type: CONSTRAINT; Schema: public; Owner: youyesyet; Tablespace:
--
ALTER TABLE ONLY followuprequests
ADD CONSTRAINT followuprequests_pkey PRIMARY KEY (id);
--;;
--
-- Name: issues_pkey; Type: CONSTRAINT; Schema: public; Owner: youyesyet; Tablespace:
--
ALTER TABLE ONLY issues
ADD CONSTRAINT issues_pkey PRIMARY KEY (id);
--;;
--
-- Name: options_pkey; Type: CONSTRAINT; Schema: public; Owner: youyesyet; Tablespace:
--
ALTER TABLE ONLY options
ADD CONSTRAINT options_pkey PRIMARY KEY (id);
--;;
--
-- Name: schema_migrations_id_key; Type: CONSTRAINT; Schema: public; Owner: youyesyet; Tablespace:
--
--ALTER TABLE ONLY schema_migrations
-- ADD CONSTRAINT schema_migrations_id_key UNIQUE (id);
--;;
--
-- Name: visits_pkey; Type: CONSTRAINT; Schema: public; Owner: youyesyet; Tablespace:
--
ALTER TABLE ONLY visits
ADD CONSTRAINT visits_pkey PRIMARY KEY (id);
--;;
--
-- Name: addresses_district_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: youyesyet
--
ALTER TABLE ONLY addresses
ADD CONSTRAINT addresses_district_id_fkey FOREIGN KEY (district_id) REFERENCES districts(id);
--;;
--
-- Name: canvassers_address_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: youyesyet
--
ALTER TABLE ONLY canvassers
ADD CONSTRAINT canvassers_address_id_fkey FOREIGN KEY (address_id) REFERENCES addresses(id);
--;;
--
-- Name: canvassers_authority_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: youyesyet
--
ALTER TABLE ONLY canvassers
ADD CONSTRAINT canvassers_authority_id_fkey FOREIGN KEY (authority_id) REFERENCES authorities(id);
--;;
--
-- Name: canvassers_elector_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: youyesyet
--
ALTER TABLE ONLY canvassers
ADD CONSTRAINT canvassers_elector_id_fkey FOREIGN KEY (elector_id) REFERENCES electors(id);
--;;
create unique index canvassers_username_ix on canvassers (username);
create unique index canvassers_email_ix on canvassers(email);
--
-- Name: electors_address_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: youyesyet
--
ALTER TABLE ONLY electors
ADD CONSTRAINT electors_address_id_fkey FOREIGN KEY (address_id) REFERENCES addresses(id);
--;;
--
-- Name: followupactions_actor_fkey; Type: FK CONSTRAINT; Schema: public; Owner: youyesyet
--
ALTER TABLE ONLY followupactions
ADD CONSTRAINT followupactions_actor_fkey FOREIGN KEY (actor) REFERENCES canvassers(id);
--;;
--
-- Name: followupactions_request_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: youyesyet
--
ALTER TABLE ONLY followupactions
ADD CONSTRAINT followupactions_request_id_fkey FOREIGN KEY (request_id) REFERENCES followuprequests(id);
--;;
--
-- Name: followuprequests_elector_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: youyesyet
--
ALTER TABLE ONLY followuprequests
ADD CONSTRAINT followuprequests_elector_id_fkey FOREIGN KEY (elector_id) REFERENCES electors(id);
--;;
--
-- Name: followuprequests_issue_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: youyesyet
--
ALTER TABLE ONLY followuprequests
ADD CONSTRAINT followuprequests_issue_id_fkey FOREIGN KEY (issue_id) REFERENCES issues(id);
--;;
--
-- Name: followuprequests_method_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: youyesyet
--
ALTER TABLE ONLY followuprequests
ADD CONSTRAINT followuprequests_method_id_fkey FOREIGN KEY (method_id) REFERENCES followupmethods(id);
--;;
--
-- Name: followuprequests_visit_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: youyesyet
--
ALTER TABLE ONLY followuprequests
ADD CONSTRAINT followuprequests_visit_id_fkey FOREIGN KEY (visit_id) REFERENCES visits(id);
--;;
--
-- Name: issueexpertise_canvasser_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: youyesyet
--
ALTER TABLE ONLY issueexpertise
ADD CONSTRAINT issueexpertise_canvasser_id_fkey FOREIGN KEY (canvasser_id) REFERENCES canvassers(id);
--;;
--
-- Name: issueexpertise_issue_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: youyesyet
--
ALTER TABLE ONLY issueexpertise
ADD CONSTRAINT issueexpertise_issue_id_fkey FOREIGN KEY (issue_id) REFERENCES issues(id);
--;;
--
-- Name: issueexpertise_method_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: youyesyet
--
ALTER TABLE ONLY issueexpertise
ADD CONSTRAINT issueexpertise_method_id_fkey FOREIGN KEY (method_id) REFERENCES followupmethods(id);
--;;
--
-- Name: visits_address_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: youyesyet
--
ALTER TABLE ONLY visits
ADD CONSTRAINT visits_address_id_fkey FOREIGN KEY (address_id) REFERENCES addresses(id);
--;;
--
-- Name: visits_canvasser_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: youyesyet
--
ALTER TABLE ONLY visits
ADD CONSTRAINT visits_canvasser_id_fkey FOREIGN KEY (canvasser_id) REFERENCES canvassers(id);
--;;
--
-- Name: public; Type: ACL; Schema: -; Owner: postgres
--
REVOKE ALL ON SCHEMA public FROM PUBLIC;
--;;
REVOKE ALL ON SCHEMA public FROM postgres;
--;;
GRANT ALL ON SCHEMA public TO postgres;
--;;
GRANT ALL ON SCHEMA public TO PUBLIC;
--;;
--
-- PostgreSQL database dump complete
--

View file

@ -1,13 +0,0 @@
drop table teammemberships;
drop table teamorganiserships;
drop index ix_teams_name;
drop table teams;
drop table rolememberships;
drop index ix_roles_name;
drop table roles;

View file

@ -1,39 +0,0 @@
create table if not exists roles (
id serial primary key,
name varchar(64) not null
);
create unique index ix_roles_name on roles(name);
create table if not exists rolememberships (
role_id integer not null references roles(id),
canvasser_id integer not null references canvassers(id)
);
create table if not exists teams (
id serial primary key,
name varchar(64) not null,
district_id integer not null references districts(id),
latitude real,
longitude real
);
create unique index ix_teams_name on teams(name);
create table if not exists teammemberships (
team_id integer not null references teams(id),
canvasser_id integer not null references canvassers(id)
);
create table if not exists teamorganiserships (
team_id integer not null references teams(id),
canvasser_id integer not null references canvassers(id)
);
alter table roles owner to youyesyet;
alter table rolememberships owner to youyesyet;
alter table teams owner to youyesyet;
alter table teammemberships owner to youyesyet;

View file

@ -1,17 +0,0 @@
-- this is just a teardown of everything set up in the corresponding .up.sql file
delete from roles where name = 'Expert';
delete from roles where name = 'Administrator';
delete from roles where name = 'Recruiter';
delete from roles where name = 'Organiser';
delete from roles where name = 'Editor';
alter table issues drop column content;
alter table issues drop column current;
delete from issues where id = 'Currency';
delete from issues where id = 'Monarchy';
delete from issues where id = 'Defence';
delete from options where id = 'Yes';
delete from options where id = 'No';

View file

@ -1,58 +0,0 @@
-- We don't explicitly instantiate the 'Canvasser' role since every user is
-- deemed to be a canvasser.
-- an 'Expert' is someone with expertise in one or more issues, who is
-- trusted to discuss those issues in detail with electors.
insert into roles (name) values ('Expert');
-- an 'Administrator' is someone entitled to broadly alter reference data
-- throughout the system.
insert into roles (name) values ('Administrator');
-- a 'Recruiter' is someone entitled to invite other people to become users
-- ('Canvassers'). A Recruiter is entitled to lock the account of anyone they
-- have recruited, recursively.
insert into roles (name) values ('Recruiter');
-- an 'Organiser' is someone who organises one or more local teams. An Organiser
-- is entitled to exclude any Canvasser from any team they organise.
insert into roles (name) values ('Organiser');
-- an 'Editor' is someone entitled to add and edit issues.
insert into roles (name) values ('Editor');
-- issue text is local; there may still in addition be a further link to more
-- information, but the basic issue text should be part of the issue record.
-- The text should fit on a phone screen without scrolling, so is reasonably
-- short.
alter table issues add column content varchar(1024);
-- an issue may be current or not current; when not current it is not deleted
-- from the system but kept because it may become current again later. Only
-- current issues are shown in the app. Typically not fewer than three and not
-- more than about seven issues should be current at any time.
alter table issues add column current boolean default false;
insert into issues (id, content, current) values ('Currency',
'Scotland could keep the Pound, or use the Euro. But we could also set up a new currency of our own.',
true);
insert into issues (id, content, current) values ('Monarchy',
'Scotland could keep the Queen. This is an issue to be decided after independence.',
true);
insert into issues (id, content, current) values ('Defence',
'Scotland will not have nuclear weapons, and will probably not choose to engage in far-off wars. But we could remain members of NATO.',
true);
insert into options (id) values ('Yes');
insert into options (id) values ('No');

View file

@ -1,11 +0,0 @@
drop view if exists roles_by_canvasser;
drop view if exists teams_by_canvasser;
drop view if exists canvassers_by_team;
drop view if exists canvassers_by_introducer;
drop view if exists teams_by_organiser;
drop view if exists organisers_by_team;

View file

@ -1,59 +0,0 @@
create view roles_by_canvasser as
select canvassers.id as canvasser, roles.name
from roles, rolememberships, canvassers
where roles.id = rolememberships.role_id
and canvassers.id = rolememberships.canvasser_id
and canvassers.authorised = true;
create view teams_by_canvasser as
select canvassers.id as canvasser, teams.id, teams.name, teams.latitude, teams.longitude
from teams, teammemberships, canvassers
where teams.id = teammemberships.team_id
and canvassers.id = teammemberships.canvasser_id;
create view canvassers_by_team as
select teams.id as team,
canvassers.id,
canvassers.username,
canvassers.fullname,
canvassers.email,
canvassers.phone
from teams, teammemberships, canvassers
where teams.id = teammemberships.team_id
and canvassers.id = teammemberships.canvasser_id
and canvassers.authorised = true;
create view canvassers_by_introducer as
select introducers.id as introducer,
canvassers.id as canvasser,
canvassers.username,
canvassers.fullname,
canvassers.email,
canvassers.phone,
canvassers.authorised
from canvassers, canvassers as introducers
where introducers.id = canvassers.introduced_by;
create view teams_by_organiser as
select canvassers.id as organiser,
teams.id,
teams.name,
teams.latitude,
teams.longitude
from teams, teamorganiserships, canvassers
where teams.id = teamorganiserships.team_id
and canvassers.id = teamorganiserships.canvasser_id
and canvassers.authorised = true;
create view organisers_by_team as
select teams.id as team,
canvassers.id,
canvassers.username,
canvassers.fullname,
canvassers.email,
canvassers.phone
from teams, teamorganiserships, canvassers
where teams.id = teamorganiserships.team_id
and canvassers.id = teamorganiserships.canvasser_id
and canvassers.authorised = true;

View file

@ -1,69 +0,0 @@
--------------------------------------------------------------------------------
----
---- 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;
--;;

View file

@ -1,87 +0,0 @@
--------------------------------------------------------------------------------
----
---- 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 references addresses(id),
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;
--;;

View file

@ -1,24 +0,0 @@
--------------------------------------------------------------------------------
----
---- 20180316110100intentions-and-options.down.sql: remove intentions and options
----
---- 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) 2016 Simon Brooke for Radical Independence Campaign
----
--------------------------------------------------------------------------------
drop table intentions;

View file

@ -1,30 +0,0 @@
--------------------------------------------------------------------------------
----
---- 20180316110100intentions-and-options.up.sql: add intentions and options
----
---- 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) 2016 Simon Brooke for Radical Independence Campaign
----
--------------------------------------------------------------------------------
CREATE TABLE IF NOT EXISTS intentions (
visit_id int not null references visits(id) on delete no action,
elector_id int not null references electors(id) on delete no action,
option_id varchar(32) not null references options(id) on delete no action
);
ALTER TABLE intentions owner to youyesyet;

View file

@ -1,3 +0,0 @@
alter table electors drop column gender;
drop table genders;

View file

@ -1,11 +0,0 @@
create table genders (
id varchar(32) not null primary key
);
-- genders is reference data
insert into genders values ('Female');
insert into genders values ('Male');
insert into genders values ('Non-binary');
insert into genders values ('Unknown');
alter table electors add column gender varchar(32) references genders(id) default 'Unknown';

View file

@ -1,10 +0,0 @@
delete from options where id = 'Yes';
delete from options where id = 'No';
delete from issues where id = 'Currency';
delete from issues where id = 'Monarchy';
delete from issues where id = 'Defence';

View file

@ -1,18 +0,0 @@
insert into options values ('Yes');
insert into options values ('No');
insert into issues (id, url) values ('Currency', 'https://www.yyy.scot/wiki/issues/Currency');
insert into issues (id, url) values ('Monarchy', 'https://www.yyy.scot/wiki/issues/Monarchy');
insert into issues (id, url) values ('Defence', 'https://www.yyy.scot/wiki/issues/Defence');
insert into genders (id ) values ('Female');
insert into genders (id ) values ('Male');
insert into genders (id ) values ('Non-binary');
insert into genders (id ) values ('Unknown');

View file

@ -1,3 +0,0 @@
delete from addresses where id < = 4;
delete from electors where id <= 10;

View file

@ -1,41 +0,0 @@
insert into addresses (id, address, postcode, latitude, longitude)
values (1, '13 Imaginary Terrace, IM1 3TE', 'IM1 3TE', 55.8253043, -4.2569057);
insert into addresses (id, address, postcode, latitude, longitude)
values (2, '15 Imaginary Terrace, IM1 3TE', 'IM1 3TE', 55.8252354, -4.2572778);
insert into addresses (id, address, postcode, latitude, longitude)
values (3, '17 Imaginary Terrace, IM1 3TE', 'IM1 3TE', 55.825166, -4.257026);
insert into addresses (id, address, postcode, latitude, longitude)
values (4, '19 Imaginary Terrace, IM1 3TE', 'IM1 3TE', 55.8250695, -4.2570239);
insert into electors (id, name, address_id, gender)
values (1, 'Alan Anderson', 1, 'Male');
insert into electors (id, name, address_id, gender)
values (2, 'Ann Anderson', 1, 'Female');
insert into electors (id, name, address_id, gender)
values (3, 'Alex Anderson', 1, 'Non-binary');
insert into electors (id, name, address_id)
values (4, 'Andy Anderson', 1);
insert into electors (id, name, address_id, gender)
values (5, 'Beryl Brown', 2, 'Female');
insert into electors (id, name, address_id, gender)
values (6, 'Betty Black', 2, 'Female');
insert into electors (id, name, address_id, gender)
values (7, 'Catriona Crathie', 3, 'Female');
insert into electors (id, name, address_id, gender)
values (8, 'Colin Caruthers', 3, 'Male');
insert into electors (id, name, address_id, gender)
values (9, 'Calum Crathie', 3, 'Unknown');
insert into electors (id, name, address_id, gender)
values (10, 'David Dewar', 4, 'Male');

View file

@ -1 +0,0 @@
alter table issues drop column current;

View file

@ -1,2 +0,0 @@
alter table issues add column current boolean default true;

View file

@ -1,8 +0,0 @@
alter table electors
add column address_id references addresses on delete no action;
update electors
set address_id =
(select address_id
from dwellings
where dwellings.id electors.dwelling_id);

View file

@ -1,11 +0,0 @@
CREATE TABLE dwellings
(
id INT NOT NULL PRIMARY KEY,
address_id INT NOT NULL references addresses on delete no action,
sub_address VARCHAR( 32)
);
alter table electors
add column dwelling_id int references dwellings on delete no action;
alter table electors drop column address_id;

View file

@ -1,15 +0,0 @@
-- enough data to get the system working and real logins
insert into addresses (address, postcode, latitude, longitude)
values ('West Croft, Standingstone, Auchencairn', 'DG7 1RF', 54.822389, -3.920265);
insert into dwellings (id, address_id, sub_address)
values (5, 5, '');
insert into electors (name, dwelling_id, gender)
values ('Simon Brooke', 1, 'Male');
insert into authorities (id) values ('GitHub');
insert into canvassers (username, fullname, elector_id, address_id, authority_id, authorised)
values ('simon_brooke', 'Simon Brooke', 2, 2, 'GitHub', true);

View file

@ -23,13 +23,22 @@
</p>
</div>
{% endblock %}
{% block extra-script %}
var user = {
"username": "{{user.username}}",
"fullname": "{{user.fullname}}",
"id": {{user.id|default:-1}},
"authorised": {{user.authorised|default:false}}
};
{% endblock %}
{% block extra-tail %}
<!-- scripts and styles -->
<!-- ATTENTION \/ -->
<!-- ATTENTION /\ -->
<!-- Leaflet -->
<link rel="stylesheet" href="js/lib/leaflet/dist/leaflet.css" />
{% script "js/lib/leaflet/dist/leaflet.js" %}
{% script "js/lib/node_modules/signature_pad/dist/signature_pad.min.js" %}
{% script "js/lib/node_modules/leaflet/dist/leaflet.js" %}
{% script "/js/app.js" %}
{% endblock %}

View file

@ -10,7 +10,6 @@
<link rel="stylesheet" type="text/css" href="css/spinner.css" />
<link href="https://fonts.googleapis.com/css?family=Archivo+Black|Archivo+Narrow" rel="stylesheet"/>
<title>{{site-title}}: {{title}}</title>
{% script "js/lib/jquery/dist/jquery.min.js" %}
{% endblock %}
{% block extra-head %}
<!-- extra-head: put any additional markup to go into the head of your document into this block -->
@ -76,10 +75,6 @@
</footer>
{% endblock %}
{% endblock %}
{% block extra-tail %}
<!-- extra-tail: put markup here which needs to be at the very end of the body -->
<!-- e.g. some javascript script tags, some link tags -->
{% endblock %}
<script type="text/javascript">
var context = "{{servlet-context}}";
var csrfToken = "{{csrf-token}}";
@ -87,6 +82,10 @@
/* extra-script: put any actual javascript source text you need into this block */
{% endblock %}
</script>
{% block extra-tail %}
<!-- extra-tail: put markup here which needs to be at the very end of the body -->
<!-- e.g. some javascript script tags, some link tags -->
{% endblock %}
</body>
</html>

View file

@ -1,60 +0,0 @@
{% extends "base.html" %}
{% block title %}
{% endblock %}
{% block content %}
<form action="edit-canvasser" method="post">
{% if canvasser %}
<input type="hidden" name="id" id="id" value="{{canvasser.id}}"/>
{% endif %}
<p class="widget">
<label for="fullname">Full name</label>
<input type="text" name="fullname" id="fullname" value="{{canvasser.fullname}}"/>
</p>
<p class="widget">
(TODO: Not absolutely sure what I'm going to do for an elector id widget yet.)
</p>
<p class="widget">
<label for="address">Address</label>
{% if address.id %}
<!-- if we already have an address, just show it with a link to edit it -->
<span class="pseudo-widget" id="address">
{{address.address}}
</span>
{% else %}
(TODO: Some sort of address lookup widget goes here.)
{% endif %}
</p>
<p class="widget">
<label for="phone">Phone number</label>
<input type="tel" name="phone" id="phone" value="{{canvasser.phone}}"/>
</p>
<p class="widget">
<label for="email">Email address</label>
<input type="email" name="email" id="email" value="{{canvasser.email}}"/>
</p>
<p class="widget">
<label for="authority_id">Authorised by</label>
<select name="authority_id" id="authority_id">
{% for authority in authorities %}
<option value="{{authority.id}}"
{% ifequal authority.id canvasser.authority_id %}selected {% endifequal %}>
{{authority.id}}
</option>
</select>
</p>
</p>
id serial,
username character varying(32) NOT NULL,
fullname character varying(64) NOT NULL,
elector_id integer,
address_id integer NOT NULL,
phone character varying(16),
email character varying(128),
authority_id character varying(32) NOT NULL,
introduced_by int references canvassers(id),
authorised boolean
</form>
{% endblock %}