colouring-montreal/migrations
2022-07-22 16:21:14 +01:00
..
unreleased Rename migrations to released 2021-10-11 14:20:58 +02: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.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 remove changed to 015 migration not needed 2022-05-05 15:10:05 +01: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 Fix typo in a comment 2022-02-16 14:22:50 +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
021.building-user-attributes.down.sql Rename migrations to released 2021-10-11 14:20:58 +02:00
021.building-user-attributes.up.sql Rename migrations to released 2021-10-11 14:20:58 +02:00
022.community.down.sql Rename migrations to released 2021-10-11 14:20:58 +02:00
022.community.up.sql fix typo 2022-07-04 08:40:59 +02:00
023.garden_buildings.down.sql Note that downgrades will fail of such data is present 2022-02-14 13:36:19 +01:00
023.garden_buildings.up.sql Add ability to mark constructions as garden buildings 2022-01-11 17:51:07 +01:00
024.unclassified_buildings.down.sql Modify already commited migration 2022-02-14 13:36:19 +01:00
024.unclassified_buildings.up.sql Note that downgrades will fail of such data is present 2022-02-14 13:36:19 +01:00
025.state_to_government.down.sql Replace State-owned by Government-owned 2022-02-16 16:08:29 +01:00
025.state_to_government.up.sql Replace State-owned by Government-owned 2022-02-16 16:08:29 +01:00
026.community_use.down.sql Final resolve of duplication 2022-02-23 09:51:01 +01:00
026.community_use.up.sql Final resolve of duplication 2022-02-23 09:51:01 +01:00
027.demolish-date.down.sql ADD MIGRATION 2022-04-14 10:50:20 +01:00
027.demolish-date.up.sql ADD MIGRATION 2022-04-14 10:50:20 +01:00
028.landuse-source.down.sql update buildings table to have current_landuse_verified bool 2022-05-05 12:00:08 +01:00
028.landuse-source.up.sql limit current_landuse_verified to the correct attribute 2022-05-05 15:45:20 +01:00
029.team.down.sql add developer_name 2nd attempt 2022-06-10 13:38:54 +01:00
029.team.up.sql add developer_name 2nd attempt 2022-06-10 13:38:54 +01:00
030.planning_expected.down.sql Allow community to mark expected applications 2022-07-04 11:40:14 +02:00
030.planning_expected.up.sql Allow community to mark expected applications 2022-07-04 11:40:14 +02:00
031.landowner.down.sql add landowner db migration 2022-07-22 16:21:14 +01:00
031.landowner.up.sql add landowner db migration 2022-07-22 16:21:14 +01: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