Notes - jpnws/bassline GitHub Wiki

Notes

Installing and running development server on MacOS:

  1. Install postgres: brew install postgresql@15
  2. Start postgres: sudo service postgresql start
  3. Launch psql prompt: sudo -u postgres psql
  4. Set default password:
postgres=# ALTER USER postgres PASSWORD 'password';
  1. Create database:
postgres=# CREATE DATABASE discodb;
  1. bun install
  2. bunx prisma migrate dev
  3. bunx prisma generate
  4. bunx prisma db seed
  5. bun dev
  6. check localhost:8000/boards/1/posts

Environment: WSL Ubuntu LTS v22

Install git and configure basic things

sudo apt update
sudo apt install git
git --version

# Set default branch, user.name, user.email
git config --global init.defaultBranch main
git config --global user.name "<your-name-on-github>"
git config --global user.email "<your-email-address-on-github>"

# confirm global config
git config --global --get user.name
git config --global --get user.email
git config --global --get init.defaultBranch

# confirm local config (execute this inside a repo)
git config --local --get user.name
git config --local --get user.email
git config --local --get init.defaultBranch

Install Bun on WSL Ubuntu w/ Bash

  1. sudo apt update
  2. sudo apt install zip
  3. curl -fsSL https://bun.sh/install | bash
  4. source /home/uname/.bashrc
  5. bun

Change WSL user password

  1. wsl -u root on Windows Terminal.
  2. passwd <username> - <username> = ubuntu username
  3. Type in new password.

List all git branches

git branch -r - remote branches git branch -a - local & remote branches

Pull remote branch into local

git pull origin <remote-branch>

Git checkout and pull from origin

  1. git checkout <branch>
  2. git pull origin <branch>

Create a new git branch

  1. git checkout -b <new-feature>

Git status, add, and commit

  1. git status
  2. git add <some-file>
  3. git commit

Install NVM and Node, then install Node LTS

  1. sudo apt install curl
  2. curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash
  3. source ~/.bashrc
  4. nvm install --lts

Set up postgres

  1. sudo apt update
  2. sudo apt install postgresql
  3. sudo service postgresql start
  4. sudo -u postgres psql
postgres=# ALTER USER postgres PASSWORD '<postgres-password>';

Accessing psql prompt from normal terminal session

This command switches to the postgres system user on Linux for the duration of the psql prompt session.

sudo -u postgres psql

Postgres Commands inside psql prompt

  1. \q to quit prompt.
  2. \l to list all databases.
  3. \c <db-name> to switch DB to <db-name>.
  4. \dt to show all tables in db.

Workaround for Prisma not working with Bun on WSL.

https://github.com/oven-sh/bun/issues/5320#issuecomment-1730927088

  1. Ensure that you have node.js installed on WSL. Instructions at the top.
  2. Trust the Prisma client package, so it can execute postinstall scripts:

package.json:

"trustedDependencies": [
  "@prisma/client"
],
  1. Now, bunx prisma commands will work.

Prisma Commands

Seeding DB

Ensure that you have prisma/seed.ts file. Also, install tsx as a dev dependency. Then, have the following in package.json:

"prisma": {
  "seed": "tsx prisma/seed.ts"
}

bunx prisma db seed

Resetting DB

bunx prisma migrate reset

This will:

  • Drop the database
  • Create a new database
  • Apply all migrations
  • Generate the Prisma client

Migrating development DB

bunx prisma migrate dev

bunx prisma migrate dev --name <migration-name>

Docker commands

  1. Create a docker image: docker build -t <your-docker-img-name> .
  2. Run the docker image: docker run -dp 8000:3000 <your-docker-img-name>
    • -d is for detaching the image from terminal.
    • -p is for port mapping.
    • 8000 is the local port.
    • 3000 is the container's port.

Create app and DB on DigitalOcean

  1. Follow instructions in the link below to install doctl and generate API token.
  2. Once you have installed doctl and generated a token:
    • Execute doctl auth init and follow the prompt to input your token.
  3. Validate that doctl is working: doctl account get.
  4. Go to your GitHub account -> Settings -> Applications.
    • Add DigitalOcean app and then allow your repo to be connected.
  5. Create the app with doctl and spec.yaml:
    • doctl apps create --spec spec.yaml

Do this whenever modifying spec.yaml.

  1. Retrieve app ID with command:

    doctl apps list --format ID
    
  2. Update DigitalOcean's app with the updated spec (no quotes around app id):

    doctl apps update <app-id> --spec spec.yaml
    
⚠️ **GitHub.com Fallback** ⚠️