migrate_projects.sql 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. USE inventory_db;
  2. -- Add hour_price field to clients table
  3. ALTER TABLE clients ADD COLUMN hour_price DECIMAL(10,2) DEFAULT 0.00 AFTER country;
  4. -- Create projects table
  5. CREATE TABLE IF NOT EXISTS projects (
  6. id INT(11) AUTO_INCREMENT PRIMARY KEY,
  7. customer_id INT(11) NOT NULL,
  8. project_name VARCHAR(255) NOT NULL,
  9. description TEXT NULL,
  10. status ENUM('planning', 'in_progress', 'completed', 'on_hold', 'cancelled') DEFAULT 'planning',
  11. start_date DATE NULL,
  12. end_date DATE NULL,
  13. budget DECIMAL(10,2) NULL,
  14. created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  15. updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  16. FOREIGN KEY (customer_id) REFERENCES clients(id) ON DELETE CASCADE,
  17. INDEX idx_customer (customer_id),
  18. INDEX idx_status (status),
  19. INDEX idx_dates (start_date, end_date)
  20. );
  21. -- Create subprojects table
  22. CREATE TABLE IF NOT EXISTS subprojects (
  23. id INT(11) AUTO_INCREMENT PRIMARY KEY,
  24. project_id INT(11) NOT NULL,
  25. subproject_name VARCHAR(255) NOT NULL,
  26. description TEXT NULL,
  27. status ENUM('planning', 'in_progress', 'completed', 'on_hold', 'cancelled') DEFAULT 'planning',
  28. start_date DATE NULL,
  29. end_date DATE NULL,
  30. budget DECIMAL(10,2) NULL,
  31. created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  32. updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  33. FOREIGN KEY (project_id) REFERENCES projects(id) ON DELETE CASCADE,
  34. INDEX idx_project (project_id),
  35. INDEX idx_status (status),
  36. INDEX idx_dates (start_date, end_date)
  37. );