diff --git a/apps/cli/.env.local~ b/apps/cli/.env.local~ new file mode 100644 index 0000000..759f647 --- /dev/null +++ b/apps/cli/.env.local~ @@ -0,0 +1,5 @@ +SERVER_VERSION=0.1.0 +DATA_DIR=/home/ryan/Notes/lifetracker +AUTH_SECRET=ryanisthebest +LIFETRACKER_API_KEY=ak1_b9b17eb909ce0ecdbf33_789b3a1f59390aad84be +LIFETRACKER_SERVER_ADDR=localhost diff --git a/apps/cli/package.json b/apps/cli/package.json index 4fc8ecb..c155b81 100644 --- a/apps/cli/package.json +++ b/apps/cli/package.json @@ -18,7 +18,9 @@ "dependencies": { "@lifetracker/db": "workspace:*", "@lifetracker/trpc": "workspace:^", - "vite-tsconfig-paths": "^5.1.0" + "table": "^6.8.2", + "vite-tsconfig-paths": "^5.1.0", + "dotenv": "^16.4.1" }, "devDependencies": { "@commander-js/extra-typings": "^12.1.0", diff --git a/apps/cli/src/commands/colors.ts b/apps/cli/src/commands/colors.ts new file mode 100644 index 0000000..48b978d --- /dev/null +++ b/apps/cli/src/commands/colors.ts @@ -0,0 +1,77 @@ +import { getGlobalOptions } from "@/lib/globals"; +import { + printError, + printErrorMessageWithReason, + printObject, + printSuccess, +} from "@/lib/output"; +import { getAPIClient } from "@/lib/trpc"; +import { Command } from "@commander-js/extra-typings"; +import { getBorderCharacters, table } from "table"; + +export const colorsCmd = new Command() + .name("colors") + .description("Manipulate custom colors"); + +colorsCmd + .command("list") + .description("lists all custom colors") + .action(async () => { + const api = getAPIClient(); + + try { + const colors = (await api.colors.list.query()).colors; + colors.sort((a, b) => b.numCategories - a.numCategories); + if (getGlobalOptions().json) { + printObject(colors); + } else { + const data: string[][] = [["Id", "Name", "Hexcode", "Num categories"]]; + + colors.forEach((color) => { + data.push([color.id, color.name, color.hexcode, color.numCategories.toString()]); + }); + console.log( + data.length <= 1 ? + "No colors found. Add one with `lifetracker colors create `" : + table(data, { + border: getBorderCharacters("ramac"), + singleLine: true, + }), + ); + } + } catch (error) { + printErrorMessageWithReason("Failed to list all colors", error as object); + } + }); + +colorsCmd + .command("create") + .description("create a color") + .argument("", "the name of the color") + .argument("", "the hexcode of the color") + .action(async (name: string, hexcode: string) => { + const api = getAPIClient(); + + await api.colors.create + .mutate({ + name: name, + hexcode: hexcode, + }) + .then(printSuccess(`Successfully created the color "${name}"`)) + .catch(printError(`Failed to create the color "${name}"`)); + }); + +// colorsCmd +// .command("delete") +// .description("delete a color") +// .argument("", "the id of the color") +// .action(async (id) => { +// const api = getAPIClient(); + +// await api.colors.delete +// .mutate({ +// colorId: id, +// }) +// .then(printSuccess(`Successfully deleted the color with the id "${id}"`)) +// .catch(printError(`Failed to delete the color with the id "${id}"`)); +// }); \ No newline at end of file diff --git a/apps/cli/src/commands/reset.ts b/apps/cli/src/commands/reset.ts new file mode 100644 index 0000000..dd53757 --- /dev/null +++ b/apps/cli/src/commands/reset.ts @@ -0,0 +1,26 @@ +import { + printError, + printErrorMessageWithReason, + printObject, +} from "@/lib/output"; +import { getAPIClient } from "@/lib/trpc"; +import { Command } from "@commander-js/extra-typings"; + +export const resetCmd = new Command() + .name("reset") + .description("Initializes the database with default data") + .action(async () => { + await getAPIClient() + .users.create.mutate({ + email: "ryan@ryanpandya.com", + name: "Ryan Pandya", + password: "pleasework", + confirmPassword: "pleasework", + }) + .then(printObject) + .catch( + printError( + `Unable to create user for Ryan`, + ), + ); + }); diff --git a/apps/cli/src/index.ts b/apps/cli/src/index.ts index dbf0b45..72d428e 100644 --- a/apps/cli/src/index.ts +++ b/apps/cli/src/index.ts @@ -1,7 +1,16 @@ -import { whoamiCmd } from "@/commands/whoami"; import { setGlobalOptions } from "@/lib/globals"; import { Command, Option } from "@commander-js/extra-typings"; +import { whoamiCmd } from "@/commands/whoami"; +import { colorsCmd } from "@/commands/colors"; + +import { config } from "dotenv"; + +config({ + path: "./.env.local", +} +) + const program = new Command() .name("lifetracker") .description("A CLI interface to interact with my lifetracker api") @@ -28,6 +37,9 @@ const program = new Command() program.addCommand(whoamiCmd, { isDefault: true }); +program.addCommand(colorsCmd); + + setGlobalOptions(program.opts()); diff --git a/apps/web/app/dashboard/labels/[labelId]/page.tsx b/apps/web/app/dashboard/categories/[categoryId]/page.tsx similarity index 100% rename from apps/web/app/dashboard/labels/[labelId]/page.tsx rename to apps/web/app/dashboard/categories/[categoryId]/page.tsx diff --git a/apps/web/app/dashboard/categories/page.tsx b/apps/web/app/dashboard/categories/page.tsx new file mode 100644 index 0000000..87ddb75 --- /dev/null +++ b/apps/web/app/dashboard/categories/page.tsx @@ -0,0 +1,10 @@ +import React from "react"; +import CategoriesView from "@/components/dashboard/categories/CategoriesView"; + +export default async function CategoriesPage() { + return ( +
+ +
+ ); +} \ No newline at end of file diff --git a/apps/web/app/dashboard/labels/page.tsx b/apps/web/app/dashboard/labels/page.tsx deleted file mode 100644 index 5e549a8..0000000 --- a/apps/web/app/dashboard/labels/page.tsx +++ /dev/null @@ -1,10 +0,0 @@ -import React from "react"; -import LabelsView from "@/components/dashboard/labels/LabelsView"; - -export default async function LabelsPage() { - return ( -
- -
- ); -} \ No newline at end of file diff --git a/apps/web/app/settings/colors/page.tsx b/apps/web/app/settings/colors/page.tsx new file mode 100644 index 0000000..9e4d357 --- /dev/null +++ b/apps/web/app/settings/colors/page.tsx @@ -0,0 +1,9 @@ +import ColorSettings from "@/components/settings/ColorSettings"; + +export default async function ColorsPage() { + return ( +
+ +
+ ); +} diff --git a/apps/web/components/dashboard/labels/AddLabelDialog.tsx b/apps/web/components/dashboard/categories/AddCategoryDialog.tsx similarity index 88% rename from apps/web/components/dashboard/labels/AddLabelDialog.tsx rename to apps/web/components/dashboard/categories/AddCategoryDialog.tsx index 37297b6..38b55ce 100644 --- a/apps/web/components/dashboard/labels/AddLabelDialog.tsx +++ b/apps/web/components/dashboard/categories/AddCategoryDialog.tsx @@ -33,25 +33,25 @@ import { TRPCClientError } from "@trpc/client"; import { useForm } from "react-hook-form"; import { z } from "zod"; -import { zLabelSchema } from "@lifetracker/shared/types/labels"; +import { zCategorySchema } from "@lifetracker/shared/types/categories"; import { Textarea } from "@/components/ui/textarea"; -type CreateLabelSchema = z.infer; +type CreateCategorySchema = z.infer; -export default function AddLabelDialog({ +export default function AddCategoryDialog({ children, }: { children?: React.ReactNode; }) { const apiUtils = api.useUtils(); const [isOpen, onOpenChange] = useState(false); - const form = useForm({ - resolver: zodResolver(zLabelSchema), + const form = useForm({ + resolver: zodResolver(zCategorySchema), }); - const { mutate, isPending } = api.labels.createLabel.useMutation({ + const { mutate, isPending } = api.categories.createCategory.useMutation({ onSuccess: () => { toast({ - description: "Label created successfully", + description: "Category created successfully", }); onOpenChange(false); }, @@ -64,7 +64,7 @@ export default function AddLabelDialog({ } else { toast({ variant: "destructive", - description: "Failed to create label", + description: "Failed to create category", }); } }, @@ -81,7 +81,7 @@ export default function AddLabelDialog({ {children} - Create Label + Create Category
mutate(val))}> diff --git a/apps/web/components/dashboard/categories/CategoriesView.tsx b/apps/web/components/dashboard/categories/CategoriesView.tsx new file mode 100644 index 0000000..2c76a90 --- /dev/null +++ b/apps/web/components/dashboard/categories/CategoriesView.tsx @@ -0,0 +1,110 @@ +"use client"; + +import { ActionButtonWithTooltip } from "@/components/ui/action-button"; +import { ButtonWithTooltip } from "@/components/ui/button"; +import LoadingSpinner from "@/components/ui/spinner"; +import { + Table, + TableBody, + TableCell, + TableHead, + TableHeader, + TableRow, +} from "@/components/ui/table"; +import { toast } from "@/components/ui/use-toast"; +import { api } from "@/lib/trpc"; +import { Pencil, Trash, FilePlus, Palette } from "lucide-react"; +import { useSession } from "next-auth/react"; +import AddCategoryDialog from "./AddCategoryDialog"; +import EditCategoryDialog from "./EditCategoryDialog"; +import Link from "next/link"; + +export default function CategoriesView() { + const { data: session } = useSession(); + const { data: categories } = api.categories.list.useQuery(); + const { data: categoryStats } = api.categories.categoryStats.useQuery(); + + const invalidateCategoryList = api.useUtils().categories.list.invalidate; + const { mutate: deleteCategory, isPending: isDeletionPending } = + api.categories.delete.useMutation({ + onSuccess: () => { + toast({ + description: "Category deleted", + }); + invalidateCategoryList(); + }, + onError: (e) => { + toast({ + variant: "destructive", + description: `Something went wrong: ${e.message}`, + }); + }, + }); + + const CategoriesTable = ({ categories }) => ( + + + Code + Name + Description + Entries + Actions + + + {categories.categories.map((c) => ( + + {c.code} + {c.name} + {c.description} + + {categoryStats[c.id].numEntries} + + + deleteCategory({ categoryId: c.id })} + loading={false} + > + + + + + + + + + + ))} + +
+ ); + + return ( + <> +
+ All Categories +
+ + + + + + + + + + +
+ + {categories === undefined ? ( + + ) : ( + + )} + + ); +} diff --git a/apps/web/components/dashboard/labels/DeleteLabelConfirmationDialog.tsx b/apps/web/components/dashboard/categories/DeleteCategoryConfirmationDialog.tsx similarity index 99% rename from apps/web/components/dashboard/labels/DeleteLabelConfirmationDialog.tsx rename to apps/web/components/dashboard/categories/DeleteCategoryConfirmationDialog.tsx index 50277c1..72022cf 100644 --- a/apps/web/components/dashboard/labels/DeleteLabelConfirmationDialog.tsx +++ b/apps/web/components/dashboard/categories/DeleteCategoryConfirmationDialog.tsx @@ -3,7 +3,7 @@ import { ActionButton } from "@/components/ui/action-button"; import ActionConfirmingDialog from "@/components/ui/action-confirming-dialog"; import { toast } from "@/components/ui/use-toast"; -import { useDeleteLabel } from "@lifetracker/shared-react/hooks/labels"; +import { useDeleteLabel } from "@lifetracker/shared-react/hooks/categories"; export default function DeleteLabelConfirmationDialog({ label, diff --git a/apps/web/components/dashboard/labels/EditLabelDialog.tsx b/apps/web/components/dashboard/categories/EditCategoryDialog.tsx similarity index 84% rename from apps/web/components/dashboard/labels/EditLabelDialog.tsx rename to apps/web/components/dashboard/categories/EditCategoryDialog.tsx index d72a7c5..65d6161 100644 --- a/apps/web/components/dashboard/labels/EditLabelDialog.tsx +++ b/apps/web/components/dashboard/categories/EditCategoryDialog.tsx @@ -33,31 +33,24 @@ import { TRPCClientError } from "@trpc/client"; import { useForm } from "react-hook-form"; import { z } from "zod"; -import { zLabelSchema } from "@lifetracker/shared/types/labels"; +import { zLabelSchema } from "@lifetracker/shared/types/categories"; -type CreateLabelSchema = z.infer; +type CreateLabelSchema = z.infer; -export default function EditLabelDialog({ +export default function EditCategoryDialog({ children, }: { children?: React.ReactNode; }) { const apiUtils = api.useUtils(); const [isOpen, onOpenChange] = useState(false); - const form = useForm({ - resolver: zodResolver(zLabelSchema), - defaultValues: { - id: "69", - name: "Fuckdicks", - code: 420, - description: "This shit sucks", - color: "#004400", - }, + const form = useForm({ + resolver: zodResolver(zCategorySchema), }); - const { mutate, isPending } = api.labels.update.useMutation({ + const { mutate, isPending } = api.categories.update.useMutation({ onSuccess: () => { toast({ - description: "Label updated successfully", + description: "Category updated successfully", }); onOpenChange(false); }, @@ -70,7 +63,7 @@ export default function EditLabelDialog({ } else { toast({ variant: "destructive", - description: "Failed to update label", + description: "Failed to update category", }); } }, @@ -87,7 +80,7 @@ export default function EditLabelDialog({ {children} - Edit Label + Edit Category mutate(val))}> @@ -151,7 +144,7 @@ export default function EditLabelDialog({ name="color" render={({ field }) => ( - Color, hope you like hex codes + Color { - toast({ - description: "Label deleted", - }); - invalidateLabelList(); - }, - onError: (e) => { - toast({ - variant: "destructive", - description: `Something went wrong: ${e.message}`, - }); - }, - }); - - const LabelsTable = ({ labels }) => ( - - - Parent - Code - Name - Description - Entries With Label - Actions - - - {labels.labels.map((l) => ( - - {l.parent} - {l.code} - {l.name} - {l.description} - - {labelStats[l.id].numEntries} - - - deleteLabel({ labelId: l.id })} - loading={false} - > - - - - - - - - - - ))} - -
- ); - - return ( - <> -
- All Labels - - - - - -
- - {labels === undefined ? ( - - ) : ( - - )} - - ); -} diff --git a/apps/web/components/dashboard/sidebar/Sidebar.tsx b/apps/web/components/dashboard/sidebar/Sidebar.tsx index a20c986..b2bdc4e 100644 --- a/apps/web/components/dashboard/sidebar/Sidebar.tsx +++ b/apps/web/components/dashboard/sidebar/Sidebar.tsx @@ -39,9 +39,9 @@ export default async function Sidebar() { }, ...searchItem, { - name: "Labels", + name: "Categories", icon: , - path: "/dashboard/labels", + path: "/dashboard/categories", }, ]; diff --git a/apps/web/components/settings/AddColor.tsx b/apps/web/components/settings/AddColor.tsx new file mode 100644 index 0000000..5728d96 --- /dev/null +++ b/apps/web/components/settings/AddColor.tsx @@ -0,0 +1,168 @@ +import { useEffect, useState } from "react"; +import { ActionButton } from "@/components/ui/action-button"; +import { Button } from "@/components/ui/button"; +import { + Dialog, + DialogClose, + DialogContent, + DialogFooter, + DialogHeader, + DialogTitle, + DialogTrigger, +} from "@/components/ui/dialog"; +import { + Form, + FormControl, + FormField, + FormItem, + FormLabel, + FormMessage, +} from "@/components/ui/form"; +import { Input } from "@/components/ui/input"; +import { + Select, + SelectContent, + SelectItem, + SelectTrigger, + SelectValue, +} from "@/components/ui/select"; +import { toast } from "@/components/ui/use-toast"; +import { api } from "@/lib/trpc"; +import { zodResolver } from "@hookform/resolvers/zod"; +import { TRPCClientError } from "@trpc/client"; +import { useForm } from "react-hook-form"; +import { z } from "zod"; +import { titleCase } from "title-case"; + +import { zColorSchema, ZColor } from "@lifetracker/shared/types/colors"; +import { HexColorPicker, HexColorInput } from 'react-colorful'; +import { closest } from 'color-2-name'; + +export default function AddCategoryDialog({ + children, +}: { + children?: React.ReactNode; +}) { + const apiUtils = api.useUtils(); + const [isOpen, onOpenChange] = useState(false); + const [color, setColor] = useState("#000000"); + const [guessedName, setGuessedName] = useState("Name"); + + const form = useForm({ + resolver: zodResolver(zColorSchema), + }); + const { mutate, isPending } = api.colors.create.useMutation({ + onSuccess: () => { + toast({ + description: "Color created successfully", + }); + onOpenChange(false); + apiUtils.colors.list.invalidate(); + }, + onError: (error) => { + if (error instanceof TRPCClientError) { + toast({ + variant: "destructive", + description: error.message, + }); + } else { + toast({ + variant: "destructive", + description: "Failed to create color", + }); + } + }, + }); + + useEffect(() => { + if (!isOpen) { + form.reset(); + } + }, [isOpen, form]); + + return ( + + {children} + + + Create Color + + + mutate(val))}> +
+ ( +
+ + + + + + + { + setGuessedName(titleCase(closest(color).name)); + field.onChange(titleCase(closest(color).name)); + }} + > + Guess + +
+ )} + /> + ( + +
+ {/* Description */} + { + setColor(newColor); + field.onChange(newColor); + }} + prefixed className="flex h-10 border-input bg-background text-sm ring-offset-background file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50 w-full rounded border p-2" /> + { + setColor(newColor); + field.onChange(newColor); + }} + className="w-full" /> + +
+
+ )} + /> + + + + + + Create + + +
+ + +
+
+ ); +} diff --git a/apps/web/components/settings/ColorSettings.tsx b/apps/web/components/settings/ColorSettings.tsx new file mode 100644 index 0000000..7b729f4 --- /dev/null +++ b/apps/web/components/settings/ColorSettings.tsx @@ -0,0 +1,94 @@ +"use client"; + +import { ActionButtonWithTooltip } from "@/components/ui/action-button"; +import { ButtonWithTooltip } from "@/components/ui/button"; +import LoadingSpinner from "@/components/ui/spinner"; +import { + Table, + TableBody, + TableCell, + TableHead, + TableHeader, + TableRow, +} from "@/components/ui/table"; +import { toast } from "@/components/ui/use-toast"; +import { api } from "@/lib/trpc"; +import { Pencil, Trash, FilePlus, Palette } from "lucide-react"; +import { useSession } from "next-auth/react"; +import AddColor from "./AddColor"; +// import EditCategoryDialog from "./EditCategoryDialog"; +import Link from "next/link"; + +export default function ColorssView() { + const { data: session } = useSession(); + const { data: colors } = api.colors.list.useQuery(); + + // const invalidateColorList = api.useUtils().colors.list.invalidate; + // const { mutate: deleteColor, isPending: isDeletionPending } = + // api.colors.delete.useMutation({ + // onSuccess: () => { + // toast({ + // description: "Color deleted", + // }); + // invalidateCategoryList(); + // }, + // onError: (e) => { + // toast({ + // variant: "destructive", + // description: `Something went wrong: ${e.message}`, + // }); + // }, + // }); + + const ColorsTable = ({ colors }) => ( + + + Name + Categories + Actions + + + {colors.colors.map((c) => ( + + {c.name} + + numEntries + + + deleteColor({ colorId: c.id })} + loading={false} + > + + + Edit + + + ))} + +
+ ); + + return ( + <> +
+ All Colors ({colors === undefined ? 0 : colors.colors.length}) +
+ + + + + +
+ + {colors === undefined ? ( + + ) : ( + + ) + } + + ); +} diff --git a/apps/web/components/settings/sidebar/items.tsx b/apps/web/components/settings/sidebar/items.tsx index 8665d80..262775a 100644 --- a/apps/web/components/settings/sidebar/items.tsx +++ b/apps/web/components/settings/sidebar/items.tsx @@ -4,6 +4,7 @@ import { Download, KeyRound, User, + Palette, } from "lucide-react"; export const settingsSidebarItems: { @@ -21,6 +22,11 @@ export const settingsSidebarItems: { icon: , path: "/settings/info", }, + { + name: "Color Settings", + icon: , + path: "/settings/colors", + }, { name: "Import / Export", icon: , diff --git a/apps/web/package.json b/apps/web/package.json index d0c632a..71b2405 100644 --- a/apps/web/package.json +++ b/apps/web/package.json @@ -47,6 +47,7 @@ "cheerio": "^1.0.0", "class-variance-authority": "^0.7.0", "clsx": "^2.1.0", + "color-2-name": "^1.4.4", "csv-parse": "^5.5.6", "dayjs": "^1.11.10", "drizzle-orm": "^0.33.0", @@ -74,6 +75,7 @@ "sharp": "^0.33.3", "superjson": "^2.2.1", "tailwind-merge": "^2.2.1", + "title-case": "^4.3.2", "zod": "^3.22.4", "zustand": "^4.5.1" }, diff --git a/packages/db/migrations/0002_minor_toxin.sql b/packages/db/migrations/0000_gigantic_doctor_strange.sql similarity index 54% rename from packages/db/migrations/0002_minor_toxin.sql rename to packages/db/migrations/0000_gigantic_doctor_strange.sql index b54ab4f..7275c61 100644 --- a/packages/db/migrations/0002_minor_toxin.sql +++ b/packages/db/migrations/0000_gigantic_doctor_strange.sql @@ -24,6 +24,42 @@ CREATE TABLE `apiKey` ( FOREIGN KEY (`userId`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE cascade ); --> statement-breakpoint +CREATE TABLE `category` ( + `id` text PRIMARY KEY NOT NULL, + `createdAt` integer NOT NULL, + `name` text NOT NULL, + `code` integer NOT NULL, + `description` text, + `colorId` text NOT NULL, + `parentId` text, + `userId` text NOT NULL, + FOREIGN KEY (`colorId`) REFERENCES `color`(`id`) ON UPDATE no action ON DELETE no action, + FOREIGN KEY (`parentId`) REFERENCES `category`(`id`) ON UPDATE no action ON DELETE no action, + FOREIGN KEY (`userId`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE cascade +); +--> statement-breakpoint +CREATE TABLE `color` ( + `id` text PRIMARY KEY NOT NULL, + `createdAt` integer NOT NULL, + `name` text NOT NULL, + `hexcode` text NOT NULL, + `inverse` text, + `userId` text NOT NULL, + FOREIGN KEY (`userId`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE cascade +); +--> statement-breakpoint +CREATE TABLE `config` ( + `key` text PRIMARY KEY NOT NULL, + `value` text NOT NULL +); +--> statement-breakpoint +CREATE TABLE `day` ( + `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL, + `mood` integer, + `date` text NOT NULL, + `comment` text NOT NULL +); +--> statement-breakpoint CREATE TABLE `session` ( `sessionToken` text PRIMARY KEY NOT NULL, `userId` text NOT NULL, @@ -50,4 +86,7 @@ CREATE TABLE `verificationToken` ( --> statement-breakpoint CREATE UNIQUE INDEX `apiKey_keyId_unique` ON `apiKey` (`keyId`);--> statement-breakpoint CREATE UNIQUE INDEX `apiKey_name_userId_unique` ON `apiKey` (`name`,`userId`);--> statement-breakpoint +CREATE UNIQUE INDEX `category_userId_name_unique` ON `category` (`userId`,`name`);--> statement-breakpoint +CREATE UNIQUE INDEX `color_userId_name_unique` ON `color` (`userId`,`name`);--> statement-breakpoint +CREATE UNIQUE INDEX `day_date_unique` ON `day` (`date`);--> statement-breakpoint CREATE UNIQUE INDEX `user_email_unique` ON `user` (`email`); \ No newline at end of file diff --git a/packages/db/migrations/0000_worried_may_parker.sql b/packages/db/migrations/0000_worried_may_parker.sql deleted file mode 100644 index bee6d4c..0000000 --- a/packages/db/migrations/0000_worried_may_parker.sql +++ /dev/null @@ -1,4 +0,0 @@ -CREATE TABLE `events` ( - `id` integer PRIMARY KEY AUTOINCREMENT NOT NULL, - `description` text NOT NULL -); diff --git a/packages/db/migrations/0001_hard_lionheart.sql b/packages/db/migrations/0001_hard_lionheart.sql deleted file mode 100644 index eda0df0..0000000 --- a/packages/db/migrations/0001_hard_lionheart.sql +++ /dev/null @@ -1,5 +0,0 @@ -ALTER TABLE `events` RENAME TO `days`;--> statement-breakpoint -ALTER TABLE `days` RENAME COLUMN `description` TO `comment`;--> statement-breakpoint -ALTER TABLE `days` ADD `mood` integer;--> statement-breakpoint -ALTER TABLE `days` ADD `date` text NOT NULL;--> statement-breakpoint -CREATE UNIQUE INDEX `days_date_unique` ON `days` (`date`); \ No newline at end of file diff --git a/packages/db/migrations/0003_complex_ares.sql b/packages/db/migrations/0003_complex_ares.sql deleted file mode 100644 index 27f10a4..0000000 --- a/packages/db/migrations/0003_complex_ares.sql +++ /dev/null @@ -1,3 +0,0 @@ -ALTER TABLE `days` RENAME TO `day`;--> statement-breakpoint -DROP INDEX IF EXISTS `days_date_unique`;--> statement-breakpoint -CREATE UNIQUE INDEX `day_date_unique` ON `day` (`date`); \ No newline at end of file diff --git a/packages/db/migrations/0004_sad_sally_floyd.sql b/packages/db/migrations/0004_sad_sally_floyd.sql deleted file mode 100644 index 25978b1..0000000 --- a/packages/db/migrations/0004_sad_sally_floyd.sql +++ /dev/null @@ -1,4 +0,0 @@ -CREATE TABLE `config` ( - `key` text PRIMARY KEY NOT NULL, - `value` text NOT NULL -); diff --git a/packages/db/migrations/0005_ambitious_famine.sql b/packages/db/migrations/0005_ambitious_famine.sql deleted file mode 100644 index c868796..0000000 --- a/packages/db/migrations/0005_ambitious_famine.sql +++ /dev/null @@ -1,11 +0,0 @@ -CREATE TABLE `label` ( - `id` text PRIMARY KEY NOT NULL, - `name` text NOT NULL, - `createdAt` integer NOT NULL, - `userId` text NOT NULL, - FOREIGN KEY (`userId`) REFERENCES `user`(`id`) ON UPDATE no action ON DELETE cascade -); ---> statement-breakpoint -CREATE INDEX `labels_name_idx` ON `label` (`name`);--> statement-breakpoint -CREATE INDEX `labels_userId_idx` ON `label` (`userId`);--> statement-breakpoint -CREATE UNIQUE INDEX `label_userId_name_unique` ON `label` (`userId`,`name`); \ No newline at end of file diff --git a/packages/db/migrations/0006_milky_hellion.sql b/packages/db/migrations/0006_milky_hellion.sql deleted file mode 100644 index 23c6efd..0000000 --- a/packages/db/migrations/0006_milky_hellion.sql +++ /dev/null @@ -1,4 +0,0 @@ -DROP INDEX IF EXISTS `labels_name_idx`;--> statement-breakpoint -DROP INDEX IF EXISTS `labels_userId_idx`;--> statement-breakpoint -ALTER TABLE `label` ADD `description` text;--> statement-breakpoint -ALTER TABLE `label` ADD `color` text DEFAULT '#000000'; \ No newline at end of file diff --git a/packages/db/migrations/0007_unusual_terror.sql b/packages/db/migrations/0007_unusual_terror.sql deleted file mode 100644 index 3f7659c..0000000 --- a/packages/db/migrations/0007_unusual_terror.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE `label` ADD `code` integer NOT NULL; \ No newline at end of file diff --git a/packages/db/migrations/0008_gray_selene.sql b/packages/db/migrations/0008_gray_selene.sql deleted file mode 100644 index 6078940..0000000 --- a/packages/db/migrations/0008_gray_selene.sql +++ /dev/null @@ -1,8 +0,0 @@ -ALTER TABLE `label` ADD `parentId` text REFERENCES label(id);--> statement-breakpoint -/* - SQLite does not support "Creating foreign key on existing column" out of the box, we do not generate automatic migration for that, so it has to be done manually - Please refer to: https://www.techonthenet.com/sqlite/tables/alter_table.php - https://www.sqlite.org/lang_altertable.html - - Due to that we don't generate migration automatically and it has to be done manually -*/ \ No newline at end of file diff --git a/packages/db/migrations/0009_ordinary_electro.sql b/packages/db/migrations/0009_ordinary_electro.sql deleted file mode 100644 index c0176bd..0000000 --- a/packages/db/migrations/0009_ordinary_electro.sql +++ /dev/null @@ -1,8 +0,0 @@ -/* - SQLite does not support "Dropping foreign key" out of the box, we do not generate automatic migration for that, so it has to be done manually - Please refer to: https://www.techonthenet.com/sqlite/tables/alter_table.php - https://www.sqlite.org/lang_altertable.html - - Due to that we don't generate migration automatically and it has to be done manually -*/--> statement-breakpoint -ALTER TABLE `label` DROP COLUMN `parentId`; \ No newline at end of file diff --git a/packages/db/migrations/meta/0000_snapshot.json b/packages/db/migrations/meta/0000_snapshot.json index 1cf959e..ee3d996 100644 --- a/packages/db/migrations/meta/0000_snapshot.json +++ b/packages/db/migrations/meta/0000_snapshot.json @@ -1,23 +1,400 @@ { "version": "6", "dialect": "sqlite", - "id": "74097c41-1958-4fc8-8371-6e31b3071eb9", + "id": "d35127c1-6892-410e-b933-d7ec7aabe6f5", "prevId": "00000000-0000-0000-0000-000000000000", "tables": { - "events": { - "name": "events", + "account": { + "name": "account", + "columns": { + "userId": { + "name": "userId", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "type": { + "name": "type", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "provider": { + "name": "provider", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "providerAccountId": { + "name": "providerAccountId", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "refresh_token": { + "name": "refresh_token", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "access_token": { + "name": "access_token", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "expires_at": { + "name": "expires_at", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "token_type": { + "name": "token_type", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "scope": { + "name": "scope", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "id_token": { + "name": "id_token", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "session_state": { + "name": "session_state", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": { + "account_userId_user_id_fk": { + "name": "account_userId_user_id_fk", + "tableFrom": "account", + "tableTo": "user", + "columnsFrom": [ + "userId" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": { + "account_provider_providerAccountId_pk": { + "columns": [ + "provider", + "providerAccountId" + ], + "name": "account_provider_providerAccountId_pk" + } + }, + "uniqueConstraints": {} + }, + "apiKey": { + "name": "apiKey", "columns": { "id": { "name": "id", - "type": "integer", + "type": "text", "primaryKey": true, "notNull": true, - "autoincrement": true + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "createdAt": { + "name": "createdAt", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "keyId": { + "name": "keyId", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "keyHash": { + "name": "keyHash", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "userId": { + "name": "userId", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "apiKey_keyId_unique": { + "name": "apiKey_keyId_unique", + "columns": [ + "keyId" + ], + "isUnique": true + }, + "apiKey_name_userId_unique": { + "name": "apiKey_name_userId_unique", + "columns": [ + "name", + "userId" + ], + "isUnique": true + } + }, + "foreignKeys": { + "apiKey_userId_user_id_fk": { + "name": "apiKey_userId_user_id_fk", + "tableFrom": "apiKey", + "tableTo": "user", + "columnsFrom": [ + "userId" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "category": { + "name": "category", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "createdAt": { + "name": "createdAt", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "code": { + "name": "code", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false }, "description": { "name": "description", "type": "text", "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "colorId": { + "name": "colorId", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "parentId": { + "name": "parentId", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "userId": { + "name": "userId", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "category_userId_name_unique": { + "name": "category_userId_name_unique", + "columns": [ + "userId", + "name" + ], + "isUnique": true + } + }, + "foreignKeys": { + "category_colorId_color_id_fk": { + "name": "category_colorId_color_id_fk", + "tableFrom": "category", + "tableTo": "color", + "columnsFrom": [ + "colorId" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "category_parentId_category_id_fk": { + "name": "category_parentId_category_id_fk", + "tableFrom": "category", + "tableTo": "category", + "columnsFrom": [ + "parentId" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + }, + "category_userId_user_id_fk": { + "name": "category_userId_user_id_fk", + "tableFrom": "category", + "tableTo": "user", + "columnsFrom": [ + "userId" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "color": { + "name": "color", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "createdAt": { + "name": "createdAt", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "hexcode": { + "name": "hexcode", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "inverse": { + "name": "inverse", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "userId": { + "name": "userId", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "color_userId_name_unique": { + "name": "color_userId_name_unique", + "columns": [ + "userId", + "name" + ], + "isUnique": true + } + }, + "foreignKeys": { + "color_userId_user_id_fk": { + "name": "color_userId_user_id_fk", + "tableFrom": "color", + "tableTo": "user", + "columnsFrom": [ + "userId" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "config": { + "name": "config", + "columns": { + "key": { + "name": "key", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "value": { + "name": "value", + "type": "text", + "primaryKey": false, "notNull": true, "autoincrement": false } @@ -26,6 +403,200 @@ "foreignKeys": {}, "compositePrimaryKeys": {}, "uniqueConstraints": {} + }, + "day": { + "name": "day", + "columns": { + "id": { + "name": "id", + "type": "integer", + "primaryKey": true, + "notNull": true, + "autoincrement": true + }, + "mood": { + "name": "mood", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "date": { + "name": "date", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "comment": { + "name": "comment", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": { + "day_date_unique": { + "name": "day_date_unique", + "columns": [ + "date" + ], + "isUnique": true + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "session": { + "name": "session", + "columns": { + "sessionToken": { + "name": "sessionToken", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "userId": { + "name": "userId", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "expires": { + "name": "expires", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": { + "session_userId_user_id_fk": { + "name": "session_userId_user_id_fk", + "tableFrom": "session", + "tableTo": "user", + "columnsFrom": [ + "userId" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "user": { + "name": "user", + "columns": { + "id": { + "name": "id", + "type": "text", + "primaryKey": true, + "notNull": true, + "autoincrement": false + }, + "name": { + "name": "name", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "email": { + "name": "email", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "emailVerified": { + "name": "emailVerified", + "type": "integer", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "image": { + "name": "image", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "password": { + "name": "password", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false + }, + "role": { + "name": "role", + "type": "text", + "primaryKey": false, + "notNull": false, + "autoincrement": false, + "default": "'user'" + } + }, + "indexes": { + "user_email_unique": { + "name": "user_email_unique", + "columns": [ + "email" + ], + "isUnique": true + } + }, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "verificationToken": { + "name": "verificationToken", + "columns": { + "identifier": { + "name": "identifier", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "token": { + "name": "token", + "type": "text", + "primaryKey": false, + "notNull": true, + "autoincrement": false + }, + "expires": { + "name": "expires", + "type": "integer", + "primaryKey": false, + "notNull": true, + "autoincrement": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": { + "verificationToken_identifier_token_pk": { + "columns": [ + "identifier", + "token" + ], + "name": "verificationToken_identifier_token_pk" + } + }, + "uniqueConstraints": {} } }, "enums": {}, diff --git a/packages/db/migrations/meta/0001_snapshot.json b/packages/db/migrations/meta/0001_snapshot.json deleted file mode 100644 index 40b4da3..0000000 --- a/packages/db/migrations/meta/0001_snapshot.json +++ /dev/null @@ -1,66 +0,0 @@ -{ - "version": "6", - "dialect": "sqlite", - "id": "6ad45ca2-1f2d-4e94-a8fd-b749a8577a61", - "prevId": "74097c41-1958-4fc8-8371-6e31b3071eb9", - "tables": { - "days": { - "name": "days", - "columns": { - "id": { - "name": "id", - "type": "integer", - "primaryKey": true, - "notNull": true, - "autoincrement": true - }, - "mood": { - "name": "mood", - "type": "integer", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "date": { - "name": "date", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "comment": { - "name": "comment", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "days_date_unique": { - "name": "days_date_unique", - "columns": [ - "date" - ], - "isUnique": true - } - }, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - } - }, - "enums": {}, - "_meta": { - "schemas": {}, - "tables": { - "\"events\"": "\"days\"" - }, - "columns": { - "\"days\".\"description\"": "\"days\".\"comment\"" - } - }, - "internal": { - "indexes": {} - } -} \ No newline at end of file diff --git a/packages/db/migrations/meta/0002_snapshot.json b/packages/db/migrations/meta/0002_snapshot.json deleted file mode 100644 index 2f6ea24..0000000 --- a/packages/db/migrations/meta/0002_snapshot.json +++ /dev/null @@ -1,400 +0,0 @@ -{ - "version": "6", - "dialect": "sqlite", - "id": "709a800b-1a51-4e31-96ef-0e8dd1c42a95", - "prevId": "6ad45ca2-1f2d-4e94-a8fd-b749a8577a61", - "tables": { - "account": { - "name": "account", - "columns": { - "userId": { - "name": "userId", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "type": { - "name": "type", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "provider": { - "name": "provider", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "providerAccountId": { - "name": "providerAccountId", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "refresh_token": { - "name": "refresh_token", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "access_token": { - "name": "access_token", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "expires_at": { - "name": "expires_at", - "type": "integer", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "token_type": { - "name": "token_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "scope": { - "name": "scope", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "id_token": { - "name": "id_token", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "session_state": { - "name": "session_state", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "account_userId_user_id_fk": { - "name": "account_userId_user_id_fk", - "tableFrom": "account", - "tableTo": "user", - "columnsFrom": [ - "userId" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": { - "account_provider_providerAccountId_pk": { - "columns": [ - "provider", - "providerAccountId" - ], - "name": "account_provider_providerAccountId_pk" - } - }, - "uniqueConstraints": {} - }, - "apiKey": { - "name": "apiKey", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "createdAt": { - "name": "createdAt", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "keyId": { - "name": "keyId", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "keyHash": { - "name": "keyHash", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "userId": { - "name": "userId", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "apiKey_keyId_unique": { - "name": "apiKey_keyId_unique", - "columns": [ - "keyId" - ], - "isUnique": true - }, - "apiKey_name_userId_unique": { - "name": "apiKey_name_userId_unique", - "columns": [ - "name", - "userId" - ], - "isUnique": true - } - }, - "foreignKeys": { - "apiKey_userId_user_id_fk": { - "name": "apiKey_userId_user_id_fk", - "tableFrom": "apiKey", - "tableTo": "user", - "columnsFrom": [ - "userId" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "session": { - "name": "session", - "columns": { - "sessionToken": { - "name": "sessionToken", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "userId": { - "name": "userId", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "expires": { - "name": "expires", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "session_userId_user_id_fk": { - "name": "session_userId_user_id_fk", - "tableFrom": "session", - "tableTo": "user", - "columnsFrom": [ - "userId" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "user": { - "name": "user", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "email": { - "name": "email", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "emailVerified": { - "name": "emailVerified", - "type": "integer", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "image": { - "name": "image", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "password": { - "name": "password", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "role": { - "name": "role", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false, - "default": "'user'" - } - }, - "indexes": { - "user_email_unique": { - "name": "user_email_unique", - "columns": [ - "email" - ], - "isUnique": true - } - }, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "verificationToken": { - "name": "verificationToken", - "columns": { - "identifier": { - "name": "identifier", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "token": { - "name": "token", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "expires": { - "name": "expires", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": { - "verificationToken_identifier_token_pk": { - "columns": [ - "identifier", - "token" - ], - "name": "verificationToken_identifier_token_pk" - } - }, - "uniqueConstraints": {} - }, - "days": { - "name": "days", - "columns": { - "id": { - "name": "id", - "type": "integer", - "primaryKey": true, - "notNull": true, - "autoincrement": true - }, - "mood": { - "name": "mood", - "type": "integer", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "date": { - "name": "date", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "comment": { - "name": "comment", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "days_date_unique": { - "name": "days_date_unique", - "columns": [ - "date" - ], - "isUnique": true - } - }, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - } - }, - "enums": {}, - "_meta": { - "schemas": {}, - "tables": {}, - "columns": {} - }, - "internal": { - "indexes": {} - } -} \ No newline at end of file diff --git a/packages/db/migrations/meta/0003_snapshot.json b/packages/db/migrations/meta/0003_snapshot.json deleted file mode 100644 index c4c058c..0000000 --- a/packages/db/migrations/meta/0003_snapshot.json +++ /dev/null @@ -1,402 +0,0 @@ -{ - "version": "6", - "dialect": "sqlite", - "id": "67edcacc-ad95-4e34-b368-4beeda535072", - "prevId": "709a800b-1a51-4e31-96ef-0e8dd1c42a95", - "tables": { - "account": { - "name": "account", - "columns": { - "userId": { - "name": "userId", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "type": { - "name": "type", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "provider": { - "name": "provider", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "providerAccountId": { - "name": "providerAccountId", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "refresh_token": { - "name": "refresh_token", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "access_token": { - "name": "access_token", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "expires_at": { - "name": "expires_at", - "type": "integer", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "token_type": { - "name": "token_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "scope": { - "name": "scope", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "id_token": { - "name": "id_token", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "session_state": { - "name": "session_state", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "account_userId_user_id_fk": { - "name": "account_userId_user_id_fk", - "tableFrom": "account", - "tableTo": "user", - "columnsFrom": [ - "userId" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": { - "account_provider_providerAccountId_pk": { - "columns": [ - "provider", - "providerAccountId" - ], - "name": "account_provider_providerAccountId_pk" - } - }, - "uniqueConstraints": {} - }, - "apiKey": { - "name": "apiKey", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "createdAt": { - "name": "createdAt", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "keyId": { - "name": "keyId", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "keyHash": { - "name": "keyHash", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "userId": { - "name": "userId", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "apiKey_keyId_unique": { - "name": "apiKey_keyId_unique", - "columns": [ - "keyId" - ], - "isUnique": true - }, - "apiKey_name_userId_unique": { - "name": "apiKey_name_userId_unique", - "columns": [ - "name", - "userId" - ], - "isUnique": true - } - }, - "foreignKeys": { - "apiKey_userId_user_id_fk": { - "name": "apiKey_userId_user_id_fk", - "tableFrom": "apiKey", - "tableTo": "user", - "columnsFrom": [ - "userId" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "session": { - "name": "session", - "columns": { - "sessionToken": { - "name": "sessionToken", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "userId": { - "name": "userId", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "expires": { - "name": "expires", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "session_userId_user_id_fk": { - "name": "session_userId_user_id_fk", - "tableFrom": "session", - "tableTo": "user", - "columnsFrom": [ - "userId" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "user": { - "name": "user", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "email": { - "name": "email", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "emailVerified": { - "name": "emailVerified", - "type": "integer", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "image": { - "name": "image", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "password": { - "name": "password", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "role": { - "name": "role", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false, - "default": "'user'" - } - }, - "indexes": { - "user_email_unique": { - "name": "user_email_unique", - "columns": [ - "email" - ], - "isUnique": true - } - }, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "verificationToken": { - "name": "verificationToken", - "columns": { - "identifier": { - "name": "identifier", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "token": { - "name": "token", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "expires": { - "name": "expires", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": { - "verificationToken_identifier_token_pk": { - "columns": [ - "identifier", - "token" - ], - "name": "verificationToken_identifier_token_pk" - } - }, - "uniqueConstraints": {} - }, - "day": { - "name": "day", - "columns": { - "id": { - "name": "id", - "type": "integer", - "primaryKey": true, - "notNull": true, - "autoincrement": true - }, - "mood": { - "name": "mood", - "type": "integer", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "date": { - "name": "date", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "comment": { - "name": "comment", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "day_date_unique": { - "name": "day_date_unique", - "columns": [ - "date" - ], - "isUnique": true - } - }, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - } - }, - "enums": {}, - "_meta": { - "schemas": {}, - "tables": { - "\"days\"": "\"day\"" - }, - "columns": {} - }, - "internal": { - "indexes": {} - } -} \ No newline at end of file diff --git a/packages/db/migrations/meta/0004_snapshot.json b/packages/db/migrations/meta/0004_snapshot.json deleted file mode 100644 index 4941b63..0000000 --- a/packages/db/migrations/meta/0004_snapshot.json +++ /dev/null @@ -1,423 +0,0 @@ -{ - "version": "6", - "dialect": "sqlite", - "id": "bcdf4680-869f-4b4a-9690-1bd45a196387", - "prevId": "67edcacc-ad95-4e34-b368-4beeda535072", - "tables": { - "account": { - "name": "account", - "columns": { - "userId": { - "name": "userId", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "type": { - "name": "type", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "provider": { - "name": "provider", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "providerAccountId": { - "name": "providerAccountId", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "refresh_token": { - "name": "refresh_token", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "access_token": { - "name": "access_token", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "expires_at": { - "name": "expires_at", - "type": "integer", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "token_type": { - "name": "token_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "scope": { - "name": "scope", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "id_token": { - "name": "id_token", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "session_state": { - "name": "session_state", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "account_userId_user_id_fk": { - "name": "account_userId_user_id_fk", - "tableFrom": "account", - "tableTo": "user", - "columnsFrom": [ - "userId" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": { - "account_provider_providerAccountId_pk": { - "columns": [ - "provider", - "providerAccountId" - ], - "name": "account_provider_providerAccountId_pk" - } - }, - "uniqueConstraints": {} - }, - "apiKey": { - "name": "apiKey", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "createdAt": { - "name": "createdAt", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "keyId": { - "name": "keyId", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "keyHash": { - "name": "keyHash", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "userId": { - "name": "userId", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "apiKey_keyId_unique": { - "name": "apiKey_keyId_unique", - "columns": [ - "keyId" - ], - "isUnique": true - }, - "apiKey_name_userId_unique": { - "name": "apiKey_name_userId_unique", - "columns": [ - "name", - "userId" - ], - "isUnique": true - } - }, - "foreignKeys": { - "apiKey_userId_user_id_fk": { - "name": "apiKey_userId_user_id_fk", - "tableFrom": "apiKey", - "tableTo": "user", - "columnsFrom": [ - "userId" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "config": { - "name": "config", - "columns": { - "key": { - "name": "key", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "value": { - "name": "value", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "day": { - "name": "day", - "columns": { - "id": { - "name": "id", - "type": "integer", - "primaryKey": true, - "notNull": true, - "autoincrement": true - }, - "mood": { - "name": "mood", - "type": "integer", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "date": { - "name": "date", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "comment": { - "name": "comment", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "day_date_unique": { - "name": "day_date_unique", - "columns": [ - "date" - ], - "isUnique": true - } - }, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "session": { - "name": "session", - "columns": { - "sessionToken": { - "name": "sessionToken", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "userId": { - "name": "userId", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "expires": { - "name": "expires", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "session_userId_user_id_fk": { - "name": "session_userId_user_id_fk", - "tableFrom": "session", - "tableTo": "user", - "columnsFrom": [ - "userId" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "user": { - "name": "user", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "email": { - "name": "email", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "emailVerified": { - "name": "emailVerified", - "type": "integer", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "image": { - "name": "image", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "password": { - "name": "password", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "role": { - "name": "role", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false, - "default": "'user'" - } - }, - "indexes": { - "user_email_unique": { - "name": "user_email_unique", - "columns": [ - "email" - ], - "isUnique": true - } - }, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "verificationToken": { - "name": "verificationToken", - "columns": { - "identifier": { - "name": "identifier", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "token": { - "name": "token", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "expires": { - "name": "expires", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": { - "verificationToken_identifier_token_pk": { - "columns": [ - "identifier", - "token" - ], - "name": "verificationToken_identifier_token_pk" - } - }, - "uniqueConstraints": {} - } - }, - "enums": {}, - "_meta": { - "schemas": {}, - "tables": {}, - "columns": {} - }, - "internal": { - "indexes": {} - } -} \ No newline at end of file diff --git a/packages/db/migrations/meta/0005_snapshot.json b/packages/db/migrations/meta/0005_snapshot.json deleted file mode 100644 index 3ccb61e..0000000 --- a/packages/db/migrations/meta/0005_snapshot.json +++ /dev/null @@ -1,497 +0,0 @@ -{ - "version": "6", - "dialect": "sqlite", - "id": "06e873b5-ab39-469c-9437-bb1cf4bc60e8", - "prevId": "bcdf4680-869f-4b4a-9690-1bd45a196387", - "tables": { - "account": { - "name": "account", - "columns": { - "userId": { - "name": "userId", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "type": { - "name": "type", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "provider": { - "name": "provider", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "providerAccountId": { - "name": "providerAccountId", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "refresh_token": { - "name": "refresh_token", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "access_token": { - "name": "access_token", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "expires_at": { - "name": "expires_at", - "type": "integer", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "token_type": { - "name": "token_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "scope": { - "name": "scope", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "id_token": { - "name": "id_token", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "session_state": { - "name": "session_state", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "account_userId_user_id_fk": { - "name": "account_userId_user_id_fk", - "tableFrom": "account", - "tableTo": "user", - "columnsFrom": [ - "userId" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": { - "account_provider_providerAccountId_pk": { - "columns": [ - "provider", - "providerAccountId" - ], - "name": "account_provider_providerAccountId_pk" - } - }, - "uniqueConstraints": {} - }, - "apiKey": { - "name": "apiKey", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "createdAt": { - "name": "createdAt", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "keyId": { - "name": "keyId", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "keyHash": { - "name": "keyHash", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "userId": { - "name": "userId", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "apiKey_keyId_unique": { - "name": "apiKey_keyId_unique", - "columns": [ - "keyId" - ], - "isUnique": true - }, - "apiKey_name_userId_unique": { - "name": "apiKey_name_userId_unique", - "columns": [ - "name", - "userId" - ], - "isUnique": true - } - }, - "foreignKeys": { - "apiKey_userId_user_id_fk": { - "name": "apiKey_userId_user_id_fk", - "tableFrom": "apiKey", - "tableTo": "user", - "columnsFrom": [ - "userId" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "config": { - "name": "config", - "columns": { - "key": { - "name": "key", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "value": { - "name": "value", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "day": { - "name": "day", - "columns": { - "id": { - "name": "id", - "type": "integer", - "primaryKey": true, - "notNull": true, - "autoincrement": true - }, - "mood": { - "name": "mood", - "type": "integer", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "date": { - "name": "date", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "comment": { - "name": "comment", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "day_date_unique": { - "name": "day_date_unique", - "columns": [ - "date" - ], - "isUnique": true - } - }, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "label": { - "name": "label", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "createdAt": { - "name": "createdAt", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "userId": { - "name": "userId", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "labels_name_idx": { - "name": "labels_name_idx", - "columns": [ - "name" - ], - "isUnique": false - }, - "labels_userId_idx": { - "name": "labels_userId_idx", - "columns": [ - "userId" - ], - "isUnique": false - }, - "label_userId_name_unique": { - "name": "label_userId_name_unique", - "columns": [ - "userId", - "name" - ], - "isUnique": true - } - }, - "foreignKeys": { - "label_userId_user_id_fk": { - "name": "label_userId_user_id_fk", - "tableFrom": "label", - "tableTo": "user", - "columnsFrom": [ - "userId" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "session": { - "name": "session", - "columns": { - "sessionToken": { - "name": "sessionToken", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "userId": { - "name": "userId", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "expires": { - "name": "expires", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "session_userId_user_id_fk": { - "name": "session_userId_user_id_fk", - "tableFrom": "session", - "tableTo": "user", - "columnsFrom": [ - "userId" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "user": { - "name": "user", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "email": { - "name": "email", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "emailVerified": { - "name": "emailVerified", - "type": "integer", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "image": { - "name": "image", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "password": { - "name": "password", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "role": { - "name": "role", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false, - "default": "'user'" - } - }, - "indexes": { - "user_email_unique": { - "name": "user_email_unique", - "columns": [ - "email" - ], - "isUnique": true - } - }, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "verificationToken": { - "name": "verificationToken", - "columns": { - "identifier": { - "name": "identifier", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "token": { - "name": "token", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "expires": { - "name": "expires", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": { - "verificationToken_identifier_token_pk": { - "columns": [ - "identifier", - "token" - ], - "name": "verificationToken_identifier_token_pk" - } - }, - "uniqueConstraints": {} - } - }, - "enums": {}, - "_meta": { - "schemas": {}, - "tables": {}, - "columns": {} - }, - "internal": { - "indexes": {} - } -} \ No newline at end of file diff --git a/packages/db/migrations/meta/0006_snapshot.json b/packages/db/migrations/meta/0006_snapshot.json deleted file mode 100644 index 849d489..0000000 --- a/packages/db/migrations/meta/0006_snapshot.json +++ /dev/null @@ -1,498 +0,0 @@ -{ - "version": "6", - "dialect": "sqlite", - "id": "22c67302-ebcd-4ad9-8393-feea41c17455", - "prevId": "06e873b5-ab39-469c-9437-bb1cf4bc60e8", - "tables": { - "account": { - "name": "account", - "columns": { - "userId": { - "name": "userId", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "type": { - "name": "type", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "provider": { - "name": "provider", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "providerAccountId": { - "name": "providerAccountId", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "refresh_token": { - "name": "refresh_token", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "access_token": { - "name": "access_token", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "expires_at": { - "name": "expires_at", - "type": "integer", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "token_type": { - "name": "token_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "scope": { - "name": "scope", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "id_token": { - "name": "id_token", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "session_state": { - "name": "session_state", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "account_userId_user_id_fk": { - "name": "account_userId_user_id_fk", - "tableFrom": "account", - "tableTo": "user", - "columnsFrom": [ - "userId" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": { - "account_provider_providerAccountId_pk": { - "columns": [ - "provider", - "providerAccountId" - ], - "name": "account_provider_providerAccountId_pk" - } - }, - "uniqueConstraints": {} - }, - "apiKey": { - "name": "apiKey", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "createdAt": { - "name": "createdAt", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "keyId": { - "name": "keyId", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "keyHash": { - "name": "keyHash", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "userId": { - "name": "userId", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "apiKey_keyId_unique": { - "name": "apiKey_keyId_unique", - "columns": [ - "keyId" - ], - "isUnique": true - }, - "apiKey_name_userId_unique": { - "name": "apiKey_name_userId_unique", - "columns": [ - "name", - "userId" - ], - "isUnique": true - } - }, - "foreignKeys": { - "apiKey_userId_user_id_fk": { - "name": "apiKey_userId_user_id_fk", - "tableFrom": "apiKey", - "tableTo": "user", - "columnsFrom": [ - "userId" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "config": { - "name": "config", - "columns": { - "key": { - "name": "key", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "value": { - "name": "value", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "day": { - "name": "day", - "columns": { - "id": { - "name": "id", - "type": "integer", - "primaryKey": true, - "notNull": true, - "autoincrement": true - }, - "mood": { - "name": "mood", - "type": "integer", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "date": { - "name": "date", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "comment": { - "name": "comment", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "day_date_unique": { - "name": "day_date_unique", - "columns": [ - "date" - ], - "isUnique": true - } - }, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "label": { - "name": "label", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "createdAt": { - "name": "createdAt", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "description": { - "name": "description", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "color": { - "name": "color", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false, - "default": "'#000000'" - }, - "userId": { - "name": "userId", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "label_userId_name_unique": { - "name": "label_userId_name_unique", - "columns": [ - "userId", - "name" - ], - "isUnique": true - } - }, - "foreignKeys": { - "label_userId_user_id_fk": { - "name": "label_userId_user_id_fk", - "tableFrom": "label", - "tableTo": "user", - "columnsFrom": [ - "userId" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "session": { - "name": "session", - "columns": { - "sessionToken": { - "name": "sessionToken", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "userId": { - "name": "userId", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "expires": { - "name": "expires", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "session_userId_user_id_fk": { - "name": "session_userId_user_id_fk", - "tableFrom": "session", - "tableTo": "user", - "columnsFrom": [ - "userId" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "user": { - "name": "user", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "email": { - "name": "email", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "emailVerified": { - "name": "emailVerified", - "type": "integer", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "image": { - "name": "image", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "password": { - "name": "password", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "role": { - "name": "role", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false, - "default": "'user'" - } - }, - "indexes": { - "user_email_unique": { - "name": "user_email_unique", - "columns": [ - "email" - ], - "isUnique": true - } - }, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "verificationToken": { - "name": "verificationToken", - "columns": { - "identifier": { - "name": "identifier", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "token": { - "name": "token", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "expires": { - "name": "expires", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": { - "verificationToken_identifier_token_pk": { - "columns": [ - "identifier", - "token" - ], - "name": "verificationToken_identifier_token_pk" - } - }, - "uniqueConstraints": {} - } - }, - "enums": {}, - "_meta": { - "schemas": {}, - "tables": {}, - "columns": {} - }, - "internal": { - "indexes": {} - } -} \ No newline at end of file diff --git a/packages/db/migrations/meta/0007_snapshot.json b/packages/db/migrations/meta/0007_snapshot.json deleted file mode 100644 index a9be07d..0000000 --- a/packages/db/migrations/meta/0007_snapshot.json +++ /dev/null @@ -1,505 +0,0 @@ -{ - "version": "6", - "dialect": "sqlite", - "id": "d5294e8b-976b-4c92-bc82-b4e35e2683bb", - "prevId": "22c67302-ebcd-4ad9-8393-feea41c17455", - "tables": { - "account": { - "name": "account", - "columns": { - "userId": { - "name": "userId", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "type": { - "name": "type", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "provider": { - "name": "provider", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "providerAccountId": { - "name": "providerAccountId", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "refresh_token": { - "name": "refresh_token", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "access_token": { - "name": "access_token", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "expires_at": { - "name": "expires_at", - "type": "integer", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "token_type": { - "name": "token_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "scope": { - "name": "scope", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "id_token": { - "name": "id_token", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "session_state": { - "name": "session_state", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "account_userId_user_id_fk": { - "name": "account_userId_user_id_fk", - "tableFrom": "account", - "tableTo": "user", - "columnsFrom": [ - "userId" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": { - "account_provider_providerAccountId_pk": { - "columns": [ - "provider", - "providerAccountId" - ], - "name": "account_provider_providerAccountId_pk" - } - }, - "uniqueConstraints": {} - }, - "apiKey": { - "name": "apiKey", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "createdAt": { - "name": "createdAt", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "keyId": { - "name": "keyId", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "keyHash": { - "name": "keyHash", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "userId": { - "name": "userId", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "apiKey_keyId_unique": { - "name": "apiKey_keyId_unique", - "columns": [ - "keyId" - ], - "isUnique": true - }, - "apiKey_name_userId_unique": { - "name": "apiKey_name_userId_unique", - "columns": [ - "name", - "userId" - ], - "isUnique": true - } - }, - "foreignKeys": { - "apiKey_userId_user_id_fk": { - "name": "apiKey_userId_user_id_fk", - "tableFrom": "apiKey", - "tableTo": "user", - "columnsFrom": [ - "userId" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "config": { - "name": "config", - "columns": { - "key": { - "name": "key", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "value": { - "name": "value", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "day": { - "name": "day", - "columns": { - "id": { - "name": "id", - "type": "integer", - "primaryKey": true, - "notNull": true, - "autoincrement": true - }, - "mood": { - "name": "mood", - "type": "integer", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "date": { - "name": "date", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "comment": { - "name": "comment", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "day_date_unique": { - "name": "day_date_unique", - "columns": [ - "date" - ], - "isUnique": true - } - }, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "label": { - "name": "label", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "createdAt": { - "name": "createdAt", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "code": { - "name": "code", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "description": { - "name": "description", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "color": { - "name": "color", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false, - "default": "'#000000'" - }, - "userId": { - "name": "userId", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "label_userId_name_unique": { - "name": "label_userId_name_unique", - "columns": [ - "userId", - "name" - ], - "isUnique": true - } - }, - "foreignKeys": { - "label_userId_user_id_fk": { - "name": "label_userId_user_id_fk", - "tableFrom": "label", - "tableTo": "user", - "columnsFrom": [ - "userId" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "session": { - "name": "session", - "columns": { - "sessionToken": { - "name": "sessionToken", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "userId": { - "name": "userId", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "expires": { - "name": "expires", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "session_userId_user_id_fk": { - "name": "session_userId_user_id_fk", - "tableFrom": "session", - "tableTo": "user", - "columnsFrom": [ - "userId" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "user": { - "name": "user", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "email": { - "name": "email", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "emailVerified": { - "name": "emailVerified", - "type": "integer", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "image": { - "name": "image", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "password": { - "name": "password", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "role": { - "name": "role", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false, - "default": "'user'" - } - }, - "indexes": { - "user_email_unique": { - "name": "user_email_unique", - "columns": [ - "email" - ], - "isUnique": true - } - }, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "verificationToken": { - "name": "verificationToken", - "columns": { - "identifier": { - "name": "identifier", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "token": { - "name": "token", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "expires": { - "name": "expires", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": { - "verificationToken_identifier_token_pk": { - "columns": [ - "identifier", - "token" - ], - "name": "verificationToken_identifier_token_pk" - } - }, - "uniqueConstraints": {} - } - }, - "enums": {}, - "_meta": { - "schemas": {}, - "tables": {}, - "columns": {} - }, - "internal": { - "indexes": {} - } -} \ No newline at end of file diff --git a/packages/db/migrations/meta/0008_snapshot.json b/packages/db/migrations/meta/0008_snapshot.json deleted file mode 100644 index 0bfb8dd..0000000 --- a/packages/db/migrations/meta/0008_snapshot.json +++ /dev/null @@ -1,525 +0,0 @@ -{ - "version": "6", - "dialect": "sqlite", - "id": "fb2c8ded-5e0a-4d12-b729-a5d89be3ca14", - "prevId": "d5294e8b-976b-4c92-bc82-b4e35e2683bb", - "tables": { - "account": { - "name": "account", - "columns": { - "userId": { - "name": "userId", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "type": { - "name": "type", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "provider": { - "name": "provider", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "providerAccountId": { - "name": "providerAccountId", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "refresh_token": { - "name": "refresh_token", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "access_token": { - "name": "access_token", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "expires_at": { - "name": "expires_at", - "type": "integer", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "token_type": { - "name": "token_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "scope": { - "name": "scope", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "id_token": { - "name": "id_token", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "session_state": { - "name": "session_state", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "account_userId_user_id_fk": { - "name": "account_userId_user_id_fk", - "tableFrom": "account", - "tableTo": "user", - "columnsFrom": [ - "userId" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": { - "account_provider_providerAccountId_pk": { - "columns": [ - "provider", - "providerAccountId" - ], - "name": "account_provider_providerAccountId_pk" - } - }, - "uniqueConstraints": {} - }, - "apiKey": { - "name": "apiKey", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "createdAt": { - "name": "createdAt", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "keyId": { - "name": "keyId", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "keyHash": { - "name": "keyHash", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "userId": { - "name": "userId", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "apiKey_keyId_unique": { - "name": "apiKey_keyId_unique", - "columns": [ - "keyId" - ], - "isUnique": true - }, - "apiKey_name_userId_unique": { - "name": "apiKey_name_userId_unique", - "columns": [ - "name", - "userId" - ], - "isUnique": true - } - }, - "foreignKeys": { - "apiKey_userId_user_id_fk": { - "name": "apiKey_userId_user_id_fk", - "tableFrom": "apiKey", - "tableTo": "user", - "columnsFrom": [ - "userId" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "config": { - "name": "config", - "columns": { - "key": { - "name": "key", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "value": { - "name": "value", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "day": { - "name": "day", - "columns": { - "id": { - "name": "id", - "type": "integer", - "primaryKey": true, - "notNull": true, - "autoincrement": true - }, - "mood": { - "name": "mood", - "type": "integer", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "date": { - "name": "date", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "comment": { - "name": "comment", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "day_date_unique": { - "name": "day_date_unique", - "columns": [ - "date" - ], - "isUnique": true - } - }, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "label": { - "name": "label", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "createdAt": { - "name": "createdAt", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "code": { - "name": "code", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "description": { - "name": "description", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "color": { - "name": "color", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false, - "default": "'#000000'" - }, - "parentId": { - "name": "parentId", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "userId": { - "name": "userId", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "label_userId_name_unique": { - "name": "label_userId_name_unique", - "columns": [ - "userId", - "name" - ], - "isUnique": true - } - }, - "foreignKeys": { - "label_parentId_label_id_fk": { - "name": "label_parentId_label_id_fk", - "tableFrom": "label", - "tableTo": "label", - "columnsFrom": [ - "parentId" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - }, - "label_userId_user_id_fk": { - "name": "label_userId_user_id_fk", - "tableFrom": "label", - "tableTo": "user", - "columnsFrom": [ - "userId" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "session": { - "name": "session", - "columns": { - "sessionToken": { - "name": "sessionToken", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "userId": { - "name": "userId", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "expires": { - "name": "expires", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "session_userId_user_id_fk": { - "name": "session_userId_user_id_fk", - "tableFrom": "session", - "tableTo": "user", - "columnsFrom": [ - "userId" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "user": { - "name": "user", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "email": { - "name": "email", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "emailVerified": { - "name": "emailVerified", - "type": "integer", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "image": { - "name": "image", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "password": { - "name": "password", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "role": { - "name": "role", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false, - "default": "'user'" - } - }, - "indexes": { - "user_email_unique": { - "name": "user_email_unique", - "columns": [ - "email" - ], - "isUnique": true - } - }, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "verificationToken": { - "name": "verificationToken", - "columns": { - "identifier": { - "name": "identifier", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "token": { - "name": "token", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "expires": { - "name": "expires", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": { - "verificationToken_identifier_token_pk": { - "columns": [ - "identifier", - "token" - ], - "name": "verificationToken_identifier_token_pk" - } - }, - "uniqueConstraints": {} - } - }, - "enums": {}, - "_meta": { - "schemas": {}, - "tables": {}, - "columns": {} - }, - "internal": { - "indexes": {} - } -} \ No newline at end of file diff --git a/packages/db/migrations/meta/0009_snapshot.json b/packages/db/migrations/meta/0009_snapshot.json deleted file mode 100644 index 8154d42..0000000 --- a/packages/db/migrations/meta/0009_snapshot.json +++ /dev/null @@ -1,505 +0,0 @@ -{ - "version": "6", - "dialect": "sqlite", - "id": "c4fbb77c-3439-446a-92e4-14a4b681f83e", - "prevId": "fb2c8ded-5e0a-4d12-b729-a5d89be3ca14", - "tables": { - "account": { - "name": "account", - "columns": { - "userId": { - "name": "userId", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "type": { - "name": "type", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "provider": { - "name": "provider", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "providerAccountId": { - "name": "providerAccountId", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "refresh_token": { - "name": "refresh_token", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "access_token": { - "name": "access_token", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "expires_at": { - "name": "expires_at", - "type": "integer", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "token_type": { - "name": "token_type", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "scope": { - "name": "scope", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "id_token": { - "name": "id_token", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "session_state": { - "name": "session_state", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "account_userId_user_id_fk": { - "name": "account_userId_user_id_fk", - "tableFrom": "account", - "tableTo": "user", - "columnsFrom": [ - "userId" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": { - "account_provider_providerAccountId_pk": { - "columns": [ - "provider", - "providerAccountId" - ], - "name": "account_provider_providerAccountId_pk" - } - }, - "uniqueConstraints": {} - }, - "apiKey": { - "name": "apiKey", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "createdAt": { - "name": "createdAt", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "keyId": { - "name": "keyId", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "keyHash": { - "name": "keyHash", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "userId": { - "name": "userId", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "apiKey_keyId_unique": { - "name": "apiKey_keyId_unique", - "columns": [ - "keyId" - ], - "isUnique": true - }, - "apiKey_name_userId_unique": { - "name": "apiKey_name_userId_unique", - "columns": [ - "name", - "userId" - ], - "isUnique": true - } - }, - "foreignKeys": { - "apiKey_userId_user_id_fk": { - "name": "apiKey_userId_user_id_fk", - "tableFrom": "apiKey", - "tableTo": "user", - "columnsFrom": [ - "userId" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "config": { - "name": "config", - "columns": { - "key": { - "name": "key", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "value": { - "name": "value", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "day": { - "name": "day", - "columns": { - "id": { - "name": "id", - "type": "integer", - "primaryKey": true, - "notNull": true, - "autoincrement": true - }, - "mood": { - "name": "mood", - "type": "integer", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "date": { - "name": "date", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "comment": { - "name": "comment", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "day_date_unique": { - "name": "day_date_unique", - "columns": [ - "date" - ], - "isUnique": true - } - }, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "label": { - "name": "label", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "createdAt": { - "name": "createdAt", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "code": { - "name": "code", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "description": { - "name": "description", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "color": { - "name": "color", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false, - "default": "'#000000'" - }, - "userId": { - "name": "userId", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": { - "label_userId_name_unique": { - "name": "label_userId_name_unique", - "columns": [ - "userId", - "name" - ], - "isUnique": true - } - }, - "foreignKeys": { - "label_userId_user_id_fk": { - "name": "label_userId_user_id_fk", - "tableFrom": "label", - "tableTo": "user", - "columnsFrom": [ - "userId" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "session": { - "name": "session", - "columns": { - "sessionToken": { - "name": "sessionToken", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "userId": { - "name": "userId", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "expires": { - "name": "expires", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": { - "session_userId_user_id_fk": { - "name": "session_userId_user_id_fk", - "tableFrom": "session", - "tableTo": "user", - "columnsFrom": [ - "userId" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "user": { - "name": "user", - "columns": { - "id": { - "name": "id", - "type": "text", - "primaryKey": true, - "notNull": true, - "autoincrement": false - }, - "name": { - "name": "name", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "email": { - "name": "email", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "emailVerified": { - "name": "emailVerified", - "type": "integer", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "image": { - "name": "image", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "password": { - "name": "password", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false - }, - "role": { - "name": "role", - "type": "text", - "primaryKey": false, - "notNull": false, - "autoincrement": false, - "default": "'user'" - } - }, - "indexes": { - "user_email_unique": { - "name": "user_email_unique", - "columns": [ - "email" - ], - "isUnique": true - } - }, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "verificationToken": { - "name": "verificationToken", - "columns": { - "identifier": { - "name": "identifier", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "token": { - "name": "token", - "type": "text", - "primaryKey": false, - "notNull": true, - "autoincrement": false - }, - "expires": { - "name": "expires", - "type": "integer", - "primaryKey": false, - "notNull": true, - "autoincrement": false - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": { - "verificationToken_identifier_token_pk": { - "columns": [ - "identifier", - "token" - ], - "name": "verificationToken_identifier_token_pk" - } - }, - "uniqueConstraints": {} - } - }, - "enums": {}, - "_meta": { - "schemas": {}, - "tables": {}, - "columns": {} - }, - "internal": { - "indexes": {} - } -} \ No newline at end of file diff --git a/packages/db/migrations/meta/_journal.json b/packages/db/migrations/meta/_journal.json index 5204fec..9d840bf 100644 --- a/packages/db/migrations/meta/_journal.json +++ b/packages/db/migrations/meta/_journal.json @@ -5,71 +5,8 @@ { "idx": 0, "version": "6", - "when": 1728109876982, - "tag": "0000_worried_may_parker", - "breakpoints": true - }, - { - "idx": 1, - "version": "6", - "when": 1731100507972, - "tag": "0001_hard_lionheart", - "breakpoints": true - }, - { - "idx": 2, - "version": "6", - "when": 1731542160896, - "tag": "0002_minor_toxin", - "breakpoints": true - }, - { - "idx": 3, - "version": "6", - "when": 1731542202120, - "tag": "0003_complex_ares", - "breakpoints": true - }, - { - "idx": 4, - "version": "6", - "when": 1731637559763, - "tag": "0004_sad_sally_floyd", - "breakpoints": true - }, - { - "idx": 5, - "version": "6", - "when": 1731648881226, - "tag": "0005_ambitious_famine", - "breakpoints": true - }, - { - "idx": 6, - "version": "6", - "when": 1731649046343, - "tag": "0006_milky_hellion", - "breakpoints": true - }, - { - "idx": 7, - "version": "6", - "when": 1731656341890, - "tag": "0007_unusual_terror", - "breakpoints": true - }, - { - "idx": 8, - "version": "6", - "when": 1731660055561, - "tag": "0008_gray_selene", - "breakpoints": true - }, - { - "idx": 9, - "version": "6", - "when": 1731660203861, - "tag": "0009_ordinary_electro", + "when": 1732260188078, + "tag": "0000_gigantic_doctor_strange", "breakpoints": true } ] diff --git a/packages/db/package.json b/packages/db/package.json index 2c4bca6..411de91 100644 --- a/packages/db/package.json +++ b/packages/db/package.json @@ -7,6 +7,7 @@ "scripts": { "dev": "drizzle-kit studio", "generate": "drizzle-kit generate", + "reset": "tsc reset.ts", "typecheck": "tsc --noEmit", "migrate": "tsx migrate.ts", "studio": "drizzle-kit studio" diff --git a/packages/db/reset.ts b/packages/db/reset.ts new file mode 100644 index 0000000..c5f33ca --- /dev/null +++ b/packages/db/reset.ts @@ -0,0 +1,27 @@ +import { db } from "./drizzle"; +import { apiKeys, users } from "./schema"; +import { generateApiKey } from "../trpc/auth"; +import { and, count, eq } from "drizzle-orm"; + +db.transaction(async (trx) => { + const ryan = await trx + .insert(users) + .values({ + name: "Ryan Pandya", + email: "ryan@ryanpandya.com", + password: "$2a$10$ngv9752uxDT11hSPfdZmAe2D8VXLB9mcXkN7TRPI5GZQCuriIu1gC", + role: "admin", + }) + .returning({ + id: users.id, + name: users.name, + email: users.email, + role: users.role, + }); + + db.query.users.findFirst({ + where: eq(users.email, "ryan@ryanpandya.com"), + }).then((user) => { + generateApiKey("CLI App", ryan.id); + }); +}); diff --git a/packages/db/schema.ts b/packages/db/schema.ts index 1bd828b..8b47144 100644 --- a/packages/db/schema.ts +++ b/packages/db/schema.ts @@ -1,6 +1,6 @@ import type { AdapterAccount } from "@auth/core/adapters"; import { createId } from "@paralleldrive/cuid2"; -import { relations } from "drizzle-orm"; +import { relations, SQL, sql } from "drizzle-orm"; import { AnySQLiteColumn, index, @@ -9,6 +9,7 @@ import { sqliteTable, text, unique, + } from "drizzle-orm/sqlite-core"; function createdAtField() { @@ -17,6 +18,23 @@ function createdAtField() { .$defaultFn(() => new Date()); } +export function calcInverseColor(hexcode: string): string { + console.log(hexcode); + const hex = hexcode.replace("#", ""); + const r = parseInt(hex.substr(0, 2), 16); + const g = parseInt(hex.substr(2, 2), 16); + const b = parseInt(hex.substr(4, 2), 16); + const luminance = r * 0.299 + g * 0.587 + b * 0.114; + return luminance > 186 ? "#000000" : "#ffffff"; +} + + + +export const config = sqliteTable("config", { + key: text("key").notNull().primaryKey(), + value: text("value").notNull(), +}); + export const apiKeys = sqliteTable( "apiKey", { @@ -105,8 +123,27 @@ export const days = sqliteTable("day", { comment: text("comment").notNull(), }); -export const labels = sqliteTable( - "label", +export const colors = sqliteTable( + "color", + { + id: text("id") + .notNull() + .primaryKey() + .$defaultFn(() => createId()), + createdAt: createdAtField(), + name: text("name").notNull(), + hexcode: text("hexcode").notNull(), + inverse: text("inverse"), + userId: text("userId") + .notNull() + .references(() => users.id, { onDelete: "cascade" }), + }, + (c) => ({ + uniq: unique().on(c.userId, c.name) + }), +); +export const categories = sqliteTable( + "category", { id: text("id") .notNull() @@ -116,7 +153,10 @@ export const labels = sqliteTable( name: text("name").notNull(), code: integer("code").notNull(), description: text("description"), - color: text("color").default("#000000"), + colorId: text("colorId") + .notNull() + .references(() => colors.id), + parentId: text("parentId").references(() => categories.id), userId: text("userId") .notNull() .references(() => users.id, { onDelete: "cascade" }), @@ -126,11 +166,6 @@ export const labels = sqliteTable( }), ); -export const config = sqliteTable("config", { - key: text("key").notNull().primaryKey(), - value: text("value").notNull(), -}); - // Relations export const apiKeyRelations = relations(apiKeys, ({ one }) => ({ @@ -140,16 +175,36 @@ export const apiKeyRelations = relations(apiKeys, ({ one }) => ({ }), })); export const userRelations = relations(users, ({ many }) => ({ - labels: many(labels), + categories: many(categories), + colors: many(colors), })); -export const labelsRelations = relations( - labels, +export const categoriesRelations = relations( + categories, ({ many, one }) => ({ user: one(users, { - fields: [labels.userId], + fields: [categories.userId], references: [users.id], }), + color: one(colors, { + fields: [categories.colorId], + references: [colors.id], + }), + parent: one(categories, { + fields: [categories.parentId], + references: [categories.id], + }), + }), +); + +export const colorsRelations = relations( + colors, + ({ many, one }) => ({ + user: one(users, { + fields: [colors.userId], + references: [users.id], + }), + categories: many(categories), }), ); \ No newline at end of file diff --git a/packages/shared-react/hooks/labels.ts b/packages/shared-react/hooks/categories.ts similarity index 100% rename from packages/shared-react/hooks/labels.ts rename to packages/shared-react/hooks/categories.ts diff --git a/packages/shared/colors.ts b/packages/shared/colors.ts new file mode 100644 index 0000000..e69de29 diff --git a/packages/shared/types/labels.ts b/packages/shared/types/categories.ts similarity index 51% rename from packages/shared/types/labels.ts rename to packages/shared/types/categories.ts index ecac0c3..34b7ec2 100644 --- a/packages/shared/types/labels.ts +++ b/packages/shared/types/categories.ts @@ -1,25 +1,25 @@ import { z } from "zod"; -export const zLabelSchema = z.object({ +export const zCategorySchema = z.object({ id: z.string(), code: z.coerce.number(), name: z.string(), - color: z.string().default("#000000"), + colorId: z.string(), description: z.string().optional(), }); -export type ZLabels = z.infer; +export type ZCategories = z.infer; -export const zGetLabelResponseSchema = z.object({ +export const zGetCategoryResponseSchema = z.object({ id: z.string(), code: z.number(), - color: z.string(), + colorId: z.string(), description: z.string().optional(), name: z.string(), numEntries: z.number(), }); -export type ZGetLabelResponse = z.infer; +export type ZGetCategoryResponse = z.infer; -export const zUpdateLabelRequestSchema = z.object({ +export const zUpdateCategoryRequestSchema = z.object({ labelId: z.string(), code: z.number(), name: z.string().optional(), diff --git a/packages/shared/types/colors.ts b/packages/shared/types/colors.ts new file mode 100644 index 0000000..abf3e0c --- /dev/null +++ b/packages/shared/types/colors.ts @@ -0,0 +1,7 @@ +import { z } from "zod"; + +export const zColorSchema = z.object({ + name: z.string(), + hexcode: z.string(), +}); +export type ZColor = z.infer; diff --git a/packages/trpc/routers/_app.ts b/packages/trpc/routers/_app.ts index 0cdd3f3..9f6ff43 100644 --- a/packages/trpc/routers/_app.ts +++ b/packages/trpc/routers/_app.ts @@ -3,13 +3,15 @@ import { router } from "../index"; import { usersAppRouter } from "./users"; import { apiKeysAppRouter } from "./apiKeys"; import { adminAppRouter } from "./admin"; -import { labelsAppRouter } from "./labels"; +import { categoriesAppRouter } from "./categories"; +import { colorsAppRouter } from "./colors"; export const appRouter = router({ users: usersAppRouter, apiKeys: apiKeysAppRouter, admin: adminAppRouter, - labels: labelsAppRouter, + colors: colorsAppRouter, + categories: categoriesAppRouter, }); // export type definition of API export type AppRouter = typeof appRouter; \ No newline at end of file diff --git a/packages/trpc/routers/labels.ts b/packages/trpc/routers/categories.ts similarity index 70% rename from packages/trpc/routers/labels.ts rename to packages/trpc/routers/categories.ts index 0bfa9b5..88749ca 100644 --- a/packages/trpc/routers/labels.ts +++ b/packages/trpc/routers/categories.ts @@ -3,32 +3,32 @@ import { and, desc, eq, inArray, notExists } from "drizzle-orm"; import { z } from "zod"; import { SqliteError } from "@lifetracker/db"; -import { labels } from "@lifetracker/db/schema"; +import { categories } from "@lifetracker/db/schema"; import { - zLabelSchema, - zGetLabelResponseSchema, - zUpdateLabelRequestSchema -} from "@lifetracker/shared/types/labels"; + zCategorySchema, + zGetCategoryResponseSchema, + zUpdateCategoryRequestSchema +} from "@lifetracker/shared/types/categories"; import type { Context } from "../index"; import { authedProcedure, router } from "../index"; -function conditionFromInput(input: { labelId: string }, userId: string) { - return and(eq(labels.id, input.labelId), eq(labels.userId, userId)); +function conditionFromInput(input: { categoryId: string }, userId: string) { + return and(eq(categories.id, input.categoryId), eq(categories.userId, userId)); } -async function createLabel( - input: z.infer, +async function createCategory( + input: z.infer, ctx: Context, ) { - console.log("Creating a label"); + console.log("Creating a category"); return ctx.db.transaction(async (trx) => { try { const result = await trx - .insert(labels) + .insert(categories) .values({ name: input.name, code: input.code, @@ -37,11 +37,11 @@ async function createLabel( userId: ctx.user!.id, }) .returning({ - id: labels.id, - name: labels.name, - code: labels.code, - description: labels.description, - color: labels.color, + id: categories.id, + name: categories.name, + code: categories.code, + description: categories.description, + color: categories.color, }); return result[0]; } catch (e) { @@ -49,7 +49,7 @@ async function createLabel( if (e.code == "SQLITE_CONSTRAINT_UNIQUE") { throw new TRPCError({ code: "BAD_REQUEST", - message: "Line 48 trpc routers labels.ts", + message: "Line 48 trpc routers categories.ts", }); } } @@ -61,8 +61,8 @@ async function createLabel( }); } -export const labelsAppRouter = router({ - labelStats: authedProcedure +export const categoriesAppRouter = router({ + categoryStats: authedProcedure .output( z.record( z.string(), @@ -72,16 +72,16 @@ export const labelsAppRouter = router({ ), ) .query(async ({ ctx }) => { - const [labelIds] = await Promise.all([ - ctx.db.select({ id: labels.id }).from(labels) + const [categoryIds] = await Promise.all([ + ctx.db.select({ id: categories.id }).from(categories) ]); const results: Record< string, { numEntries: number } > = {}; - for (const label of labelIds) { - results[label.id] = { + for (const category of categoryIds) { + results[category.id] = { numEntries: 3330, }; } @@ -90,50 +90,52 @@ export const labelsAppRouter = router({ list: authedProcedure .output( z.object({ - labels: z.array(zGetLabelResponseSchema), + categories: z.array( + z.object({ + id: z.string(), + name: z.string(), + }), + ), }), ) .query(async ({ ctx }) => { - const res = await ctx.db + const dbCategories = await ctx.db .select({ - id: labels.id, - name: labels.name, - code: labels.code, - color: labels.color, - description: labels.description, + id: categories.id, + name: categories.name, }) - .from(labels) - .where(eq(labels.userId, ctx.user.id)); + .from(categories); + + // console.log("Listing cats"); + // console.log(dbCategories); + // console.log(dbCategories.map(({ ...category }) => ({ + // ...category + // }))); return { - labels: res.map((r) => ({ - id: r.id, - name: r.name, - code: r.code, - color: r.color, - description: r.description, - numEntries: 420, + categories: dbCategories.map(({ ...category }) => ({ + ...category })), }; }), get: authedProcedure .input( z.object({ - labelId: z.string(), + categoryId: z.string(), }), ) - .output(zGetLabelResponseSchema) + .output(zGetCategoryResponseSchema) .query(async ({ input, ctx }) => { const res = await ctx.db .select({ - id: labels.id, - name: labels.name + id: categories.id, + name: categories.name }) - .from(labels) + .from(categories) .where( and( conditionFromInput(input, ctx.user.id), - eq(labels.userId, ctx.user.id), + eq(categories.userId, ctx.user.id), ), ); @@ -141,12 +143,12 @@ export const labelsAppRouter = router({ throw new TRPCError({ code: "NOT_FOUND" }); } - const numEntriesWithLabel = res.reduce< - Record + const numEntriesWithCategory = res.reduce< + Record >( (acc, curr) => { - if (curr.labeledBy) { - acc[curr.labeledBy]++; + if (curr.categorizedBy) { + acc[curr.categorizedBy]++; } return acc; }, @@ -160,7 +162,7 @@ export const labelsAppRouter = router({ }; }), create: authedProcedure - .input(zLabelSchema) + .input(zCategorySchema) .output( z.object({ id: z.string(), @@ -171,11 +173,11 @@ export const labelsAppRouter = router({ }), ) .mutation(async ({ input, ctx }) => { - console.log("Just started creating a label"); - return createLabel(input, ctx); + console.log("Just started creating a category"); + return createCategory(input, ctx); }), update: authedProcedure - .input(zUpdateLabelRequestSchema) + .input(zUpdateCategoryRequestSchema) .output( z.object({ id: z.string(), @@ -238,7 +240,7 @@ export const labelsAppRouter = router({ delete: authedProcedure .input( z.object({ - labelId: z.string(), + categoryId: z.string(), }), ) .mutation(async ({ input, ctx }) => { @@ -256,7 +258,7 @@ export const labelsAppRouter = router({ // ); const res = await ctx.db - .delete(labels) + .delete(categories) .where(conditionFromInput(input, ctx.user.id)); if (res.changes == 0) { throw new TRPCError({ code: "NOT_FOUND" }); diff --git a/packages/trpc/routers/colors.ts b/packages/trpc/routers/colors.ts new file mode 100644 index 0000000..a47ce2d --- /dev/null +++ b/packages/trpc/routers/colors.ts @@ -0,0 +1,100 @@ +import { experimental_trpcMiddleware, TRPCError } from "@trpc/server"; +import { and, desc, eq, inArray, notExists } from "drizzle-orm"; +import { z } from "zod"; + +import { SqliteError } from "@lifetracker/db"; +import { colors, calcInverseColor } from "@lifetracker/db/schema"; +import { + zColorSchema, ZColor +} from "@lifetracker/shared/types/colors"; +import type { Context } from "../index"; +import { authedProcedure, router } from "../index"; + + +function conditionFromInput(input: { colorId: string }, userId: string) { + return and(eq(colors.id, input.colorId), eq(colors.userId, userId)); +} + +async function createColor( + input: ZColor, + ctx: Context, +) { + + console.log("[TRPC Router] Begin Create Color"); + + return ctx.db.transaction(async (trx) => { + + try { + const result = await trx + .insert(colors) + .values({ + name: input.name, + hexcode: input.hexcode, + inverse: calcInverseColor(input.hexcode), + userId: ctx.user!.id, + }) + .returning({ + id: colors.id, + name: colors.name, + hexcode: colors.hexcode, + }); + return result[0]; + } catch (e) { + console.log(e); + if (e instanceof SqliteError) { + if (e.code == "SQLITE_CONSTRAINT_UNIQUE") { + throw new TRPCError({ + code: "BAD_REQUEST", + message: "This color already exists", + }); + } + } + throw new TRPCError({ + code: "INTERNAL_SERVER_ERROR", + message: "Something went wrong", + }); + } + }); +} + +export const colorsAppRouter = router({ + list: authedProcedure + .output(z.object({ + colors: z.array( + z.object({ + id: z.string(), + name: z.string(), + hexcode: z.string(), + numCategories: z.number(), + }), + ), + })) + .query(async ({ ctx }) => { + const dbColors = await ctx.db + .select({ + id: colors.id, + name: colors.name, + hexcode: colors.hexcode, + }) + .from(colors); + + return { + colors: dbColors.map(({ ...color }) => ({ + ...color, + numCategories: 0, + })), + }; + }), + create: authedProcedure + .input(zColorSchema) + .output( + z.object({ + id: z.string(), + hexcode: z.string(), + name: z.string(), + }), + ) + .mutation(async ({ input, ctx }) => { + return createColor(input, ctx); + }), +}); \ No newline at end of file diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d484677..efd40a5 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -26,6 +26,12 @@ importers: '@lifetracker/trpc': specifier: workspace:^ version: link:../../packages/trpc + dotenv: + specifier: ^16.4.1 + version: 16.4.5 + table: + specifier: ^6.8.2 + version: 6.8.2 vite-tsconfig-paths: specifier: ^5.1.0 version: 5.1.0(typescript@5.6.3)(vite@5.4.10(@types/node@20.11.24)(lightningcss@1.28.1)(terser@5.34.1)) @@ -223,6 +229,9 @@ importers: clsx: specifier: ^2.1.0 version: 2.1.1 + color-2-name: + specifier: ^1.4.4 + version: 1.4.4 csv-parse: specifier: ^5.5.6 version: 5.5.6 @@ -304,6 +313,9 @@ importers: tailwind-merge: specifier: ^2.2.1 version: 2.5.4 + title-case: + specifier: ^4.3.2 + version: 4.3.2 zod: specifier: ^3.22.4 version: 3.23.8 @@ -4743,6 +4755,10 @@ packages: resolution: {integrity: sha512-c27loCv9QkZinsa5ProX751khO9DJl/AcB5c2KNtA6NRvHKS0PgLfcftz72KVq504vB0Gku5s2kUZzDBvQWvHg==} engines: {node: '>=4'} + astral-regex@2.0.0: + resolution: {integrity: sha512-Z7tMw1ytTXt5jqMcOP+OQteU1VuNK9Y02uuJtKQ1Sv69jXQKKg5cibLwGJow8yzZP+eAc18EmLGPal0bp36rvQ==} + engines: {node: '>=8'} + astring@1.9.0: resolution: {integrity: sha512-LElXdjswlqjWrPpJFg1Fx4wpkOCxj1TDHlSV4PlaRxHGWko024xICaa97ZkMfs6DRKlCguiAI+rbXv5GWwXIkg==} hasBin: true @@ -5294,6 +5310,10 @@ packages: collapse-white-space@2.1.0: resolution: {integrity: sha512-loKTxY1zCOuG4j9f6EPnuyyYkf58RnhhWTvRoZEokgB+WbdXehfjFviyOVYkqzEWz1Q5kRiZdBYS5SwxbQYwzw==} + color-2-name@1.4.4: + resolution: {integrity: sha512-CSF+PANU5YSZYviiU88GJBeJADD4g9mydxLRMYtMEqVxhcLyl72b6PkMQnvomZyUZZLbPhfXs42QZcR0We4JOA==} + engines: {node: '>=14.0.0', npm: '>=6.0.0'} + color-convert@1.9.3: resolution: {integrity: sha512-QfAUtd+vFdAtFQcC8CCyYt1fYWxSqAiK2cSD6zDB8N3cpsEBAvRxp9zOGg6G/SHHJYAT88/az/IuDGALsNVbGg==} @@ -8095,6 +8115,9 @@ packages: lodash.throttle@4.1.1: resolution: {integrity: sha512-wIkUCfVKpVsWo3JSZlc+8MB5it+2AN5W8J7YVMST30UrvcQNZ1Okbj+rbVniijTWE6FGYy4XJq/rHkas8qJMLQ==} + lodash.truncate@4.4.2: + resolution: {integrity: sha512-jttmRe7bRse52OsWIMDLaXxWqRAmtIUccAQ3garviCqJjafXOfNMO0yMfNpdD6zbGaTU0P5Nz7e7gAT6cKmJRw==} + lodash.uniq@4.5.0: resolution: {integrity: sha512-xfBaXQd9ryd9dlSDvnvI0lvxfLJlYAZzXomUYzLKtUeOQvOP5piqAWuGtrhWeqaXK9hhoM/iyJc5AV+XfsX3HQ==} @@ -10438,6 +10461,10 @@ packages: resolution: {integrity: sha512-3dOsAHXXUkQTpOYcoAxLIorMTp4gIQr5IW3iVb7A7lFIp0VHhnynm9izx6TssdrIcVIESAlVjtnO2K8bg+Coew==} engines: {node: '>=12'} + slice-ansi@4.0.0: + resolution: {integrity: sha512-qMCMfhY040cVHT43K9BFygqYbUPFZKHOg7K73mtTWJRb8pyP3fzf4Ixd5SzdEJQ6MRUg/WBnOLxghZtKKurENQ==} + engines: {node: '>=10'} + slugify@1.6.6: resolution: {integrity: sha512-h+z7HKHYXj6wJU+AnS/+IH8Uh9fdcX1Lrhg1/VMdf9PwoBQXFcXiAdsy2tSK0P6gKwJLXp02r90ahUCqHk9rrw==} engines: {node: '>=8.0.0'} @@ -10764,6 +10791,10 @@ packages: resolution: {integrity: sha512-L1dapNV6vu2s/4Sputv8xGsCdAVlb5nRDMFU/E27D44l5U6cw1g0dGd45uLc+OXjNMmF4ntiMdCimzcjFKQI8Q==} engines: {node: ^14.18.0 || >=16.0.0} + table@6.8.2: + resolution: {integrity: sha512-w2sfv80nrAh2VCbqR5AK27wswXhqcck2AhfnNW76beQXskGZ1V12GwS//yYVa3d3fcvAip2OUnbDAjW2k3v9fA==} + engines: {node: '>=10.0.0'} + tailwind-merge@2.5.4: resolution: {integrity: sha512-0q8cfZHMu9nuYP/b5Shb7Y7Sh1B7Nnl5GqNr1U+n2p6+mybvRtayrQ+0042Z5byvTA8ihjlP8Odo8/VnHbZu4Q==} @@ -10918,6 +10949,9 @@ packages: title-case@2.1.1: resolution: {integrity: sha512-EkJoZ2O3zdCz3zJsYCsxyq2OC5hrxR9mfdd5I+w8h/tmFfeOxJ+vvkxsKxdmN0WtS9zLdHEgfgVOiMVgv+Po4Q==} + title-case@4.3.2: + resolution: {integrity: sha512-I/nkcBo73mO42Idfv08jhInV61IMb61OdIFxk+B4Gu1oBjWBPOLmhZdsli+oJCVaD+86pYQA93cJfFt224ZFAA==} + titleize@3.0.0: resolution: {integrity: sha512-KxVu8EYHDPBdUYdKZdKtU2aj2XfEx9AfjXxE/Aj0vT06w2icA09Vus1rh6eSu1y01akYg6BjIK/hxyLJINoMLQ==} engines: {node: '>=12'} @@ -17893,6 +17927,8 @@ snapshots: dependencies: tslib: 2.8.1 + astral-regex@2.0.0: {} + astring@1.9.0: {} async-limiter@1.0.1: {} @@ -18613,6 +18649,8 @@ snapshots: collapse-white-space@2.1.0: {} + color-2-name@1.4.4: {} + color-convert@1.9.3: dependencies: color-name: 1.1.3 @@ -19693,7 +19731,7 @@ snapshots: eslint: 8.57.0 eslint-import-resolver-node: 0.3.9 eslint-import-resolver-typescript: 3.6.1(@typescript-eslint/parser@7.1.0(eslint@8.57.0)(typescript@5.3.3))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.29.0(eslint@8.57.0))(eslint@8.57.0) - eslint-plugin-import: 2.29.0(@typescript-eslint/parser@7.1.0(eslint@8.57.0)(typescript@5.3.3))(eslint-import-resolver-typescript@3.6.1)(eslint@8.57.0) + eslint-plugin-import: 2.29.0(@typescript-eslint/parser@7.1.0(eslint@8.57.0)(typescript@5.3.3))(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@7.1.0(eslint@8.57.0)(typescript@5.3.3))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.29.0(eslint@8.57.0))(eslint@8.57.0))(eslint@8.57.0) eslint-plugin-jsx-a11y: 6.8.0(eslint@8.57.0) eslint-plugin-react: 7.33.2(eslint@8.57.0) eslint-plugin-react-hooks: 4.6.0(eslint@8.57.0) @@ -19747,7 +19785,7 @@ snapshots: enhanced-resolve: 5.15.0 eslint: 8.57.0 eslint-module-utils: 2.8.0(@typescript-eslint/parser@7.1.0(eslint@8.57.0)(typescript@5.3.3))(eslint-import-resolver-node@0.3.9)(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@7.1.0(eslint@8.57.0)(typescript@5.3.3))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.29.0(eslint@8.57.0))(eslint@8.57.0))(eslint@8.57.0) - eslint-plugin-import: 2.29.0(@typescript-eslint/parser@7.1.0(eslint@8.57.0)(typescript@5.3.3))(eslint-import-resolver-typescript@3.6.1)(eslint@8.57.0) + eslint-plugin-import: 2.29.0(@typescript-eslint/parser@7.1.0(eslint@8.57.0)(typescript@5.3.3))(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@7.1.0(eslint@8.57.0)(typescript@5.3.3))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.29.0(eslint@8.57.0))(eslint@8.57.0))(eslint@8.57.0) fast-glob: 3.3.1 get-tsconfig: 4.7.2 is-core-module: 2.13.1 @@ -19786,7 +19824,7 @@ snapshots: eslint: 8.57.0 ignore: 5.3.1 - eslint-plugin-import@2.29.0(@typescript-eslint/parser@7.1.0(eslint@8.57.0)(typescript@5.3.3))(eslint-import-resolver-typescript@3.6.1)(eslint@8.57.0): + eslint-plugin-import@2.29.0(@typescript-eslint/parser@7.1.0(eslint@8.57.0)(typescript@5.3.3))(eslint-import-resolver-typescript@3.6.1(@typescript-eslint/parser@7.1.0(eslint@8.57.0)(typescript@5.3.3))(eslint-import-resolver-node@0.3.9)(eslint-plugin-import@2.29.0(eslint@8.57.0))(eslint@8.57.0))(eslint@8.57.0): dependencies: array-includes: 3.1.7 array.prototype.findlastindex: 1.2.3 @@ -21944,6 +21982,8 @@ snapshots: lodash.throttle@4.1.1: {} + lodash.truncate@4.4.2: {} + lodash.uniq@4.5.0: {} lodash@4.17.21: {} @@ -25122,6 +25162,12 @@ snapshots: slash@4.0.0: {} + slice-ansi@4.0.0: + dependencies: + ansi-styles: 4.3.0 + astral-regex: 2.0.0 + is-fullwidth-code-point: 3.0.0 + slugify@1.6.6: {} smart-buffer@4.2.0: {} @@ -25482,6 +25528,14 @@ snapshots: '@pkgr/utils': 2.4.2 tslib: 2.6.2 + table@6.8.2: + dependencies: + ajv: 8.17.1 + lodash.truncate: 4.4.2 + slice-ansi: 4.0.0 + string-width: 4.2.3 + strip-ansi: 6.0.1 + tailwind-merge@2.5.4: {} tailwindcss-animate@1.0.7(tailwindcss@3.4.15(ts-node@10.9.1(@types/node@20.11.24)(typescript@5.6.3))): @@ -25654,6 +25708,8 @@ snapshots: no-case: 2.3.2 upper-case: 1.1.3 + title-case@4.3.2: {} + titleize@3.0.0: {} tmp@0.0.33: