maailma / kansa

Open-source convention member services
Apache License 2.0
17 stars 6 forks source link

Database updates #48

Closed eemeli closed 6 years ago

eemeli commented 6 years ago

As this set of changes modifies the database, this PR serves to document the steps needed to apply this update to any pre-existing instance. The changes are:

To verify that the changes didn't break things and that updating is not too arduous, here are the steps that were required to port the Worldcon 75 data across this update:

  1. Dump the database to a text format with pg_dump -a api > w75-data.sql

  2. Save a SQL file w75-prepare.sql:

    SET ROLE kansa;
    
    ALTER TABLE people RENAME COLUMN hugo_nominator TO can_hugo_nominate;
    ALTER TABLE people RENAME COLUMN hugo_voter TO can_hugo_vote;
    ALTER TABLE people ADD COLUMN can_site_select bool;
    
    DELETE FROM countries; -- Also filled by postgres/init/25-public-data.sql
    DELETE FROM daypass_amounts; -- Also filled by config/database/payments.sql
    DELETE FROM stripe_keys; -- Also filled by config/database/payments.sql
  3. Save a SQL file w75-cleanup.sql:

    SET ROLE kansa;
    
    ALTER TABLE people RENAME COLUMN can_hugo_nominate TO hugo_nominator;
    ALTER TABLE people RENAME COLUMN can_hugo_vote TO hugo_voter;
    ALTER TABLE people DROP COLUMN can_site_select;
  4. Add the following to the Docker Compose config, making sure that in the container the file names are prefixed to get the right order. Note that here we're using the "development" version of config/payments.sql which is in fact the Worldcon 75 payments data; you'll need to modify this file to match your own data:

    services:
      postgres:
        volumes:
          - ../config/database/payments.sql:/docker-entrypoint-initdb.d/90-payments.sql:ro
          - /path/to/w75-prepare.sql:/docker-entrypoint-initdb.d/91-w75-prepare.sql:ro
          - /path/to/w75-data.sql:/docker-entrypoint-initdb.d/92-w75-data.sql:ro
          - /path/to/w75-cleanup.sql:/docker-entrypoint-initdb.d/93-w75-cleanup.sql:ro
  5. Run make prod.