Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Drizzle, pnpm, schema overhaul
Its a lot going on, but its cool.
- Loading branch information
Showing
119 changed files
with
13,645 additions
and
33,172 deletions.
There are no files selected for viewing
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
layout node | ||
|
||
# dotenv .env | ||
dotenv .env | ||
# dotenv .env.local |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,28 @@ | ||
name: CI | ||
inputs: | ||
node-version: | ||
required: false | ||
description: Node version for setup-node | ||
default: 18.x | ||
on: | ||
push: | ||
branches: | ||
- main | ||
pull_request: | ||
|
||
jobs: | ||
main: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
- uses: nrwl/nx-set-shas@v3 | ||
- run: npm ci | ||
- run: docker-compose up -d | ||
- run: npx nx affected -t test --parallel=3 --configuration=ci | ||
- run: npx nx affected -t build --parallel=3 | ||
- name: Install pnpm | ||
uses: pnpm/action-setup@v2 | ||
- name: Set node version to ${{ inputs.node-version }} | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: ${{ inputs.node-version }} | ||
- name: Run docker images | ||
run: docker-compose up -d | ||
- name: Run tests | ||
run: npm run test:ci |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
node_modules/ | ||
.pnp/ | ||
.pnp.js | ||
package-lock.json | ||
|
||
# testing | ||
coverage/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
PG_CONTAINER=docker exec -t peated-postgres-1 | ||
|
||
reset-db: | ||
$(MAKE) drop-db | ||
$(MAKE) create-db | ||
|
||
drop-db: | ||
$(PG_CONTAINER) dropdb --if-exists -h 127.0.0.1 -p 5432 -U postgres peated | ||
$(PG_CONTAINER) dropdb --if-exists -h 127.0.0.1 -p 5432 -U postgres test_peated | ||
|
||
create-db: | ||
$(PG_CONTAINER) createdb -E utf-8 -h 127.0.0.1 -p 5432 -U postgres peated || exit 0 | ||
$(PG_CONTAINER) createdb -E utf-8 -h 127.0.0.1 -p 5432 -U postgres test_peated || exit 0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
web: npm run dev:web | ||
api: npm run dev:api |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
NODE_ENV=test | ||
# DATABASE_URL=postgresql://postgres:postgres@localhost:5432/test_peated | ||
DATABASE_URL=postgresql://postgres:postgres@localhost:5432/postgres | ||
JWT_SECRET=super-secret-test-secret |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"out": "./migrations", | ||
"schema": "./src/db/schema.ts", | ||
"breakpoints": false | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,176 @@ | ||
DO $$ BEGIN | ||
CREATE TYPE "category" AS ENUM('blend', 'bourbon', 'rye', 'single_grain', 'single_malt', 'spirit'); | ||
EXCEPTION | ||
WHEN duplicate_object THEN null; | ||
END $$; | ||
|
||
DO $$ BEGIN | ||
CREATE TYPE "entity_type" AS ENUM('brand', 'distiller'); | ||
EXCEPTION | ||
WHEN duplicate_object THEN null; | ||
END $$; | ||
|
||
DO $$ BEGIN | ||
CREATE TYPE "identity_provider" AS ENUM('google'); | ||
EXCEPTION | ||
WHEN duplicate_object THEN null; | ||
END $$; | ||
|
||
DO $$ BEGIN | ||
CREATE TYPE "object_type" AS ENUM('bottle', 'edition', 'entity'); | ||
EXCEPTION | ||
WHEN duplicate_object THEN null; | ||
END $$; | ||
|
||
CREATE TABLE IF NOT EXISTS "bottle" ( | ||
"id" bigserial PRIMARY KEY NOT NULL, | ||
"name" varchar(255) NOT NULL, | ||
"category" category, | ||
"brand_id" bigint NOT NULL, | ||
"stated_age" smallint, | ||
"created_at" timestamp DEFAULT now() NOT NULL, | ||
"created_by_id" bigint NOT NULL | ||
); | ||
|
||
CREATE TABLE IF NOT EXISTS "bottle_distiller" ( | ||
"bottle_id" bigint NOT NULL, | ||
"distiller_id" bigint NOT NULL | ||
); | ||
--> statement-breakpoint | ||
ALTER TABLE "bottle_distiller" ADD CONSTRAINT "bottle_distiller_bottle_id_distiller_id" PRIMARY KEY("bottle_id","distiller_id"); | ||
|
||
CREATE TABLE IF NOT EXISTS "change" ( | ||
"id" bigserial PRIMARY KEY NOT NULL, | ||
"object_id" bigint NOT NULL, | ||
"object_type" object_type NOT NULL, | ||
"data" text NOT NULL, | ||
"created_at" timestamp DEFAULT now() NOT NULL, | ||
"created_by_id" bigint NOT NULL | ||
); | ||
|
||
CREATE TABLE IF NOT EXISTS "edition" ( | ||
"id" bigserial PRIMARY KEY NOT NULL, | ||
"name" varchar(255) NOT NULL, | ||
"barrel" smallint, | ||
"bottle_id" bigint NOT NULL, | ||
"created_at" timestamp DEFAULT now() NOT NULL, | ||
"created_by_id" bigint NOT NULL | ||
); | ||
|
||
CREATE TABLE IF NOT EXISTS "entity" ( | ||
"id" bigserial PRIMARY KEY NOT NULL, | ||
"name" text NOT NULL, | ||
"country" text, | ||
"region" text, | ||
"type" entity_type[] NOT NULL, | ||
"created_at" timestamp DEFAULT now() NOT NULL, | ||
"created_by_id" bigint NOT NULL | ||
); | ||
|
||
CREATE TABLE IF NOT EXISTS "identity" ( | ||
"id" bigserial PRIMARY KEY NOT NULL, | ||
"provider" identity_provider NOT NULL, | ||
"external_id" text NOT NULL, | ||
"user_id" bigint NOT NULL | ||
); | ||
|
||
CREATE TABLE IF NOT EXISTS "tasting" ( | ||
"id" bigserial PRIMARY KEY NOT NULL, | ||
"bottle_id" bigint NOT NULL, | ||
"edition_id" bigint, | ||
"comments" text, | ||
"tags" text[], | ||
"rating" double precision NOT NULL, | ||
"image_url" text, | ||
"created_at" timestamp DEFAULT now() NOT NULL, | ||
"created_by_id" bigint NOT NULL | ||
); | ||
|
||
CREATE TABLE IF NOT EXISTS "user" ( | ||
"id" bigserial PRIMARY KEY NOT NULL, | ||
"email" text NOT NULL, | ||
"password_hash" varchar(256), | ||
"display_name" text, | ||
"picture_url" text, | ||
"active" boolean DEFAULT true NOT NULL, | ||
"admin" boolean DEFAULT false NOT NULL, | ||
"created_at" timestamp DEFAULT now() NOT NULL | ||
); | ||
|
||
DO $$ BEGIN | ||
ALTER TABLE "bottle" ADD CONSTRAINT "bottle_brand_id_entity_id_fk" FOREIGN KEY ("brand_id") REFERENCES "entity"("id") ON DELETE no action ON UPDATE no action; | ||
EXCEPTION | ||
WHEN duplicate_object THEN null; | ||
END $$; | ||
|
||
DO $$ BEGIN | ||
ALTER TABLE "bottle" ADD CONSTRAINT "bottle_created_by_id_user_id_fk" FOREIGN KEY ("created_by_id") REFERENCES "user"("id") ON DELETE no action ON UPDATE no action; | ||
EXCEPTION | ||
WHEN duplicate_object THEN null; | ||
END $$; | ||
|
||
DO $$ BEGIN | ||
ALTER TABLE "bottle_distiller" ADD CONSTRAINT "bottle_distiller_bottle_id_bottle_id_fk" FOREIGN KEY ("bottle_id") REFERENCES "bottle"("id") ON DELETE no action ON UPDATE no action; | ||
EXCEPTION | ||
WHEN duplicate_object THEN null; | ||
END $$; | ||
|
||
DO $$ BEGIN | ||
ALTER TABLE "bottle_distiller" ADD CONSTRAINT "bottle_distiller_distiller_id_entity_id_fk" FOREIGN KEY ("distiller_id") REFERENCES "entity"("id") ON DELETE no action ON UPDATE no action; | ||
EXCEPTION | ||
WHEN duplicate_object THEN null; | ||
END $$; | ||
|
||
DO $$ BEGIN | ||
ALTER TABLE "change" ADD CONSTRAINT "change_created_by_id_user_id_fk" FOREIGN KEY ("created_by_id") REFERENCES "user"("id") ON DELETE no action ON UPDATE no action; | ||
EXCEPTION | ||
WHEN duplicate_object THEN null; | ||
END $$; | ||
|
||
DO $$ BEGIN | ||
ALTER TABLE "edition" ADD CONSTRAINT "edition_bottle_id_bottle_id_fk" FOREIGN KEY ("bottle_id") REFERENCES "bottle"("id") ON DELETE no action ON UPDATE no action; | ||
EXCEPTION | ||
WHEN duplicate_object THEN null; | ||
END $$; | ||
|
||
DO $$ BEGIN | ||
ALTER TABLE "edition" ADD CONSTRAINT "edition_created_by_id_user_id_fk" FOREIGN KEY ("created_by_id") REFERENCES "user"("id") ON DELETE no action ON UPDATE no action; | ||
EXCEPTION | ||
WHEN duplicate_object THEN null; | ||
END $$; | ||
|
||
DO $$ BEGIN | ||
ALTER TABLE "entity" ADD CONSTRAINT "entity_created_by_id_user_id_fk" FOREIGN KEY ("created_by_id") REFERENCES "user"("id") ON DELETE no action ON UPDATE no action; | ||
EXCEPTION | ||
WHEN duplicate_object THEN null; | ||
END $$; | ||
|
||
DO $$ BEGIN | ||
ALTER TABLE "identity" ADD CONSTRAINT "identity_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "user"("id") ON DELETE no action ON UPDATE no action; | ||
EXCEPTION | ||
WHEN duplicate_object THEN null; | ||
END $$; | ||
|
||
DO $$ BEGIN | ||
ALTER TABLE "tasting" ADD CONSTRAINT "tasting_bottle_id_bottle_id_fk" FOREIGN KEY ("bottle_id") REFERENCES "bottle"("id") ON DELETE no action ON UPDATE no action; | ||
EXCEPTION | ||
WHEN duplicate_object THEN null; | ||
END $$; | ||
|
||
DO $$ BEGIN | ||
ALTER TABLE "tasting" ADD CONSTRAINT "tasting_edition_id_bottle_id_fk" FOREIGN KEY ("edition_id") REFERENCES "bottle"("id") ON DELETE no action ON UPDATE no action; | ||
EXCEPTION | ||
WHEN duplicate_object THEN null; | ||
END $$; | ||
|
||
DO $$ BEGIN | ||
ALTER TABLE "tasting" ADD CONSTRAINT "tasting_created_by_id_user_id_fk" FOREIGN KEY ("created_by_id") REFERENCES "user"("id") ON DELETE no action ON UPDATE no action; | ||
EXCEPTION | ||
WHEN duplicate_object THEN null; | ||
END $$; | ||
|
||
CREATE UNIQUE INDEX IF NOT EXISTS "bottle_brand_unq" ON "bottle" ("name","brand_id"); | ||
CREATE UNIQUE INDEX IF NOT EXISTS "edition_unq" ON "edition" ("bottle_id","name","barrel"); | ||
CREATE UNIQUE INDEX IF NOT EXISTS "entity_name_unq" ON "entity" ("name"); | ||
CREATE UNIQUE INDEX IF NOT EXISTS "identity_unq" ON "identity" ("provider","external_id"); | ||
CREATE UNIQUE INDEX IF NOT EXISTS "user_email_unq" ON "user" ("email"); |
Oops, something went wrong.