Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add follower graph implementation #8

Merged
merged 1 commit into from May 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion .eslintcache

This file was deleted.

3 changes: 2 additions & 1 deletion .gitignore
Expand Up @@ -16,6 +16,7 @@ dev-dist/

# misc
.DS_Store
.env
.env.local
.env.development.local
.env.test.local
Expand All @@ -27,6 +28,6 @@ yarn-error.log*

.nyc-output/
.turbo/
.eslintcache

/.env
/postgres-data
1 change: 1 addition & 0 deletions .prettierignore
Expand Up @@ -2,3 +2,4 @@ dev-dist/
dist/
pnpm-lock.yaml
pnpm-workspace.yaml
migrations/
12 changes: 10 additions & 2 deletions Makefile
Expand Up @@ -4,10 +4,18 @@ reset-db:
$(MAKE) drop-db
$(MAKE) create-db

drop-db:
drop-db: drop-db-dev drop-db-test

drop-db-dev:
$(PG_CONTAINER) dropdb --if-exists -h 127.0.0.1 -p 5432 -U postgres peated

drop-db-test:
$(PG_CONTAINER) dropdb --if-exists -h 127.0.0.1 -p 5432 -U postgres test_peated

create-db:
create-db: create-db-dev create-db-test

create-db-dev:
$(PG_CONTAINER) createdb -E utf-8 -h 127.0.0.1 -p 5432 -U postgres peated || exit 0

create-db-test:
$(PG_CONTAINER) createdb -E utf-8 -h 127.0.0.1 -p 5432 -U postgres test_peated || exit 0
26 changes: 26 additions & 0 deletions apps/api/migrations/0003_military_preak.sql
@@ -0,0 +1,26 @@
DO $$ BEGIN
CREATE TYPE "follow_status" AS ENUM('none', 'pending', 'following');
EXCEPTION
WHEN duplicate_object THEN null;
END $$;

CREATE TABLE IF NOT EXISTS "follow" (
"from_user_id" bigint NOT NULL,
"to_user_id" bigint NOT NULL,
"status" follow_status DEFAULT 'pending' NOT NULL,
"created_at" timestamp DEFAULT now() NOT NULL
);
--> statement-breakpoint
ALTER TABLE "follow" ADD CONSTRAINT "follow_from_user_id_to_user_id" PRIMARY KEY("from_user_id","to_user_id");

DO $$ BEGIN
ALTER TABLE "follow" ADD CONSTRAINT "follow_from_user_id_user_id_fk" FOREIGN KEY ("from_user_id") REFERENCES "user"("id") ON DELETE no action ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;

DO $$ BEGIN
ALTER TABLE "follow" ADD CONSTRAINT "follow_to_user_id_user_id_fk" FOREIGN KEY ("to_user_id") REFERENCES "user"("id") ON DELETE no action ON UPDATE no action;
EXCEPTION
WHEN duplicate_object THEN null;
END $$;