migrate_db.py 801 B

123456789101112131415161718192021
  1. import db
  2. query = """
  3. CREATE TABLE IF NOT EXISTS `warehouse_stock` (
  4. `id` int(11) NOT NULL AUTO_INCREMENT,
  5. `material_id` int(11) NOT NULL,
  6. `color_name` varchar(100) NOT NULL,
  7. `quantity` decimal(10,2) DEFAULT 0.00,
  8. `notes` text DEFAULT NULL,
  9. `is_active` tinyint(1) DEFAULT 1,
  10. `created_at` timestamp NULL DEFAULT current_timestamp(),
  11. `updated_at` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
  12. PRIMARY KEY (`id`),
  13. KEY `material_id` (`material_id`),
  14. CONSTRAINT `fk_warehouse_material` FOREIGN KEY (`material_id`) REFERENCES `materials` (`id`) ON DELETE CASCADE
  15. ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
  16. """
  17. try:
  18. db.execute_commit(query)
  19. print("TABLE CREATED SUCCESSFULLY")
  20. except Exception as e:
  21. print(f"ERROR: {e}")