Skip to content

Commit

Permalink
add createdAtV2 column
Browse files Browse the repository at this point in the history
  • Loading branch information
jameszhang-a committed Apr 14, 2024
1 parent 7f90c23 commit 5b13898
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 7 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
/prisma/db.sqlite
/prisma/db.sqlite-journal
/prisma/*.db
migration_lock.toml
*.db-journal

# next.js
/.next/
Expand All @@ -24,6 +26,7 @@ next-env.d.ts
# misc
.DS_Store
*.pem
.temp_files

# debug
npm-debug.log*
Expand Down
96 changes: 96 additions & 0 deletions prisma/migrations/20240413233925_init/migration.sql
Original file line number Diff line number Diff line change
@@ -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");
Original file line number Diff line number Diff line change
@@ -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;
15 changes: 8 additions & 7 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -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("")
Expand Down

0 comments on commit 5b13898

Please sign in to comment.