diff --git a/prisma/migrations/20260606002901_plan_categories/migration.sql b/prisma/migrations/20260606002901_plan_categories/migration.sql new file mode 100644 index 0000000..baf05d7 --- /dev/null +++ b/prisma/migrations/20260606002901_plan_categories/migration.sql @@ -0,0 +1,32 @@ +-- Add plan_categories table and convert category columns from ENUM to VARCHAR(50) + +-- CreateTable +CREATE TABLE `plan_categories` ( + `id` INTEGER NOT NULL AUTO_INCREMENT, + `key` VARCHAR(50) NOT NULL, + `label` VARCHAR(100) NOT NULL, + `color` VARCHAR(7) NOT NULL, + `sort_order` INTEGER NOT NULL DEFAULT 0, + `is_active` BOOLEAN NOT NULL DEFAULT true, + `created_at` DATETIME(0) NULL DEFAULT CURRENT_TIMESTAMP(0), + `updated_at` DATETIME(0) NULL DEFAULT CURRENT_TIMESTAMP(0), + + UNIQUE INDEX `plan_categories_key_key`(`key`), + PRIMARY KEY (`id`) +) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; + +-- AlterTable: change category from ENUM to VARCHAR(50) in work_plan_entries +ALTER TABLE `work_plan_entries` MODIFY `category` VARCHAR(50) NOT NULL DEFAULT 'work'; + +-- AlterTable: change category from ENUM to VARCHAR(50) in work_plan_overrides +ALTER TABLE `work_plan_overrides` MODIFY `category` VARCHAR(50) NOT NULL; + +-- Seed the categories that were previously the plan_category enum +INSERT INTO `plan_categories` (`key`, `label`, `color`, `sort_order`, `is_active`) VALUES + ('work', 'Práce', '#2563eb', 1, true), + ('preparation', 'Příprava', '#0d9488', 2, true), + ('travel', 'Cesta / Montáž', '#ca8a04', 3, true), + ('leave', 'Dovolená', '#16a34a', 4, true), + ('sick', 'Nemoc', '#dc2626', 5, true), + ('training', 'Školení', '#7c3aed', 6, true), + ('other', 'Jiné', '#6b7280', 7, true); diff --git a/prisma/schema.prisma b/prisma/schema.prisma index cff5b3b..5377496 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -678,16 +678,6 @@ enum sklad_inventory_status { CONFIRMED } -enum plan_category { - work - preparation - travel - leave - sick - training - other -} - model sklad_categories { id Int @id @default(autoincrement()) name String @db.VarChar(100) @@ -934,13 +924,24 @@ model sklad_inventory_lines { @@map("sklad_inventory_lines") } +model plan_categories { + id Int @id @default(autoincrement()) + key String @unique @db.VarChar(50) + label String @db.VarChar(100) + color String @db.VarChar(7) + sort_order Int @default(0) + is_active Boolean @default(true) + created_at DateTime? @default(now()) @db.DateTime(0) + updated_at DateTime? @default(now()) @updatedAt @db.DateTime(0) +} + model work_plan_entries { id Int @id @default(autoincrement()) user_id Int date_from DateTime @db.Date date_to DateTime @db.Date project_id Int? - category plan_category @default(work) + category String @default("work") @db.VarChar(50) note String @db.VarChar(500) created_by Int created_at DateTime? @default(now()) @db.Timestamp(0) @@ -961,7 +962,7 @@ model work_plan_overrides { user_id Int shift_date DateTime @db.Date project_id Int? - category plan_category + category String @db.VarChar(50) note String @db.VarChar(500) created_by Int created_at DateTime? @default(now()) @db.Timestamp(0)