Added basic setup migration.

This commit is contained in:
simon 2016-10-14 17:37:29 +01:00
parent bd9c6eccb5
commit c5900149af
5 changed files with 674 additions and 6 deletions

View file

@ -30,6 +30,7 @@
[mount "0.1.10"]
[cprop "0.1.9"]
[org.clojure/tools.cli "0.3.5"]
[migratus "0.8.31"]
[luminus-nrepl "0.1.4"]
[luminus-migrations "0.2.7"]
[conman "0.6.1"]

View file

@ -0,0 +1 @@
DROP TABLE users;

View file

@ -0,0 +1,665 @@
--------------------------------------------------------------------------------
----
---- 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 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 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 canvassers (
id 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,
authorised boolean
);
--;;
ALTER TABLE public.canvassers OWNER TO youyesyet;
--;;
--
-- Name: districts; Type: TABLE; Schema: public; Owner: youyesyet; Tablespace:
--
CREATE TABLE 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 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 followupactions (
id integer NOT NULL,
request_id integer NOT NULL,
actor character varying(32) 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 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 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 issueexpertise (
canvasser_id character varying(32) 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 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 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 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 visits (
id integer NOT NULL,
address_id integer NOT NULL,
canvasser_id character varying(32) 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);
--;;
--
-- 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

@ -3,7 +3,7 @@
<head>
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Welcome to youyesyet</title>
<title>Welcome to YouYesYet</title>
</head>
<body>
@ -11,7 +11,7 @@
<div class="container-fluid">
<div class="card-deck">
<div class="card-block">
<h4>Welcome to youyesyet</h4>
<h4>Welcome to YouYesYet</h4>
<p>If you're seeing this message, that means you haven't yet compiled your ClojureScript!</p>
<p>Please run <code>lein figwheel</code> to start the ClojureScript compiler and reload the page.</p>
<h4>For better ClojureScript development experience in Chrome follow these steps:</h4>

View file

@ -22,7 +22,7 @@
;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
;;;; USA.
;;;;
;;;; Copyright (C) 2016 Simon Brooke
;;;; Copyright (C) 2016 Simon Brooke for Radical Independence Campaign
;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
@ -30,8 +30,9 @@
;;; Note that this is the (old) Korma way of doing things;
;;; it may not play well with migrations, nor with the HugSQL way of doing things recommended
;;; in Web Development with Clojure, Second Ed. So this may be temporary 'get us started' code,
;;; which later gets thrown away.
;;; which later gets thrown away. The 'create-x-table!' functions in this file may be
;;; redundant, and if they are the namespace probably needs to be renamed to 'entities'.
;;; See also resources/migrations/20161014170335-basic-setup.up.sql
(defn create-districts-table!
"Create a table to hold the electoral districts in which electors are registered.