@allwhere/postgres-connector
v2.1.42
Published
This package is used to generate the `@allwhere/postgres-connector` which abstracts away the prisma client.
Maintainers
Keywords
Readme
README
About
This package is used to generate the @allwhere/postgres-connector which abstracts away the prisma client.
This file describes a few scripts, and explains how to maintaint it.
Quick-start
The typical workflow is as follows:
- create a sequelize migration in
services/mono-service/migrations - run
yarn ts-node .scripts/db/derive-prisma-from-sequelize-migrations.tsfrom the mono-repo root- follow further instructions based on the console log output, including:
- Review the generated schema.prisma file and make any necessary adjustments.
- Check for any unsupported field types like tsvector that Prisma cannot handle.
- Ensure all models have valid unique identifiers or IDs.
- Update fixtures as needed for the new schema.
- Install the updated package in your dependent workspaces using the following commands:
- yarn workspace asset-worker add @allwhere/[email protected].?????
- yarn workspace mono-service add -D @allwhere/[email protected].?????
- yarn workspace store-ui-bff add @allwhere/[email protected].?????
- continue updating your mono-service as needed.
Prisma
Introspection is used by Prisma to read the existing state of the database and define a schema (schema.prisma, which is in the same folder as this file).
** NEVER DELETE THE schema.prisma FILE!!!** the file has manual changes that will be preserved when prisma introspects. Deleting it before introspection will cause the loss of these changes
Scripts
The following usefull scripts exists in package.json
prisma:introspect, which does the introspection. Make sure you define aDATABASE_URLin your environmental variables before running that. you can use a.envfile for that (an example file is included:env.example)prisma:fix-cases, which fixes the field name casing strategies in theschema.prismaprisma:pre-fix, which prependev2to all the models in theprisma.schemafileprisma:generate, which generates:- the
PrismaClientitself, which is a whole new package being generated in the/libssubfolder - the dto's in the
/src/dtossubfolder
- the
prisma:all, which consecutively runs the 4 scripts abovebuilddoes 3 commands, which is required as part of the build command in the CI:prisma:generatewhich is described aboveyarn wrap-typeswhich removes circular dependencies from the models graphql introspection on start-uptscthe normal build script
patch-and-publish, which callssrc/publish.sh, which updates the version of the package and publishes it to npm
How to use
After you have made a database update, you run in this folder:
yarn install(just in case)yarn prisma:allyarn buildyarn testto confirm all is working as expected.*npm run patch-and-publishto get it published on npm. note that yarn doesn't work here
** If you use non-standard database change, that Prisma doesn't understand (like introducing a sequence or defining a ts_vector column), you may need to make the change in the migration (`migrations/0__init/migration.sql).*
** In addition, the ./test/global-setup file does one more thing that couldn't be done through a migration: set up a second user / role for the app.*
CI
The package will be published together with the @allwhere/mono-service-api package.
Environmental Variables
The following environmental variables are used. They are designed to match the mono-service normal database variables. Not all of them are currently used:
DB_DATABASEDB_DIALECTDB_HOSTDB_PASSWORDDB_POOL_ACQUIRE_MSDB_POOL_EVICTDB_POOL_IDLE_MSDB_POOL_MAXDB_POOL_MINDB_PORTDB_SCHEMADB_USERNAME
There are additional fields, required for testing. Again, these will already exist on the mono-service.
JEST_WORKER_IDis automatically defined by nest. We use it to spin up one database per jest workerNODE_ENVthis should be no surprise. During testing this will automatically beTESTTEST_SET(optional) an additional field for custom database naming, typically used to descript the test commands (see mono-servicepackage.jsontest:ci:*commands)ALLOW_PRISMA_WRITE- DANGER! do not use in production!
