34853-vm/db/migrations/004_create_orders_table.sql
2025-10-11 05:03:50 +00:00

14 lines
597 B
SQL

-- Create the orders table
CREATE TABLE IF NOT EXISTS `orders` (
`id` INT AUTO_INCREMENT PRIMARY KEY,
`customer_id` INT NOT NULL,
`plan_id` INT NOT NULL,
`order_status` VARCHAR(50) NOT NULL DEFAULT 'pending', -- e.g., pending, active, cancelled
`total_amount` DECIMAL(10, 2) NOT NULL,
`order_date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
`activation_date` DATE NULL,
`notes` TEXT NULL,
FOREIGN KEY (`customer_id`) REFERENCES `customers`(`id`) ON DELETE CASCADE,
FOREIGN KEY (`plan_id`) REFERENCES `plans`(`id`) ON DELETE RESTRICT
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;