~M•29
Published on

CS06 - Adding PostgreSQL

Authors
  • avatar
    Name
    MDolce
    Twitter
Table of Contents

Problems we need to solve:

Adding a PostgresSQL database using @vercel/postgres

Also, because of this error message:

Solution:

  1. Import the project to GitHub
  2. Connect and deploy the project to a Vercel account
  3. Create a new Store from the project dashboard in Vercel
  4. Install Vercel CLI and postgres package npm i -g vercel @vercel/postgres
  5. Select Postgres Serverless SQL
  6. Accept terms, assign a database name then select a region
  7. Copy .env.local snippet to a .env project file
  8. Update .gitignore and add .env

Seed data

roles-placeholder-data-js
const roles = [
  {
    rolename: 'guest', //unconfirmed registration
  },
{
    rolename: 'subscriber', //confirmed registration, unpaid membership
  },
{
    rolename: 'member', //confirmed registration, paid membership
  },
{
    rolename: 'author', //confirmed registration, approved author
  },
{
    rolename: 'admin', // one
  },
];

users-placeholder-data-js
const { db } = require('@vercel/postgres');
const {
 users,

Ref