migrate_new_tables.sql 1.0 KB

123456789101112131415161718192021222324252627
  1. USE inventory_db;
  2. CREATE TABLE IF NOT EXISTS rental_prices (
  3. id INT(11) AUTO_INCREMENT PRIMARY KEY,
  4. item_id INT(11) NOT NULL,
  5. start_date DATE NOT NULL,
  6. end_date DATE NOT NULL,
  7. daily_price DECIMAL(10,2) NOT NULL DEFAULT 0.00,
  8. created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  9. updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  10. FOREIGN KEY (item_id) REFERENCES items(id) ON DELETE CASCADE,
  11. INDEX idx_item_dates (item_id, start_date, end_date)
  12. );
  13. CREATE TABLE IF NOT EXISTS attachments (
  14. id INT(11) AUTO_INCREMENT PRIMARY KEY,
  15. item_id INT(11) NOT NULL,
  16. filename VARCHAR(255) NOT NULL,
  17. original_name VARCHAR(255) NOT NULL,
  18. file_type ENUM('receipt', 'warranty', 'other') NOT NULL DEFAULT 'other',
  19. file_path VARCHAR(255) NOT NULL,
  20. file_size INT(11) NOT NULL,
  21. mime_type VARCHAR(100) NOT NULL,
  22. created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  23. FOREIGN KEY (item_id) REFERENCES items(id) ON DELETE CASCADE,
  24. INDEX idx_item_type (item_id, file_type)
  25. );