forked from lobehub/lobe-chat
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
♻️ refactor: refactor the server db implement (lobehub#2991)
* ♻️ refactor: refactor the server db implement * ✅ test: fix tests
Showing
24 changed files
with
2,117 additions
and
126 deletions.
There are no files selected for viewing
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
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
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,28 @@ | ||
import { fetchRequestHandler } from '@trpc/server/adapters/fetch'; | ||
import type { NextRequest } from 'next/server'; | ||
|
||
import { pino } from '@/libs/logger'; | ||
import { createContext } from '@/server/context'; | ||
import { toolsRouter } from '@/server/routers/tools'; | ||
|
||
export const maxDuration = 120; | ||
|
||
const handler = (req: NextRequest) => | ||
fetchRequestHandler({ | ||
/** | ||
* @link https://trpc.io/docs/v11/context | ||
*/ | ||
createContext: () => createContext(req), | ||
|
||
endpoint: '/trpc/tools', | ||
|
||
onError: ({ error, path, type }) => { | ||
pino.info(`Error in tRPC handler (tools) on path: ${path}, type: ${type}`); | ||
console.error(error); | ||
}, | ||
|
||
req, | ||
router: toolsRouter, | ||
}); | ||
|
||
export { handler as GET, handler as POST }; |
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,46 @@ | ||
CREATE TABLE IF NOT EXISTS "user_budgets" ( | ||
"id" text PRIMARY KEY NOT NULL, | ||
"free_budget_id" text, | ||
"free_budget_key" text, | ||
"subscription_budget_id" text, | ||
"subscription_budget_key" text, | ||
"package_budget_id" text, | ||
"package_budget_key" text, | ||
"created_at" timestamp with time zone DEFAULT now() NOT NULL, | ||
"updated_at" timestamp with time zone DEFAULT now() NOT NULL | ||
); | ||
--> statement-breakpoint | ||
CREATE TABLE IF NOT EXISTS "user_subscriptions" ( | ||
"id" text PRIMARY KEY NOT NULL, | ||
"user_id" text NOT NULL, | ||
"stripe_id" text, | ||
"currency" text, | ||
"pricing" integer, | ||
"billing_paid_at" integer, | ||
"billing_cycle_start" integer, | ||
"billing_cycle_end" integer, | ||
"cancel_at_period_end" boolean, | ||
"cancel_at" integer, | ||
"next_billing" jsonb, | ||
"plan" text, | ||
"recurring" text, | ||
"storage_limit" integer, | ||
"status" integer, | ||
"created_at" timestamp with time zone DEFAULT now() NOT NULL, | ||
"updated_at" timestamp with time zone DEFAULT now() NOT NULL | ||
); | ||
--> statement-breakpoint | ||
ALTER TABLE "users" ALTER COLUMN "preference" DROP DEFAULT;--> statement-breakpoint | ||
DO $$ BEGIN | ||
ALTER TABLE "user_budgets" ADD CONSTRAINT "user_budgets_id_users_id_fk" FOREIGN KEY ("id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action; | ||
EXCEPTION | ||
WHEN duplicate_object THEN null; | ||
END $$; | ||
--> statement-breakpoint | ||
DO $$ BEGIN | ||
ALTER TABLE "user_subscriptions" ADD CONSTRAINT "user_subscriptions_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action; | ||
EXCEPTION | ||
WHEN duplicate_object THEN null; | ||
END $$; | ||
--> statement-breakpoint | ||
ALTER TABLE "users" DROP COLUMN IF EXISTS "key"; |
Oops, something went wrong.