A toy project to simulate opening cases in Counter-Strike. Built with Next.js, Tailwind, PostgreSQL, Drizzle ORM, and TypeScript.
- Clone repo
- Run in dev provided dev container
- Run
npm install
- Run
npm run db:sync
to create the database structure - Run
npm run db:seed
to seed the database - Run
npm run dev
to start the server - Browse to http://localhost:3000
- To import/manipulate the database, the
npm run db:studio
launches Drizzle Studio on https://local.drizzle.studio
- Create Postgres database resource (postgres:16-alpine)
- Ensure the Next.js is also a resource in the same project (deploy using /Dockerfile)
- Create the
DATABASE_URL
environment variable in the Next.js resource (The PG resource will have it ready to copy) - Make sure both the Next.js and DB resources are deployed
- Next.js app: Use the Coolify terminal to run
npm run db:sync
andnpm run db:seed
- The app should now be running
- To import data, run the following command from Windows:
type path/to/data.sql | ssh root@<IP> "docker exec -i <running PG container id> psql -U postgres -d case_sim"
- Run
npm run db:delete-old-non-coverts
on production data - Create a dev branch and seed it with production data
- Remove any unused columns (except
item_name
for now) - Add a new column
is_stat_trak
to thecase_sim_items
table - If
item_name
contains "StatTrak", setis_stat_trak
toTRUE
- Remove the
item_name
column - Use the PlanetScale CLI to dump the dev branch
- Take note of the current amount of unboxes / covert unboxes (
max(id)
andcount(*)
respectively) - Do a bunch of find and replaces such as 0 -> false, 1 -> true
- Dev: Import .sql file(s) by running
type data.sql | docker exec -i db psql -U postgres -d case_sim
- Prod: Import .sql file(s) using the following command from Windows:
type data.sql | ssh root@<IP> "docker exec -i <running PG container id> psql -U postgres -d case_sim"
. This will SSH into my VPS, exec into the running PG container, and run the psql command to import the data - Both: Set the values in the
settings
table with the total amount of unboxes and covert unboxes as noted earlier
- Locally: Run
ssh -L 5432:<postgres_ip>:5432 root@<VPS_ip>
. This will open a tunnel to the VPS that you can run the next commands on - Get the Postgres IP by running the following:
docker ps
-> grab the Posgres container ID ->docker inspect <container_id> | grep "IPAddress"
- Copy the Postgres URL from the Coolify resource and use that as the
DATABASE_URL
, but replace the host withlocalhost:5432
- Run
npm run db:studio
to open Drizzle Studio against the production DB