Files
2026-09-16 23:20:08 +07:00

73 lines
2.7 KiB
SQL

-- Database Schema for Enterprise Procurement & Asset Management
CREATE TABLE `users` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`username` varchar(50) NOT NULL,
`password` varchar(255) NOT NULL,
`role` enum('Admin','Manager','User') DEFAULT 'User',
`department_id` int(11) DEFAULT NULL,
`created_at` timestamp DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE `vendors` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(150) NOT NULL,
`contact_person` varchar(100) DEFAULT NULL,
`email` varchar(100) DEFAULT NULL,
`phone` varchar(50) DEFAULT NULL,
`created_at` timestamp DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE `software_licenses` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(150) NOT NULL,
`vendor_id` int(11) DEFAULT NULL,
`version` varchar(50) DEFAULT NULL,
`license_type` enum('Perpetual','Subscription') NOT NULL,
`department_id` int(11) DEFAULT NULL,
`responsible_user_id` int(11) DEFAULT NULL,
`price` decimal(10,2) DEFAULT '0.00',
`purchase_date` date DEFAULT NULL,
`start_date` date DEFAULT NULL,
`expiry_date` date DEFAULT NULL,
`license_count` int(11) DEFAULT 1,
`renewal_cycle_years` int(11) DEFAULT NULL COMMENT '1, 2, 3, 4, 5. NULL if Perpetual',
`status` enum('Active','Expiring Soon','Expired') DEFAULT 'Active',
`created_at` timestamp DEFAULT CURRENT_TIMESTAMP,
`updated_at` timestamp DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
FOREIGN KEY (`vendor_id`) REFERENCES `vendors`(`id`),
FOREIGN KEY (`responsible_user_id`) REFERENCES `users`(`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE `software_renewal_history` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`software_license_id` int(11) NOT NULL,
`old_expiry_date` date DEFAULT NULL,
`new_expiry_date` date NOT NULL,
`old_renewal_cycle` int(11) DEFAULT NULL,
`new_renewal_cycle` int(11) NOT NULL,
`price` decimal(10,2) DEFAULT '0.00',
`renewed_by_user_id` int(11) NOT NULL,
`renewed_at` timestamp DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
FOREIGN KEY (`software_license_id`) REFERENCES `software_licenses`(`id`),
FOREIGN KEY (`renewed_by_user_id`) REFERENCES `users`(`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
CREATE TABLE `audit_logs` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`user_id` int(11) DEFAULT NULL,
`module` varchar(50) NOT NULL,
`reference_id` int(11) NOT NULL,
`action` varchar(50) NOT NULL,
`field_changed` varchar(50) DEFAULT NULL,
`old_value` text DEFAULT NULL,
`new_value` text DEFAULT NULL,
`ip_address` varchar(45) DEFAULT NULL,
`created_at` timestamp DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;