diff --git a/.gitignore b/.gitignore index 851c46d..d08f636 100644 --- a/.gitignore +++ b/.gitignore @@ -12,6 +12,8 @@ /prisma/db.sqlite /prisma/db.sqlite-journal /prisma/*.db +migration_lock.toml +*.db-journal # next.js /.next/ @@ -24,6 +26,7 @@ next-env.d.ts # misc .DS_Store *.pem +.temp_files # debug npm-debug.log* diff --git a/prisma/migrations/20240413233925_init/migration.sql b/prisma/migrations/20240413233925_init/migration.sql new file mode 100644 index 0000000..31929ae --- /dev/null +++ b/prisma/migrations/20240413233925_init/migration.sql @@ -0,0 +1,96 @@ +-- CreateTable +CREATE TABLE "Account" ( + "id" TEXT NOT NULL PRIMARY KEY, + "userId" TEXT NOT NULL, + "type" TEXT NOT NULL, + "provider" TEXT NOT NULL, + "providerAccountId" TEXT NOT NULL, + "refresh_token" TEXT, + "access_token" TEXT, + "expires_at" INTEGER, + "token_type" TEXT, + "scope" TEXT, + "id_token" TEXT, + "session_state" TEXT +); + +-- CreateTable +CREATE TABLE "Session" ( + "id" TEXT NOT NULL PRIMARY KEY, + "sessionToken" TEXT NOT NULL, + "userId" TEXT NOT NULL, + "expires" DATETIME NOT NULL +); + +-- CreateTable +CREATE TABLE "User" ( + "id" TEXT NOT NULL PRIMARY KEY, + "name" TEXT NOT NULL, + "email" TEXT NOT NULL, + "emailVerified" DATETIME, + "image" TEXT, + "theme" TEXT NOT NULL DEFAULT 'default', + "lightTheme" TEXT NOT NULL DEFAULT 'dark', + "timezone" TEXT NOT NULL DEFAULT 'America/New_York', + "notionToken" TEXT +); + +-- CreateTable +CREATE TABLE "VerificationToken" ( + "identifier" TEXT NOT NULL, + "token" TEXT NOT NULL, + "expires" DATETIME NOT NULL +); + +-- CreateTable +CREATE TABLE "Habit" ( + "id" TEXT NOT NULL PRIMARY KEY, + "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" DATETIME NOT NULL, + "name" TEXT NOT NULL, + "emoji" TEXT NOT NULL DEFAULT '🔥', + "userId" TEXT NOT NULL, + "frequency" INTEGER NOT NULL DEFAULT 1, + "goal" INTEGER NOT NULL DEFAULT 1, + "inversedGoal" BOOLEAN NOT NULL DEFAULT false, + "order" INTEGER NOT NULL DEFAULT 0, + "archived" BOOLEAN NOT NULL DEFAULT false +); + +-- CreateTable +CREATE TABLE "HabitLog" ( + "id" TEXT NOT NULL PRIMARY KEY, + "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" DATETIME NOT NULL, + "habitId" TEXT NOT NULL, + "date" DATETIME NOT NULL, + "completed" BOOLEAN NOT NULL DEFAULT false, + "weekKey" TEXT NOT NULL DEFAULT '' +); + +-- CreateIndex +CREATE INDEX "Account_userId_idx" ON "Account"("userId"); + +-- CreateIndex +CREATE UNIQUE INDEX "Account_provider_providerAccountId_key" ON "Account"("provider", "providerAccountId"); + +-- CreateIndex +CREATE UNIQUE INDEX "Session_sessionToken_key" ON "Session"("sessionToken"); + +-- CreateIndex +CREATE INDEX "Session_userId_idx" ON "Session"("userId"); + +-- CreateIndex +CREATE UNIQUE INDEX "User_email_key" ON "User"("email"); + +-- CreateIndex +CREATE UNIQUE INDEX "VerificationToken_token_key" ON "VerificationToken"("token"); + +-- CreateIndex +CREATE UNIQUE INDEX "VerificationToken_identifier_token_key" ON "VerificationToken"("identifier", "token"); + +-- CreateIndex +CREATE INDEX "Habit_userId_idx" ON "Habit"("userId"); + +-- CreateIndex +CREATE INDEX "HabitLog_habitId_idx" ON "HabitLog"("habitId"); diff --git a/prisma/migrations/20240413234119_add_created_at_v2_to_habit_logs/migration.sql b/prisma/migrations/20240413234119_add_created_at_v2_to_habit_logs/migration.sql new file mode 100644 index 0000000..f9d1cba --- /dev/null +++ b/prisma/migrations/20240413234119_add_created_at_v2_to_habit_logs/migration.sql @@ -0,0 +1,18 @@ +-- RedefineTables +PRAGMA foreign_keys=OFF; +CREATE TABLE "new_HabitLog" ( + "id" TEXT NOT NULL PRIMARY KEY, + "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + "createdAtV2" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" DATETIME NOT NULL, + "habitId" TEXT NOT NULL, + "date" DATETIME NOT NULL, + "completed" BOOLEAN NOT NULL DEFAULT false, + "weekKey" TEXT NOT NULL DEFAULT '' +); +INSERT INTO "new_HabitLog" ("completed", "createdAt", "date", "habitId", "id", "updatedAt", "weekKey") SELECT "completed", "createdAt", "date", "habitId", "id", "updatedAt", "weekKey" FROM "HabitLog"; +DROP TABLE "HabitLog"; +ALTER TABLE "new_HabitLog" RENAME TO "HabitLog"; +CREATE INDEX "HabitLog_habitId_idx" ON "HabitLog"("habitId"); +PRAGMA foreign_key_check; +PRAGMA foreign_keys=ON; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index c3bef99..2d79715 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -84,13 +84,14 @@ model Habit { } model HabitLog { - id String @id @default(cuid()) - createdAt DateTime @default(now()) - updatedAt DateTime @updatedAt - habit Habit @relation(fields: [habitId], references: [id], onDelete: Cascade) - habitId String - date DateTime - completed Boolean @default(false) + id String @id @default(cuid()) + createdAt DateTime @default(now()) + createdAtV2 DateTime @default(now()) + updatedAt DateTime @updatedAt + habit Habit @relation(fields: [habitId], references: [id], onDelete: Cascade) + habitId String + date DateTime + completed Boolean @default(false) weekKey String @default("")