Run through build of a ts remix social app using Planetscale, Prisma, Tailwind, deployed on Vercel. Used: https://egghead.io/lessons/remix-install-and-model-data-with-prisma
- Connect to pscale:
pscale connect remix-social main --port 3309
- Load up prisma studio:
npx prisma studio
- Run remix dev server:
npm run dev
- Get setup
- fetch latest changes from remote -
git fetch origin
- Make dev updates & test locally
- for new data models, see pscale notes below
- Push changes:
git checkout -b feature/{{feature name e.g. add-h1}}
git status // check which branch you're on and where its at
git add .
// or:git add app/routes/index.tsx
git add -A
stages all changesgit add .
stages new files and modifications, without deletions (on the current directory and its subdirectories).git add -u
stages modifications and deletions, without new files
git commit -m 'commit message'
- push changes:
git push --set-upstream origin feature/update-h1
- can't use
git push
because the remote branch won't exist yet
- can't use
- Access PR via terminal output
- Take a screenshot of UI change and add to the PR
- Create PR
- Vercel auto-creates a preview deployment to the PR
- Show Environemnt > View deployment > Review PR
- Add review comments
- Merge branch if ready
- Delete feature branch
- Vercel will start building
New model creation (or any db changes) process:
- create new branch in pscale:
pscale branch create remix-social {{new model e.g. user}}
- IMPORTANT: make sure there are no open connections to pscale
- connect to pscale branch:
pscale connect remix-social user --port 3309
- create git branch:
- make sure all local repo changes have been commited / pushed etc
- checkout the master
git checkout main
- fetch commits from master branch of origin remote and then merge into the branch currently checked out
git pull origin main
- create branch on the latest main -
git checkout -b {{initials eg. rg}}/{{feature eg user}}
- create user model in schema.prisma
- push to prisma
npx prisma db push
- note - must be a change to schema for a deploy request to be available in pscale
- note that you may receive errors where new models require relationships to existing data - you'll need to work out how to handle e.g.
- set as optional
- push up changes and update relations
- update schema.prisma and re-push
- redeploy to gh
- vercel triggers rebuild
- SWITCH branches across all: pscale, pscale connection, git
- close connection to pscale dev branch and relauch prod if needed
- always branch both db and code - allows to document step by step the changes
- debugging server issues: where having server/production only issues, use the Vercel CLI & dev to debug
- if not installed:
npm i -g vercel
vercel dev
- this is just a dev version of your vercel- Link to the existing vercel project if you've previously deployed to prod
- load the
localhost
dev server and compare to your remix dev server - make sure to test out various functionality as it could be functions that need to be fired whereas the prod server is auto-testing them
- confirm .vercel is in gitignore
- if not installed:
Written in order of implementation
- remix - create-remix - from scratch
- vercel
- prisma - server side ts node ORM - setup as sqlite pre-Planetscale setup (see below):
- prisma makes it super easy to switch providers via schema.prisma
npm i --save-dev prisma
npx prisma init --datasource-provider sqlite
- avoids heavy db software e.g. postgres & mysql
- later replaced w mysql
- Prisma Studio to have UI to manage the db: npx prisma studio
- install prisma client to retrieve from client side:
npm i @prisma/client
- tailwind
- npm i -D tailwindcss postcss autoprefixer concurrently
- get started with tailwind init utility:
npx tailwindcss init -p
- 2 scripts
- dev needs to watch the fs for any updates whereas build only needs to build once
"dev:css": "tailwindcss -w -i ./styles/app.css -o app/styles/app.css"
,"dev": "concurrently \"npm run dev:css\" \"remix dev\""
,- dev is constantly watching and so both need to run concurrently vs the build
"build:css": "tailwindcss -m -i ./styles/app.css -o app/styles/app.css"
,"build": "npm run build:css && remix build"
,
- tailwindUI for pre-built - backpocket has access
- Zod - ts validation libary - https://zod.dev/
- Planetscale - MySQL serverless db built for scale - like supabase for MySQL but more oriented at scale. Uses a Git like system to track changes in the db
- with Prisma installed, it makes it easy to switch between db providers
- this also switched us from SQLite to MySQL (pscale uses)
- wire up with prisma: https://planetscale.com/docs/tutorials/prisma-quickstart
- followed most of the steps here in the course
- when setup, deploy main branch to prod: https://planetscale.com/docs/tutorials/prisma-quickstart#deploy-development-branch-to-production
- can actually delete the initial-setup branch after its been deployed
- dev process very powerful
- you can setup db/app/schema changes
- run test data on a new branche
- then push the branch
- data on old branch will be cleared but main branch data retained
- Vercel - hosting
- connect via git and import the app
- will fail initially because prisma requires a db url to be set
- fix by going to Dash > Integrations > Planet Scale > Add > Select Project > select Prisma > Env vars will be auto-generated
- Then, remix-social > Settings > Env vars > check DATABASE_URL is setup. This should match the planetscale > remix-social > connect > Prisma/Node value
- Likely need to REDEPLOY
To pull down the latest changes from the remote repo without losing your local changes, you can follow these steps:
Add and commit any untracked files:
git add .
git commit -m "Add Button.tsx"
Stash your local changes:
git stash save "My local changes"
This command will save your local changes in a temporary area (the stash) and revert your working directory to the last commit.
Pull the latest changes from the remote repo:
git pull origin main
This command will fetch the latest changes from the remote 'origin' and branch 'main', and merge them into your local branch.
If divergent:
To pull changes and merge them with your local branch:
git pull --no-rebase origin main
To pull changes and rebase your local branch onto the remote branch:
git pull --rebase origin main
Apply your stashed local changes:
git stash apply
This command will apply the changes you stashed earlier to the updated working directory. If there are any conflicts, you will need to resolve them manually.
If everything looks good, you can remove the stash (optional):
git stash drop
Now, your local branch is up-to-date with the remote branch, and your local changes have been applied on top of the latest changes.