-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcreate_test_databases.py
More file actions
352 lines (310 loc) · 14.1 KB
/
Copy pathcreate_test_databases.py
File metadata and controls
352 lines (310 loc) · 14.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
"""
Script to create sample SQLite databases for testing the Database Viewer app
"""
import sqlite3
import os
from datetime import datetime, timedelta
import random
# Create test_databases folder if it doesn't exist
os.makedirs('test_databases', exist_ok=True)
def create_customers_db():
"""Create a simple customers database"""
conn = sqlite3.connect('test_databases/customers.db')
cursor = conn.cursor()
# Create customers table
cursor.execute('''
CREATE TABLE IF NOT EXISTS customers (
id INTEGER PRIMARY KEY AUTOINCREMENT,
first_name TEXT NOT NULL,
last_name TEXT NOT NULL,
email TEXT UNIQUE NOT NULL,
phone TEXT,
city TEXT,
country TEXT,
registration_date TEXT,
is_active INTEGER DEFAULT 1
)
''')
# Sample customer data
customers = [
('John', 'Doe', 'john.doe@email.com', '+1-555-0101', 'New York', 'USA', '2024-01-15', 1),
('Jane', 'Smith', 'jane.smith@email.com', '+1-555-0102', 'Los Angeles', 'USA', '2024-02-20', 1),
('Mike', 'Johnson', 'mike.j@email.com', '+1-555-0103', 'Chicago', 'USA', '2024-03-10', 1),
('Emily', 'Brown', 'emily.b@email.com', '+44-20-5550104', 'London', 'UK', '2024-01-25', 1),
('David', 'Wilson', 'david.w@email.com', '+1-555-0105', 'Houston', 'USA', '2024-04-05', 0),
('Sarah', 'Davis', 'sarah.d@email.com', '+1-555-0106', 'Phoenix', 'USA', '2024-02-14', 1),
('Tom', 'Martinez', 'tom.m@email.com', '+1-555-0107', 'Philadelphia', 'USA', '2024-03-22', 1),
('Lisa', 'Anderson', 'lisa.a@email.com', '+61-2-5550108', 'Sydney', 'Australia', '2024-01-30', 1),
('Chris', 'Taylor', 'chris.t@email.com', '+1-555-0109', 'San Diego', 'USA', '2024-04-12', 1),
('Anna', 'Thomas', 'anna.t@email.com', '+49-30-5550110', 'Berlin', 'Germany', '2024-02-28', 1),
]
cursor.executemany('''
INSERT INTO customers (first_name, last_name, email, phone, city, country, registration_date, is_active)
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
''', customers)
conn.commit()
conn.close()
print("✓ Created customers.db with 10 customers")
def create_ecommerce_db():
"""Create a more complex e-commerce database with multiple tables"""
conn = sqlite3.connect('test_databases/ecommerce.db')
cursor = conn.cursor()
# Products table
cursor.execute('''
CREATE TABLE IF NOT EXISTS products (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
category TEXT,
price REAL NOT NULL,
stock INTEGER DEFAULT 0,
description TEXT
)
''')
products = [
('Laptop Pro 15"', 'Electronics', 1299.99, 25, 'High-performance laptop with 16GB RAM'),
('Wireless Mouse', 'Electronics', 29.99, 150, 'Ergonomic wireless mouse'),
('USB-C Cable', 'Accessories', 12.99, 500, '6ft USB-C charging cable'),
('Desk Chair', 'Furniture', 249.99, 40, 'Ergonomic office chair with lumbar support'),
('Monitor 27"', 'Electronics', 349.99, 60, '4K UHD monitor'),
('Keyboard Mechanical', 'Electronics', 89.99, 75, 'RGB mechanical keyboard'),
('Desk Lamp', 'Furniture', 34.99, 120, 'LED desk lamp with adjustable brightness'),
('Laptop Stand', 'Accessories', 45.99, 200, 'Aluminum laptop stand'),
('Webcam HD', 'Electronics', 79.99, 85, '1080p HD webcam'),
('Phone Stand', 'Accessories', 15.99, 300, 'Adjustable phone stand'),
]
cursor.executemany('''
INSERT INTO products (name, category, price, stock, description)
VALUES (?, ?, ?, ?, ?)
''', products)
# Orders table
cursor.execute('''
CREATE TABLE IF NOT EXISTS orders (
id INTEGER PRIMARY KEY AUTOINCREMENT,
customer_name TEXT NOT NULL,
customer_email TEXT NOT NULL,
order_date TEXT NOT NULL,
total_amount REAL NOT NULL,
status TEXT DEFAULT 'Pending'
)
''')
orders = [
('John Doe', 'john.doe@email.com', '2024-10-01', 1329.98, 'Delivered'),
('Jane Smith', 'jane.smith@email.com', '2024-10-02', 379.98, 'Shipped'),
('Mike Johnson', 'mike.j@email.com', '2024-10-03', 249.99, 'Processing'),
('Emily Brown', 'emily.b@email.com', '2024-10-04', 89.99, 'Delivered'),
('David Wilson', 'david.w@email.com', '2024-10-05', 1699.96, 'Pending'),
('Sarah Davis', 'sarah.d@email.com', '2024-10-06', 45.99, 'Delivered'),
('Tom Martinez', 'tom.m@email.com', '2024-10-07', 79.99, 'Shipped'),
('Lisa Anderson', 'lisa.a@email.com', '2024-10-08', 424.97, 'Processing'),
]
cursor.executemany('''
INSERT INTO orders (customer_name, customer_email, order_date, total_amount, status)
VALUES (?, ?, ?, ?, ?)
''', orders)
# Reviews table
cursor.execute('''
CREATE TABLE IF NOT EXISTS reviews (
id INTEGER PRIMARY KEY AUTOINCREMENT,
product_id INTEGER,
customer_name TEXT,
rating INTEGER CHECK(rating >= 1 AND rating <= 5),
comment TEXT,
review_date TEXT,
FOREIGN KEY (product_id) REFERENCES products(id)
)
''')
reviews = [
(1, 'John Doe', 5, 'Excellent laptop! Very fast and reliable.', '2024-10-05'),
(1, 'Jane Smith', 4, 'Great performance but a bit pricey.', '2024-10-06'),
(2, 'Mike Johnson', 5, 'Perfect mouse, very comfortable.', '2024-10-07'),
(4, 'Emily Brown', 5, 'Best chair I ever bought!', '2024-10-08'),
(5, 'David Wilson', 4, 'Beautiful display, worth the money.', '2024-10-09'),
(6, 'Sarah Davis', 5, 'Love the mechanical feel!', '2024-10-10'),
(9, 'Tom Martinez', 3, 'Good webcam but could be better in low light.', '2024-10-11'),
]
cursor.executemany('''
INSERT INTO reviews (product_id, customer_name, rating, comment, review_date)
VALUES (?, ?, ?, ?, ?)
''', reviews)
conn.commit()
conn.close()
print("✓ Created ecommerce.db with products, orders, and reviews tables")
def create_employees_db():
"""Create an employees database"""
conn = sqlite3.connect('test_databases/employees.db')
cursor = conn.cursor()
# Departments table
cursor.execute('''
CREATE TABLE IF NOT EXISTS departments (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
location TEXT,
budget REAL
)
''')
departments = [
('Engineering', 'Building A', 500000),
('Marketing', 'Building B', 250000),
('Sales', 'Building B', 300000),
('Human Resources', 'Building C', 150000),
('Finance', 'Building C', 200000),
]
cursor.executemany('''
INSERT INTO departments (name, location, budget)
VALUES (?, ?, ?)
''', departments)
# Employees table
cursor.execute('''
CREATE TABLE IF NOT EXISTS employees (
id INTEGER PRIMARY KEY AUTOINCREMENT,
first_name TEXT NOT NULL,
last_name TEXT NOT NULL,
email TEXT UNIQUE NOT NULL,
department_id INTEGER,
position TEXT,
salary REAL,
hire_date TEXT,
FOREIGN KEY (department_id) REFERENCES departments(id)
)
''')
employees = [
('Alice', 'Johnson', 'alice.j@company.com', 1, 'Senior Engineer', 95000, '2020-03-15'),
('Bob', 'Williams', 'bob.w@company.com', 1, 'Software Engineer', 75000, '2021-06-01'),
('Carol', 'Davis', 'carol.d@company.com', 1, 'Lead Engineer', 110000, '2019-01-10'),
('Dan', 'Miller', 'dan.m@company.com', 2, 'Marketing Manager', 85000, '2020-08-20'),
('Eve', 'Garcia', 'eve.g@company.com', 2, 'Content Specialist', 60000, '2022-02-14'),
('Frank', 'Martinez', 'frank.m@company.com', 3, 'Sales Director', 100000, '2018-11-05'),
('Grace', 'Rodriguez', 'grace.r@company.com', 3, 'Sales Representative', 55000, '2021-09-12'),
('Henry', 'Wilson', 'henry.w@company.com', 4, 'HR Manager', 70000, '2020-05-18'),
('Iris', 'Lopez', 'iris.l@company.com', 5, 'Financial Analyst', 72000, '2021-03-22'),
('Jack', 'Lee', 'jack.l@company.com', 5, 'Accountant', 65000, '2022-07-01'),
]
cursor.executemany('''
INSERT INTO employees (first_name, last_name, email, department_id, position, salary, hire_date)
VALUES (?, ?, ?, ?, ?, ?, ?)
''', employees)
# Projects table
cursor.execute('''
CREATE TABLE IF NOT EXISTS projects (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
department_id INTEGER,
start_date TEXT,
end_date TEXT,
status TEXT,
budget REAL,
FOREIGN KEY (department_id) REFERENCES departments(id)
)
''')
projects = [
('Website Redesign', 1, '2024-01-15', '2024-06-30', 'Completed', 75000),
('Mobile App Development', 1, '2024-03-01', '2024-12-31', 'In Progress', 150000),
('Q4 Marketing Campaign', 2, '2024-09-01', '2024-12-31', 'In Progress', 50000),
('Customer Database Migration', 1, '2024-02-01', '2024-04-30', 'Completed', 40000),
('Employee Training Program', 4, '2024-01-01', '2024-12-31', 'In Progress', 25000),
]
cursor.executemany('''
INSERT INTO projects (name, department_id, start_date, end_date, status, budget)
VALUES (?, ?, ?, ?, ?, ?)
''', projects)
conn.commit()
conn.close()
print("✓ Created employees.db with departments, employees, and projects tables")
def create_library_db():
"""Create a library database"""
conn = sqlite3.connect('test_databases/library.db')
cursor = conn.cursor()
# Books table
cursor.execute('''
CREATE TABLE IF NOT EXISTS books (
id INTEGER PRIMARY KEY AUTOINCREMENT,
title TEXT NOT NULL,
author TEXT NOT NULL,
isbn TEXT UNIQUE,
publisher TEXT,
year INTEGER,
genre TEXT,
copies_available INTEGER DEFAULT 1
)
''')
books = [
('The Great Gatsby', 'F. Scott Fitzgerald', '978-0743273565', 'Scribner', 1925, 'Fiction', 3),
('To Kill a Mockingbird', 'Harper Lee', '978-0061120084', 'Harper Perennial', 1960, 'Fiction', 4),
('1984', 'George Orwell', '978-0451524935', 'Signet Classic', 1949, 'Science Fiction', 5),
('Pride and Prejudice', 'Jane Austen', '978-0141439518', 'Penguin Classics', 1813, 'Romance', 2),
('The Catcher in the Rye', 'J.D. Salinger', '978-0316769174', 'Little, Brown', 1951, 'Fiction', 3),
('Harry Potter and the Sorcerer\'s Stone', 'J.K. Rowling', '978-0439708180', 'Scholastic', 1997, 'Fantasy', 6),
('The Hobbit', 'J.R.R. Tolkien', '978-0547928227', 'Houghton Mifflin', 1937, 'Fantasy', 4),
('Fahrenheit 451', 'Ray Bradbury', '978-1451673319', 'Simon & Schuster', 1953, 'Science Fiction', 3),
('Jane Eyre', 'Charlotte Brontë', '978-0141441146', 'Penguin Classics', 1847, 'Romance', 2),
('Animal Farm', 'George Orwell', '978-0451526342', 'Signet Classic', 1945, 'Political Fiction', 4),
]
cursor.executemany('''
INSERT INTO books (title, author, isbn, publisher, year, genre, copies_available)
VALUES (?, ?, ?, ?, ?, ?, ?)
''', books)
# Members table
cursor.execute('''
CREATE TABLE IF NOT EXISTS members (
id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
email TEXT UNIQUE NOT NULL,
phone TEXT,
join_date TEXT,
membership_type TEXT
)
''')
members = [
('Alice Cooper', 'alice.c@email.com', '555-0201', '2023-01-15', 'Premium'),
('Bob Taylor', 'bob.t@email.com', '555-0202', '2023-03-20', 'Standard'),
('Carol White', 'carol.w@email.com', '555-0203', '2023-05-10', 'Premium'),
('David Green', 'david.g@email.com', '555-0204', '2023-07-05', 'Standard'),
('Emma Black', 'emma.b@email.com', '555-0205', '2023-09-12', 'Standard'),
('Frank Blue', 'frank.b@email.com', '555-0206', '2024-01-08', 'Premium'),
]
cursor.executemany('''
INSERT INTO members (name, email, phone, join_date, membership_type)
VALUES (?, ?, ?, ?, ?)
''', members)
# Loans table
cursor.execute('''
CREATE TABLE IF NOT EXISTS loans (
id INTEGER PRIMARY KEY AUTOINCREMENT,
book_id INTEGER,
member_id INTEGER,
loan_date TEXT,
due_date TEXT,
return_date TEXT,
status TEXT DEFAULT 'Active',
FOREIGN KEY (book_id) REFERENCES books(id),
FOREIGN KEY (member_id) REFERENCES members(id)
)
''')
loans = [
(1, 1, '2024-09-15', '2024-10-15', None, 'Active'),
(3, 2, '2024-09-20', '2024-10-20', None, 'Active'),
(6, 3, '2024-09-25', '2024-10-25', '2024-10-10', 'Returned'),
(7, 4, '2024-09-28', '2024-10-28', None, 'Active'),
(2, 5, '2024-10-01', '2024-11-01', None, 'Active'),
(8, 1, '2024-10-05', '2024-11-05', None, 'Active'),
]
cursor.executemany('''
INSERT INTO loans (book_id, member_id, loan_date, due_date, return_date, status)
VALUES (?, ?, ?, ?, ?, ?)
''', loans)
conn.commit()
conn.close()
print("✓ Created library.db with books, members, and loans tables")
if __name__ == '__main__':
print("\n🗄️ Creating test databases...\n")
create_customers_db()
create_ecommerce_db()
create_employees_db()
create_library_db()
print("\n✅ All test databases created successfully in 'test_databases/' folder!")
print("\nYou can now upload these databases to test the application:")
print(" - customers.db (Simple customer data)")
print(" - ecommerce.db (Products, orders, and reviews)")
print(" - employees.db (Departments, employees, and projects)")
print(" - library.db (Books, members, and loans)")
print()