- Added ownerId field to Task model to associate tasks with users. - Updated TaskService methods to enforce user ownership in task operations. - Enhanced API routes to include user authentication and ownership checks. - Modified DailyService and analytics services to filter tasks by user. - Integrated user session handling in various components for personalized task management.
57 lines
1.9 KiB
SQL
57 lines
1.9 KiB
SQL
-- Add ownerId column to tasks table if it doesn't exist
|
|
ALTER TABLE "tasks" ADD COLUMN "ownerId" TEXT;
|
|
|
|
-- Create a temporary user if no users exist
|
|
INSERT OR IGNORE INTO "users" ("id", "email", "name", "password", "createdAt", "updatedAt")
|
|
VALUES ('temp-user', 'temp@example.com', 'Temporary User', '$2b$10$temp', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP);
|
|
|
|
-- Assign all existing tasks to the first user (or temp user if none exist)
|
|
UPDATE "tasks"
|
|
SET "ownerId" = (
|
|
SELECT "id" FROM "users"
|
|
ORDER BY "createdAt" ASC
|
|
LIMIT 1
|
|
)
|
|
WHERE "ownerId" IS NULL;
|
|
|
|
-- Now make ownerId NOT NULL by recreating the table
|
|
CREATE TABLE "tasks_new" (
|
|
"id" TEXT NOT NULL PRIMARY KEY,
|
|
"title" TEXT NOT NULL,
|
|
"description" TEXT,
|
|
"status" TEXT NOT NULL DEFAULT 'todo',
|
|
"priority" TEXT NOT NULL DEFAULT 'medium',
|
|
"source" TEXT NOT NULL,
|
|
"sourceId" TEXT,
|
|
"dueDate" DATETIME,
|
|
"completedAt" DATETIME,
|
|
"createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
"updatedAt" DATETIME NOT NULL,
|
|
"jiraProject" TEXT,
|
|
"jiraKey" TEXT,
|
|
"assignee" TEXT,
|
|
"ownerId" TEXT NOT NULL,
|
|
"jiraType" TEXT,
|
|
"tfsProject" TEXT,
|
|
"tfsPullRequestId" INTEGER,
|
|
"tfsRepository" TEXT,
|
|
"tfsSourceBranch" TEXT,
|
|
"tfsTargetBranch" TEXT,
|
|
"primaryTagId" TEXT,
|
|
CONSTRAINT "tasks_ownerId_fkey" FOREIGN KEY ("ownerId") REFERENCES "users" ("id") ON DELETE CASCADE ON UPDATE CASCADE,
|
|
CONSTRAINT "tasks_primaryTagId_fkey" FOREIGN KEY ("primaryTagId") REFERENCES "tags" ("id") ON DELETE SET NULL ON UPDATE CASCADE
|
|
);
|
|
|
|
-- Copy data from old table to new table
|
|
INSERT INTO "tasks_new" SELECT * FROM "tasks";
|
|
|
|
-- Drop old table
|
|
DROP TABLE "tasks";
|
|
|
|
-- Rename new table
|
|
ALTER TABLE "tasks_new" RENAME TO "tasks";
|
|
|
|
-- Recreate indexes
|
|
CREATE UNIQUE INDEX "tasks_source_sourceId_key" ON "tasks"("source", "sourceId");
|
|
CREATE INDEX "tasks_ownerId_idx" ON "tasks"("ownerId");
|