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.
-
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.TipSee Heroku’s import/export docs for PostgreSQL if you need additional information. -
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;
-
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/.
-
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
-
Copy the results to
src/main/resources/config/liquibase/changelog
and add a reference to it insrc/main/resources/config/liquibase/master.xml
. -
Update
application-prod.xml
to point to thehealth
database you downloaded from Heroku. -
Run
./gradlew bootRun -Pprod
, log in, and browse the app. Update Liquibase migration script as necessary.
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.
Then, I installed the JHipster Elasticsearch Reindexer module and fixed some imports for JHipster 7.9.3.
I enabled it in application.yml
:
application:
elasticsearch:
reindex-on-startup: true
-
Use Heroku’s Dashboard to turn on maintenance mode.
-
Change the version number in
package.json
andbuild.gradle
and commit the changes. -
Enable the service worker in
app.module.ts
for PWA support in production. -
Push the changes to GitHub and do a release.
-
Run the
heroku-deploy.sh
script, and start everything back up. -
Turn off the reindexer after the first deploy.
heroku config:set APPLICATION_ELASTICSEARCH_REINDEXONSTARTUP=false
-
Disable the service worker in
app.module.ts
, update the versions inpackage.json
andbuild.gradle
, then commit and push.
-
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
toLB
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