From 9e45b8767ddbb27a0f8e6da8e904f25fee16d861 Mon Sep 17 00:00:00 2001 From: dylanbenzi Date: Wed, 19 Jun 2024 00:04:36 -0400 Subject: [PATCH] db schema updates and mock event data --- src/app/page.tsx | 2 +- src/components/calendar/MonthCalendar.tsx | 2 +- src/db/db.ts | 38 --- src/db/db_calls.ts | 78 ++++++ src/db/migrations/0000_dear_dagger.sql | 57 +++++ src/db/migrations/0001_flowery_harpoon.sql | 1 + src/db/migrations/0002_grey_white_tiger.sql | 1 + src/db/migrations/0003_flat_wind_dancer.sql | 1 + src/db/migrations/meta/0000_snapshot.json | 251 +++++++++++++++++++ src/db/migrations/meta/0001_snapshot.json | 257 ++++++++++++++++++++ src/db/migrations/meta/0002_snapshot.json | 257 ++++++++++++++++++++ src/db/migrations/meta/0003_snapshot.json | 257 ++++++++++++++++++++ src/db/migrations/meta/_journal.json | 35 ++- src/db/schema.ts | 38 +-- 14 files changed, 1217 insertions(+), 58 deletions(-) create mode 100644 src/db/db_calls.ts create mode 100644 src/db/migrations/0000_dear_dagger.sql create mode 100644 src/db/migrations/0001_flowery_harpoon.sql create mode 100644 src/db/migrations/0002_grey_white_tiger.sql create mode 100644 src/db/migrations/0003_flat_wind_dancer.sql create mode 100644 src/db/migrations/meta/0000_snapshot.json create mode 100644 src/db/migrations/meta/0001_snapshot.json create mode 100644 src/db/migrations/meta/0002_snapshot.json create mode 100644 src/db/migrations/meta/0003_snapshot.json diff --git a/src/app/page.tsx b/src/app/page.tsx index 72d514c..b28c383 100644 --- a/src/app/page.tsx +++ b/src/app/page.tsx @@ -1,4 +1,4 @@ -import { syncUsers } from "@/db/db"; +import { syncUsers } from "@/db/db_calls"; import { SignInButton, SignedOut } from "@clerk/nextjs"; import { auth, currentUser } from "@clerk/nextjs/server"; import React from "react"; diff --git a/src/components/calendar/MonthCalendar.tsx b/src/components/calendar/MonthCalendar.tsx index 5ea1a4c..d9450e2 100644 --- a/src/components/calendar/MonthCalendar.tsx +++ b/src/components/calendar/MonthCalendar.tsx @@ -1,4 +1,4 @@ -"use client"; +// "use client"; import { format } from "date-fns-tz"; import React, { useState } from "react"; diff --git a/src/db/db.ts b/src/db/db.ts index 85d0a7f..2b22217 100644 --- a/src/db/db.ts +++ b/src/db/db.ts @@ -14,41 +14,3 @@ const connectionString = export const client = postgres(connectionString, { prepare: false }); export const db = drizzle(client, { schema }); - -// DB Calls -export const syncUsers = async ({ - id, - firstName, - lastName, - primaryEmailAddress, - primaryPhoneNumber, -}: User) => { - const existingUser = await db.query.UsersTable.findFirst({ - where: (UsersTable, { eq }) => eq(UsersTable.userId, id), - }); - - if (primaryEmailAddress == null) { - throw new Error("No email address for user"); - } - - if (!existingUser) { - await db - .insert(UsersTable) - .values({ - userId: id, - firstName: firstName, - lastName: lastName, - emailAddress: primaryEmailAddress.emailAddress, - phoneNumber: primaryPhoneNumber?.phoneNumber, - }) - .onConflictDoUpdate({ - target: UsersTable.userId, - set: { - firstName: firstName, - lastName: lastName, - emailAddress: primaryEmailAddress.emailAddress, - phoneNumber: primaryPhoneNumber?.phoneNumber, - }, - }); - } -}; diff --git a/src/db/db_calls.ts b/src/db/db_calls.ts new file mode 100644 index 0000000..5c70989 --- /dev/null +++ b/src/db/db_calls.ts @@ -0,0 +1,78 @@ +import { User } from "@clerk/nextjs/server"; +import { eq, sql, lte, gte, and, asc } from "drizzle-orm"; +import { EventsTable, UsersTable } from "./schema"; +import { db } from "./db"; +import { format } from "date-fns"; + +export const syncUsers = async ({ + id, + firstName, + lastName, + primaryEmailAddress, + primaryPhoneNumber, +}: User) => { + const existingUser = await db.query.UsersTable.findFirst({ + where: (UsersTable, { eq }) => eq(UsersTable.userId, id), + }); + + if (primaryEmailAddress == null) { + throw new Error("No email address for user"); + } + + if (!existingUser) { + await db + .insert(UsersTable) + .values({ + userId: id, + firstName: firstName, + lastName: lastName, + emailAddress: primaryEmailAddress.emailAddress, + phoneNumber: primaryPhoneNumber?.phoneNumber, + }) + .onConflictDoUpdate({ + target: UsersTable.userId, + set: { + firstName: firstName, + lastName: lastName, + emailAddress: primaryEmailAddress.emailAddress, + phoneNumber: primaryPhoneNumber?.phoneNumber, + }, + }); + } +}; + +export interface EventArray { + date: string; + events: Event[]; +} + +export interface Event { + id: string; + title: string; + variant: + | "earnings" + | "conference" + | "split" + | "dividend" + | "economic" + | "default"; + datetime: Date; + description?: string | null; + symbol?: string | null; +} + +export const getEvents = async (startDate: Date, endDate: Date) => { + const events: Event[] = await db + .select() + .from(EventsTable) + .where(and(gte(EventsTable, startDate), lte(EventsTable, endDate))) + .orderBy(asc(EventsTable.datetime)); + + events.forEach((e) => { + e.datetime = new Date( + e.datetime.toLocaleString("en-US", { timeZone: "America/New_York" }) + ); + }); + + // return eventArray; +}; diff --git a/src/db/migrations/0000_dear_dagger.sql b/src/db/migrations/0000_dear_dagger.sql new file mode 100644 index 0000000..ce9c64b --- /dev/null +++ b/src/db/migrations/0000_dear_dagger.sql @@ -0,0 +1,57 @@ +DO $$ BEGIN + CREATE TYPE "public"."eventVariant" AS ENUM('earnings', 'conference', 'split', 'dividend', 'econonmic', 'default'); +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + CREATE TYPE "public"."themeMode" AS ENUM('light', 'dark', 'system'); +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "companies" ( + "symbol" text PRIMARY KEY NOT NULL, + "cik" text NOT NULL, + "companyName" text NOT NULL, + CONSTRAINT "companies_symbol_unique" UNIQUE("symbol"), + CONSTRAINT "companies_companyName_unique" UNIQUE("companyName") +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "events" ( + "eventId" uuid PRIMARY KEY DEFAULT gen_random_uuid() NOT NULL, + "title" text NOT NULL, + "symbol" text NOT NULL, + "variant" "eventVariant" NOT NULL, + "datetime" timestamp with time zone NOT NULL +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "userPreferences" ( + "userId" text PRIMARY KEY NOT NULL, + "theme" "themeMode" DEFAULT 'dark' NOT NULL, + "timezone" text DEFAULT 'America/New_York' NOT NULL, + "currencyUnits" text DEFAULT 'USD' NOT NULL, + CONSTRAINT "userPreferences_userId_unique" UNIQUE("userId") +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "users" ( + "userId" text PRIMARY KEY NOT NULL, + "firstName" text, + "lastName" text, + "emailAddress" text NOT NULL, + "phoneNumber" text, + CONSTRAINT "users_userId_unique" UNIQUE("userId"), + CONSTRAINT "users_emailAddress_unique" UNIQUE("emailAddress") +); +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "events" ADD CONSTRAINT "events_symbol_companies_symbol_fk" FOREIGN KEY ("symbol") REFERENCES "public"."companies"("symbol") ON DELETE no action ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "userPreferences" ADD CONSTRAINT "userPreferences_userId_users_userId_fk" FOREIGN KEY ("userId") REFERENCES "public"."users"("userId") ON DELETE no action ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; diff --git a/src/db/migrations/0001_flowery_harpoon.sql b/src/db/migrations/0001_flowery_harpoon.sql new file mode 100644 index 0000000..30477c3 --- /dev/null +++ b/src/db/migrations/0001_flowery_harpoon.sql @@ -0,0 +1 @@ +ALTER TABLE "events" ADD COLUMN "description" text; \ No newline at end of file diff --git a/src/db/migrations/0002_grey_white_tiger.sql b/src/db/migrations/0002_grey_white_tiger.sql new file mode 100644 index 0000000..1803618 --- /dev/null +++ b/src/db/migrations/0002_grey_white_tiger.sql @@ -0,0 +1 @@ +ALTER TABLE "events" ALTER COLUMN "symbol" DROP NOT NULL; \ No newline at end of file diff --git a/src/db/migrations/0003_flat_wind_dancer.sql b/src/db/migrations/0003_flat_wind_dancer.sql new file mode 100644 index 0000000..c6af6ae --- /dev/null +++ b/src/db/migrations/0003_flat_wind_dancer.sql @@ -0,0 +1 @@ +ALTER TYPE "eventVariant" ADD VALUE 'economic'; \ No newline at end of file diff --git a/src/db/migrations/meta/0000_snapshot.json b/src/db/migrations/meta/0000_snapshot.json new file mode 100644 index 0000000..8be9736 --- /dev/null +++ b/src/db/migrations/meta/0000_snapshot.json @@ -0,0 +1,251 @@ +{ + "id": "c02a41be-90a6-486e-9324-d6b9b276b1f0", + "prevId": "00000000-0000-0000-0000-000000000000", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.companies": { + "name": "companies", + "schema": "", + "columns": { + "symbol": { + "name": "symbol", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "cik": { + "name": "cik", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "companyName": { + "name": "companyName", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "companies_symbol_unique": { + "name": "companies_symbol_unique", + "nullsNotDistinct": false, + "columns": [ + "symbol" + ] + }, + "companies_companyName_unique": { + "name": "companies_companyName_unique", + "nullsNotDistinct": false, + "columns": [ + "companyName" + ] + } + } + }, + "public.events": { + "name": "events", + "schema": "", + "columns": { + "eventId": { + "name": "eventId", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "symbol": { + "name": "symbol", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "variant": { + "name": "variant", + "type": "eventVariant", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "datetime": { + "name": "datetime", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "events_symbol_companies_symbol_fk": { + "name": "events_symbol_companies_symbol_fk", + "tableFrom": "events", + "tableTo": "companies", + "columnsFrom": [ + "symbol" + ], + "columnsTo": [ + "symbol" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "public.userPreferences": { + "name": "userPreferences", + "schema": "", + "columns": { + "userId": { + "name": "userId", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "theme": { + "name": "theme", + "type": "themeMode", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'dark'" + }, + "timezone": { + "name": "timezone", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'America/New_York'" + }, + "currencyUnits": { + "name": "currencyUnits", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'USD'" + } + }, + "indexes": {}, + "foreignKeys": { + "userPreferences_userId_users_userId_fk": { + "name": "userPreferences_userId_users_userId_fk", + "tableFrom": "userPreferences", + "tableTo": "users", + "columnsFrom": [ + "userId" + ], + "columnsTo": [ + "userId" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "userPreferences_userId_unique": { + "name": "userPreferences_userId_unique", + "nullsNotDistinct": false, + "columns": [ + "userId" + ] + } + } + }, + "public.users": { + "name": "users", + "schema": "", + "columns": { + "userId": { + "name": "userId", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "firstName": { + "name": "firstName", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "lastName": { + "name": "lastName", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "emailAddress": { + "name": "emailAddress", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "phoneNumber": { + "name": "phoneNumber", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "users_userId_unique": { + "name": "users_userId_unique", + "nullsNotDistinct": false, + "columns": [ + "userId" + ] + }, + "users_emailAddress_unique": { + "name": "users_emailAddress_unique", + "nullsNotDistinct": false, + "columns": [ + "emailAddress" + ] + } + } + } + }, + "enums": { + "public.eventVariant": { + "name": "eventVariant", + "schema": "public", + "values": [ + "earnings", + "conference", + "split", + "dividend", + "econonmic", + "default" + ] + }, + "public.themeMode": { + "name": "themeMode", + "schema": "public", + "values": [ + "light", + "dark", + "system" + ] + } + }, + "schemas": {}, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} \ No newline at end of file diff --git a/src/db/migrations/meta/0001_snapshot.json b/src/db/migrations/meta/0001_snapshot.json new file mode 100644 index 0000000..4690a17 --- /dev/null +++ b/src/db/migrations/meta/0001_snapshot.json @@ -0,0 +1,257 @@ +{ + "id": "0f787722-b7c9-4a90-9fb0-ffbbadd33c8e", + "prevId": "c02a41be-90a6-486e-9324-d6b9b276b1f0", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.companies": { + "name": "companies", + "schema": "", + "columns": { + "symbol": { + "name": "symbol", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "cik": { + "name": "cik", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "companyName": { + "name": "companyName", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "companies_symbol_unique": { + "name": "companies_symbol_unique", + "nullsNotDistinct": false, + "columns": [ + "symbol" + ] + }, + "companies_companyName_unique": { + "name": "companies_companyName_unique", + "nullsNotDistinct": false, + "columns": [ + "companyName" + ] + } + } + }, + "public.events": { + "name": "events", + "schema": "", + "columns": { + "eventId": { + "name": "eventId", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "symbol": { + "name": "symbol", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "variant": { + "name": "variant", + "type": "eventVariant", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "datetime": { + "name": "datetime", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "events_symbol_companies_symbol_fk": { + "name": "events_symbol_companies_symbol_fk", + "tableFrom": "events", + "tableTo": "companies", + "columnsFrom": [ + "symbol" + ], + "columnsTo": [ + "symbol" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "public.userPreferences": { + "name": "userPreferences", + "schema": "", + "columns": { + "userId": { + "name": "userId", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "theme": { + "name": "theme", + "type": "themeMode", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'dark'" + }, + "timezone": { + "name": "timezone", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'America/New_York'" + }, + "currencyUnits": { + "name": "currencyUnits", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'USD'" + } + }, + "indexes": {}, + "foreignKeys": { + "userPreferences_userId_users_userId_fk": { + "name": "userPreferences_userId_users_userId_fk", + "tableFrom": "userPreferences", + "tableTo": "users", + "columnsFrom": [ + "userId" + ], + "columnsTo": [ + "userId" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "userPreferences_userId_unique": { + "name": "userPreferences_userId_unique", + "nullsNotDistinct": false, + "columns": [ + "userId" + ] + } + } + }, + "public.users": { + "name": "users", + "schema": "", + "columns": { + "userId": { + "name": "userId", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "firstName": { + "name": "firstName", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "lastName": { + "name": "lastName", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "emailAddress": { + "name": "emailAddress", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "phoneNumber": { + "name": "phoneNumber", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "users_userId_unique": { + "name": "users_userId_unique", + "nullsNotDistinct": false, + "columns": [ + "userId" + ] + }, + "users_emailAddress_unique": { + "name": "users_emailAddress_unique", + "nullsNotDistinct": false, + "columns": [ + "emailAddress" + ] + } + } + } + }, + "enums": { + "public.eventVariant": { + "name": "eventVariant", + "schema": "public", + "values": [ + "earnings", + "conference", + "split", + "dividend", + "econonmic", + "default" + ] + }, + "public.themeMode": { + "name": "themeMode", + "schema": "public", + "values": [ + "light", + "dark", + "system" + ] + } + }, + "schemas": {}, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} \ No newline at end of file diff --git a/src/db/migrations/meta/0002_snapshot.json b/src/db/migrations/meta/0002_snapshot.json new file mode 100644 index 0000000..0070435 --- /dev/null +++ b/src/db/migrations/meta/0002_snapshot.json @@ -0,0 +1,257 @@ +{ + "id": "afc01ef3-4513-45a7-8a87-88c54d7d1ad1", + "prevId": "0f787722-b7c9-4a90-9fb0-ffbbadd33c8e", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.companies": { + "name": "companies", + "schema": "", + "columns": { + "symbol": { + "name": "symbol", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "cik": { + "name": "cik", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "companyName": { + "name": "companyName", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "companies_symbol_unique": { + "name": "companies_symbol_unique", + "nullsNotDistinct": false, + "columns": [ + "symbol" + ] + }, + "companies_companyName_unique": { + "name": "companies_companyName_unique", + "nullsNotDistinct": false, + "columns": [ + "companyName" + ] + } + } + }, + "public.events": { + "name": "events", + "schema": "", + "columns": { + "eventId": { + "name": "eventId", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "symbol": { + "name": "symbol", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "variant": { + "name": "variant", + "type": "eventVariant", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "datetime": { + "name": "datetime", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "events_symbol_companies_symbol_fk": { + "name": "events_symbol_companies_symbol_fk", + "tableFrom": "events", + "tableTo": "companies", + "columnsFrom": [ + "symbol" + ], + "columnsTo": [ + "symbol" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "public.userPreferences": { + "name": "userPreferences", + "schema": "", + "columns": { + "userId": { + "name": "userId", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "theme": { + "name": "theme", + "type": "themeMode", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'dark'" + }, + "timezone": { + "name": "timezone", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'America/New_York'" + }, + "currencyUnits": { + "name": "currencyUnits", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'USD'" + } + }, + "indexes": {}, + "foreignKeys": { + "userPreferences_userId_users_userId_fk": { + "name": "userPreferences_userId_users_userId_fk", + "tableFrom": "userPreferences", + "tableTo": "users", + "columnsFrom": [ + "userId" + ], + "columnsTo": [ + "userId" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "userPreferences_userId_unique": { + "name": "userPreferences_userId_unique", + "nullsNotDistinct": false, + "columns": [ + "userId" + ] + } + } + }, + "public.users": { + "name": "users", + "schema": "", + "columns": { + "userId": { + "name": "userId", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "firstName": { + "name": "firstName", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "lastName": { + "name": "lastName", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "emailAddress": { + "name": "emailAddress", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "phoneNumber": { + "name": "phoneNumber", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "users_userId_unique": { + "name": "users_userId_unique", + "nullsNotDistinct": false, + "columns": [ + "userId" + ] + }, + "users_emailAddress_unique": { + "name": "users_emailAddress_unique", + "nullsNotDistinct": false, + "columns": [ + "emailAddress" + ] + } + } + } + }, + "enums": { + "public.eventVariant": { + "name": "eventVariant", + "schema": "public", + "values": [ + "earnings", + "conference", + "split", + "dividend", + "econonmic", + "default" + ] + }, + "public.themeMode": { + "name": "themeMode", + "schema": "public", + "values": [ + "light", + "dark", + "system" + ] + } + }, + "schemas": {}, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} \ No newline at end of file diff --git a/src/db/migrations/meta/0003_snapshot.json b/src/db/migrations/meta/0003_snapshot.json new file mode 100644 index 0000000..a57b2c0 --- /dev/null +++ b/src/db/migrations/meta/0003_snapshot.json @@ -0,0 +1,257 @@ +{ + "id": "878a3666-4f47-4528-aca9-5a7750887307", + "prevId": "afc01ef3-4513-45a7-8a87-88c54d7d1ad1", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.companies": { + "name": "companies", + "schema": "", + "columns": { + "symbol": { + "name": "symbol", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "cik": { + "name": "cik", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "companyName": { + "name": "companyName", + "type": "text", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "companies_symbol_unique": { + "name": "companies_symbol_unique", + "nullsNotDistinct": false, + "columns": [ + "symbol" + ] + }, + "companies_companyName_unique": { + "name": "companies_companyName_unique", + "nullsNotDistinct": false, + "columns": [ + "companyName" + ] + } + } + }, + "public.events": { + "name": "events", + "schema": "", + "columns": { + "eventId": { + "name": "eventId", + "type": "uuid", + "primaryKey": true, + "notNull": true, + "default": "gen_random_uuid()" + }, + "title": { + "name": "title", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "symbol": { + "name": "symbol", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "variant": { + "name": "variant", + "type": "eventVariant", + "typeSchema": "public", + "primaryKey": false, + "notNull": true + }, + "datetime": { + "name": "datetime", + "type": "timestamp with time zone", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "events_symbol_companies_symbol_fk": { + "name": "events_symbol_companies_symbol_fk", + "tableFrom": "events", + "tableTo": "companies", + "columnsFrom": [ + "symbol" + ], + "columnsTo": [ + "symbol" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "public.userPreferences": { + "name": "userPreferences", + "schema": "", + "columns": { + "userId": { + "name": "userId", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "theme": { + "name": "theme", + "type": "themeMode", + "typeSchema": "public", + "primaryKey": false, + "notNull": true, + "default": "'dark'" + }, + "timezone": { + "name": "timezone", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'America/New_York'" + }, + "currencyUnits": { + "name": "currencyUnits", + "type": "text", + "primaryKey": false, + "notNull": true, + "default": "'USD'" + } + }, + "indexes": {}, + "foreignKeys": { + "userPreferences_userId_users_userId_fk": { + "name": "userPreferences_userId_users_userId_fk", + "tableFrom": "userPreferences", + "tableTo": "users", + "columnsFrom": [ + "userId" + ], + "columnsTo": [ + "userId" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "userPreferences_userId_unique": { + "name": "userPreferences_userId_unique", + "nullsNotDistinct": false, + "columns": [ + "userId" + ] + } + } + }, + "public.users": { + "name": "users", + "schema": "", + "columns": { + "userId": { + "name": "userId", + "type": "text", + "primaryKey": true, + "notNull": true + }, + "firstName": { + "name": "firstName", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "lastName": { + "name": "lastName", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "emailAddress": { + "name": "emailAddress", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "phoneNumber": { + "name": "phoneNumber", + "type": "text", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "users_userId_unique": { + "name": "users_userId_unique", + "nullsNotDistinct": false, + "columns": [ + "userId" + ] + }, + "users_emailAddress_unique": { + "name": "users_emailAddress_unique", + "nullsNotDistinct": false, + "columns": [ + "emailAddress" + ] + } + } + } + }, + "enums": { + "public.eventVariant": { + "name": "eventVariant", + "schema": "public", + "values": [ + "earnings", + "conference", + "split", + "dividend", + "economic", + "default" + ] + }, + "public.themeMode": { + "name": "themeMode", + "schema": "public", + "values": [ + "light", + "dark", + "system" + ] + } + }, + "schemas": {}, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} \ No newline at end of file diff --git a/src/db/migrations/meta/_journal.json b/src/db/migrations/meta/_journal.json index f04877e..6a3378c 100644 --- a/src/db/migrations/meta/_journal.json +++ b/src/db/migrations/meta/_journal.json @@ -1 +1,34 @@ -{"version":"7","dialect":"postgresql","entries":[]} \ No newline at end of file +{ + "version": "7", + "dialect": "postgresql", + "entries": [ + { + "idx": 0, + "version": "7", + "when": 1718764999793, + "tag": "0000_dear_dagger", + "breakpoints": true + }, + { + "idx": 1, + "version": "7", + "when": 1718765213486, + "tag": "0001_flowery_harpoon", + "breakpoints": true + }, + { + "idx": 2, + "version": "7", + "when": 1718765530419, + "tag": "0002_grey_white_tiger", + "breakpoints": true + }, + { + "idx": 3, + "version": "7", + "when": 1718765763155, + "tag": "0003_flat_wind_dancer", + "breakpoints": true + } + ] +} \ No newline at end of file diff --git a/src/db/schema.ts b/src/db/schema.ts index eb8d956..ee11420 100644 --- a/src/db/schema.ts +++ b/src/db/schema.ts @@ -1,38 +1,42 @@ import { pgEnum, pgTable, text, timestamp, uuid } from "drizzle-orm/pg-core"; import { sql } from "drizzle-orm"; -export const DateTable = pgTable("dates", { - date: timestamp("date", { withTimezone: true }) - .unique() - .notNull() - .primaryKey(), -}); +// export const DateTable = pgTable("dates", { +// date: timestamp("date", { withTimezone: true }) +// .unique() +// .notNull() +// .primaryKey(), +// }); export const EventVariant = pgEnum("eventVariant", [ "earnings", "conference", "split", "dividend", - "econonmic", + "economic", "default", ]); export const EventsTable = pgTable("events", { id: uuid("eventId").primaryKey().defaultRandom(), title: text("title").notNull(), - companyName: text("companyName") - .notNull() - .unique() - .references(() => SymbolsTable.symbol), + // companyName: text("companyName") + // .notNull() + // .unique() + // .references(() => SymbolsTable.symbol), + symbol: text("symbol").references(() => CompanyTable.symbol), variant: EventVariant("variant").notNull(), - time: timestamp("time", { withTimezone: true }).notNull(), - date: timestamp("date") - .references(() => DateTable.date) - .notNull(), + datetime: timestamp("datetime", { withTimezone: true }).notNull(), + description: text("description"), + // time: timestamp("time", { withTimezone: true }).notNull(), + // date: timestamp("date") + // .references(() => DateTable.date) + // .notNull(), }); -export const SymbolsTable = pgTable("symbols", { - symbol: text("symbol").notNull().primaryKey().unique(), +export const CompanyTable = pgTable("companies", { + symbol: text("symbol").notNull().unique().primaryKey(), + cik: text("cik").notNull(), companyName: text("companyName").notNull().unique(), });