Skip to content
This repository has been archived by the owner on Jul 3, 2021. It is now read-only.
/ database Public archive
forked from Yes-Theory-Fam/database

The definition for the database used in various projects of the organisation in the form of a Prisma 2 based NPM package.

Notifications You must be signed in to change notification settings

hasanlatch007/database

 
 

Repository files navigation

Database

This project contains an NPM package used for accessing the central database of YesBot and YesTheory.Family.

The package uses Prisma 2 as base and exports all generated code to make it available for use in the subprojects.

Peer Dependencies

You are required to install two mandatory peerDependencies (dev) yourself:

yarn add -D prisma typegraphql-prisma
# or using npm
npm install --save-dev prisma typegraphql-prisma

If you also want to use the generated graphql code, you additionally need to install type-graphql.

NPM Configuration

It's available through GitHub Packages and can be installed using your favorite package manager. Note that (since it's published through the GitHub Registry) it requires a few configuration steps to install properly:

  1. Create a Personal Access Token (Settings > Developer Settings > Personal Access Token) with the scope read:packages and make sure you have it saved somewhere.
  2. Open (or create if it doesn't exist yet) ~/.npmrc and add the following content:
@yes-theory-fam:registry=https://npm.pkg.github.com
//npm.pkg.github.com/:_authToken=TOKEN

replacing TOKEN with the Access Token obtained in step 1.

Once that is saved, you can install the package:

yarn add @yes-theory-fam/database
# or using npm
npm install --save @yes-theory-fam/database

Package configuration

This package expects the environment variable PRISMA_DATABASE_URL to be set to a valid PostgreSQL connection string, for example:

postgresql://username:password@localhost:5432/database?schema=public

The environment variable is required for the prisma commands migrate and db pull, etc. and for using the package to access the database.

Running prisma for this package

Since this package includes the schema, it is required to reference it with one of prisma's schema location options.

The recommended way of doing so is adding an entry in your project's package.json:

"prisma": {
  "schema": "./node_modules/@yes-theory-fam/database/prisma/schema.prisma"
}

Alternatively you can provide the location on command invocation using the --schema flag:

yarn prisma --schema node_modules/@yes-theory-fam/database/prisma/schema.prisma
# or using npm
npm run prisma -- --schema node_modules/@yes-theory-fam/database/prisma/schema.prisma

It is advisable to create a script in your package.json as shorthand like db:prisma which allows you to also create db:generate and db:migrate for generating the sources and migrating the database respectively.

Using this package

Simply import @yes-theory-fam/database to get access to both everything generated to @prisma/client and all exported type-graphql code. If you don't have type-graphql installed, you have to import from @yes-theory-fam/database/client which only exports the Prisma client to avoid TypeScript errors.

About

The definition for the database used in various projects of the organisation in the form of a Prisma 2 based NPM package.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Shell 61.5%
  • JavaScript 38.5%