Skip to content

Commit 7de889c

Browse files
committed
feat: update migration and schema files for PlannerData and Semester models, including type changes and new migration scripts
1 parent 3486cd0 commit 7de889c

File tree

8 files changed

+58
-9
lines changed

8 files changed

+58
-9
lines changed

generateMigration.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
const { execSync } = require('child_process');
22
const { format } = require('date-fns');
33
const path = require('path');
4+
const fs = require('fs');
45

56
try {
67
const timestamp = format(new Date(), 'yyyyMMdd_HHmmss');
@@ -10,7 +11,9 @@ try {
1011
execSync(command, { stdio: 'inherit' });
1112
console.log(`Generated migration file: ${outputFile}`);
1213
// copy schema.prisma to schema.previous.prisma
13-
execSync(`cp ./src/prisma/schema.prisma ./src/prisma/schema.previous.prisma`, { stdio: 'inherit' });
14+
const src = path.resolve(__dirname, 'src/prisma/schema.prisma');
15+
const dest = path.resolve(__dirname, 'src/prisma/schema.previous.prisma');
16+
fs.copyFileSync(src, dest);
1417
console.log('Updated schema.previous.prisma with the current schema.prisma');
1518
} catch (error) {
1619
console.error('Error generating migration:', error.message);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-- Migration number: 20250417 2025-04-20T04:03:53.132Z
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
-- RedefineTables
2+
PRAGMA defer_foreign_keys=ON;
3+
PRAGMA foreign_keys=OFF;
4+
CREATE TABLE "new_PlannerData" (
5+
"id" TEXT NOT NULL PRIMARY KEY,
6+
"title" TEXT NOT NULL,
7+
"department" TEXT NOT NULL,
8+
"requiredCredits" REAL NOT NULL,
9+
"enrollmentYear" TEXT NOT NULL,
10+
"graduationYear" TEXT NOT NULL,
11+
"includedSemesters" TEXT NOT NULL,
12+
"description" TEXT,
13+
"serverTimestamp" DATETIME NOT NULL,
14+
"userId" TEXT NOT NULL,
15+
"deleted" BOOLEAN NOT NULL DEFAULT false
16+
);
17+
INSERT INTO "new_PlannerData" ("deleted", "department", "description", "enrollmentYear", "graduationYear", "id", "includedSemesters", "requiredCredits", "serverTimestamp", "title", "userId") SELECT "deleted", "department", "description", "enrollmentYear", "graduationYear", "id", "includedSemesters", "requiredCredits", "serverTimestamp", "title", "userId" FROM "PlannerData";
18+
DROP TABLE "PlannerData";
19+
ALTER TABLE "new_PlannerData" RENAME TO "PlannerData";
20+
CREATE INDEX "PlannerData_userId_idx" ON "PlannerData"("userId");
21+
CREATE UNIQUE INDEX "PlannerData_userId_id_key" ON "PlannerData"("userId", "id");
22+
PRAGMA foreign_keys=ON;
23+
PRAGMA defer_foreign_keys=OFF;
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
-- RedefineTables
2+
PRAGMA defer_foreign_keys=ON;
3+
PRAGMA foreign_keys=OFF;
4+
CREATE TABLE "new_Semester" (
5+
"id" TEXT NOT NULL PRIMARY KEY,
6+
"name" TEXT NOT NULL,
7+
"status" TEXT NOT NULL,
8+
"year" TEXT NOT NULL,
9+
"term" TEXT NOT NULL,
10+
"startDate" TEXT,
11+
"endDate" TEXT,
12+
"isActive" BOOLEAN NOT NULL,
13+
"order" INTEGER,
14+
"serverTimestamp" DATETIME NOT NULL,
15+
"userId" TEXT NOT NULL,
16+
"deleted" BOOLEAN NOT NULL DEFAULT false
17+
);
18+
INSERT INTO "new_Semester" ("deleted", "endDate", "id", "isActive", "name", "order", "serverTimestamp", "startDate", "status", "term", "userId", "year") SELECT "deleted", "endDate", "id", "isActive", "name", "order", "serverTimestamp", "startDate", "status", "term", "userId", "year" FROM "Semester";
19+
DROP TABLE "Semester";
20+
ALTER TABLE "new_Semester" RENAME TO "Semester";
21+
CREATE INDEX "Semester_userId_idx" ON "Semester"("userId");
22+
CREATE UNIQUE INDEX "Semester_userId_id_key" ON "Semester"("userId", "id");
23+
PRAGMA foreign_keys=ON;
24+
PRAGMA defer_foreign_keys=OFF;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
-- Migration number: 20250421 2025-04-20T09:23:08.782Z

src/planner-replication.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -519,6 +519,7 @@ const app = new Hono<{ Bindings: Bindings }>()
519519
{
520520
async findItems(userId, idField, id, lastPulledTimestamp, batchSize) {
521521
if (lastPulledTimestamp) {
522+
522523
return prisma.plannerData.findMany({
523524
where: {
524525
userId,

src/prisma/schema.previous.prisma

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ model PlannerData {
6565
graduationYear String
6666
includedSemesters String // Store as JSON string
6767
description String?
68-
createdAt DateTime
69-
updatedAt DateTime
7068
serverTimestamp DateTime @updatedAt
7169
userId String
7270
deleted Boolean @default(false)
@@ -81,8 +79,8 @@ model Semester {
8179
status String
8280
year String
8381
term String
84-
startDate DateTime?
85-
endDate DateTime?
82+
startDate String?
83+
endDate String?
8684
isActive Boolean
8785
order Int?
8886
serverTimestamp DateTime @updatedAt

src/prisma/schema.prisma

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ model PlannerData {
6565
graduationYear String
6666
includedSemesters String // Store as JSON string
6767
description String?
68-
createdAt DateTime?
69-
updatedAt DateTime?
7068
serverTimestamp DateTime @updatedAt
7169
userId String
7270
deleted Boolean @default(false)
@@ -81,8 +79,8 @@ model Semester {
8179
status String
8280
year String
8381
term String
84-
startDate DateTime?
85-
endDate DateTime?
82+
startDate String?
83+
endDate String?
8684
isActive Boolean
8785
order Int?
8886
serverTimestamp DateTime @updatedAt

0 commit comments

Comments
 (0)