Skip to content

Commit 5460e52

Browse files
authored
Create SqLDatabaseStructure.sql
Signed-off-by: BloxiSkid <85189373+imBloxi@users.noreply.github.com>
1 parent d9d84f4 commit 5460e52

File tree

1 file changed

+211
-0
lines changed

1 file changed

+211
-0
lines changed

SQL/SqLDatabaseStructure.sql

+211
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
1+
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
2+
3+
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
4+
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
5+
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
6+
/*!40101 SET NAMES utf8mb4 */;
7+
8+
9+
DROP TABLE IF EXISTS `businesses`;
10+
CREATE TABLE IF NOT EXISTS `businesses` (
11+
`id` int(11) NOT NULL AUTO_INCREMENT,
12+
`name` varchar(100) NOT NULL,
13+
`owner_id` int(11) NOT NULL,
14+
`business_type` varchar(100) NOT NULL,
15+
`address` varchar(255) NOT NULL,
16+
`registration_date` date NOT NULL,
17+
PRIMARY KEY (`id`),
18+
KEY `idx_business_owner_id` (`owner_id`)
19+
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
20+
21+
INSERT INTO `businesses` (`id`, `name`, `owner_id`, `business_type`, `address`, `registration_date`) VALUES
22+
(1, 'Tech Innovations', 1, 'Technology', '789 Tech Blvd', '2019-07-01'),
23+
(2, 'Health Solutions', 2, 'Healthcare', '123 Health St', '2020-09-01');
24+
25+
DROP TABLE IF EXISTS `civilians`;
26+
CREATE TABLE IF NOT EXISTS `civilians` (
27+
`id` int(11) NOT NULL AUTO_INCREMENT,
28+
`username` varchar(50) NOT NULL,
29+
`password` varchar(255) NOT NULL,
30+
`first_name` varchar(50) NOT NULL,
31+
`last_name` varchar(50) NOT NULL,
32+
`gender` enum('male','female','other') NOT NULL,
33+
`email` varchar(100) NOT NULL,
34+
`phone` varchar(20) NOT NULL,
35+
`address` varchar(255) NOT NULL,
36+
`occupation` varchar(50) NOT NULL,
37+
`dob` date NOT NULL,
38+
`person_code` varchar(50) NOT NULL,
39+
PRIMARY KEY (`id`),
40+
UNIQUE KEY `username` (`username`),
41+
UNIQUE KEY `email` (`email`),
42+
UNIQUE KEY `person_code` (`person_code`)
43+
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
44+
45+
INSERT INTO `civilians` (`id`, `username`, `password`, `first_name`, `last_name`, `gender`, `email`, `phone`, `address`, `occupation`, `dob`, `person_code`) VALUES
46+
(1, 'john_doe', 'hashed_password1', 'John', 'Doe', 'male', 'john.doe@example.com', '1234567890', '123 Main St', 'Engineer', '1980-01-01', '1980-1234'),
47+
(2, 'jane_smith', 'hashed_password2', 'Jane', 'Smith', 'female', 'jane.smith@example.com', '0987654321', '456 Elm St', 'Doctor', '1990-02-02', '1990-5678'),
48+
49+
DROP TABLE IF EXISTS `court_charges`;
50+
CREATE TABLE IF NOT EXISTS `court_charges` (
51+
`id` int(11) NOT NULL AUTO_INCREMENT,
52+
`document_id` varchar(50) NOT NULL,
53+
`charge` varchar(255) NOT NULL,
54+
PRIMARY KEY (`id`),
55+
KEY `document_id` (`document_id`)
56+
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
57+
58+
59+
DROP TABLE IF EXISTS `court_documents`;
60+
CREATE TABLE IF NOT EXISTS `court_documents` (
61+
`document_id` varchar(50) NOT NULL,
62+
`court_name` varchar(255) NOT NULL,
63+
`person_name` varchar(255) NOT NULL,
64+
`court_date` date NOT NULL,
65+
`judge_name` varchar(255) NOT NULL,
66+
`case_number` varchar(255) NOT NULL,
67+
`description` text DEFAULT NULL,
68+
PRIMARY KEY (`document_id`)
69+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
70+
71+
72+
DROP TABLE IF EXISTS `court_files`;
73+
CREATE TABLE IF NOT EXISTS `court_files` (
74+
`id` int(11) NOT NULL AUTO_INCREMENT,
75+
`file_number` varchar(50) NOT NULL,
76+
`case_title` varchar(255) NOT NULL,
77+
`description` text NOT NULL,
78+
`filing_date` date NOT NULL,
79+
PRIMARY KEY (`id`),
80+
UNIQUE KEY `file_number` (`file_number`)
81+
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
82+
83+
INSERT INTO `court_files` (`id`, `file_number`, `case_title`, `description`, `filing_date`) VALUES
84+
(1, 'CF123456', 'State vs John Doe', 'Theft case against John Doe', '2022-01-10');
85+
86+
DROP TABLE IF EXISTS `criminal_records`;
87+
CREATE TABLE IF NOT EXISTS `criminal_records` (
88+
`id` int(11) NOT NULL AUTO_INCREMENT,
89+
`full_name` varchar(100) NOT NULL,
90+
`crime_type` varchar(100) NOT NULL,
91+
`description` text DEFAULT NULL,
92+
`crime_date` date NOT NULL,
93+
`created_at` timestamp NOT NULL DEFAULT current_timestamp(),
94+
PRIMARY KEY (`id`)
95+
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
96+
97+
98+
DROP TABLE IF EXISTS `dispatch_notifications`;
99+
CREATE TABLE IF NOT EXISTS `dispatch_notifications` (
100+
`id` int(11) NOT NULL AUTO_INCREMENT,
101+
`notification_text` text NOT NULL,
102+
`date` timestamp NOT NULL DEFAULT current_timestamp(),
103+
PRIMARY KEY (`id`)
104+
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
105+
106+
INSERT INTO `dispatch_notifications` (`id`, `notification_text`, `date`) VALUES
107+
(1, 'All units respond to a robbery in progress at 123 Main St', '2024-06-23 23:15:15');
108+
109+
DROP TABLE IF EXISTS `government_operations`;
110+
CREATE TABLE IF NOT EXISTS `government_operations` (
111+
`id` int(11) NOT NULL AUTO_INCREMENT,
112+
`operation_type` varchar(100) NOT NULL,
113+
`description` text NOT NULL,
114+
`date` date NOT NULL,
115+
PRIMARY KEY (`id`)
116+
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
117+
118+
INSERT INTO `government_operations` (`id`, `operation_type`, `description`, `date`) VALUES
119+
(1, 'Public Health', 'COVID-19 vaccination drive', '2021-01-15'),
120+
(2, 'Infrastructure', 'Road construction project', '2021-09-01');
121+
122+
DROP TABLE IF EXISTS `licenses`;
123+
CREATE TABLE IF NOT EXISTS `licenses` (
124+
`id` int(11) NOT NULL AUTO_INCREMENT,
125+
`civilian_id` int(11) NOT NULL,
126+
`license_type` enum('car','bike','scooter') NOT NULL,
127+
`license_number` varchar(50) NOT NULL,
128+
`issue_date` date NOT NULL,
129+
`expiration_date` date NOT NULL,
130+
`expiry_date` date DEFAULT NULL,
131+
PRIMARY KEY (`id`),
132+
UNIQUE KEY `license_number` (`license_number`),
133+
KEY `idx_license_civilian_id` (`civilian_id`)
134+
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
135+
136+
INSERT INTO `licenses` (`id`, `civilian_id`, `license_type`, `license_number`, `issue_date`, `expiration_date`, `expiry_date`) VALUES
137+
(1, 1, 'car', 'CAR123456', '2022-01-01', '2026-01-01', NULL),
138+
(2, 2, 'bike', 'BIKE654321', '2021-06-01', '2025-06-01', NULL);
139+
140+
DROP TABLE IF EXISTS `operations`;
141+
CREATE TABLE IF NOT EXISTS `operations` (
142+
`id` int(11) NOT NULL AUTO_INCREMENT,
143+
`operation_name` varchar(255) NOT NULL,
144+
`operation_type` varchar(255) NOT NULL,
145+
`start_date` date NOT NULL,
146+
`end_date` date DEFAULT NULL,
147+
`status` varchar(50) NOT NULL,
148+
`description` text DEFAULT NULL,
149+
PRIMARY KEY (`id`)
150+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
151+
152+
DROP TABLE IF EXISTS `police_records`;
153+
CREATE TABLE IF NOT EXISTS `police_records` (
154+
`id` int(11) NOT NULL AUTO_INCREMENT,
155+
`officer_id` int(11) NOT NULL,
156+
`record_type` varchar(100) NOT NULL,
157+
`description` text NOT NULL,
158+
`date` date NOT NULL,
159+
PRIMARY KEY (`id`),
160+
KEY `idx_officer_id` (`officer_id`)
161+
) ENGINE=InnoDB AUTO_INCREMENT=3 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
162+
163+
INSERT INTO `police_records` (`id`, `officer_id`, `record_type`, `description`, `date`) VALUES
164+
(1, 1, 'Patrol', 'Patrolled downtown area', '2022-05-10'),
165+
(2, 2, 'Investigation', 'Investigated a robbery', '2022-06-15');
166+
167+
DROP TABLE IF EXISTS `users`;
168+
CREATE TABLE IF NOT EXISTS `users` (
169+
`id` int(11) NOT NULL AUTO_INCREMENT,
170+
`username` varchar(50) NOT NULL,
171+
`password` varchar(255) NOT NULL,
172+
`role` enum('admin','moderator','officer','user') NOT NULL,
173+
PRIMARY KEY (`id`),
174+
UNIQUE KEY `username` (`username`)
175+
) ENGINE=InnoDB AUTO_INCREMENT=2 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
176+
177+
INSERT INTO `users` (`id`, `username`, `password`, `role`) VALUES
178+
(1, 'admin', '$2y$10$5fxugaLoQQh0zse1JWorTeebiBR4.nyE4bgHXHgOHO4UGZzkz/zn.', 'admin');
179+
180+
DROP TABLE IF EXISTS `warrants`;
181+
CREATE TABLE IF NOT EXISTS `warrants` (
182+
`warrant_id` varchar(20) NOT NULL,
183+
`civilian_id` int(11) NOT NULL,
184+
`issue_date` date NOT NULL,
185+
`status` enum('issued','pending','cancelled') NOT NULL DEFAULT 'issued',
186+
`warrant_description` text DEFAULT NULL,
187+
`created_at` timestamp NOT NULL DEFAULT current_timestamp(),
188+
PRIMARY KEY (`warrant_id`),
189+
KEY `civilian_id` (`civilian_id`)
190+
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
191+
192+
193+
194+
ALTER TABLE `businesses`
195+
ADD CONSTRAINT `businesses_ibfk_1` FOREIGN KEY (`owner_id`) REFERENCES `civilians` (`id`);
196+
197+
ALTER TABLE `court_charges`
198+
ADD CONSTRAINT `court_charges_ibfk_1` FOREIGN KEY (`document_id`) REFERENCES `court_documents` (`document_id`) ON DELETE CASCADE ON UPDATE CASCADE;
199+
200+
ALTER TABLE `licenses`
201+
ADD CONSTRAINT `licenses_ibfk_1` FOREIGN KEY (`civilian_id`) REFERENCES `civilians` (`id`);
202+
203+
ALTER TABLE `police_records`
204+
ADD CONSTRAINT `police_records_ibfk_1` FOREIGN KEY (`officer_id`) REFERENCES `civilians` (`id`);
205+
206+
ALTER TABLE `warrants`
207+
ADD CONSTRAINT `warrants_ibfk_1` FOREIGN KEY (`civilian_id`) REFERENCES `civilians` (`id`);
208+
209+
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
210+
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
211+
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

0 commit comments

Comments
 (0)