Skip to content

Latest commit

 

History

History
114 lines (81 loc) · 4.63 KB

UPGRADE.adoc

File metadata and controls

114 lines (81 loc) · 4.63 KB

Upgrade Guide

This document describes steps necessary to upgrade 21-points.com on Heroku. It contains the lessons learned in upgrading from version 1 to 4, version 4 to 5, and version 5 to 7.

Copy production database locally

  1. To export the production database to a local database, use the pg:pull command:

    heroku pg:pull HEROKU_POSTGRESQL_SILVER_URL health --app health-by-points

    This command will create a local database called health and populate it with the data from the production database.

    Tip
    See Heroku’s import/export docs for PostgreSQL if you need additional information.
  2. Then, log in to the database and run the following commands to fix the data:

    psql health
    \dt;
    reassign owned by mraible to twentyonepoints;
    update databasechangelog set md5sum=null;
    delete from databasechangeloglock;
  3. Download Liquibase and installed it in /opt/tools. I ran the following command to copy the PostgreSQL JDBC driver from my local Maven repo to Liquibase’s classpath.

    cp ~/.m2/repository/org/postgresql/postgresql/42.2.19/postgresql-42.2.19.jar lib/.
  4. Run Liquibase to generate an XML changelog for the differences between the two databases.

    ./liquibase \
      --driver=org.postgresql.Driver --url=jdbc:postgresql://localhost:5432/health \
      --username=postgres diffChangeLog \
      --referenceUrl=jdbc:postgresql://localhost:5432/twentyonepoints \
      --referenceUsername=twentyonepoints --referencePassword=21points \
      --changelog-file=migrate_from_v5.xml
  5. Copy the results to src/main/resources/config/liquibase/changelog and add a reference to it in src/main/resources/config/liquibase/master.xml.

  6. Update application-prod.xml to point to the health database you downloaded from Heroku.

  7. Run ./gradlew bootRun -Pprod, log in, and browse the app. Update Liquibase migration script as necessary.

Migrate from Bansai to Elastic Cloud

On Heroku, the Bonsai Elasticsearch is configured as an add-on. JHipster is automatically configured to talk to it.

Unfortunately, as of JHipster 7.9.3, Elasticsearch doesn’t work out of the box with Heroku. To solve this, you can create a Docker image with Elasticsearch and deploy it to somewhere that can run it, or you can use Elastic Cloud. I chose to use Elastic Cloud.

I enabled it in application.yml:

application:
  elasticsearch:
    reindex-on-startup: true

Deploy to Heroku

  1. Use Heroku’s Dashboard to turn on maintenance mode.

  2. Change the version number in package.json and build.gradle and commit the changes.

  3. Enable the service worker in app.module.ts for PWA support in production.

  4. Push the changes to GitHub and do a release.

  5. Run the heroku-deploy.sh script, and start everything back up.

  6. Turn off the reindexer after the first deploy.

    heroku config:set APPLICATION_ELASTICSEARCH_REINDEXONSTARTUP=false
  7. Disable the service worker in app.module.ts, update the versions in package.json and build.gradle, then commit and push.

Post Upgrade Notes

  • Elastic Cloud was using v8 instead of v7, so I had to turn reindexing off to get things to start.

  • The database updates for lg to LB did not happen, so I had to manually update them.

    heroku pg:psql --app health-by-points
    update preferences set weight_units='KG' where weight_units='kg';
    update preferences set weight_units='LB' where weight_units='lb';
  • After upgrading, there’s an error when creating new records.

    relation "sequence_generator" does not exist

    Running the following commands fixed it:

    heroku pg:psql --app health-by-points
    # pause and take a deep breath
    create sequence sequence_generator minvalue 1 maxvalue 9223372036854775807;
  • The CSP for connect-src needed to be added:

    connect-src 'self' https://*.staticflickr.com https://fonts.gstatic.com