feat(plan): add plan_categories table, migrate category enum to varchar
- Add `plan_categories` model (id, key, label, color, sort_order, is_active) - Change `work_plan_entries.category` from ENUM plan_category to VARCHAR(50) - Change `work_plan_overrides.category` from ENUM plan_category to VARCHAR(50) - Remove the `plan_category` enum from schema - Seed 7 built-in categories (work, preparation, travel, leave, sick, training, other) Also fixes two pre-existing migration issues that blocked shadow-DB execution: - 20260605122718: swap CREATE INDEX before DROP INDEX so MySQL FK constraint is not broken - 20260514071455_init: fix quotations.project_code VARCHAR(50→100) to match actual DB schema Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -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);
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user