colouring-montreal/migrations
2021-09-27 13:47:27 +03:00
..
unreleased Add community fields about public ownership 2021-09-27 13:47:27 +03:00
001.core.down.sql Make sure to drop base tables (and cascade) 2018-10-21 19:46:14 +00:00
001.core.up.sql Allow requesting user API key 2018-10-20 12:21:11 +01:00
002.index-geometries.down.sql Add index-dropping migrations 2018-09-27 21:38:37 +01:00
002.index-geometries.up.sql Create/drop database elements conditionally 2018-09-29 18:13:34 +01:00
003.index-buildings.down.sql Remove unused index from drop list 2018-09-30 20:31:20 +01:00
003.index-buildings.up.sql Update etl to load UPRNs to table 2018-10-02 21:12:46 +01:00
004.location-date-size-like.down.sql Add location, date, size, likes to database 2018-09-29 18:14:06 +01:00
004.location-date-size-like.up.sql Limit likes to one per-user per-building (db constraint) 2018-12-11 17:17:41 +00:00
005.limit-likes.down.sql Limit likes to one per-user per-building (db constraint) 2018-12-11 17:17:41 +00:00
005.limit-likes.up.sql Drop duplicate likes and reset counts 2019-01-20 14:36:15 +00:00
006.controls.down.sql Add planning controls database fields 2019-01-10 09:08:26 +00:00
006.controls.up.sql Update 006.controls.up.sql 2019-03-23 09:16:51 +00:00
007.date-details.down.sql Add date details migrations 2019-01-19 17:46:51 +00:00
007.date-details.up.sql Add date details migrations 2019-01-19 17:46:51 +00:00
008.search.up.sql Update GIN/GIST index note 2019-02-05 21:15:48 +00:00
009.user-deleted.down.sql Add user delete database migrations 2019-08-16 11:12:18 +01:00
009.user-deleted.up.sql Add user delete database migrations 2019-08-16 11:12:18 +01:00
010.password-reset.down.sql Add password reset token database migrations 2019-08-21 14:20:53 +01:00
010.password-reset.up.sql Add password reset token database migrations 2019-08-21 14:20:53 +01:00
011.sustainability.down1-extra.sql Ready for staging, tested on local for #405 2020-02-27 16:19:52 +00:00
011.sustainability.down.sql Fix/category default values (#451) 2019-10-02 16:47:17 +01:00
011.sustainability.up1-extra.sql Ready for staging, tested on local for #405 2020-02-27 16:19:52 +00:00
011.sustainability.up.sql Fix/category default values (#451) 2019-10-02 16:47:17 +01:00
012.community.down.sql WIP for #432 2019-09-27 16:05:35 +01:00
012.community.up.sql WIP for #432 2019-09-27 16:05:35 +01:00
012.type.down.sql Fix/category default values (#451) 2019-10-02 16:47:17 +01:00
012.type.up.sql Fix/category default values (#451) 2019-10-02 16:47:17 +01:00
013.bulk-extracts.down.sql Reorder bulk extract migration 012->013 2019-10-01 17:11:35 +01:00
013.bulk-extracts.up.sql Reorder bulk extract migration 012->013 2019-10-01 17:11:35 +01:00
014.block-users.down.sql Add user blocking migrations 2019-11-22 18:12:48 +00:00
014.block-users.up.sql Add user blocking migrations 2019-11-22 18:12:48 +00:00
015.bulk_data_sources.down.sql Rename migration files 2019-12-03 18:33:12 +00:00
015.bulk_data_sources.up.sql Rename migration files 2019-12-03 18:33:12 +00:00
016.landuse.down.sql Migrations to enable the original landuse to be added to site 2019-12-13 16:24:39 +00:00
016.landuse.up.sql Rename migration files 2019-12-03 18:33:12 +00:00
017.construction-materials.down.sql Rename construction migration to 017, fix tile definition 2020-04-17 17:01:21 +01:00
017.construction-materials.up.sql Rename construction migration to 017, fix tile definition 2020-04-17 17:01:21 +01:00
018.verification.down.sql Add migrations for user verification of building attributes 2020-08-04 15:53:33 +01:00
018.verification.up.sql Add migrations for user verification of building attributes 2020-08-04 15:53:33 +01:00
019.simple-dynamics.down.sql Add simple dynamics API support 2021-03-11 19:15:58 +00:00
019.simple-dynamics.up.sql Add simple dynamics API support 2021-03-11 19:15:58 +00:00
020.dynamics-bool.down.sql Release dynamics toggle migrations 2021-03-19 15:09:38 +00:00
020.dynamics-bool.up.sql Release dynamics toggle migrations 2021-03-19 15:09:38 +00:00
README.md Add note on building_verification table permissions 2020-08-04 16:52:21 +01:00

Database setup

Initial setup, on first connection (replacing hostname, username, port, dbname as required):

$ psql "host={hostname} user={username} port={port} sslmode=require dbname=postgres"
> create database colouringlondon;
> \c colouringlondon
> create extension postgis;
> create extension pgcrypto;
> create extension pg_trgm;
> \q

To run all up migrations:

$ ls ./*.up.sql 2>/dev/null | while read -r migration; do psql < $migration; done;

Or all down migrations in reverse order:

$ ls -r ./*.down.sql 2>/dev/null | while read -r migration; do psql < $migration; done;

Create an app user:

-- role for server-side of front end (HTTP POST)
CREATE ROLE appusername WITH LOGIN;
-- create/update, authenticate and authorise users
GRANT SELECT, UPDATE, INSERT, DELETE ON TABLE users, user_sessions TO appusername;
-- join users against categories and access levels
GRANT SELECT ON TABLE user_access_levels, user_categories TO appusername;
-- read/write building data
GRANT SELECT, UPDATE ON TABLE buildings TO appusername;
GRANT SELECT, INSERT, DELETE ON TABLE building_user_likes TO appusername;
GRANT SELECT ON TABLE building_properties TO appusername;
-- read geometry data
GRANT SELECT ON TABLE geometries TO appusername;
-- read/append to logs
GRANT SELECT, INSERT ON TABLE logs to appusername;
-- use id sequences
GRANT USAGE ON ALL SEQUENCES IN SCHEMA public to appusername;
-- use postgis/pgcrypto functions
GRANT EXECUTE ON ALL FUNCTIONS IN SCHEMA public TO appusername;
-- read map search locations
GRANT SELECT ON TABLE search_locations to appusername;
-- add/save user building attribute verification
GRANT SELECT, INSERT, DELETE ON TABLE building_verification TO appusername;

Set or update passwords:

psql -c "ALTER USER appusername WITH PASSWORD 'longsecurerandompassword';"

File naming syntax

Initial up and down migrations as ###.name.up.sql file number should be sequential and incremental to last migrations file number is same for up/down.

If adjusting a prior migration syntax is:

###.name.up.sql

Syntax for adding to existing migration:

0##.filename-extension-#.up.sql