in setting up the starter, i had to comment some lines out from the server index.ts file. this is because they reference the starter's authorization design (User). This could be refactored to be a bit easier, but not so hard to work around manually. in fact, it gives me a roadmap to implement my own stuff on all fronts. some reorganization of this code and comments explaining as much might be good:
/*
* Middleware is installed from the /server/middleware directory. These
* helpers may augment the express app with new settings and/or install
* express middleware. These helpers may be asynchronous, but they should
* operate very rapidly to enable quick as possible server startup.
*/
await middleware.installDatabasePools(app);
// await middleware.installSession(app);
// await middleware.installPassport(app);
await middleware.installLogging(app);
// These are our assets: images/etc; served out of the /client/public folder
await middleware.installSharedStatic(app);
// if (isTest || isDev) {
// await middleware.installCypressServerCommand(app);
// }
await middleware.installPostGraphile(app);
// await middleware.installNext(app);
also PassportLoginPlugin and SubscriptionsPlugin had to be commented out of installPostgraphile.ts
for the db migrations, i created a new template database by pg_dump -s my old db, then using psql to run that file on the new template
i added TEMPLATE_DATABASE_NAME to my .env
added preAfterReset to .gmrc
"afterReset": [
{
"_": "command",
"command": "scripts/preAfterReset"
},
"afterReset.sql",
{
"_": "command",
"command": "cd backend/dist/worker && npx --no-install graphile-worker --once"
}
],
in scripts, added preAfterReset
#!/usr/bin/env bash
set -e
export NODE_ENV=development
if [ -x .env ]; then
. .env
fail () {
echo ".env already exists, but it doesn't define $1 - aborting!"
exit 1;
}
if [ "$DATABASE_HOST" = "" ]; then fail DATABASE_HOST; fi;
if [ "$DATABASE_OWNER" = "" ]; then fail DATABASE_OWNER; fi;
if [ "$DATABASE_OWNER_PASSWORD" = "" ]; then fail DATABASE_OWNER_PASSWORD; fi;
if [ "$DATABASE_AUTHENTICATOR" = "" ]; then fail DATABASE_AUTHENTICATOR; fi;
if [ "$DATABASE_AUTHENTICATOR_PASSWORD" = "" ]; then fail DATABASE_AUTHENTICATOR_PASSWORD; fi;
if [ "$TEMPLATE_DATABASE_NAME" = "" ]; then fail DATABASE_RESET_TEMPLATE; fi;
echo "Configuration already exists, using existing secrets."
fi
echo "Rebuilding database from template..."
echo $DATABASE_NAME $ROOT_DATABASE_URL
PSQL="psql"
$PSQL -X -v ON_ERROR_STOP=1 "${ROOT_DATABASE_URL}" <<SQL
DROP DATABASE IF EXISTS ${DATABASE_NAME};
CREATE DATABASE ${DATABASE_NAME} TEMPLATE ${TEMPLATE_DATABASE_NAME};
DROP DATABASE IF EXISTS ${DATABASE_NAME}_shadow;
CREATE DATABASE ${DATABASE_NAME}_shadow TEMPLATE ${TEMPLATE_DATABASE_NAME};
DROP DATABASE IF EXISTS ${DATABASE_NAME}_test;
CREATE DATABASE ${DATABASE_NAME}_test TEMPLATE ${TEMPLATE_DATABASE_NAME};
SQL
echo "✅ preAfterReset success"