#47, #48, #49, #50: Auto-generated admin system largely done

This work is closely coupled with work on [ADL](https://github.com/simon-brooke/adl), q.v. At present ADL largely supports this project.
This commit is contained in:
Simon Brooke 2018-06-10 22:31:12 +01:00
parent 79bf3ed7eb
commit a00da8079c
28 changed files with 4018 additions and 47 deletions

View file

@ -1,11 +1,11 @@
-- File queries.sql
-- autogenerated by adl.to-hugsql-queries at
-- 2018-05-26T15:03:25.295Z
-- 2018-06-05T12:33:53.043Z
-- See [Application Description Language](https://github.com/simon-brooke/adl).
-- :name create-address! :! :n
-- :name create-address! :! :n
-- :doc creates a new address record
INSERT INTO addresses (address,
postcode,
@ -21,13 +21,13 @@ VALUES (:address,
:longitude)
returning id
-- :name create-authority! :! :n
-- :name create-authority! :! :n
-- :doc creates a new authority record
INSERT INTO authorities (id)
VALUES (:id)
returning id
-- :name create-canvasser! :! :n
-- :name create-canvasser! :! :n
-- :doc creates a new canvasser record
INSERT INTO canvassers (username,
fullname,
@ -36,7 +36,8 @@ INSERT INTO canvassers (username,
phone,
email,
authority_id,
authorised)
authorised,
roles)
VALUES (:username,
:fullname,
:elector_id,
@ -44,16 +45,17 @@ VALUES (:username,
:phone,
:email,
:authority_id,
:authorised)
:authorised,
:roles)
returning id
-- :name create-district! :! :n
-- :name create-district! :! :n
-- :doc creates a new district record
INSERT INTO districts (name)
VALUES (:name)
returning id
-- :name create-dwelling! :! :n
-- :name create-dwelling! :! :n
-- :doc creates a new dwelling record
INSERT INTO dwellings (address_id,
sub-address)
@ -61,7 +63,7 @@ VALUES (:address_id,
:sub-address)
returning id
-- :name create-elector! :! :n
-- :name create-elector! :! :n
-- :doc creates a new elector record
INSERT INTO electors (name,
dwelling_id,
@ -75,7 +77,7 @@ VALUES (:name,
:gender)
returning id
-- :name create-followupaction! :! :n
-- :name create-followupaction! :! :n
-- :doc creates a new followupaction record
INSERT INTO followupactions (request_id,
actor,
@ -89,13 +91,13 @@ VALUES (:request_id,
:closed)
returning id
-- :name create-followupmethod! :! :n
-- :name create-followupmethod! :! :n
-- :doc creates a new followupmethod record
INSERT INTO followupmethods (id)
VALUES (:id)
returning id
-- :name create-followuprequest! :! :n
-- :name create-followuprequest! :! :n
-- :doc creates a new followuprequest record
INSERT INTO followuprequests (elector_id,
visit_id,
@ -107,13 +109,13 @@ VALUES (:elector_id,
:method_id)
returning id
-- :name create-gender! :! :n
-- :name create-gender! :! :n
-- :doc creates a new gender record
INSERT INTO genders (id)
VALUES (:id)
returning id
-- :name create-intention! :! :n
-- :name create-intention! :! :n
-- :doc creates a new intention record
INSERT INTO intentions (visit_id,
elector_id,
@ -123,7 +125,7 @@ VALUES (:visit_id,
:option_id)
returning Id
-- :name create-issue! :! :n
-- :name create-issue! :! :n
-- :doc creates a new issue record
INSERT INTO issues (url,
current,
@ -133,8 +135,8 @@ VALUES (:url,
:id)
returning id
-- :name create-issueexpertis! :! :n
-- :doc creates a new issueexpertis record
-- :name create-issueexpertise! :! :n
-- :doc creates a new issueexpertise record
INSERT INTO issueexpertise (canvasser_id,
issue_id,
method_id)
@ -143,19 +145,19 @@ VALUES (:canvasser_id,
:method_id)
returning Id
-- :name create-option! :! :n
-- :name create-option! :! :n
-- :doc creates a new option record
INSERT INTO options (id)
VALUES (:id)
returning id
-- :name create-role! :! :n
-- :name create-role! :! :n
-- :doc creates a new role record
INSERT INTO roles (name)
VALUES (:name)
returning id
-- :name create-rolemembership! :! :n
-- :name create-rolemembership! :! :n
-- :doc creates a new rolemembership record
INSERT INTO rolememberships (role_id,
canvasser_id)
@ -163,7 +165,7 @@ VALUES (:role_id,
:canvasser_id)
returning Id
-- :name create-team! :! :n
-- :name create-team! :! :n
-- :doc creates a new team record
INSERT INTO teams (name,
district_id,
@ -175,7 +177,7 @@ VALUES (:name,
:longitude)
returning id
-- :name create-teammembership! :! :n
-- :name create-teammembership! :! :n
-- :doc creates a new teammembership record
INSERT INTO teammemberships (team_id,
canvasser_id)
@ -183,7 +185,7 @@ VALUES (:team_id,
:canvasser_id)
returning Id
-- :name create-teamorganisership! :! :n
-- :name create-teamorganisership! :! :n
-- :doc creates a new teamorganisership record
INSERT INTO teamorganiserships (team_id,
canvasser_id)
@ -191,7 +193,7 @@ VALUES (:team_id,
:canvasser_id)
returning Id
-- :name create-visit! :! :n
-- :name create-visit! :! :n
-- :doc creates a new visit record
INSERT INTO visits (address_id,
canvasser_id,
@ -261,8 +263,8 @@ WHERE intentions.Id = :Id
DELETE FROM issues
WHERE issues.id = :id
-- :name delete-issueexpertis! :! :n
-- :doc updates an existing issueexpertis record
-- :name delete-issueexpertise! :! :n
-- :doc updates an existing issueexpertise record
DELETE FROM issueexpertise
WHERE issueexpertise.Id = :Id
@ -323,6 +325,15 @@ ORDER BY canvassers.username,
canvassers.email,
canvassers.id
-- :name get-canvasser-by-username :? :1
-- :doc selects an existing canvasser record
SELECT * FROM canvassers
WHERE canvassers.username = :username
ORDER BY canvassers.username,
canvassers.fullname,
canvassers.email,
canvassers.id
-- :name get-district :? :1
-- :doc selects an existing district record
SELECT * FROM districts
@ -374,8 +385,8 @@ WHERE intentions.Id = :Id
SELECT * FROM issues
WHERE issues.id = :id
-- :name get-issueexpertis :? :1
-- :doc selects an existing issueexpertis record
-- :name get-issueexpertise :? :1
-- :doc selects an existing issueexpertise record
SELECT * FROM issueexpertise
WHERE issueexpertise.Id = :Id
@ -482,6 +493,16 @@ ORDER BY canvassers.username,
canvassers.email,
canvassers.id
-- :name list-canvassers-by-role :? :*
-- :doc lists all existing canvasser records related to a given role
SELECT *
FROM canvassers
WHERE canvassers.roles = :id
ORDER BY canvassers.username,
canvassers.fullname,
canvassers.email,
canvassers.id
-- :name list-districts :? :*
-- :doc lists all existing district records
SELECT * FROM districts
@ -496,8 +517,8 @@ SELECT * FROM dwellings
--~ (if (:offset params) "OFFSET :offset ")
--~ (if (:limit params) "LIMIT :limit" "LIMIT 100")
-- :name list-dwellings-by-addres :? :*
-- :doc lists all existing dwelling records related to a given addres
-- :name list-dwellings-by-address :? :*
-- :doc lists all existing dwelling records related to a given address
SELECT *
FROM dwellings
WHERE dwellings.address_id = :id
@ -617,25 +638,25 @@ FROM intentions
WHERE intentions.visit_id = :id
-- :name list-issueexpertise :? :*
-- :doc lists all existing issueexpertis records
-- :doc lists all existing issueexpertise records
SELECT * FROM issueexpertise
--~ (if (:offset params) "OFFSET :offset ")
--~ (if (:limit params) "LIMIT :limit" "LIMIT 100")
-- :name list-issueexpertise-by-canvasser :? :*
-- :doc lists all existing issueexpertis records related to a given canvasser
-- :doc lists all existing issueexpertise records related to a given canvasser
SELECT *
FROM issueexpertise
WHERE issueexpertise.canvasser_id = :id
-- :name list-issueexpertise-by-followupmethod :? :*
-- :doc lists all existing issueexpertis records related to a given followupmethod
-- :doc lists all existing issueexpertise records related to a given followupmethod
SELECT *
FROM issueexpertise
WHERE issueexpertise.method_id = :id
-- :name list-issueexpertise-by-issue :? :*
-- :doc lists all existing issueexpertis records related to a given issue
-- :doc lists all existing issueexpertise records related to a given issue
SELECT *
FROM issueexpertise
WHERE issueexpertise.issue_id = :id
@ -760,6 +781,14 @@ ORDER BY addresses.address,
--~ (if (:offset params) "OFFSET :offset ")
--~ (if (:limit params) "LIMIT :limit" "LIMIT 100")
-- :name search-strings-authority :? :1
-- :doc selects existing authority records having any string field matching `:pattern` by substring match
SELECT * FROM authorities
WHERE
id LIKE '%:pattern%'
--~ (if (:offset params) "OFFSET :offset ")
--~ (if (:limit params) "LIMIT :limit" "LIMIT 100")
-- :name search-strings-canvasser :? :1
-- :doc selects existing canvasser records having any string field matching `:pattern` by substring match
SELECT * FROM canvassers
@ -807,11 +836,65 @@ ORDER BY electors.name,
--~ (if (:offset params) "OFFSET :offset ")
--~ (if (:limit params) "LIMIT :limit" "LIMIT 100")
-- :name search-strings-followupaction :? :1
-- :doc selects existing followupaction records having any string field matching `:pattern` by substring match
SELECT * FROM followupactions
WHERE
notes LIKE '%:pattern%'
--~ (if (:offset params) "OFFSET :offset ")
--~ (if (:limit params) "LIMIT :limit" "LIMIT 100")
-- :name search-strings-followupmethod :? :1
-- :doc selects existing followupmethod records having any string field matching `:pattern` by substring match
SELECT * FROM followupmethods
WHERE
id LIKE '%:pattern%'
--~ (if (:offset params) "OFFSET :offset ")
--~ (if (:limit params) "LIMIT :limit" "LIMIT 100")
-- :name search-strings-followuprequest :? :1
-- :doc selects existing followuprequest records having any string field matching `:pattern` by substring match
SELECT * FROM followuprequests
WHERE
--~ (if (:offset params) "OFFSET :offset ")
--~ (if (:limit params) "LIMIT :limit" "LIMIT 100")
-- :name search-strings-gender :? :1
-- :doc selects existing gender records having any string field matching `:pattern` by substring match
SELECT * FROM genders
WHERE
id LIKE '%:pattern%'
--~ (if (:offset params) "OFFSET :offset ")
--~ (if (:limit params) "LIMIT :limit" "LIMIT 100")
-- :name search-strings-intention :? :1
-- :doc selects existing intention records having any string field matching `:pattern` by substring match
SELECT * FROM intentions
WHERE
--~ (if (:offset params) "OFFSET :offset ")
--~ (if (:limit params) "LIMIT :limit" "LIMIT 100")
-- :name search-strings-issue :? :1
-- :doc selects existing issue records having any string field matching `:pattern` by substring match
SELECT * FROM issues
WHERE
url LIKE '%:pattern%'
OR id LIKE '%:pattern%'
--~ (if (:offset params) "OFFSET :offset ")
--~ (if (:limit params) "LIMIT :limit" "LIMIT 100")
-- :name search-strings-issueexpertise :? :1
-- :doc selects existing issueexpertise records having any string field matching `:pattern` by substring match
SELECT * FROM issueexpertise
WHERE
--~ (if (:offset params) "OFFSET :offset ")
--~ (if (:limit params) "LIMIT :limit" "LIMIT 100")
-- :name search-strings-option :? :1
-- :doc selects existing option records having any string field matching `:pattern` by substring match
SELECT * FROM options
WHERE
id LIKE '%:pattern%'
--~ (if (:offset params) "OFFSET :offset ")
--~ (if (:limit params) "LIMIT :limit" "LIMIT 100")
@ -825,6 +908,13 @@ ORDER BY roles.name,
--~ (if (:offset params) "OFFSET :offset ")
--~ (if (:limit params) "LIMIT :limit" "LIMIT 100")
-- :name search-strings-rolemembership :? :1
-- :doc selects existing rolemembership records having any string field matching `:pattern` by substring match
SELECT * FROM rolememberships
WHERE
--~ (if (:offset params) "OFFSET :offset ")
--~ (if (:limit params) "LIMIT :limit" "LIMIT 100")
-- :name search-strings-team :? :1
-- :doc selects existing team records having any string field matching `:pattern` by substring match
SELECT * FROM teams
@ -834,3 +924,159 @@ ORDER BY teams.name,
teams.id
--~ (if (:offset params) "OFFSET :offset ")
--~ (if (:limit params) "LIMIT :limit" "LIMIT 100")
-- :name search-strings-teammembership :? :1
-- :doc selects existing teammembership records having any string field matching `:pattern` by substring match
SELECT * FROM teammemberships
WHERE
--~ (if (:offset params) "OFFSET :offset ")
--~ (if (:limit params) "LIMIT :limit" "LIMIT 100")
-- :name search-strings-teamorganisership :? :1
-- :doc selects existing teamorganisership records having any string field matching `:pattern` by substring match
SELECT * FROM teamorganiserships
WHERE
--~ (if (:offset params) "OFFSET :offset ")
--~ (if (:limit params) "LIMIT :limit" "LIMIT 100")
-- :name search-strings-visit :? :1
-- :doc selects existing visit records having any string field matching `:pattern` by substring match
SELECT * FROM visits
WHERE
--~ (if (:offset params) "OFFSET :offset ")
--~ (if (:limit params) "LIMIT :limit" "LIMIT 100")
-- :name update-address! :! :n
-- :doc updates an existing address record
UPDATE addresses
SET address = :address,
postcode = :postcode,
phone = :phone,
district_id = :district_id,
latitude = :latitude,
longitude = :longitude
WHERE addresses.id = :id
-- :name update-canvasser! :! :n
-- :doc updates an existing canvasser record
UPDATE canvassers
SET username = :username,
fullname = :fullname,
elector_id = :elector_id,
address_id = :address_id,
phone = :phone,
email = :email,
authority_id = :authority_id,
authorised = :authorised,
roles = :roles
WHERE canvassers.id = :id
-- :name update-district! :! :n
-- :doc updates an existing district record
UPDATE districts
SET name = :name
WHERE districts.id = :id
-- :name update-dwelling! :! :n
-- :doc updates an existing dwelling record
UPDATE dwellings
SET address_id = :address_id,
sub-address = :sub-address
WHERE dwellings.id = :id
-- :name update-elector! :! :n
-- :doc updates an existing elector record
UPDATE electors
SET name = :name,
dwelling_id = :dwelling_id,
phone = :phone,
email = :email,
gender = :gender
WHERE electors.id = :id
-- :name update-followupaction! :! :n
-- :doc updates an existing followupaction record
UPDATE followupactions
SET request_id = :request_id,
actor = :actor,
date = :date,
notes = :notes,
closed = :closed
WHERE followupactions.id = :id
-- :name update-followuprequest! :! :n
-- :doc updates an existing followuprequest record
UPDATE followuprequests
SET elector_id = :elector_id,
visit_id = :visit_id,
issue_id = :issue_id,
method_id = :method_id
WHERE followuprequests.id = :id
-- :name update-intention! :! :n
-- :doc updates an existing intention record
UPDATE intentions
SET visit_id = :visit_id,
elector_id = :elector_id,
option_id = :option_id
WHERE intentions.Id = :Id
-- :name update-issue! :! :n
-- :doc updates an existing issue record
UPDATE issues
SET url = :url,
current = :current,
id = :id
WHERE issues.id = :id
-- :name update-issueexpertise! :! :n
-- :doc updates an existing issueexpertise record
UPDATE issueexpertise
SET canvasser_id = :canvasser_id,
issue_id = :issue_id,
method_id = :method_id
WHERE issueexpertise.Id = :Id
-- :name update-role! :! :n
-- :doc updates an existing role record
UPDATE roles
SET name = :name
WHERE roles.id = :id
-- :name update-rolemembership! :! :n
-- :doc updates an existing rolemembership record
UPDATE rolememberships
SET role_id = :role_id,
canvasser_id = :canvasser_id
WHERE rolememberships.Id = :Id
-- :name update-team! :! :n
-- :doc updates an existing team record
UPDATE teams
SET name = :name,
district_id = :district_id,
latitude = :latitude,
longitude = :longitude
WHERE teams.id = :id
-- :name update-teammembership! :! :n
-- :doc updates an existing teammembership record
UPDATE teammemberships
SET team_id = :team_id,
canvasser_id = :canvasser_id
WHERE teammemberships.Id = :Id
-- :name update-teamorganisership! :! :n
-- :doc updates an existing teamorganisership record
UPDATE teamorganiserships
SET team_id = :team_id,
canvasser_id = :canvasser_id
WHERE teamorganiserships.Id = :Id
-- :name update-visit! :! :n
-- :doc updates an existing visit record
UPDATE visits
SET address_id = :address_id,
canvasser_id = :canvasser_id,
date = :date
WHERE visits.id = :id