Refactor drizzle and db folder

This commit is contained in:
Jared Palmer 2024-11-15 10:13:21 -05:00
parent e96dfb2d74
commit c493ac342b
31 changed files with 22 additions and 23 deletions

View file

@ -2,7 +2,7 @@
import { z } from 'zod'; import { z } from 'zod';
import { createUser, getUser } from '@/db/queries'; import { createUser, getUser } from '@/lib/db/queries';
import { signIn } from './auth'; import { signIn } from './auth';

View file

@ -2,7 +2,7 @@ import { compare } from 'bcrypt-ts';
import NextAuth, { User, Session } from 'next-auth'; import NextAuth, { User, Session } from 'next-auth';
import Credentials from 'next-auth/providers/credentials'; import Credentials from 'next-auth/providers/credentials';
import { getUser } from '@/db/queries'; import { getUser } from '@/lib/db/queries';
import { authConfig } from './auth.config'; import { authConfig } from './auth.config';

View file

@ -19,8 +19,8 @@ import {
saveDocument, saveDocument,
saveMessages, saveMessages,
saveSuggestions, saveSuggestions,
} from '@/db/queries'; } from '@/lib/db/queries';
import { Suggestion } from '@/db/schema'; import { Suggestion } from '@/lib/db/schema';
import { import {
generateUUID, generateUUID,
getMostRecentUserMessage, getMostRecentUserMessage,

View file

@ -3,7 +3,7 @@ import {
deleteDocumentsByIdAfterTimestamp, deleteDocumentsByIdAfterTimestamp,
getDocumentsById, getDocumentsById,
saveDocument, saveDocument,
} from '@/db/queries'; } from '@/lib/db/queries';
export async function GET(request: Request) { export async function GET(request: Request) {
const { searchParams } = new URL(request.url); const { searchParams } = new URL(request.url);

View file

@ -1,5 +1,5 @@
import { auth } from '@/app/(auth)/auth'; import { auth } from '@/app/(auth)/auth';
import { getChatsByUserId } from '@/db/queries'; import { getChatsByUserId } from '@/lib/db/queries';
export async function GET() { export async function GET() {
const session = await auth(); const session = await auth();

View file

@ -1,5 +1,5 @@
import { auth } from '@/app/(auth)/auth'; import { auth } from '@/app/(auth)/auth';
import { getSuggestionsByDocumentId } from '@/db/queries'; import { getSuggestionsByDocumentId } from '@/lib/db/queries';
export async function GET(request: Request) { export async function GET(request: Request) {
const { searchParams } = new URL(request.url); const { searchParams } = new URL(request.url);

View file

@ -1,5 +1,5 @@
import { auth } from '@/app/(auth)/auth'; import { auth } from '@/app/(auth)/auth';
import { getVotesByChatId, voteMessage } from '@/db/queries'; import { getVotesByChatId, voteMessage } from '@/lib/db/queries';
export async function GET(request: Request) { export async function GET(request: Request) {
const { searchParams } = new URL(request.url); const { searchParams } = new URL(request.url);

View file

@ -5,7 +5,7 @@ import { notFound } from 'next/navigation';
import { DEFAULT_MODEL_NAME, models } from '@/ai/models'; import { DEFAULT_MODEL_NAME, models } from '@/ai/models';
import { auth } from '@/app/(auth)/auth'; import { auth } from '@/app/(auth)/auth';
import { Chat as PreviewChat } from '@/components/custom/chat'; import { Chat as PreviewChat } from '@/components/custom/chat';
import { getChatById, getMessagesByChatId } from '@/db/queries'; import { getChatById, getMessagesByChatId } from '@/lib/db/queries';
import { convertToUIMessages } from '@/lib/utils'; import { convertToUIMessages } from '@/lib/utils';
export default async function Page(props: { params: Promise<any> }) { export default async function Page(props: { params: Promise<any> }) {

View file

@ -17,7 +17,7 @@ import {
useWindowSize, useWindowSize,
} from 'usehooks-ts'; } from 'usehooks-ts';
import { Document, Suggestion, Vote } from '@/db/schema'; import { Document, Suggestion, Vote } from '@/lib/db/schema';
import { fetcher } from '@/lib/utils'; import { fetcher } from '@/lib/utils';
import { DiffView } from './diffview'; import { DiffView } from './diffview';

View file

@ -10,7 +10,7 @@ import { useWindowSize } from 'usehooks-ts';
import { ChatHeader } from '@/components/custom/chat-header'; import { ChatHeader } from '@/components/custom/chat-header';
import { PreviewMessage, ThinkingMessage } from '@/components/custom/message'; import { PreviewMessage, ThinkingMessage } from '@/components/custom/message';
import { useScrollToBottom } from '@/components/custom/use-scroll-to-bottom'; import { useScrollToBottom } from '@/components/custom/use-scroll-to-bottom';
import { Vote } from '@/db/schema'; import { Vote } from '@/lib/db/schema';
import { fetcher } from '@/lib/utils'; import { fetcher } from '@/lib/utils';
import { Block, UIBlock } from './block'; import { Block, UIBlock } from './block';

View file

@ -6,7 +6,7 @@ import { EditorState } from 'prosemirror-state';
import { EditorView } from 'prosemirror-view'; import { EditorView } from 'prosemirror-view';
import React, { memo, useEffect, useRef } from 'react'; import React, { memo, useEffect, useRef } from 'react';
import { Suggestion } from '@/db/schema'; import { Suggestion } from '@/lib/db/schema';
import { import {
documentSchema, documentSchema,
handleTransaction, handleTransaction,

View file

@ -3,7 +3,7 @@ import { toast } from 'sonner';
import { useSWRConfig } from 'swr'; import { useSWRConfig } from 'swr';
import { useCopyToClipboard } from 'usehooks-ts'; import { useCopyToClipboard } from 'usehooks-ts';
import { Vote } from '@/db/schema'; import { Vote } from '@/lib/db/schema';
import { getMessageIdFromAnnotations } from '@/lib/utils'; import { getMessageIdFromAnnotations } from '@/lib/utils';
import { CopyIcon, ThumbDownIcon, ThumbUpIcon } from './icons'; import { CopyIcon, ThumbDownIcon, ThumbUpIcon } from './icons';

View file

@ -5,7 +5,7 @@ import cx from 'classnames';
import { motion } from 'framer-motion'; import { motion } from 'framer-motion';
import { Dispatch, SetStateAction } from 'react'; import { Dispatch, SetStateAction } from 'react';
import { Vote } from '@/db/schema'; import { Vote } from '@/lib/db/schema';
import { UIBlock } from './block'; import { UIBlock } from './block';
import { DocumentToolCall, DocumentToolResult } from './document'; import { DocumentToolCall, DocumentToolResult } from './document';

View file

@ -34,7 +34,7 @@ import {
SidebarMenuItem, SidebarMenuItem,
useSidebar, useSidebar,
} from '@/components/ui/sidebar'; } from '@/components/ui/sidebar';
import { Chat } from '@/db/schema'; import { Chat } from '@/lib/db/schema';
import { fetcher } from '@/lib/utils'; import { fetcher } from '@/lib/utils';
type GroupedChats = { type GroupedChats = {

View file

@ -2,7 +2,7 @@ import { JSONValue } from 'ai';
import { Dispatch, SetStateAction, useEffect, useState } from 'react'; import { Dispatch, SetStateAction, useEffect, useState } from 'react';
import { useSWRConfig } from 'swr'; import { useSWRConfig } from 'swr';
import { Suggestion } from '@/db/schema'; import { Suggestion } from '@/lib/db/schema';
import { UIBlock } from './block'; import { UIBlock } from './block';

View file

@ -6,7 +6,7 @@ import { useState } from 'react';
import { useSWRConfig } from 'swr'; import { useSWRConfig } from 'swr';
import { useWindowSize } from 'usehooks-ts'; import { useWindowSize } from 'usehooks-ts';
import { Document } from '@/db/schema'; import { Document } from '@/lib/db/schema';
import { getDocumentTimestampByIndex } from '@/lib/utils'; import { getDocumentTimestampByIndex } from '@/lib/utils';
import { UIBlock } from './block'; import { UIBlock } from './block';

View file

@ -6,8 +6,8 @@ config({
}); });
export default defineConfig({ export default defineConfig({
schema: './db/schema.ts', schema: './lib/db/schema.ts',
out: './lib/drizzle', out: './lib/db/migrations',
dialect: 'postgresql', dialect: 'postgresql',
dbCredentials: { dbCredentials: {
url: process.env.POSTGRES_URL!, url: process.env.POSTGRES_URL!,

View file

@ -4,7 +4,7 @@ import { Decoration, DecorationSet, EditorView } from 'prosemirror-view';
import { createRoot } from 'react-dom/client'; import { createRoot } from 'react-dom/client';
import { Suggestion as PreviewSuggestion } from '@/components/custom/suggestion'; import { Suggestion as PreviewSuggestion } from '@/components/custom/suggestion';
import { Suggestion } from '@/db/schema'; import { Suggestion } from '@/lib/db/schema';
export interface UISuggestion extends Suggestion { export interface UISuggestion extends Suggestion {
selectionStart: number; selectionStart: number;

View file

@ -8,7 +8,7 @@ import {
import { clsx, type ClassValue } from 'clsx'; import { clsx, type ClassValue } from 'clsx';
import { twMerge } from 'tailwind-merge'; import { twMerge } from 'tailwind-merge';
import { Message as DBMessage, Document } from '@/db/schema'; import { Message as DBMessage, Document } from '@/lib/db/schema';
export function cn(...inputs: ClassValue[]) { export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs)); return twMerge(clsx(inputs));

View file

@ -10,7 +10,7 @@
"lint:fix": "next lint --fix", "lint:fix": "next lint --fix",
"format": "prettier --write .", "format": "prettier --write .",
"db:generate": "drizzle-kit generate", "db:generate": "drizzle-kit generate",
"db:migrate": "npx tsx db/migrate.ts", "db:migrate": "npx tsx lib/db/migrate.ts",
"db:studio": "drizzle-kit studio" "db:studio": "drizzle-kit studio"
}, },
"dependencies": { "dependencies": {

View file

@ -13,7 +13,6 @@
"isolatedModules": true, "isolatedModules": true,
"jsx": "preserve", "jsx": "preserve",
"incremental": true, "incremental": true,
"baseUrl": ".",
"plugins": [ "plugins": [
{ {
"name": "next" "name": "next"