-
Notifications
You must be signed in to change notification settings - Fork 0
Add Drizzle migrations and expose category/task endpoints #1
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
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
d9cd6aa
chore: add project scaffold
gentamura d94261d
feat: add api handlers
gentamura e45afb4
chore: add drizzle migration setup
gentamura 4d63704
feat: expose category and task endpoints
gentamura 6603bf4
feat: support update and delete operations
gentamura 50cf902
chore: add indexes for foreign key columns
gentamura 908c540
Update package dependencies
gentamura b7979b0
Add foreign key migration for profile default category
gentamura cda6e71
Add CI workflow without release job
gentamura 4888062
Merge branch 'chore/add-workflow' into feature-project-api-init
gentamura 7ae7bdc
chore: update packages
gentamura c9c6c94
Update CI workflow and exclude drizzle artifacts from biome
gentamura File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,21 @@ | ||
| name: CI | ||
|
|
||
| on: | ||
| push: | ||
| branches: | ||
| - main | ||
| pull_request: | ||
| branches: | ||
| - "**" | ||
|
|
||
| permissions: | ||
| contents: write | ||
| pull-requests: write | ||
| id-token: write | ||
|
|
||
| jobs: | ||
| lint: | ||
| uses: listee-dev/listee-ci/.github/workflows/lint.yml@main | ||
|
|
||
| typecheck: | ||
| uses: listee-dev/listee-ci/.github/workflows/typecheck.yml@main |
This file contains hidden or 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,41 @@ | ||
| # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
|
||
| # dependencies | ||
| /node_modules | ||
| /.pnp | ||
| .pnp.* | ||
| .yarn/* | ||
| !.yarn/patches | ||
| !.yarn/plugins | ||
| !.yarn/releases | ||
| !.yarn/versions | ||
|
|
||
| # testing | ||
| /coverage | ||
|
|
||
| # next.js | ||
| /.next/ | ||
| /out/ | ||
|
|
||
| # production | ||
| /build | ||
|
|
||
| # misc | ||
| .DS_Store | ||
| *.pem | ||
|
|
||
| # debug | ||
| npm-debug.log* | ||
| yarn-debug.log* | ||
| yarn-error.log* | ||
| .pnpm-debug.log* | ||
|
|
||
| # env files (can opt-in for committing if needed) | ||
| .env* | ||
|
|
||
| # vercel | ||
| .vercel | ||
|
|
||
| # typescript | ||
| *.tsbuildinfo | ||
| next-env.d.ts |
This file contains hidden or 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,34 @@ | ||
| { | ||
| "$schema": "https://biomejs.dev/schemas/2.2.0/schema.json", | ||
| "vcs": { | ||
| "enabled": true, | ||
| "clientKind": "git", | ||
| "useIgnoreFile": true | ||
| }, | ||
| "files": { | ||
| "ignoreUnknown": true, | ||
| "includes": ["**", "!node_modules", "!.next", "!dist", "!build", "!drizzle"] | ||
| }, | ||
| "formatter": { | ||
| "enabled": true, | ||
| "indentStyle": "space", | ||
| "indentWidth": 2 | ||
| }, | ||
| "linter": { | ||
| "enabled": true, | ||
| "rules": { | ||
| "recommended": true | ||
| }, | ||
| "domains": { | ||
| "next": "recommended", | ||
| "react": "recommended" | ||
| } | ||
| }, | ||
| "assist": { | ||
| "actions": { | ||
| "source": { | ||
| "organizeImports": "on" | ||
| } | ||
| } | ||
| } | ||
| } |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or 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,20 @@ | ||
| import { schemaPath } from "@listee/db"; | ||
| import { loadEnvConfig } from "@next/env"; | ||
| import { defineConfig } from "drizzle-kit"; | ||
|
|
||
| loadEnvConfig(process.cwd()); | ||
|
|
||
| const databaseUrl = process.env.POSTGRES_URL; | ||
|
|
||
| if (databaseUrl === undefined || databaseUrl.length === 0) { | ||
| throw new Error("POSTGRES_URL is not set."); | ||
| } | ||
|
|
||
| export default defineConfig({ | ||
| dialect: "postgresql", | ||
| schema: schemaPath, | ||
| out: "./drizzle", | ||
| dbCredentials: { | ||
| url: databaseUrl, | ||
| }, | ||
| }); |
This file contains hidden or 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,92 @@ | ||
| CREATE TABLE "categories" ( | ||
| "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, | ||
| "name" text NOT NULL, | ||
| "kind" text NOT NULL, | ||
| "created_by" uuid NOT NULL, | ||
| "updated_by" uuid NOT NULL, | ||
| "created_at" timestamp with time zone DEFAULT now() NOT NULL, | ||
| "updated_at" timestamp with time zone DEFAULT now() NOT NULL | ||
| ); | ||
| --> statement-breakpoint | ||
| ALTER TABLE "categories" ENABLE ROW LEVEL SECURITY;--> statement-breakpoint | ||
| CREATE TABLE "profiles" ( | ||
| "id" uuid PRIMARY KEY NOT NULL, | ||
| "email" text NOT NULL, | ||
| "name" text, | ||
| "default_category_id" uuid, | ||
| "created_at" timestamp with time zone DEFAULT now() NOT NULL, | ||
| "updated_at" timestamp with time zone DEFAULT now() NOT NULL, | ||
| CONSTRAINT "profiles_email_unique" UNIQUE("email") | ||
| ); | ||
| --> statement-breakpoint | ||
| ALTER TABLE "profiles" ENABLE ROW LEVEL SECURITY;--> statement-breakpoint | ||
| CREATE TABLE "tasks" ( | ||
| "id" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, | ||
| "name" text NOT NULL, | ||
| "description" text, | ||
| "is_checked" boolean DEFAULT false NOT NULL, | ||
| "category_id" uuid NOT NULL, | ||
| "created_by" uuid NOT NULL, | ||
| "updated_by" uuid NOT NULL, | ||
| "created_at" timestamp with time zone DEFAULT now() NOT NULL, | ||
| "updated_at" timestamp with time zone DEFAULT now() NOT NULL | ||
| ); | ||
| --> statement-breakpoint | ||
| ALTER TABLE "tasks" ENABLE ROW LEVEL SECURITY;--> statement-breakpoint | ||
gentamura marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ALTER TABLE "categories" ADD CONSTRAINT "categories_created_by_profiles_id_fk" FOREIGN KEY ("created_by") REFERENCES "public"."profiles"("id") ON DELETE restrict ON UPDATE no action;--> statement-breakpoint | ||
| ALTER TABLE "categories" ADD CONSTRAINT "categories_updated_by_profiles_id_fk" FOREIGN KEY ("updated_by") REFERENCES "public"."profiles"("id") ON DELETE restrict ON UPDATE no action;--> statement-breakpoint | ||
| ALTER TABLE "tasks" ADD CONSTRAINT "tasks_category_id_categories_id_fk" FOREIGN KEY ("category_id") REFERENCES "public"."categories"("id") ON DELETE cascade ON UPDATE no action;--> statement-breakpoint | ||
| ALTER TABLE "tasks" ADD CONSTRAINT "tasks_created_by_profiles_id_fk" FOREIGN KEY ("created_by") REFERENCES "public"."profiles"("id") ON DELETE restrict ON UPDATE no action;--> statement-breakpoint | ||
| ALTER TABLE "tasks" ADD CONSTRAINT "tasks_updated_by_profiles_id_fk" FOREIGN KEY ("updated_by") REFERENCES "public"."profiles"("id") ON DELETE restrict ON UPDATE no action;--> statement-breakpoint | ||
| CREATE UNIQUE INDEX "categories_system_name_idx" ON "categories" USING btree ("created_by","name") WHERE "categories"."kind" = 'system';--> statement-breakpoint | ||
| CREATE POLICY "Users can view their categories" ON "categories" AS PERMISSIVE FOR SELECT TO "authenticated" USING ("categories"."created_by" = (select auth.uid()));--> statement-breakpoint | ||
| CREATE POLICY "Users can insert categories" ON "categories" AS PERMISSIVE FOR INSERT TO "authenticated" WITH CHECK ("categories"."created_by" = (select auth.uid()));--> statement-breakpoint | ||
| CREATE POLICY "Users can update their categories" ON "categories" AS PERMISSIVE FOR UPDATE TO "authenticated" USING ("categories"."created_by" = (select auth.uid())) WITH CHECK ("categories"."created_by" = (select auth.uid()));--> statement-breakpoint | ||
| CREATE POLICY "Users can delete their categories" ON "categories" AS PERMISSIVE FOR DELETE TO "authenticated" USING ("categories"."created_by" = (select auth.uid()));--> statement-breakpoint | ||
| CREATE POLICY "Users can view their profile" ON "profiles" AS PERMISSIVE FOR SELECT TO "authenticated" USING ("profiles"."id" = (select auth.uid()));--> statement-breakpoint | ||
| CREATE POLICY "Users can insert their profile" ON "profiles" AS PERMISSIVE FOR INSERT TO "authenticated" WITH CHECK ("profiles"."id" = (select auth.uid()));--> statement-breakpoint | ||
| CREATE POLICY "Users can update their profile" ON "profiles" AS PERMISSIVE FOR UPDATE TO "authenticated" USING ("profiles"."id" = (select auth.uid())) WITH CHECK ("profiles"."id" = (select auth.uid()));--> statement-breakpoint | ||
| CREATE POLICY "Users can view their tasks" ON "tasks" AS PERMISSIVE FOR SELECT TO "authenticated" USING ( | ||
| "tasks"."created_by" = (select auth.uid()) | ||
| OR EXISTS ( | ||
| SELECT 1 | ||
| FROM "categories" | ||
| WHERE "categories"."id" = "tasks"."category_id" | ||
| AND "categories"."created_by" = (select auth.uid()) | ||
| ) | ||
| );--> statement-breakpoint | ||
| CREATE POLICY "Users can insert tasks in their categories" ON "tasks" AS PERMISSIVE FOR INSERT TO "authenticated" WITH CHECK ( | ||
| "tasks"."created_by" = (select auth.uid()) | ||
| OR EXISTS ( | ||
| SELECT 1 | ||
| FROM "categories" | ||
| WHERE "categories"."id" = "tasks"."category_id" | ||
| AND "categories"."created_by" = (select auth.uid()) | ||
| ) | ||
| );--> statement-breakpoint | ||
| CREATE POLICY "Users can update their tasks" ON "tasks" AS PERMISSIVE FOR UPDATE TO "authenticated" USING ( | ||
| "tasks"."created_by" = (select auth.uid()) | ||
| OR EXISTS ( | ||
| SELECT 1 | ||
| FROM "categories" | ||
| WHERE "categories"."id" = "tasks"."category_id" | ||
| AND "categories"."created_by" = (select auth.uid()) | ||
| ) | ||
| ) WITH CHECK ( | ||
| "tasks"."created_by" = (select auth.uid()) | ||
| OR EXISTS ( | ||
| SELECT 1 | ||
| FROM "categories" | ||
| WHERE "categories"."id" = "tasks"."category_id" | ||
| AND "categories"."created_by" = (select auth.uid()) | ||
| ) | ||
| );--> statement-breakpoint | ||
| CREATE POLICY "Users can delete their tasks" ON "tasks" AS PERMISSIVE FOR DELETE TO "authenticated" USING ( | ||
| "tasks"."created_by" = (select auth.uid()) | ||
| OR EXISTS ( | ||
| SELECT 1 | ||
| FROM "categories" | ||
| WHERE "categories"."id" = "tasks"."category_id" | ||
| AND "categories"."created_by" = (select auth.uid()) | ||
| ) | ||
| ); | ||
This file contains hidden or 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,6 @@ | ||
| CREATE INDEX "idx_categories_created_by" ON "categories" USING btree ("created_by");--> statement-breakpoint | ||
| CREATE INDEX "idx_categories_updated_by" ON "categories" USING btree ("updated_by");--> statement-breakpoint | ||
| CREATE INDEX "idx_profiles_default_category_id" ON "profiles" USING btree ("default_category_id");--> statement-breakpoint | ||
| CREATE INDEX "idx_tasks_category_id" ON "tasks" USING btree ("category_id");--> statement-breakpoint | ||
| CREATE INDEX "idx_tasks_created_by" ON "tasks" USING btree ("created_by");--> statement-breakpoint | ||
| CREATE INDEX "idx_tasks_updated_by" ON "tasks" USING btree ("updated_by"); |
This file contains hidden or 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 @@ | ||
| ALTER TABLE "profiles" ADD CONSTRAINT "profiles_default_category_id_categories_id_fk" FOREIGN KEY ("default_category_id") REFERENCES "public"."categories"("id") ON DELETE restrict ON UPDATE no action; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.