Skip to content

codepath/prisma-express-setup

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

50 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Prisma Express Setup

License: MIT

Requirements

  1. Postgres
  2. NodeJS

Make sure you have set up Postgres in your dev machine.

Setup

During setup we will create the following:

  1. A app_user Postgres role, with password 1234.
  2. A shelterdb database owned by app_user.
  3. A connection URL that assumes the above, and also that your Postgres server is running on localhost on port 5432.

If you wish to use different names, password or port number, you will need to adapt the following instructions, as well as the psql script inside your package.json file.

Instructions

  1. We will create a Postgres app_user role with password 1234, and a shelterdb Postgres database.

    Connect to the postgres database:

    psql postgres

    Paste and run the following SQL commands:

    DROP DATABASE IF EXISTS shelterdb;
    DROP ROLE IF EXISTS app_user;
    CREATE ROLE app_user WITH LOGIN PASSWORD '1234';
    ALTER ROLE app_user CREATEDB;
    CREATE DATABASE shelterdb OWNER app_user;

    Quit the connection to the postgres database:

    \q
  2. Create a .env file at the root of the project:

    DATABASE_URL="postgresql://app_user:1234@localhost:5432/shelterdb?schema=public"
    
  3. Launch the project:

    npm install
    npm run dev

Deployment to Render.com

  • Provision a Postgres database, deploy the web service to Render by linking your GitHub repo, set DATABASE_URL env variable.

  • The build command in Render should be npm run build

Follow Along

  1. Test the current state of the application (should work)
  2. Run through the steps above to set up the local database
  3. Fix the dev script so it injects the .env file
  4. Use helmet middleware
  5. Disconnect the old model and connect the Prisma one
  6. Flesh out the schema for Pet
  7. Create migration files, explain scripts
  8. Alter schema to add favToy, run migrations
  9. Inspect the db using PgAdmin 4
  10. Demo pull request
  11. Walk over deployment

Catching Up With the Instructor

Make sure to have cloned this repo WITHOUT forking.

https://github.com/codepath/prisma-express-setup

git fetch
git reset --hard origin/feature

Finished Schema

model Pet {
  id          Int      @id @default(autoincrement())
  name        String
  type        String
  age         Int?
  adopted     Boolean  @default(false)
  createdAt   DateTime @default(now())
  updatedAt   DateTime @updatedAt @default(now())
}

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published