Add target DB setup
This commit is contained in:
25
backend/docker-compose.target-db.yml
Normal file
25
backend/docker-compose.target-db.yml
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
services:
|
||||||
|
db-target:
|
||||||
|
image: mysql:8.0
|
||||||
|
container_name: petshop-db-target
|
||||||
|
restart: always
|
||||||
|
environment:
|
||||||
|
MYSQL_ROOT_PASSWORD: root
|
||||||
|
MYSQL_DATABASE: Petstoredb_target
|
||||||
|
MYSQL_USER: petshop
|
||||||
|
MYSQL_PASSWORD: petshop
|
||||||
|
ports:
|
||||||
|
- "3307:3306"
|
||||||
|
volumes:
|
||||||
|
- db_target_data:/var/lib/mysql
|
||||||
|
- ./src/main/resources/dev/final-target/final_target_schema.sql:/docker-entrypoint-initdb.d/01_final_target_schema.sql:ro
|
||||||
|
- ./src/main/resources/dev/final-target/final_target_seed.sql:/docker-entrypoint-initdb.d/02_final_target_seed.sql:ro
|
||||||
|
healthcheck:
|
||||||
|
test: ["CMD", "mysqladmin", "ping", "-h", "127.0.0.1", "-uroot", "-proot"]
|
||||||
|
interval: 10s
|
||||||
|
timeout: 5s
|
||||||
|
retries: 30
|
||||||
|
start_period: 40s
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
db_target_data:
|
||||||
@@ -197,6 +197,57 @@
|
|||||||
</arguments>
|
</arguments>
|
||||||
</configuration>
|
</configuration>
|
||||||
</execution>
|
</execution>
|
||||||
|
<execution>
|
||||||
|
<id>docker-up-target-db</id>
|
||||||
|
<goals>
|
||||||
|
<goal>exec</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<executable>docker</executable>
|
||||||
|
<arguments>
|
||||||
|
<argument>compose</argument>
|
||||||
|
<argument>-f</argument>
|
||||||
|
<argument>docker-compose.target-db.yml</argument>
|
||||||
|
<argument>up</argument>
|
||||||
|
<argument>-d</argument>
|
||||||
|
<argument>--wait</argument>
|
||||||
|
<argument>db-target</argument>
|
||||||
|
</arguments>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
<execution>
|
||||||
|
<id>docker-down-target-db</id>
|
||||||
|
<goals>
|
||||||
|
<goal>exec</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<executable>docker</executable>
|
||||||
|
<arguments>
|
||||||
|
<argument>compose</argument>
|
||||||
|
<argument>-f</argument>
|
||||||
|
<argument>docker-compose.target-db.yml</argument>
|
||||||
|
<argument>down</argument>
|
||||||
|
<argument>-v</argument>
|
||||||
|
<argument>--remove-orphans</argument>
|
||||||
|
</arguments>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
<execution>
|
||||||
|
<id>docker-logs-target-db</id>
|
||||||
|
<goals>
|
||||||
|
<goal>exec</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<executable>docker</executable>
|
||||||
|
<arguments>
|
||||||
|
<argument>compose</argument>
|
||||||
|
<argument>-f</argument>
|
||||||
|
<argument>docker-compose.target-db.yml</argument>
|
||||||
|
<argument>logs</argument>
|
||||||
|
<argument>db-target</argument>
|
||||||
|
</arguments>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
|
|||||||
@@ -1,2 +0,0 @@
|
|||||||
INSERT INTO service (serviceName, serviceDesc, serviceDuration, servicePrice)
|
|
||||||
VALUES ('Pet Adoption', 'Schedule a visit to meet and adopt an available pet', 30, 0.00);
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
CREATE TABLE IF NOT EXISTS appointment_customer_pet (
|
|
||||||
appointment_id BIGINT NOT NULL,
|
|
||||||
customer_pet_id BIGINT NOT NULL,
|
|
||||||
PRIMARY KEY (appointment_id, customer_pet_id),
|
|
||||||
FOREIGN KEY (appointment_id) REFERENCES appointment(appointmentId),
|
|
||||||
FOREIGN KEY (customer_pet_id) REFERENCES customer_pet(customer_pet_id)
|
|
||||||
);
|
|
||||||
@@ -1,91 +0,0 @@
|
|||||||
INSERT INTO users (username, password, email, fullName, phone, role, active, tokenVersion)
|
|
||||||
SELECT
|
|
||||||
CONCAT('customer_', c.customerId) AS username,
|
|
||||||
'$2a$10$mE0D/HrnCuqFeEqMy0NJwuy2jkoRYjQ7GrKcc/7QQ0r2AqnZTvyGq' AS password,
|
|
||||||
CASE
|
|
||||||
WHEN c.email IS NOT NULL
|
|
||||||
AND c.email <> ''
|
|
||||||
AND (SELECT COUNT(*) FROM customer c2 WHERE c2.email = c.email) = 1
|
|
||||||
AND NOT EXISTS (SELECT 1 FROM employee e2 WHERE e2.email = c.email)
|
|
||||||
AND NOT EXISTS (SELECT 1 FROM users u WHERE u.email = c.email)
|
|
||||||
THEN c.email
|
|
||||||
ELSE CONCAT('customer_', c.customerId, '@petshop.local')
|
|
||||||
END AS email,
|
|
||||||
CONCAT(c.firstName, ' ', c.lastName) AS fullName,
|
|
||||||
CONCAT('200-000-', LPAD(c.customerId, 4, '0')) AS phone,
|
|
||||||
'CUSTOMER' AS role,
|
|
||||||
FALSE AS active,
|
|
||||||
0 AS tokenVersion
|
|
||||||
FROM customer c
|
|
||||||
WHERE c.user_id IS NULL
|
|
||||||
AND NOT EXISTS (
|
|
||||||
SELECT 1
|
|
||||||
FROM users u
|
|
||||||
WHERE u.username = CONCAT('customer_', c.customerId)
|
|
||||||
);
|
|
||||||
|
|
||||||
INSERT INTO users (username, password, email, fullName, phone, role, active, tokenVersion)
|
|
||||||
SELECT
|
|
||||||
CONCAT('employee_', e.employeeId) AS username,
|
|
||||||
'$2a$10$mE0D/HrnCuqFeEqMy0NJwuy2jkoRYjQ7GrKcc/7QQ0r2AqnZTvyGq' AS password,
|
|
||||||
CASE
|
|
||||||
WHEN e.email IS NOT NULL
|
|
||||||
AND e.email <> ''
|
|
||||||
AND (SELECT COUNT(*) FROM employee e2 WHERE e2.email = e.email) = 1
|
|
||||||
AND NOT EXISTS (SELECT 1 FROM customer c2 WHERE c2.email = e.email)
|
|
||||||
AND NOT EXISTS (SELECT 1 FROM users u WHERE u.email = e.email)
|
|
||||||
THEN e.email
|
|
||||||
ELSE CONCAT('employee_', e.employeeId, '@petshop.local')
|
|
||||||
END AS email,
|
|
||||||
CONCAT(e.firstName, ' ', e.lastName) AS fullName,
|
|
||||||
CONCAT('300-000-', LPAD(e.employeeId, 4, '0')) AS phone,
|
|
||||||
CASE
|
|
||||||
WHEN UPPER(e.role) = 'MANAGER' THEN 'ADMIN'
|
|
||||||
ELSE 'STAFF'
|
|
||||||
END AS role,
|
|
||||||
FALSE AS active,
|
|
||||||
0 AS tokenVersion
|
|
||||||
FROM employee e
|
|
||||||
WHERE e.user_id IS NULL
|
|
||||||
AND NOT EXISTS (
|
|
||||||
SELECT 1
|
|
||||||
FROM users u
|
|
||||||
WHERE u.username = CONCAT('employee_', e.employeeId)
|
|
||||||
);
|
|
||||||
|
|
||||||
UPDATE customer c
|
|
||||||
JOIN users u ON u.username = CONCAT('customer_', c.customerId)
|
|
||||||
AND u.role = 'CUSTOMER'
|
|
||||||
SET c.user_id = u.id
|
|
||||||
WHERE c.user_id IS NULL;
|
|
||||||
|
|
||||||
UPDATE employee e
|
|
||||||
JOIN users u ON u.username = CONCAT('employee_', e.employeeId)
|
|
||||||
AND u.role IN ('STAFF', 'ADMIN')
|
|
||||||
SET e.user_id = u.id
|
|
||||||
WHERE e.user_id IS NULL;
|
|
||||||
|
|
||||||
UPDATE users
|
|
||||||
SET
|
|
||||||
fullName = CASE
|
|
||||||
WHEN fullName IS NULL OR fullName = '' THEN username
|
|
||||||
ELSE fullName
|
|
||||||
END,
|
|
||||||
email = CASE
|
|
||||||
WHEN email IS NULL OR email = '' THEN CONCAT(username, '@petshop.local')
|
|
||||||
ELSE email
|
|
||||||
END,
|
|
||||||
phone = CASE
|
|
||||||
WHEN phone IS NULL OR phone = '' THEN CONCAT('000-000-', LPAD(id, 4, '0'))
|
|
||||||
ELSE phone
|
|
||||||
END,
|
|
||||||
active = COALESCE(active, TRUE),
|
|
||||||
tokenVersion = COALESCE(tokenVersion, 0)
|
|
||||||
WHERE fullName IS NULL
|
|
||||||
OR fullName = ''
|
|
||||||
OR email IS NULL
|
|
||||||
OR email = ''
|
|
||||||
OR phone IS NULL
|
|
||||||
OR phone = ''
|
|
||||||
OR active IS NULL
|
|
||||||
OR tokenVersion IS NULL;
|
|
||||||
@@ -1,3 +0,0 @@
|
|||||||
UPDATE sale
|
|
||||||
SET paymentMethod = 'Card'
|
|
||||||
WHERE LOWER(paymentMethod) = 'debit';
|
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
-- Consolidated Updates: Phone Normalization and Refund Items
|
|
||||||
|
|
||||||
-- 1. Create refund_item table
|
|
||||||
CREATE TABLE IF NOT EXISTS refund_item (
|
|
||||||
id BIGINT AUTO_INCREMENT PRIMARY KEY,
|
|
||||||
refund_id BIGINT NOT NULL,
|
|
||||||
prod_id BIGINT NOT NULL,
|
|
||||||
quantity INT NOT NULL,
|
|
||||||
unit_price DECIMAL(10, 2) NOT NULL,
|
|
||||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
|
||||||
FOREIGN KEY (refund_id) REFERENCES refund(id) ON DELETE CASCADE,
|
|
||||||
FOREIGN KEY (prod_id) REFERENCES product(prodId)
|
|
||||||
);
|
|
||||||
|
|
||||||
-- 2. Normalize existing phone numbers (MySQL Set-based)
|
|
||||||
UPDATE users
|
|
||||||
SET phone = CONCAT('(', SUBSTRING(REGEXP_REPLACE(phone, '[^0-9]', ''), -10, 3), ') ',
|
|
||||||
SUBSTRING(REGEXP_REPLACE(phone, '[^0-9]', ''), -7, 3), '-',
|
|
||||||
SUBSTRING(REGEXP_REPLACE(phone, '[^0-9]', ''), -4))
|
|
||||||
WHERE phone REGEXP '[0-9].*[0-9].*[0-9].*[0-9].*[0-9].*[0-9].*[0-9].*[0-9].*[0-9].*[0-9]';
|
|
||||||
|
|
||||||
UPDATE supplier
|
|
||||||
SET supPhone = CONCAT('(', SUBSTRING(REGEXP_REPLACE(supPhone, '[^0-9]', ''), -10, 3), ') ',
|
|
||||||
SUBSTRING(REGEXP_REPLACE(supPhone, '[^0-9]', ''), -7, 3), '-',
|
|
||||||
SUBSTRING(REGEXP_REPLACE(supPhone, '[^0-9]', ''), -4))
|
|
||||||
WHERE supPhone REGEXP '[0-9].*[0-9].*[0-9].*[0-9].*[0-9].*[0-9].*[0-9].*[0-9].*[0-9].*[0-9]';
|
|
||||||
|
|
||||||
UPDATE storeLocation
|
|
||||||
SET phone = CONCAT('(', SUBSTRING(REGEXP_REPLACE(phone, '[^0-9]', ''), -10, 3), ') ',
|
|
||||||
SUBSTRING(REGEXP_REPLACE(phone, '[^0-9]', ''), -7, 3), '-',
|
|
||||||
SUBSTRING(REGEXP_REPLACE(phone, '[^0-9]', ''), -4))
|
|
||||||
WHERE phone REGEXP '[0-9].*[0-9].*[0-9].*[0-9].*[0-9].*[0-9].*[0-9].*[0-9].*[0-9].*[0-9]';
|
|
||||||
@@ -1,61 +0,0 @@
|
|||||||
ALTER TABLE appointment
|
|
||||||
ADD COLUMN employeeId BIGINT NULL;
|
|
||||||
|
|
||||||
UPDATE appointment a
|
|
||||||
SET a.employeeId = (
|
|
||||||
SELECT es.employeeId
|
|
||||||
FROM employeeStore es
|
|
||||||
JOIN employee e ON e.employeeId = es.employeeId
|
|
||||||
JOIN users u ON u.id = e.user_id
|
|
||||||
WHERE es.storeId = a.storeId
|
|
||||||
AND e.isActive = TRUE
|
|
||||||
AND u.role = 'STAFF'
|
|
||||||
ORDER BY es.employeeId ASC
|
|
||||||
LIMIT 1
|
|
||||||
)
|
|
||||||
WHERE a.employeeId IS NULL;
|
|
||||||
|
|
||||||
UPDATE appointment a
|
|
||||||
SET a.employeeId = (
|
|
||||||
SELECT e.employeeId
|
|
||||||
FROM employee e
|
|
||||||
JOIN users u ON u.id = e.user_id
|
|
||||||
WHERE e.isActive = TRUE
|
|
||||||
AND u.role = 'STAFF'
|
|
||||||
ORDER BY e.employeeId ASC
|
|
||||||
LIMIT 1
|
|
||||||
)
|
|
||||||
WHERE a.employeeId IS NULL;
|
|
||||||
|
|
||||||
ALTER TABLE appointment
|
|
||||||
ADD CONSTRAINT fk_appointment_employee
|
|
||||||
FOREIGN KEY (employeeId) REFERENCES employee(employeeId);
|
|
||||||
|
|
||||||
CREATE INDEX idx_appointment_employeeId ON appointment(employeeId);
|
|
||||||
|
|
||||||
ALTER TABLE appointment
|
|
||||||
MODIFY employeeId BIGINT NOT NULL;
|
|
||||||
|
|
||||||
ALTER TABLE adoption
|
|
||||||
ADD COLUMN employeeId BIGINT NULL;
|
|
||||||
|
|
||||||
UPDATE adoption a
|
|
||||||
SET a.employeeId = (
|
|
||||||
SELECT e.employeeId
|
|
||||||
FROM employee e
|
|
||||||
JOIN users u ON u.id = e.user_id
|
|
||||||
WHERE e.isActive = TRUE
|
|
||||||
AND u.role = 'STAFF'
|
|
||||||
ORDER BY e.employeeId ASC
|
|
||||||
LIMIT 1
|
|
||||||
)
|
|
||||||
WHERE a.employeeId IS NULL;
|
|
||||||
|
|
||||||
ALTER TABLE adoption
|
|
||||||
ADD CONSTRAINT fk_adoption_employee
|
|
||||||
FOREIGN KEY (employeeId) REFERENCES employee(employeeId);
|
|
||||||
|
|
||||||
CREATE INDEX idx_adoption_employeeId ON adoption(employeeId);
|
|
||||||
|
|
||||||
ALTER TABLE adoption
|
|
||||||
MODIFY employeeId BIGINT NOT NULL;
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
UPDATE users u
|
|
||||||
SET u.active = TRUE
|
|
||||||
WHERE u.role IN ('STAFF', 'ADMIN')
|
|
||||||
AND EXISTS (SELECT 1 FROM employee e WHERE e.user_id = u.id);
|
|
||||||
@@ -1,22 +0,0 @@
|
|||||||
INSERT INTO customer_pet (customer_id, pet_name, species, breed)
|
|
||||||
SELECT DISTINCT a.customerId, p.petName, p.petSpecies, p.petBreed
|
|
||||||
FROM appointmentPet ap
|
|
||||||
JOIN appointment a ON a.appointmentId = ap.appointmentId
|
|
||||||
JOIN pet p ON p.petId = ap.petId
|
|
||||||
WHERE NOT EXISTS (
|
|
||||||
SELECT 1 FROM customer_pet cp
|
|
||||||
WHERE cp.customer_id = a.customerId AND cp.pet_name = p.petName
|
|
||||||
);
|
|
||||||
|
|
||||||
INSERT INTO appointment_customer_pet (appointment_id, customer_pet_id)
|
|
||||||
SELECT ap.appointmentId, cp.customer_pet_id
|
|
||||||
FROM appointmentPet ap
|
|
||||||
JOIN appointment a ON a.appointmentId = ap.appointmentId
|
|
||||||
JOIN pet p ON p.petId = ap.petId
|
|
||||||
JOIN customer_pet cp ON cp.customer_id = a.customerId AND cp.pet_name = p.petName
|
|
||||||
WHERE NOT EXISTS (
|
|
||||||
SELECT 1 FROM appointment_customer_pet acp
|
|
||||||
WHERE acp.appointment_id = ap.appointmentId AND acp.customer_pet_id = cp.customer_pet_id
|
|
||||||
);
|
|
||||||
|
|
||||||
DELETE FROM appointmentPet;
|
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
UPDATE appointment
|
|
||||||
SET appointmentStatus = 'Missed'
|
|
||||||
WHERE LOWER(appointmentStatus) = 'booked'
|
|
||||||
AND (
|
|
||||||
appointmentDate < CURRENT_DATE
|
|
||||||
OR (appointmentDate = CURRENT_DATE AND appointmentTime < CURRENT_TIME)
|
|
||||||
);
|
|
||||||
|
|
||||||
UPDATE appointment a1
|
|
||||||
JOIN (
|
|
||||||
SELECT a3.appointmentId
|
|
||||||
FROM appointment a3
|
|
||||||
INNER JOIN appointment a4
|
|
||||||
ON a4.employeeId = a3.employeeId
|
|
||||||
AND a4.appointmentDate = a3.appointmentDate
|
|
||||||
AND a4.appointmentTime = a3.appointmentTime
|
|
||||||
AND a4.appointmentId < a3.appointmentId
|
|
||||||
WHERE LOWER(a3.appointmentStatus) NOT IN ('cancelled', 'missed')
|
|
||||||
) conflicting ON conflicting.appointmentId = a1.appointmentId
|
|
||||||
SET a1.employeeId = (
|
|
||||||
SELECT es.employeeId
|
|
||||||
FROM employeeStore es
|
|
||||||
JOIN employee e ON e.employeeId = es.employeeId
|
|
||||||
JOIN users u ON u.id = e.user_id
|
|
||||||
WHERE es.storeId = a1.storeId
|
|
||||||
AND e.isActive = TRUE
|
|
||||||
AND u.role = 'STAFF'
|
|
||||||
AND NOT EXISTS (
|
|
||||||
SELECT 1 FROM (
|
|
||||||
SELECT employeeId, appointmentDate, appointmentTime, appointmentId
|
|
||||||
FROM appointment
|
|
||||||
) snap
|
|
||||||
WHERE snap.employeeId = es.employeeId
|
|
||||||
AND snap.appointmentDate = a1.appointmentDate
|
|
||||||
AND snap.appointmentTime = a1.appointmentTime
|
|
||||||
AND snap.appointmentId <> a1.appointmentId
|
|
||||||
)
|
|
||||||
ORDER BY es.employeeId ASC
|
|
||||||
LIMIT 1
|
|
||||||
);
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
ALTER TABLE pet ADD COLUMN customerId BIGINT NULL;
|
|
||||||
ALTER TABLE pet ADD COLUMN storeId BIGINT NULL;
|
|
||||||
|
|
||||||
ALTER TABLE pet ADD CONSTRAINT fk_pet_customer
|
|
||||||
FOREIGN KEY (customerId) REFERENCES customer(customerId);
|
|
||||||
ALTER TABLE pet ADD CONSTRAINT fk_pet_store
|
|
||||||
FOREIGN KEY (storeId) REFERENCES storeLocation(storeId);
|
|
||||||
|
|
||||||
CREATE INDEX idx_pet_customerId ON pet(customerId);
|
|
||||||
CREATE INDEX idx_pet_storeId ON pet(storeId);
|
|
||||||
|
|
||||||
UPDATE pet
|
|
||||||
SET storeId = (SELECT storeId FROM storeLocation ORDER BY storeId ASC LIMIT 1)
|
|
||||||
WHERE LOWER(petStatus) IN ('available', 'unadopted');
|
|
||||||
|
|
||||||
UPDATE pet p
|
|
||||||
JOIN (
|
|
||||||
SELECT a.petId, a.customerId
|
|
||||||
FROM adoption a
|
|
||||||
WHERE LOWER(a.adoptionStatus) = 'completed'
|
|
||||||
) latest ON latest.petId = p.petId
|
|
||||||
SET p.customerId = latest.customerId
|
|
||||||
WHERE LOWER(p.petStatus) = 'adopted';
|
|
||||||
@@ -1,250 +0,0 @@
|
|||||||
-- Create Tables
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS storeLocation (
|
|
||||||
storeId BIGINT AUTO_INCREMENT PRIMARY KEY,
|
|
||||||
storeName VARCHAR(100) NOT NULL,
|
|
||||||
address VARCHAR(255) NOT NULL,
|
|
||||||
phone VARCHAR(20) NOT NULL,
|
|
||||||
email VARCHAR(100) NOT NULL,
|
|
||||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS employee (
|
|
||||||
employeeId BIGINT AUTO_INCREMENT PRIMARY KEY,
|
|
||||||
user_id BIGINT NULL,
|
|
||||||
firstName VARCHAR(50) NOT NULL,
|
|
||||||
lastName VARCHAR(50) NOT NULL,
|
|
||||||
email VARCHAR(100) NOT NULL,
|
|
||||||
phone VARCHAR(20) NOT NULL,
|
|
||||||
role VARCHAR(50) NOT NULL,
|
|
||||||
isActive BOOLEAN DEFAULT TRUE NOT NULL,
|
|
||||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
|
||||||
CONSTRAINT uk_employee_user_id UNIQUE (user_id)
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS employeeStore (
|
|
||||||
employeeId BIGINT NOT NULL,
|
|
||||||
storeId BIGINT NOT NULL,
|
|
||||||
PRIMARY KEY (employeeId, storeId),
|
|
||||||
FOREIGN KEY (employeeId) REFERENCES employee(employeeId),
|
|
||||||
FOREIGN KEY (storeId) REFERENCES storeLocation(storeId)
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS customer (
|
|
||||||
customerId BIGINT AUTO_INCREMENT PRIMARY KEY,
|
|
||||||
user_id BIGINT NULL,
|
|
||||||
firstName VARCHAR(50) NOT NULL,
|
|
||||||
lastName VARCHAR(50) NOT NULL,
|
|
||||||
email VARCHAR(100) NOT NULL,
|
|
||||||
phone VARCHAR(20) NOT NULL,
|
|
||||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
|
||||||
CONSTRAINT uk_customer_user_id UNIQUE (user_id)
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS pet (
|
|
||||||
petId BIGINT AUTO_INCREMENT PRIMARY KEY,
|
|
||||||
petName VARCHAR(50) NOT NULL,
|
|
||||||
petSpecies VARCHAR(50) NOT NULL,
|
|
||||||
petBreed VARCHAR(50) NOT NULL,
|
|
||||||
petAge INT NOT NULL,
|
|
||||||
petStatus VARCHAR(20) NOT NULL,
|
|
||||||
petPrice DECIMAL(10, 2) NOT NULL,
|
|
||||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS adoption (
|
|
||||||
adoptionId BIGINT AUTO_INCREMENT PRIMARY KEY,
|
|
||||||
petId BIGINT NOT NULL,
|
|
||||||
customerId BIGINT NOT NULL,
|
|
||||||
adoptionDate DATE NOT NULL,
|
|
||||||
adoptionStatus VARCHAR(20) NOT NULL,
|
|
||||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
|
||||||
FOREIGN KEY (petId) REFERENCES pet(petId),
|
|
||||||
FOREIGN KEY (customerId) REFERENCES customer(customerId)
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS supplier (
|
|
||||||
supId BIGINT AUTO_INCREMENT PRIMARY KEY,
|
|
||||||
supCompany VARCHAR(100) NOT NULL,
|
|
||||||
supContactFirstName VARCHAR(50) NOT NULL,
|
|
||||||
supContactLastName VARCHAR(50) NOT NULL,
|
|
||||||
supEmail VARCHAR(100) NOT NULL,
|
|
||||||
supPhone VARCHAR(20) NOT NULL,
|
|
||||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS category (
|
|
||||||
categoryId BIGINT AUTO_INCREMENT PRIMARY KEY,
|
|
||||||
categoryName VARCHAR(100) NOT NULL,
|
|
||||||
categoryType VARCHAR(50) NOT NULL,
|
|
||||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS product (
|
|
||||||
prodId BIGINT AUTO_INCREMENT PRIMARY KEY,
|
|
||||||
prodName VARCHAR(100) NOT NULL,
|
|
||||||
prodPrice DECIMAL(10, 2) NOT NULL,
|
|
||||||
categoryId BIGINT NOT NULL,
|
|
||||||
prodDesc TEXT,
|
|
||||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
|
||||||
FOREIGN KEY (categoryId) REFERENCES category(categoryId)
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS productSupplier (
|
|
||||||
supId BIGINT NOT NULL,
|
|
||||||
prodId BIGINT NOT NULL,
|
|
||||||
cost DECIMAL(10, 2) NOT NULL,
|
|
||||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
|
||||||
PRIMARY KEY (supId, prodId),
|
|
||||||
FOREIGN KEY (supId) REFERENCES supplier(supId),
|
|
||||||
FOREIGN KEY (prodId) REFERENCES product(prodId)
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS inventory (
|
|
||||||
inventoryId BIGINT AUTO_INCREMENT PRIMARY KEY,
|
|
||||||
prodId BIGINT NOT NULL,
|
|
||||||
quantity INT DEFAULT 0 NOT NULL,
|
|
||||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
|
||||||
FOREIGN KEY (prodId) REFERENCES product(prodId)
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS service (
|
|
||||||
serviceId BIGINT AUTO_INCREMENT PRIMARY KEY,
|
|
||||||
serviceName VARCHAR(100) NOT NULL,
|
|
||||||
serviceDesc TEXT,
|
|
||||||
serviceDuration INT NOT NULL,
|
|
||||||
servicePrice DECIMAL(10, 2) NOT NULL,
|
|
||||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS appointment (
|
|
||||||
appointmentId BIGINT AUTO_INCREMENT PRIMARY KEY,
|
|
||||||
serviceId BIGINT NOT NULL,
|
|
||||||
customerId BIGINT NOT NULL,
|
|
||||||
appointmentDate DATE NOT NULL,
|
|
||||||
appointmentTime TIME NOT NULL,
|
|
||||||
appointmentStatus VARCHAR(20) NOT NULL,
|
|
||||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
|
||||||
FOREIGN KEY (serviceId) REFERENCES service(serviceId),
|
|
||||||
FOREIGN KEY (customerId) REFERENCES customer(customerId)
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS appointmentPet (
|
|
||||||
appointmentId BIGINT NOT NULL,
|
|
||||||
petId BIGINT NOT NULL,
|
|
||||||
PRIMARY KEY (appointmentId, petId),
|
|
||||||
FOREIGN KEY (appointmentId) REFERENCES appointment(appointmentId),
|
|
||||||
FOREIGN KEY (petId) REFERENCES pet(petId)
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS sale (
|
|
||||||
saleId BIGINT AUTO_INCREMENT PRIMARY KEY,
|
|
||||||
saleDate DATETIME NOT NULL,
|
|
||||||
totalAmount DECIMAL(10, 2) NOT NULL,
|
|
||||||
paymentMethod VARCHAR(50) NOT NULL,
|
|
||||||
employeeId BIGINT NOT NULL,
|
|
||||||
storeId BIGINT NOT NULL,
|
|
||||||
customerId BIGINT NULL,
|
|
||||||
isRefund BOOLEAN DEFAULT FALSE NOT NULL,
|
|
||||||
originalSaleId BIGINT NULL,
|
|
||||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
|
||||||
FOREIGN KEY (employeeId) REFERENCES employee(employeeId),
|
|
||||||
FOREIGN KEY (storeId) REFERENCES storeLocation(storeId),
|
|
||||||
FOREIGN KEY (customerId) REFERENCES customer(customerId),
|
|
||||||
FOREIGN KEY (originalSaleId) REFERENCES sale(saleId)
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS saleItem (
|
|
||||||
saleItemId BIGINT AUTO_INCREMENT PRIMARY KEY,
|
|
||||||
saleId BIGINT NOT NULL,
|
|
||||||
prodId BIGINT NOT NULL,
|
|
||||||
quantity INT NOT NULL,
|
|
||||||
unitPrice DECIMAL(10, 2) NOT NULL,
|
|
||||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
|
||||||
FOREIGN KEY (saleId) REFERENCES sale(saleId),
|
|
||||||
FOREIGN KEY (prodId) REFERENCES product(prodId)
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS purchaseOrder (
|
|
||||||
purchaseOrderId BIGINT AUTO_INCREMENT PRIMARY KEY,
|
|
||||||
supId BIGINT NOT NULL,
|
|
||||||
orderDate DATE NOT NULL,
|
|
||||||
status VARCHAR(50) NOT NULL,
|
|
||||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
|
||||||
FOREIGN KEY (supId) REFERENCES supplier(supId)
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS activityLog (
|
|
||||||
logId BIGINT AUTO_INCREMENT PRIMARY KEY,
|
|
||||||
employeeId BIGINT NOT NULL,
|
|
||||||
activity TEXT NOT NULL,
|
|
||||||
logTimestamp TIMESTAMP DEFAULT CURRENT_TIMESTAMP NOT NULL,
|
|
||||||
FOREIGN KEY (employeeId) REFERENCES employee(employeeId)
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS users (
|
|
||||||
id BIGINT AUTO_INCREMENT PRIMARY KEY,
|
|
||||||
username VARCHAR(50) UNIQUE NOT NULL,
|
|
||||||
password VARCHAR(255) NOT NULL,
|
|
||||||
email VARCHAR(100) UNIQUE,
|
|
||||||
fullName VARCHAR(100),
|
|
||||||
avatarUrl VARCHAR(255),
|
|
||||||
role VARCHAR(20) NOT NULL,
|
|
||||||
active BOOLEAN NOT NULL DEFAULT TRUE,
|
|
||||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS refund (
|
|
||||||
id BIGINT AUTO_INCREMENT PRIMARY KEY,
|
|
||||||
saleId BIGINT NOT NULL,
|
|
||||||
customerId BIGINT NOT NULL,
|
|
||||||
amount DECIMAL(10, 2) NOT NULL,
|
|
||||||
reason VARCHAR(500) NOT NULL,
|
|
||||||
status VARCHAR(20) NOT NULL,
|
|
||||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
|
||||||
FOREIGN KEY (saleId) REFERENCES sale(saleId),
|
|
||||||
FOREIGN KEY (customerId) REFERENCES customer(customerId)
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS conversation (
|
|
||||||
id BIGINT AUTO_INCREMENT PRIMARY KEY,
|
|
||||||
customerId BIGINT NOT NULL,
|
|
||||||
staffId BIGINT,
|
|
||||||
status VARCHAR(20) NOT NULL DEFAULT 'OPEN',
|
|
||||||
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
|
||||||
FOREIGN KEY (customerId) REFERENCES customer(customerId),
|
|
||||||
FOREIGN KEY (staffId) REFERENCES users(id)
|
|
||||||
);
|
|
||||||
|
|
||||||
CREATE TABLE IF NOT EXISTS message (
|
|
||||||
id BIGINT AUTO_INCREMENT PRIMARY KEY,
|
|
||||||
conversationId BIGINT NOT NULL,
|
|
||||||
senderId BIGINT NOT NULL,
|
|
||||||
content TEXT NOT NULL,
|
|
||||||
timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
isRead BOOLEAN NOT NULL DEFAULT FALSE,
|
|
||||||
FOREIGN KEY (conversationId) REFERENCES conversation(id),
|
|
||||||
FOREIGN KEY (senderId) REFERENCES users(id)
|
|
||||||
);
|
|
||||||
|
|
||||||
-- Add foreign keys for user_id linkage
|
|
||||||
ALTER TABLE employee ADD CONSTRAINT fk_employee_user_id FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE SET NULL;
|
|
||||||
ALTER TABLE customer ADD CONSTRAINT fk_customer_user_id FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE SET NULL;
|
|
||||||
341
backend/src/main/resources/db/migration/V1__target_baseline.sql
Normal file
341
backend/src/main/resources/db/migration/V1__target_baseline.sql
Normal file
@@ -0,0 +1,341 @@
|
|||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS storeLocation (
|
||||||
|
storeId BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
storeName VARCHAR(100) NOT NULL,
|
||||||
|
address VARCHAR(255) NOT NULL,
|
||||||
|
phone VARCHAR(20) NOT NULL,
|
||||||
|
email VARCHAR(100) NOT NULL,
|
||||||
|
imageUrl VARCHAR(255) NULL,
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS users (
|
||||||
|
id BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
username VARCHAR(50) NULL UNIQUE,
|
||||||
|
password VARCHAR(255) NULL,
|
||||||
|
email VARCHAR(100) NULL UNIQUE,
|
||||||
|
firstName VARCHAR(50) NOT NULL,
|
||||||
|
lastName VARCHAR(50) NOT NULL,
|
||||||
|
fullName VARCHAR(100) NULL,
|
||||||
|
phone VARCHAR(20) NULL,
|
||||||
|
avatarUrl VARCHAR(255) NULL,
|
||||||
|
role VARCHAR(20) NOT NULL,
|
||||||
|
staffRole VARCHAR(50) NULL,
|
||||||
|
primaryStoreId BIGINT NULL,
|
||||||
|
loyaltyPoints INT NOT NULL DEFAULT 0,
|
||||||
|
active BOOLEAN NOT NULL DEFAULT TRUE,
|
||||||
|
tokenVersion INT NOT NULL DEFAULT 0,
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||||
|
CONSTRAINT fk_users_primary_store FOREIGN KEY (primaryStoreId) REFERENCES storeLocation(storeId) ON DELETE SET NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS supplier (
|
||||||
|
supId BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
supCompany VARCHAR(100) NOT NULL,
|
||||||
|
supContactFirstName VARCHAR(50) NOT NULL,
|
||||||
|
supContactLastName VARCHAR(50) NOT NULL,
|
||||||
|
supEmail VARCHAR(100) NOT NULL,
|
||||||
|
supPhone VARCHAR(20) NOT NULL,
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS category (
|
||||||
|
categoryId BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
categoryName VARCHAR(100) NOT NULL,
|
||||||
|
categoryType VARCHAR(50) NOT NULL,
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||||
|
CONSTRAINT uq_category_name_type UNIQUE (categoryName, categoryType)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS service (
|
||||||
|
serviceId BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
serviceName VARCHAR(100) NOT NULL,
|
||||||
|
serviceDesc TEXT NULL,
|
||||||
|
serviceDuration INT NOT NULL,
|
||||||
|
servicePrice DECIMAL(10, 2) NOT NULL,
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS service_species (
|
||||||
|
serviceId BIGINT NOT NULL,
|
||||||
|
species VARCHAR(50) NOT NULL,
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
PRIMARY KEY (serviceId, species),
|
||||||
|
CONSTRAINT fk_service_species_service FOREIGN KEY (serviceId) REFERENCES service(serviceId) ON DELETE CASCADE
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS product (
|
||||||
|
prodId BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
prodName VARCHAR(100) NOT NULL,
|
||||||
|
prodPrice DECIMAL(10, 2) NOT NULL,
|
||||||
|
categoryId BIGINT NOT NULL,
|
||||||
|
prodDesc TEXT NULL,
|
||||||
|
imageUrl VARCHAR(255) NULL,
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||||
|
CONSTRAINT fk_product_category FOREIGN KEY (categoryId) REFERENCES category(categoryId)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS inventory (
|
||||||
|
inventoryId BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
storeId BIGINT NOT NULL,
|
||||||
|
prodId BIGINT NOT NULL,
|
||||||
|
quantity INT NOT NULL DEFAULT 0,
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||||
|
CONSTRAINT uq_inventory_store_product UNIQUE (storeId, prodId),
|
||||||
|
CONSTRAINT fk_inventory_store FOREIGN KEY (storeId) REFERENCES storeLocation(storeId),
|
||||||
|
CONSTRAINT fk_inventory_product FOREIGN KEY (prodId) REFERENCES product(prodId)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS productSupplier (
|
||||||
|
supId BIGINT NOT NULL,
|
||||||
|
prodId BIGINT NOT NULL,
|
||||||
|
cost DECIMAL(10, 2) NOT NULL,
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||||
|
PRIMARY KEY (supId, prodId),
|
||||||
|
CONSTRAINT fk_product_supplier_supplier FOREIGN KEY (supId) REFERENCES supplier(supId),
|
||||||
|
CONSTRAINT fk_product_supplier_product FOREIGN KEY (prodId) REFERENCES product(prodId)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS purchaseOrder (
|
||||||
|
purchaseOrderId BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
supId BIGINT NOT NULL,
|
||||||
|
storeId BIGINT NOT NULL,
|
||||||
|
orderDate DATE NOT NULL,
|
||||||
|
status VARCHAR(50) NOT NULL,
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||||
|
CONSTRAINT fk_purchase_order_supplier FOREIGN KEY (supId) REFERENCES supplier(supId),
|
||||||
|
CONSTRAINT fk_purchase_order_store FOREIGN KEY (storeId) REFERENCES storeLocation(storeId)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS coupon (
|
||||||
|
couponId BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
couponCode VARCHAR(50) NOT NULL,
|
||||||
|
discountType VARCHAR(20) NOT NULL,
|
||||||
|
discountValue DECIMAL(10, 2) NOT NULL,
|
||||||
|
minOrderAmount DECIMAL(10, 2) NULL,
|
||||||
|
active BOOLEAN NOT NULL DEFAULT TRUE,
|
||||||
|
startsAt DATETIME NULL,
|
||||||
|
endsAt DATETIME NULL,
|
||||||
|
usageLimit INT NULL,
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||||
|
CONSTRAINT uq_coupon_code UNIQUE (couponCode)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS pet (
|
||||||
|
petId BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
petName VARCHAR(50) NOT NULL,
|
||||||
|
petSpecies VARCHAR(50) NOT NULL,
|
||||||
|
petBreed VARCHAR(50) NULL,
|
||||||
|
petAge INT NULL,
|
||||||
|
petStatus VARCHAR(20) NOT NULL,
|
||||||
|
petPrice DECIMAL(10, 2) NULL,
|
||||||
|
imageUrl VARCHAR(255) NULL,
|
||||||
|
ownerUserId BIGINT NULL,
|
||||||
|
storeId BIGINT NULL,
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||||
|
CONSTRAINT fk_pet_owner_user FOREIGN KEY (ownerUserId) REFERENCES users(id) ON DELETE SET NULL,
|
||||||
|
CONSTRAINT fk_pet_store FOREIGN KEY (storeId) REFERENCES storeLocation(storeId) ON DELETE SET NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS appointment (
|
||||||
|
appointmentId BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
serviceId BIGINT NOT NULL,
|
||||||
|
petId BIGINT NOT NULL,
|
||||||
|
customerId BIGINT NOT NULL,
|
||||||
|
storeId BIGINT NOT NULL,
|
||||||
|
employeeId BIGINT NOT NULL,
|
||||||
|
appointmentDate DATE NOT NULL,
|
||||||
|
appointmentTime TIME NOT NULL,
|
||||||
|
appointmentStatus VARCHAR(20) NOT NULL,
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||||
|
CONSTRAINT fk_appointment_service FOREIGN KEY (serviceId) REFERENCES service(serviceId),
|
||||||
|
CONSTRAINT fk_appointment_pet FOREIGN KEY (petId) REFERENCES pet(petId),
|
||||||
|
CONSTRAINT fk_appointment_customer FOREIGN KEY (customerId) REFERENCES users(id),
|
||||||
|
CONSTRAINT fk_appointment_store FOREIGN KEY (storeId) REFERENCES storeLocation(storeId),
|
||||||
|
CONSTRAINT fk_appointment_employee FOREIGN KEY (employeeId) REFERENCES users(id)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS adoption (
|
||||||
|
adoptionId BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
petId BIGINT NOT NULL,
|
||||||
|
customerId BIGINT NOT NULL,
|
||||||
|
employeeId BIGINT NOT NULL,
|
||||||
|
sourceStoreId BIGINT NOT NULL,
|
||||||
|
adoptionDate DATE NOT NULL,
|
||||||
|
adoptionStatus VARCHAR(20) NOT NULL,
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||||
|
CONSTRAINT fk_adoption_pet FOREIGN KEY (petId) REFERENCES pet(petId),
|
||||||
|
CONSTRAINT fk_adoption_customer FOREIGN KEY (customerId) REFERENCES users(id),
|
||||||
|
CONSTRAINT fk_adoption_employee FOREIGN KEY (employeeId) REFERENCES users(id),
|
||||||
|
CONSTRAINT fk_adoption_source_store FOREIGN KEY (sourceStoreId) REFERENCES storeLocation(storeId)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS cart (
|
||||||
|
cartId BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
userId BIGINT NOT NULL,
|
||||||
|
storeId BIGINT NULL,
|
||||||
|
couponId BIGINT NULL,
|
||||||
|
cartStatus VARCHAR(20) NOT NULL DEFAULT 'ACTIVE',
|
||||||
|
subtotalAmount DECIMAL(10, 2) NOT NULL DEFAULT 0.00,
|
||||||
|
discountAmount DECIMAL(10, 2) NOT NULL DEFAULT 0.00,
|
||||||
|
totalAmount DECIMAL(10, 2) NOT NULL DEFAULT 0.00,
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||||
|
CONSTRAINT fk_cart_user FOREIGN KEY (userId) REFERENCES users(id),
|
||||||
|
CONSTRAINT fk_cart_store FOREIGN KEY (storeId) REFERENCES storeLocation(storeId) ON DELETE SET NULL,
|
||||||
|
CONSTRAINT fk_cart_coupon FOREIGN KEY (couponId) REFERENCES coupon(couponId) ON DELETE SET NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS cart_item (
|
||||||
|
cartItemId BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
cartId BIGINT NOT NULL,
|
||||||
|
prodId BIGINT NOT NULL,
|
||||||
|
quantity INT NOT NULL,
|
||||||
|
unitPrice DECIMAL(10, 2) NOT NULL,
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||||
|
CONSTRAINT fk_cart_item_cart FOREIGN KEY (cartId) REFERENCES cart(cartId) ON DELETE CASCADE,
|
||||||
|
CONSTRAINT fk_cart_item_product FOREIGN KEY (prodId) REFERENCES product(prodId)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS sale (
|
||||||
|
saleId BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
saleDate DATETIME NOT NULL,
|
||||||
|
totalAmount DECIMAL(10, 2) NOT NULL,
|
||||||
|
paymentMethod VARCHAR(50) NOT NULL,
|
||||||
|
employeeId BIGINT NOT NULL,
|
||||||
|
storeId BIGINT NOT NULL,
|
||||||
|
customerId BIGINT NULL,
|
||||||
|
isRefund BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
|
originalSaleId BIGINT NULL,
|
||||||
|
channel VARCHAR(20) NOT NULL DEFAULT 'IN_STORE',
|
||||||
|
cartId BIGINT NULL,
|
||||||
|
couponId BIGINT NULL,
|
||||||
|
subtotalAmount DECIMAL(10, 2) NULL,
|
||||||
|
couponDiscountAmount DECIMAL(10, 2) NOT NULL DEFAULT 0.00,
|
||||||
|
employeeDiscountAmount DECIMAL(10, 2) NOT NULL DEFAULT 0.00,
|
||||||
|
pointsEarned INT NOT NULL DEFAULT 0,
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||||
|
CONSTRAINT fk_sale_employee FOREIGN KEY (employeeId) REFERENCES users(id),
|
||||||
|
CONSTRAINT fk_sale_store FOREIGN KEY (storeId) REFERENCES storeLocation(storeId),
|
||||||
|
CONSTRAINT fk_sale_customer FOREIGN KEY (customerId) REFERENCES users(id) ON DELETE SET NULL,
|
||||||
|
CONSTRAINT fk_sale_original_sale FOREIGN KEY (originalSaleId) REFERENCES sale(saleId),
|
||||||
|
CONSTRAINT fk_sale_cart FOREIGN KEY (cartId) REFERENCES cart(cartId) ON DELETE SET NULL,
|
||||||
|
CONSTRAINT fk_sale_coupon FOREIGN KEY (couponId) REFERENCES coupon(couponId) ON DELETE SET NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS saleItem (
|
||||||
|
saleItemId BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
saleId BIGINT NOT NULL,
|
||||||
|
prodId BIGINT NOT NULL,
|
||||||
|
quantity INT NOT NULL,
|
||||||
|
unitPrice DECIMAL(10, 2) NOT NULL,
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||||
|
CONSTRAINT fk_sale_item_sale FOREIGN KEY (saleId) REFERENCES sale(saleId) ON DELETE CASCADE,
|
||||||
|
CONSTRAINT fk_sale_item_product FOREIGN KEY (prodId) REFERENCES product(prodId)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS refund (
|
||||||
|
id BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
saleId BIGINT NOT NULL,
|
||||||
|
customerId BIGINT NOT NULL,
|
||||||
|
amount DECIMAL(10, 2) NOT NULL,
|
||||||
|
reason VARCHAR(500) NOT NULL,
|
||||||
|
status VARCHAR(20) NOT NULL,
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||||
|
CONSTRAINT fk_refund_sale FOREIGN KEY (saleId) REFERENCES sale(saleId),
|
||||||
|
CONSTRAINT fk_refund_customer FOREIGN KEY (customerId) REFERENCES users(id)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS refund_item (
|
||||||
|
id BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
refund_id BIGINT NOT NULL,
|
||||||
|
prod_id BIGINT NOT NULL,
|
||||||
|
quantity INT NOT NULL,
|
||||||
|
unit_price DECIMAL(10, 2) NOT NULL,
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||||
|
CONSTRAINT fk_refund_item_refund FOREIGN KEY (refund_id) REFERENCES refund(id) ON DELETE CASCADE,
|
||||||
|
CONSTRAINT fk_refund_item_product FOREIGN KEY (prod_id) REFERENCES product(prodId)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS conversation (
|
||||||
|
id BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
customerId BIGINT NOT NULL,
|
||||||
|
staffId BIGINT NULL,
|
||||||
|
status VARCHAR(20) NOT NULL DEFAULT 'OPEN',
|
||||||
|
mode VARCHAR(20) NOT NULL DEFAULT 'AUTOMATED',
|
||||||
|
humanRequestedAt TIMESTAMP NULL,
|
||||||
|
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||||
|
CONSTRAINT fk_conversation_customer FOREIGN KEY (customerId) REFERENCES users(id),
|
||||||
|
CONSTRAINT fk_conversation_staff FOREIGN KEY (staffId) REFERENCES users(id) ON DELETE SET NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS message (
|
||||||
|
id BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
conversationId BIGINT NOT NULL,
|
||||||
|
senderId BIGINT NOT NULL,
|
||||||
|
content TEXT NULL,
|
||||||
|
attachmentUrl VARCHAR(255) NULL,
|
||||||
|
attachmentName VARCHAR(255) NULL,
|
||||||
|
attachmentMimeType VARCHAR(100) NULL,
|
||||||
|
attachmentSizeBytes BIGINT NULL,
|
||||||
|
timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
isRead BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
|
CONSTRAINT fk_message_conversation FOREIGN KEY (conversationId) REFERENCES conversation(id) ON DELETE CASCADE,
|
||||||
|
CONSTRAINT fk_message_sender FOREIGN KEY (senderId) REFERENCES users(id)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS activityLog (
|
||||||
|
logId BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
userId BIGINT NOT NULL,
|
||||||
|
storeId BIGINT NULL,
|
||||||
|
activity TEXT NOT NULL,
|
||||||
|
logTimestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
CONSTRAINT fk_activity_log_user FOREIGN KEY (userId) REFERENCES users(id),
|
||||||
|
CONSTRAINT fk_activity_log_store FOREIGN KEY (storeId) REFERENCES storeLocation(storeId) ON DELETE SET NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX idx_users_primary_store ON users(primaryStoreId);
|
||||||
|
CREATE INDEX idx_users_role ON users(role);
|
||||||
|
CREATE INDEX idx_users_name ON users(lastName, firstName);
|
||||||
|
CREATE INDEX idx_service_species_species ON service_species(species);
|
||||||
|
CREATE INDEX idx_inventory_store ON inventory(storeId);
|
||||||
|
CREATE INDEX idx_inventory_product ON inventory(prodId);
|
||||||
|
CREATE INDEX idx_purchase_order_store ON purchaseOrder(storeId);
|
||||||
|
CREATE INDEX idx_pet_owner_user ON pet(ownerUserId);
|
||||||
|
CREATE INDEX idx_pet_store ON pet(storeId);
|
||||||
|
CREATE INDEX idx_pet_species ON pet(petSpecies);
|
||||||
|
CREATE INDEX idx_pet_name ON pet(petName);
|
||||||
|
CREATE INDEX idx_appointment_store ON appointment(storeId);
|
||||||
|
CREATE INDEX idx_appointment_employee ON appointment(employeeId);
|
||||||
|
CREATE INDEX idx_appointment_customer ON appointment(customerId);
|
||||||
|
CREATE INDEX idx_appointment_pet ON appointment(petId);
|
||||||
|
CREATE INDEX idx_appointment_date_status ON appointment(appointmentDate, appointmentStatus);
|
||||||
|
CREATE INDEX idx_adoption_store ON adoption(sourceStoreId);
|
||||||
|
CREATE INDEX idx_adoption_employee ON adoption(employeeId);
|
||||||
|
CREATE INDEX idx_sale_store ON sale(storeId);
|
||||||
|
CREATE INDEX idx_sale_employee ON sale(employeeId);
|
||||||
|
CREATE INDEX idx_sale_customer ON sale(customerId);
|
||||||
|
CREATE INDEX idx_sale_date ON sale(saleDate);
|
||||||
|
CREATE INDEX idx_cart_user ON cart(userId);
|
||||||
|
CREATE INDEX idx_conversation_customer ON conversation(customerId);
|
||||||
|
CREATE INDEX idx_conversation_staff ON conversation(staffId);
|
||||||
|
CREATE INDEX idx_activity_log_store ON activityLog(storeId);
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
INSERT INTO pet (petName, petSpecies, petBreed, petAge, petStatus, petPrice, customerId)
|
|
||||||
SELECT 'Pepper', 'Cat', 'Tabby', 3, 'Owned', 0.00, customerId FROM customer WHERE email = 'alex@gmail.com'
|
|
||||||
UNION ALL
|
|
||||||
SELECT 'Coco', 'Dog', 'Pomeranian', 2, 'Owned', 0.00, customerId FROM customer WHERE email = 'olivia@gmail.com'
|
|
||||||
UNION ALL
|
|
||||||
SELECT 'Finn', 'Dog', 'Border Collie', 5, 'Owned', 0.00, customerId FROM customer WHERE email = 'sophia@gmail.com';
|
|
||||||
@@ -1,161 +0,0 @@
|
|||||||
-- Insert 10 new customers
|
|
||||||
INSERT INTO customer (firstName, lastName, email) VALUES
|
|
||||||
('Noah', 'Parker', 'noah@gmail.com'),
|
|
||||||
('Mia', 'Evans', 'mia@gmail.com'),
|
|
||||||
('Ethan', 'Scott', 'ethan@gmail.com'),
|
|
||||||
('Chloe', 'Adams', 'chloe@gmail.com'),
|
|
||||||
('Lucas', 'Baker', 'lucas@gmail.com'),
|
|
||||||
('Lily', 'Hall', 'lily@gmail.com'),
|
|
||||||
('Mason', 'Rivera', 'mason@gmail.com'),
|
|
||||||
('Ella', 'Mitchell', 'ella@gmail.com'),
|
|
||||||
('James', 'Carter', 'jcarter@gmail.com'),
|
|
||||||
('Harper', 'Collins', 'harper@gmail.com');
|
|
||||||
|
|
||||||
-- Insert available pets linked to stores
|
|
||||||
INSERT INTO pet (petName, petSpecies, petBreed, petAge, petStatus, petPrice, storeId)
|
|
||||||
SELECT 'Rocky', 'Dog', 'German Shepherd', 1, 'Available', 475.00, storeId FROM storeLocation WHERE storeName = 'Downtown Branch' UNION ALL
|
|
||||||
SELECT 'Daisy', 'Dog', 'Poodle', 2, 'Available', 512.00, storeId FROM storeLocation WHERE storeName = 'Downtown Branch' UNION ALL
|
|
||||||
SELECT 'Cooper', 'Dog', 'Bulldog', 3, 'Available', 560.00, storeId FROM storeLocation WHERE storeName = 'Downtown Branch' UNION ALL
|
|
||||||
SELECT 'Ruby', 'Dog', 'Boxer', 4, 'Available', 575.00, storeId FROM storeLocation WHERE storeName = 'Downtown Branch' UNION ALL
|
|
||||||
SELECT 'Tucker', 'Dog', 'Dachshund', 5, 'Available', 634.00, storeId FROM storeLocation WHERE storeName = 'Downtown Branch' UNION ALL
|
|
||||||
SELECT 'Rosie', 'Dog', 'Shih Tzu', 1, 'Available', 660.00, storeId FROM storeLocation WHERE storeName = 'North Branch' UNION ALL
|
|
||||||
SELECT 'Bear', 'Dog', 'Rottweiler', 2, 'Available', 686.00, storeId FROM storeLocation WHERE storeName = 'North Branch' UNION ALL
|
|
||||||
SELECT 'Maggie', 'Dog', 'Corgi', 3, 'Available', 745.00, storeId FROM storeLocation WHERE storeName = 'North Branch' UNION ALL
|
|
||||||
SELECT 'Leo', 'Dog', 'Husky', 4, 'Available', 749.00, storeId FROM storeLocation WHERE storeName = 'North Branch' UNION ALL
|
|
||||||
SELECT 'Zoey', 'Cat', 'Ragdoll', 1, 'Available', 420.00, storeId FROM storeLocation WHERE storeName = 'Downtown Branch' UNION ALL
|
|
||||||
SELECT 'Oliver', 'Cat', 'British Shorthair', 2, 'Available', 395.00, storeId FROM storeLocation WHERE storeName = 'Downtown Branch' UNION ALL
|
|
||||||
SELECT 'Lola', 'Cat', 'Bengal', 3, 'Available', 465.00, storeId FROM storeLocation WHERE storeName = 'West Side Store' UNION ALL
|
|
||||||
SELECT 'Buster', 'Dog', 'Beagle', 2, 'Available', 440.00, storeId FROM storeLocation WHERE storeName = 'West Side Store' UNION ALL
|
|
||||||
SELECT 'Sadie', 'Dog', 'Golden Retriever', 1, 'Available', 535.00, storeId FROM storeLocation WHERE storeName = 'West Side Store' UNION ALL
|
|
||||||
SELECT 'Toby', 'Dog', 'Labrador', 5, 'Available', 490.00, storeId FROM storeLocation WHERE storeName = 'Downtown Branch' UNION ALL
|
|
||||||
SELECT 'Cleo', 'Cat', 'Abyssinian', 2, 'Available', 375.00, storeId FROM storeLocation WHERE storeName = 'North Branch' UNION ALL
|
|
||||||
SELECT 'Harley', 'Dog', 'Dalmatian', 3, 'Available', 520.00, storeId FROM storeLocation WHERE storeName = 'Downtown Branch' UNION ALL
|
|
||||||
SELECT 'Mocha', 'Cat', 'Burmese', 1, 'Available', 345.00, storeId FROM storeLocation WHERE storeName = 'West Side Store' UNION ALL
|
|
||||||
SELECT 'Rex', 'Dog', 'Doberman', 4, 'Available', 610.00, storeId FROM storeLocation WHERE storeName = 'Downtown Branch' UNION ALL
|
|
||||||
SELECT 'Willow', 'Cat', 'Scottish Fold', 2, 'Available', 480.00, storeId FROM storeLocation WHERE storeName = 'North Branch' UNION ALL
|
|
||||||
SELECT 'Gizmo', 'Dog', 'Pomeranian', 1, 'Available', 530.00, storeId FROM storeLocation WHERE storeName = 'Downtown Branch' UNION ALL
|
|
||||||
SELECT 'Nala', 'Cat', 'Siamese', 3, 'Available', 360.00, storeId FROM storeLocation WHERE storeName = 'North Branch' UNION ALL
|
|
||||||
SELECT 'Duke', 'Dog', 'Great Dane', 2, 'Available', 720.00, storeId FROM storeLocation WHERE storeName = 'West Side Store' UNION ALL
|
|
||||||
SELECT 'Misty', 'Cat', 'Russian Blue', 4, 'Available', 410.00, storeId FROM storeLocation WHERE storeName = 'Downtown Branch' UNION ALL
|
|
||||||
SELECT 'Ace', 'Dog', 'Australian Shepherd', 1, 'Available', 555.00, storeId FROM storeLocation WHERE storeName = 'Downtown Branch';
|
|
||||||
|
|
||||||
-- Insert adopted pets linked to customers
|
|
||||||
INSERT INTO pet (petName, petSpecies, petBreed, petAge, petStatus, petPrice, customerId)
|
|
||||||
SELECT 'Shadow', 'Dog', 'Labrador', 3, 'Adopted', 500.00, customerId FROM customer WHERE email = 'alex@gmail.com' UNION ALL
|
|
||||||
SELECT 'Kitty', 'Cat', 'Persian', 2, 'Adopted', 320.00, customerId FROM customer WHERE email = 'emily@gmail.com' UNION ALL
|
|
||||||
SELECT 'Bruno', 'Dog', 'Rottweiler', 4, 'Adopted', 580.00, customerId FROM customer WHERE email = 'james@gmail.com' UNION ALL
|
|
||||||
SELECT 'Snowball', 'Cat', 'Turkish Angora', 1, 'Adopted', 390.00, customerId FROM customer WHERE email = 'olivia@gmail.com' UNION ALL
|
|
||||||
SELECT 'Zeus', 'Dog', 'Husky', 3, 'Adopted', 640.00, customerId FROM customer WHERE email = 'william@gmail.com';
|
|
||||||
|
|
||||||
-- Insert owned pets linked to customers
|
|
||||||
INSERT INTO pet (petName, petSpecies, petBreed, petAge, petStatus, petPrice, customerId)
|
|
||||||
SELECT 'Biscuit', 'Dog', 'Beagle', 2, 'Owned', 0.00, customerId FROM customer WHERE email = 'sophia@gmail.com' UNION ALL
|
|
||||||
SELECT 'Patches', 'Cat', 'Calico', 5, 'Owned', 0.00, customerId FROM customer WHERE email = 'noah@gmail.com' UNION ALL
|
|
||||||
SELECT 'Scout', 'Dog', 'Border Collie', 3, 'Owned', 0.00, customerId FROM customer WHERE email = 'mia@gmail.com' UNION ALL
|
|
||||||
SELECT 'Mittens', 'Cat', 'Domestic Short', 4, 'Owned', 0.00, customerId FROM customer WHERE email = 'ethan@gmail.com' UNION ALL
|
|
||||||
SELECT 'Thor', 'Dog', 'German Shepherd', 2, 'Owned', 0.00, customerId FROM customer WHERE email = 'chloe@gmail.com';
|
|
||||||
|
|
||||||
-- Insert adoptions for the adopted pets
|
|
||||||
INSERT INTO adoption (petId, customerId, employeeId, adoptionDate, adoptionStatus)
|
|
||||||
SELECT p.petId, p.customerId,
|
|
||||||
(SELECT e.employeeId FROM employee e JOIN users u ON u.id = e.user_id
|
|
||||||
WHERE e.isActive = TRUE AND u.role = 'STAFF' ORDER BY e.employeeId LIMIT 1),
|
|
||||||
'2026-01-10', 'Completed'
|
|
||||||
FROM pet p WHERE p.petName = 'Shadow' AND p.petStatus = 'Adopted';
|
|
||||||
|
|
||||||
INSERT INTO adoption (petId, customerId, employeeId, adoptionDate, adoptionStatus)
|
|
||||||
SELECT p.petId, p.customerId,
|
|
||||||
(SELECT e.employeeId FROM employee e JOIN users u ON u.id = e.user_id
|
|
||||||
WHERE e.isActive = TRUE AND u.role = 'STAFF' ORDER BY e.employeeId LIMIT 1),
|
|
||||||
'2026-01-18', 'Completed'
|
|
||||||
FROM pet p WHERE p.petName = 'Kitty' AND p.petStatus = 'Adopted';
|
|
||||||
|
|
||||||
INSERT INTO adoption (petId, customerId, employeeId, adoptionDate, adoptionStatus)
|
|
||||||
SELECT p.petId, p.customerId,
|
|
||||||
(SELECT e.employeeId FROM employee e JOIN users u ON u.id = e.user_id
|
|
||||||
WHERE e.isActive = TRUE AND u.role = 'STAFF' ORDER BY e.employeeId LIMIT 1),
|
|
||||||
'2026-02-03', 'Completed'
|
|
||||||
FROM pet p WHERE p.petName = 'Bruno' AND p.petStatus = 'Adopted';
|
|
||||||
|
|
||||||
INSERT INTO adoption (petId, customerId, employeeId, adoptionDate, adoptionStatus)
|
|
||||||
SELECT p.petId, p.customerId,
|
|
||||||
(SELECT e.employeeId FROM employee e JOIN users u ON u.id = e.user_id
|
|
||||||
WHERE e.isActive = TRUE AND u.role = 'STAFF' ORDER BY e.employeeId LIMIT 1),
|
|
||||||
'2026-02-14', 'Completed'
|
|
||||||
FROM pet p WHERE p.petName = 'Snowball' AND p.petStatus = 'Adopted';
|
|
||||||
|
|
||||||
INSERT INTO adoption (petId, customerId, employeeId, adoptionDate, adoptionStatus)
|
|
||||||
SELECT p.petId, p.customerId,
|
|
||||||
(SELECT e.employeeId FROM employee e JOIN users u ON u.id = e.user_id
|
|
||||||
WHERE e.isActive = TRUE AND u.role = 'STAFF' ORDER BY e.employeeId LIMIT 1),
|
|
||||||
'2026-02-21', 'Completed'
|
|
||||||
FROM pet p WHERE p.petName = 'Zeus' AND p.petStatus = 'Adopted';
|
|
||||||
|
|
||||||
-- Insert customer_pet entries
|
|
||||||
INSERT INTO customer_pet (customer_id, pet_name, species, breed)
|
|
||||||
SELECT customerId, 'Rex', 'Dog', 'German Shepherd' FROM customer WHERE email = 'alex@gmail.com' UNION ALL
|
|
||||||
SELECT customerId, 'Whiskers', 'Cat', 'Tabby' FROM customer WHERE email = 'emily@gmail.com' UNION ALL
|
|
||||||
SELECT customerId, 'Goldie', 'Dog', 'Golden Retriever' FROM customer WHERE email = 'james@gmail.com' UNION ALL
|
|
||||||
SELECT customerId, 'Midnight', 'Cat', 'Black' FROM customer WHERE email = 'olivia@gmail.com' UNION ALL
|
|
||||||
SELECT customerId, 'Storm', 'Dog', 'Husky' FROM customer WHERE email = 'william@gmail.com' UNION ALL
|
|
||||||
SELECT customerId, 'Peanut', 'Dog', 'Poodle' FROM customer WHERE email = 'sophia@gmail.com' UNION ALL
|
|
||||||
SELECT customerId, 'Snowball', 'Cat', 'Persian' FROM customer WHERE email = 'noah@gmail.com' UNION ALL
|
|
||||||
SELECT customerId, 'Duke', 'Dog', 'Labrador' FROM customer WHERE email = 'mia@gmail.com' UNION ALL
|
|
||||||
SELECT customerId, 'Luna', 'Cat', 'Siamese' FROM customer WHERE email = 'ethan@gmail.com' UNION ALL
|
|
||||||
SELECT customerId, 'Buster', 'Dog', 'Beagle' FROM customer WHERE email = 'chloe@gmail.com' UNION ALL
|
|
||||||
SELECT customerId, 'Daisy', 'Dog', 'Corgi' FROM customer WHERE email = 'lucas@gmail.com' UNION ALL
|
|
||||||
SELECT customerId, 'Cleo', 'Cat', 'Ragdoll' FROM customer WHERE email = 'lily@gmail.com';
|
|
||||||
|
|
||||||
-- Helper function or complex query to seed appointments robustly
|
|
||||||
-- For simplicity and robustness, I will use individual inserts for the first few and a pattern for the rest
|
|
||||||
INSERT INTO appointment (serviceId, customerId, appointmentDate, appointmentTime, appointmentStatus, storeId, employeeId)
|
|
||||||
SELECT (SELECT serviceId FROM service WHERE serviceName = 'Pet Grooming'), (SELECT customerId FROM customer WHERE email = 'alex@gmail.com'), '2026-01-10', '09:00:00', 'Completed', (SELECT storeId FROM storeLocation WHERE storeName = 'Downtown Branch'), (SELECT employeeId FROM employee WHERE email = 'john@petshop.com') UNION ALL
|
|
||||||
SELECT (SELECT serviceId FROM service WHERE serviceName = 'Nail Trimming'), (SELECT customerId FROM customer WHERE email = 'emily@gmail.com'), '2026-01-10', '11:00:00', 'Completed', (SELECT storeId FROM storeLocation WHERE storeName = 'Downtown Branch'), (SELECT employeeId FROM employee WHERE email = 'john@petshop.com') UNION ALL
|
|
||||||
SELECT (SELECT serviceId FROM service WHERE serviceName = 'Bath and Brush'), (SELECT customerId FROM customer WHERE email = 'james@gmail.com'), '2026-01-17', '09:00:00', 'Missed', (SELECT storeId FROM storeLocation WHERE storeName = 'Downtown Branch'), (SELECT employeeId FROM employee WHERE email = 'john@petshop.com') UNION ALL
|
|
||||||
SELECT (SELECT serviceId FROM service WHERE serviceName = 'Veterinary Checkup'), (SELECT customerId FROM customer WHERE email = 'olivia@gmail.com'), '2026-01-17', '14:00:00', 'Completed', (SELECT storeId FROM storeLocation WHERE storeName = 'Downtown Branch'), (SELECT employeeId FROM employee WHERE email = 'john@petshop.com') UNION ALL
|
|
||||||
SELECT (SELECT serviceId FROM service WHERE serviceName = 'Teeth Cleaning'), (SELECT customerId FROM customer WHERE email = 'william@gmail.com'), '2026-01-24', '10:00:00', 'Completed', (SELECT storeId FROM storeLocation WHERE storeName = 'Downtown Branch'), (SELECT employeeId FROM employee WHERE email = 'john@petshop.com') UNION ALL
|
|
||||||
SELECT (SELECT serviceId FROM service WHERE serviceName = 'Pet Grooming'), (SELECT customerId FROM customer WHERE email = 'sophia@gmail.com'), '2026-01-24', '13:00:00', 'Missed', (SELECT storeId FROM storeLocation WHERE storeName = 'Downtown Branch'), (SELECT employeeId FROM employee WHERE email = 'john@petshop.com') UNION ALL
|
|
||||||
SELECT (SELECT serviceId FROM service WHERE serviceName = 'Nail Trimming'), (SELECT customerId FROM customer WHERE email = 'noah@gmail.com'), '2026-02-07', '09:00:00', 'Completed', (SELECT storeId FROM storeLocation WHERE storeName = 'Downtown Branch'), (SELECT employeeId FROM employee WHERE email = 'john@petshop.com') UNION ALL
|
|
||||||
SELECT (SELECT serviceId FROM service WHERE serviceName = 'Bath and Brush'), (SELECT customerId FROM customer WHERE email = 'mia@gmail.com'), '2026-02-07', '11:00:00', 'Completed', (SELECT storeId FROM storeLocation WHERE storeName = 'Downtown Branch'), (SELECT employeeId FROM employee WHERE email = 'john@petshop.com') UNION ALL
|
|
||||||
SELECT (SELECT serviceId FROM service WHERE serviceName = 'Pet Grooming'), (SELECT customerId FROM customer WHERE email = 'ethan@gmail.com'), '2026-01-11', '09:00:00', 'Completed', (SELECT storeId FROM storeLocation WHERE storeName = 'Downtown Branch'), (SELECT employeeId FROM employee WHERE email = 'sara@petshop.com') UNION ALL
|
|
||||||
SELECT (SELECT serviceId FROM service WHERE serviceName = 'Nail Trimming'), (SELECT customerId FROM customer WHERE email = 'chloe@gmail.com'), '2026-01-11', '11:00:00', 'Missed', (SELECT storeId FROM storeLocation WHERE storeName = 'Downtown Branch'), (SELECT employeeId FROM employee WHERE email = 'sara@petshop.com') UNION ALL
|
|
||||||
SELECT (SELECT serviceId FROM service WHERE serviceName = 'Bath and Brush'), (SELECT customerId FROM customer WHERE email = 'lucas@gmail.com'), '2026-01-18', '10:00:00', 'Completed', (SELECT storeId FROM storeLocation WHERE storeName = 'Downtown Branch'), (SELECT employeeId FROM employee WHERE email = 'sara@petshop.com') UNION ALL
|
|
||||||
SELECT (SELECT serviceId FROM service WHERE serviceName = 'Veterinary Checkup'), (SELECT customerId FROM customer WHERE email = 'lily@gmail.com'), '2026-01-18', '13:00:00', 'Completed', (SELECT storeId FROM storeLocation WHERE storeName = 'Downtown Branch'), (SELECT employeeId FROM employee WHERE email = 'sara@petshop.com') UNION ALL
|
|
||||||
SELECT (SELECT serviceId FROM service WHERE serviceName = 'Teeth Cleaning'), (SELECT customerId FROM customer WHERE email = 'alex@gmail.com'), '2026-02-01', '09:00:00', 'Completed', (SELECT storeId FROM storeLocation WHERE storeName = 'Downtown Branch'), (SELECT employeeId FROM employee WHERE email = 'sara@petshop.com') UNION ALL
|
|
||||||
SELECT (SELECT serviceId FROM service WHERE serviceName = 'Pet Grooming'), (SELECT customerId FROM customer WHERE email = 'emily@gmail.com'), '2026-02-01', '14:00:00', 'Missed', (SELECT storeId FROM storeLocation WHERE storeName = 'Downtown Branch'), (SELECT employeeId FROM employee WHERE email = 'sara@petshop.com') UNION ALL
|
|
||||||
SELECT (SELECT serviceId FROM service WHERE serviceName = 'Nail Trimming'), (SELECT customerId FROM customer WHERE email = 'james@gmail.com'), '2026-02-08', '10:00:00', 'Completed', (SELECT storeId FROM storeLocation WHERE storeName = 'Downtown Branch'), (SELECT employeeId FROM employee WHERE email = 'sara@petshop.com') UNION ALL
|
|
||||||
SELECT (SELECT serviceId FROM service WHERE serviceName = 'Bath and Brush'), (SELECT customerId FROM customer WHERE email = 'olivia@gmail.com'), '2026-02-08', '13:00:00', 'Completed', (SELECT storeId FROM storeLocation WHERE storeName = 'Downtown Branch'), (SELECT employeeId FROM employee WHERE email = 'sara@petshop.com') UNION ALL
|
|
||||||
SELECT (SELECT serviceId FROM service WHERE serviceName = 'Veterinary Checkup'), (SELECT customerId FROM customer WHERE email = 'william@gmail.com'), '2026-01-12', '09:00:00', 'Completed', (SELECT storeId FROM storeLocation WHERE storeName = 'Downtown Branch'), (SELECT employeeId FROM employee WHERE email = 'david@petshop.com') UNION ALL
|
|
||||||
SELECT (SELECT serviceId FROM service WHERE serviceName = 'Teeth Cleaning'), (SELECT customerId FROM customer WHERE email = 'sophia@gmail.com'), '2026-01-12', '11:00:00', 'Completed', (SELECT storeId FROM storeLocation WHERE storeName = 'Downtown Branch'), (SELECT employeeId FROM employee WHERE email = 'david@petshop.com') UNION ALL
|
|
||||||
SELECT (SELECT serviceId FROM service WHERE serviceName = 'Pet Grooming'), (SELECT customerId FROM customer WHERE email = 'noah@gmail.com'), '2026-01-19', '09:00:00', 'Missed', (SELECT storeId FROM storeLocation WHERE storeName = 'Downtown Branch'), (SELECT employeeId FROM employee WHERE email = 'david@petshop.com') UNION ALL
|
|
||||||
SELECT (SELECT serviceId FROM service WHERE serviceName = 'Nail Trimming'), (SELECT customerId FROM customer WHERE email = 'mia@gmail.com'), '2026-01-19', '14:00:00', 'Completed', (SELECT storeId FROM storeLocation WHERE storeName = 'Downtown Branch'), (SELECT employeeId FROM employee WHERE email = 'david@petshop.com') UNION ALL
|
|
||||||
SELECT (SELECT serviceId FROM service WHERE serviceName = 'Bath and Brush'), (SELECT customerId FROM customer WHERE email = 'ethan@gmail.com'), '2026-02-09', '10:00:00', 'Completed', (SELECT storeId FROM storeLocation WHERE storeName = 'Downtown Branch'), (SELECT employeeId FROM employee WHERE email = 'david@petshop.com') UNION ALL
|
|
||||||
SELECT (SELECT serviceId FROM service WHERE serviceName = 'Veterinary Checkup'), (SELECT customerId FROM customer WHERE email = 'chloe@gmail.com'), '2026-02-09', '13:00:00', 'Completed', (SELECT storeId FROM storeLocation WHERE storeName = 'Downtown Branch'), (SELECT employeeId FROM employee WHERE email = 'david@petshop.com') UNION ALL
|
|
||||||
SELECT (SELECT serviceId FROM service WHERE serviceName = 'Pet Grooming'), (SELECT customerId FROM customer WHERE email = 'lucas@gmail.com'), '2026-01-13', '09:00:00', 'Completed', (SELECT storeId FROM storeLocation WHERE storeName = 'North Branch'), (SELECT employeeId FROM employee WHERE email = 'michael@petshop.com') UNION ALL
|
|
||||||
SELECT (SELECT serviceId FROM service WHERE serviceName = 'Nail Trimming'), (SELECT customerId FROM customer WHERE email = 'lily@gmail.com'), '2026-01-13', '11:00:00', 'Completed', (SELECT storeId FROM storeLocation WHERE storeName = 'North Branch'), (SELECT employeeId FROM employee WHERE email = 'michael@petshop.com') UNION ALL
|
|
||||||
SELECT (SELECT serviceId FROM service WHERE serviceName = 'Bath and Brush'), (SELECT customerId FROM customer WHERE email = 'alex@gmail.com'), '2026-02-10', '09:00:00', 'Missed', (SELECT storeId FROM storeLocation WHERE storeName = 'North Branch'), (SELECT employeeId FROM employee WHERE email = 'michael@petshop.com') UNION ALL
|
|
||||||
SELECT (SELECT serviceId FROM service WHERE serviceName = 'Veterinary Checkup'), (SELECT customerId FROM customer WHERE email = 'emily@gmail.com'), '2026-02-10', '13:00:00', 'Completed', (SELECT storeId FROM storeLocation WHERE storeName = 'North Branch'), (SELECT employeeId FROM employee WHERE email = 'michael@petshop.com') UNION ALL
|
|
||||||
SELECT (SELECT serviceId FROM service WHERE serviceName = 'Pet Grooming'), (SELECT customerId FROM customer WHERE email = 'james@gmail.com'), '2026-01-14', '10:00:00', 'Completed', (SELECT storeId FROM storeLocation WHERE storeName = 'West Side Store'), (SELECT employeeId FROM employee WHERE email = 'lisa@petshop.com') UNION ALL
|
|
||||||
SELECT (SELECT serviceId FROM service WHERE serviceName = 'Nail Trimming'), (SELECT customerId FROM customer WHERE email = 'olivia@gmail.com'), '2026-01-14', '13:00:00', 'Completed', (SELECT storeId FROM storeLocation WHERE storeName = 'West Side Store'), (SELECT employeeId FROM employee WHERE email = 'lisa@petshop.com') UNION ALL
|
|
||||||
SELECT (SELECT serviceId FROM service WHERE serviceName = 'Bath and Brush'), (SELECT customerId FROM customer WHERE email = 'william@gmail.com'), '2026-02-11', '10:00:00', 'Missed', (SELECT storeId FROM storeLocation WHERE storeName = 'West Side Store'), (SELECT employeeId FROM employee WHERE email = 'lisa@petshop.com') UNION ALL
|
|
||||||
SELECT (SELECT serviceId FROM service WHERE serviceName = 'Veterinary Checkup'), (SELECT customerId FROM customer WHERE email = 'sophia@gmail.com'), '2026-02-11', '14:00:00', 'Completed', (SELECT storeId FROM storeLocation WHERE storeName = 'West Side Store'), (SELECT employeeId FROM employee WHERE email = 'lisa@petshop.com') UNION ALL
|
|
||||||
SELECT (SELECT serviceId FROM service WHERE serviceName = 'Pet Grooming'), (SELECT customerId FROM customer WHERE email = 'noah@gmail.com'), '2026-04-15', '09:00:00', 'Booked', (SELECT storeId FROM storeLocation WHERE storeName = 'Downtown Branch'), (SELECT employeeId FROM employee WHERE email = 'john@petshop.com') UNION ALL
|
|
||||||
SELECT (SELECT serviceId FROM service WHERE serviceName = 'Nail Trimming'), (SELECT customerId FROM customer WHERE email = 'mia@gmail.com'), '2026-04-15', '11:00:00', 'Booked', (SELECT storeId FROM storeLocation WHERE storeName = 'Downtown Branch'), (SELECT employeeId FROM employee WHERE email = 'sara@petshop.com') UNION ALL
|
|
||||||
SELECT (SELECT serviceId FROM service WHERE serviceName = 'Bath and Brush'), (SELECT customerId FROM customer WHERE email = 'ethan@gmail.com'), '2026-04-16', '10:00:00', 'Booked', (SELECT storeId FROM storeLocation WHERE storeName = 'Downtown Branch'), (SELECT employeeId FROM employee WHERE email = 'david@petshop.com') UNION ALL
|
|
||||||
SELECT (SELECT serviceId FROM service WHERE serviceName = 'Veterinary Checkup'), (SELECT customerId FROM customer WHERE email = 'chloe@gmail.com'), '2026-04-17', '09:00:00', 'Booked', (SELECT storeId FROM storeLocation WHERE storeName = 'North Branch'), (SELECT employeeId FROM employee WHERE email = 'michael@petshop.com') UNION ALL
|
|
||||||
SELECT (SELECT serviceId FROM service WHERE serviceName = 'Teeth Cleaning'), (SELECT customerId FROM customer WHERE email = 'lucas@gmail.com'), '2026-04-18', '14:00:00', 'Booked', (SELECT storeId FROM storeLocation WHERE storeName = 'West Side Store'), (SELECT employeeId FROM employee WHERE email = 'lisa@petshop.com');
|
|
||||||
|
|
||||||
-- Re-linking appointments to customer pets using a slightly more robust join
|
|
||||||
-- This still assumes appointments and customer_pets were inserted in a specific order,
|
|
||||||
-- but at least it uses current IDs from the database.
|
|
||||||
INSERT INTO appointment_customer_pet (appointment_id, customer_pet_id)
|
|
||||||
SELECT a.appointmentId, cp.customer_pet_id
|
|
||||||
FROM (
|
|
||||||
SELECT appointmentId, ROW_NUMBER() OVER (ORDER BY appointmentId) as row_num
|
|
||||||
FROM appointment
|
|
||||||
WHERE appointmentId > (SELECT COALESCE(MAX(appointmentId), 0) FROM (SELECT appointmentId FROM appointment LIMIT 5) t)
|
|
||||||
) a
|
|
||||||
JOIN (
|
|
||||||
SELECT customer_pet_id, ROW_NUMBER() OVER (ORDER BY customer_pet_id) as row_num
|
|
||||||
FROM customer_pet
|
|
||||||
) cp ON ((a.row_num - 1) % 12) + 1 = cp.row_num;
|
|
||||||
@@ -1,205 +0,0 @@
|
|||||||
-- Insert Sample Data
|
|
||||||
|
|
||||||
INSERT INTO storeLocation (storeName, address, phone, email)
|
|
||||||
VALUES
|
|
||||||
('Downtown Branch', '123 Main St', '123-456-7890', 'downtown@petshop.com'),
|
|
||||||
('North Branch', '456 North Ave', '987-654-3210', 'north@petshop.com'),
|
|
||||||
('West Side Store', '789 West Blvd', '555-123-4567', 'westside@petshop.com'),
|
|
||||||
('East End Shop', '321 East Road', '555-987-6543', 'eastend@petshop.com'),
|
|
||||||
('South Mall Location', '654 South Plaza', '555-246-8135', 'southmall@petshop.com');
|
|
||||||
|
|
||||||
INSERT INTO employee (firstName, lastName, email, phone, role, isActive)
|
|
||||||
VALUES
|
|
||||||
('John', 'Doe', 'john@petshop.com', '111-222-3333', 'Manager', TRUE),
|
|
||||||
('Sara', 'Smith', 'sara@petshop.com', '444-555-6666', 'Staff', TRUE),
|
|
||||||
('Michael', 'Johnson', 'michael@petshop.com', '222-333-4444', 'Groomer', TRUE),
|
|
||||||
('Lisa', 'Williams', 'lisa@petshop.com', '333-444-5555', 'Staff', TRUE),
|
|
||||||
('David', 'Brown', 'david@petshop.com', '555-666-7777', 'Veterinarian', TRUE),
|
|
||||||
('Emma', 'Davis', 'emma@petshop.com', '666-777-8888', 'Manager', FALSE);
|
|
||||||
|
|
||||||
INSERT INTO employeeStore (employeeId, storeId)
|
|
||||||
VALUES
|
|
||||||
(1, 1),
|
|
||||||
(2, 1),
|
|
||||||
(2, 2),
|
|
||||||
(3, 2),
|
|
||||||
(4, 3),
|
|
||||||
(5, 1),
|
|
||||||
(5, 4),
|
|
||||||
(6, 5);
|
|
||||||
|
|
||||||
INSERT INTO customer (firstName, lastName, email, phone)
|
|
||||||
VALUES
|
|
||||||
('Alex', 'Brown', 'alex@gmail.com', '777-888-9999'),
|
|
||||||
('Emily', 'Clark', 'emily@gmail.com', '666-555-4444'),
|
|
||||||
('James', 'Wilson', 'james@gmail.com', '888-999-0000'),
|
|
||||||
('Olivia', 'Martinez', 'olivia@gmail.com', '999-000-1111'),
|
|
||||||
('William', 'Anderson', 'william@gmail.com', '000-111-2222'),
|
|
||||||
('Sophia', 'Taylor', 'sophia@gmail.com', '111-222-3333');
|
|
||||||
|
|
||||||
INSERT INTO pet (petName, petSpecies, petBreed, petAge, petStatus, petPrice)
|
|
||||||
VALUES
|
|
||||||
('Buddy', 'Dog', 'Labrador', 2, 'Available', 500.00),
|
|
||||||
('Milo', 'Cat', 'Persian', 1, 'Available', 300.00),
|
|
||||||
('Charlie', 'Dog', 'Golden Retriever', 3, 'Available', 550.00),
|
|
||||||
('Luna', 'Cat', 'Siamese', 2, 'Adopted', 350.00),
|
|
||||||
('Max', 'Dog', 'Beagle', 1, 'Available', 450.00),
|
|
||||||
('Bella', 'Cat', 'Maine Coon', 4, 'Available', 400.00);
|
|
||||||
|
|
||||||
INSERT INTO adoption (petId, customerId, adoptionDate, adoptionStatus)
|
|
||||||
VALUES
|
|
||||||
(1, 1, '2026-01-15', 'Completed'),
|
|
||||||
(4, 3, '2026-01-20', 'Completed'),
|
|
||||||
(2, 2, '2026-01-25', 'Pending'),
|
|
||||||
(5, 4, '2026-02-01', 'Completed'),
|
|
||||||
(6, 5, '2026-02-02', 'Pending');
|
|
||||||
|
|
||||||
INSERT INTO supplier (supCompany, supContactFirstName, supContactLastName, supEmail, supPhone)
|
|
||||||
VALUES
|
|
||||||
('PetFood Inc', 'Robert', 'King', 'contact@petfood.com', '888-111-2222'),
|
|
||||||
('Toy World', 'Jennifer', 'Lee', 'sales@toyworld.com', '888-222-3333'),
|
|
||||||
('Pet Supplies Co', 'Kevin', 'White', 'info@petsupplies.com', '888-333-4444'),
|
|
||||||
('Animal Care Products', 'Nancy', 'Green', 'orders@animalcare.com', '888-444-5555'),
|
|
||||||
('Premium Pet Goods', 'Tom', 'Black', 'support@premiumpet.com', '888-555-6666');
|
|
||||||
|
|
||||||
INSERT INTO category (categoryName, categoryType)
|
|
||||||
VALUES
|
|
||||||
('Dog Food', 'Product'),
|
|
||||||
('Cat Toys', 'Product'),
|
|
||||||
('Bird Supplies', 'Product'),
|
|
||||||
('Aquarium', 'Product'),
|
|
||||||
('Small Animals', 'Product');
|
|
||||||
|
|
||||||
INSERT INTO product (prodName, prodPrice, categoryId, prodDesc)
|
|
||||||
VALUES
|
|
||||||
('Premium Dog Food', 50.00, 1, 'High quality dog food'),
|
|
||||||
('Cat Toy Ball', 10.00, 2, 'Colorful toy for cats'),
|
|
||||||
('Bird Cage Large', 120.00, 3, 'Spacious bird cage'),
|
|
||||||
('Fish Tank 20 Gallon', 80.00, 4, 'Complete aquarium kit'),
|
|
||||||
('Hamster Wheel', 15.00, 5, 'Exercise wheel for small pets'),
|
|
||||||
('Organic Dog Treats', 25.00, 1, 'Natural dog treats');
|
|
||||||
|
|
||||||
INSERT INTO productSupplier (supId, prodId, cost)
|
|
||||||
VALUES
|
|
||||||
(1, 1, 35.00),
|
|
||||||
(1, 2, 6.50),
|
|
||||||
(2, 2, 7.00),
|
|
||||||
(3, 3, 90.00),
|
|
||||||
(3, 4, 60.00),
|
|
||||||
(4, 5, 10.00),
|
|
||||||
(5, 6, 18.00),
|
|
||||||
(1, 6, 17.50);
|
|
||||||
|
|
||||||
INSERT INTO inventory (prodId, quantity)
|
|
||||||
VALUES
|
|
||||||
(1, 100),
|
|
||||||
(2, 200),
|
|
||||||
(3, 50),
|
|
||||||
(4, 30),
|
|
||||||
(5, 150),
|
|
||||||
(6, 75);
|
|
||||||
|
|
||||||
INSERT INTO service (serviceName, serviceDesc, serviceDuration, servicePrice)
|
|
||||||
VALUES
|
|
||||||
('Pet Grooming', 'Full grooming service', 60, 40.00),
|
|
||||||
('Nail Trimming', 'Quick nail trim', 15, 10.00),
|
|
||||||
('Bath and Brush', 'Bathing and brushing service', 45, 30.00),
|
|
||||||
('Veterinary Checkup', 'Complete health examination', 30, 75.00),
|
|
||||||
('Teeth Cleaning', 'Professional dental cleaning', 90, 100.00);
|
|
||||||
|
|
||||||
INSERT INTO appointment (serviceId, customerId, appointmentDate, appointmentTime, appointmentStatus)
|
|
||||||
VALUES
|
|
||||||
(1, 2, '2026-02-01', '10:30:00', 'Booked'),
|
|
||||||
(2, 1, '2026-02-03', '14:00:00', 'Booked'),
|
|
||||||
(3, 3, '2026-02-05', '09:00:00', 'Completed'),
|
|
||||||
(4, 4, '2026-02-07', '11:30:00', 'Booked'),
|
|
||||||
(5, 5, '2026-02-10', '15:00:00', 'Cancelled');
|
|
||||||
|
|
||||||
INSERT INTO appointmentPet (appointmentId, petId)
|
|
||||||
VALUES
|
|
||||||
(1, 2),
|
|
||||||
(2, 1),
|
|
||||||
(3, 3),
|
|
||||||
(4, 5),
|
|
||||||
(5, 6);
|
|
||||||
|
|
||||||
INSERT INTO sale (saleDate, totalAmount, paymentMethod, employeeId, storeId, customerId)
|
|
||||||
VALUES
|
|
||||||
('2026-01-05 09:15:00', 125.00, 'Card', 1, 1, 1),
|
|
||||||
('2026-01-08 11:30:00', 200.00, 'Card', 2, 1, 2),
|
|
||||||
('2026-01-12 14:20:00', 60.00, 'Cash', 3, 2, 3),
|
|
||||||
('2026-01-15 10:45:00', 150.00, 'Debit', 1, 1, 1),
|
|
||||||
('2026-01-18 16:30:00', 80.00, 'Card', 4, 3, 2),
|
|
||||||
('2026-01-22 13:15:00', 95.00, 'Cash', 2, 2, NULL),
|
|
||||||
('2026-01-25 15:40:00', 240.00, 'Card', 5, 4, 4),
|
|
||||||
('2026-01-28 10:30:00', 80.00, 'Cash', 1, 1, NULL),
|
|
||||||
('2026-02-01 09:00:00', 175.00, 'Card', 3, 3, 1),
|
|
||||||
('2026-02-03 11:20:00', 120.00, 'Card', 2, 1, 3),
|
|
||||||
('2026-02-05 14:50:00', 45.00, 'Cash', 4, 2, NULL),
|
|
||||||
('2026-02-08 16:15:00', 160.00, 'Debit', 1, 1, 2),
|
|
||||||
('2026-02-10 10:25:00', 100.00, 'Card', 5, 4, NULL),
|
|
||||||
('2026-02-12 13:45:00', 50.00, 'Cash', 2, 2, 1),
|
|
||||||
('2026-02-15 15:30:00', 85.00, 'Card', 3, 3, NULL),
|
|
||||||
('2026-02-18 11:10:00', 200.00, 'Card', 1, 1, 4),
|
|
||||||
('2026-02-20 14:35:00', 155.00, 'Debit', 4, 3, NULL),
|
|
||||||
('2026-02-22 16:50:00', 75.00, 'Cash', 2, 1, 2),
|
|
||||||
('2026-02-24 10:15:00', 140.00, 'Card', 5, 4, NULL),
|
|
||||||
(NOW(), 95.00, 'Card', 1, 1, 1);
|
|
||||||
|
|
||||||
INSERT INTO saleItem (saleId, prodId, quantity, unitPrice)
|
|
||||||
VALUES
|
|
||||||
(1, 1, 2, 50.00),
|
|
||||||
(1, 6, 1, 25.00),
|
|
||||||
(2, 3, 1, 120.00),
|
|
||||||
(2, 4, 1, 80.00),
|
|
||||||
(3, 2, 3, 10.00),
|
|
||||||
(3, 5, 2, 15.00),
|
|
||||||
(4, 1, 3, 50.00),
|
|
||||||
(5, 4, 1, 80.00),
|
|
||||||
(6, 2, 4, 10.00),
|
|
||||||
(6, 5, 1, 15.00),
|
|
||||||
(6, 6, 1, 25.00),
|
|
||||||
(6, 1, 1, 50.00),
|
|
||||||
(7, 3, 2, 120.00),
|
|
||||||
(8, 1, 1, 50.00),
|
|
||||||
(8, 2, 3, 10.00),
|
|
||||||
(9, 1, 3, 50.00),
|
|
||||||
(9, 6, 1, 25.00),
|
|
||||||
(10, 3, 1, 120.00),
|
|
||||||
(11, 5, 1, 15.00),
|
|
||||||
(11, 2, 3, 10.00),
|
|
||||||
(12, 4, 2, 80.00),
|
|
||||||
(13, 6, 4, 25.00),
|
|
||||||
(14, 1, 1, 50.00),
|
|
||||||
(15, 2, 2, 10.00),
|
|
||||||
(15, 5, 1, 15.00),
|
|
||||||
(15, 6, 2, 25.00),
|
|
||||||
(16, 3, 1, 120.00),
|
|
||||||
(16, 4, 1, 80.00),
|
|
||||||
(17, 4, 1, 80.00),
|
|
||||||
(17, 1, 1, 50.00),
|
|
||||||
(17, 6, 1, 25.00),
|
|
||||||
(18, 6, 2, 25.00),
|
|
||||||
(18, 2, 2, 10.00),
|
|
||||||
(18, 5, 1, 15.00),
|
|
||||||
(19, 1, 2, 50.00),
|
|
||||||
(19, 6, 2, 25.00),
|
|
||||||
(20, 2, 5, 10.00),
|
|
||||||
(20, 5, 3, 15.00);
|
|
||||||
|
|
||||||
INSERT INTO purchaseOrder (supId, orderDate, status)
|
|
||||||
VALUES
|
|
||||||
(1, '2025-01-15', 'Delivered'),
|
|
||||||
(2, '2025-01-20', 'Pending'),
|
|
||||||
(3, '2025-02-01', 'Delivered'),
|
|
||||||
(4, '2025-02-10', 'In Transit'),
|
|
||||||
(1, '2025-02-15', 'Pending');
|
|
||||||
|
|
||||||
INSERT INTO activityLog (employeeId, activity)
|
|
||||||
VALUES
|
|
||||||
(1, 'Created new sale'),
|
|
||||||
(2, 'Booked appointment'),
|
|
||||||
(3, 'Completed grooming service'),
|
|
||||||
(4, 'Processed inventory order'),
|
|
||||||
(5, 'Conducted health checkup'),
|
|
||||||
(1, 'Updated customer information');
|
|
||||||
@@ -1,19 +0,0 @@
|
|||||||
ALTER TABLE appointment
|
|
||||||
ADD COLUMN storeId BIGINT NULL AFTER customerId;
|
|
||||||
|
|
||||||
UPDATE appointment
|
|
||||||
SET storeId = 1
|
|
||||||
WHERE storeId IS NULL;
|
|
||||||
|
|
||||||
ALTER TABLE appointment
|
|
||||||
MODIFY COLUMN storeId BIGINT NOT NULL,
|
|
||||||
ADD CONSTRAINT fk_appointment_store FOREIGN KEY (storeId) REFERENCES storeLocation(storeId);
|
|
||||||
|
|
||||||
DELETE es1
|
|
||||||
FROM employeeStore es1
|
|
||||||
JOIN employeeStore es2
|
|
||||||
ON es1.employeeId = es2.employeeId
|
|
||||||
AND es1.storeId > es2.storeId;
|
|
||||||
|
|
||||||
ALTER TABLE employeeStore
|
|
||||||
ADD CONSTRAINT uk_employeeStore_employee UNIQUE (employeeId);
|
|
||||||
@@ -1,9 +0,0 @@
|
|||||||
ALTER TABLE conversation
|
|
||||||
ADD COLUMN mode VARCHAR(20) NOT NULL DEFAULT 'AUTOMATED' AFTER status,
|
|
||||||
ADD COLUMN humanRequestedAt TIMESTAMP NULL AFTER mode;
|
|
||||||
|
|
||||||
UPDATE conversation
|
|
||||||
SET mode = CASE
|
|
||||||
WHEN staffId IS NULL THEN 'AUTOMATED'
|
|
||||||
ELSE 'HUMAN'
|
|
||||||
END;
|
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
ALTER TABLE users
|
|
||||||
ADD COLUMN tokenVersion INT NOT NULL DEFAULT 0 AFTER active;
|
|
||||||
@@ -1,8 +0,0 @@
|
|||||||
ALTER TABLE users
|
|
||||||
ADD COLUMN phone VARCHAR(20) NULL AFTER fullName;
|
|
||||||
|
|
||||||
UPDATE users u
|
|
||||||
LEFT JOIN customer c ON c.user_id = u.id
|
|
||||||
LEFT JOIN employee e ON e.user_id = u.id
|
|
||||||
SET u.phone = COALESCE(NULLIF(c.phone, ''), NULLIF(e.phone, ''), u.phone)
|
|
||||||
WHERE u.phone IS NULL OR u.phone = '';
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
UPDATE users u
|
|
||||||
LEFT JOIN customer c ON c.user_id = u.id
|
|
||||||
LEFT JOIN employee e ON e.user_id = u.id
|
|
||||||
SET u.phone = COALESCE(NULLIF(u.phone, ''), NULLIF(c.phone, ''), NULLIF(e.phone, ''))
|
|
||||||
WHERE u.phone IS NULL OR u.phone = '';
|
|
||||||
|
|
||||||
ALTER TABLE customer
|
|
||||||
DROP COLUMN phone;
|
|
||||||
|
|
||||||
ALTER TABLE employee
|
|
||||||
DROP COLUMN phone;
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
ALTER TABLE pet
|
|
||||||
ADD COLUMN imageUrl VARCHAR(255) NULL;
|
|
||||||
|
|
||||||
ALTER TABLE product
|
|
||||||
ADD COLUMN imageUrl VARCHAR(255) NULL;
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
CREATE TABLE IF NOT EXISTS customer_pet (
|
|
||||||
customer_pet_id BIGINT AUTO_INCREMENT PRIMARY KEY,
|
|
||||||
customer_id BIGINT NOT NULL,
|
|
||||||
pet_name VARCHAR(50) NOT NULL,
|
|
||||||
species VARCHAR(50) NOT NULL,
|
|
||||||
breed VARCHAR(50) NULL,
|
|
||||||
image_url VARCHAR(255) NULL,
|
|
||||||
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
|
||||||
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
|
||||||
FOREIGN KEY (customer_id) REFERENCES customer(customerId)
|
|
||||||
);
|
|
||||||
@@ -0,0 +1,343 @@
|
|||||||
|
CREATE DATABASE IF NOT EXISTS Petstoredb_target CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||||
|
USE Petstoredb_target;
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS storeLocation (
|
||||||
|
storeId BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
storeName VARCHAR(100) NOT NULL,
|
||||||
|
address VARCHAR(255) NOT NULL,
|
||||||
|
phone VARCHAR(20) NOT NULL,
|
||||||
|
email VARCHAR(100) NOT NULL,
|
||||||
|
imageUrl VARCHAR(255) NULL,
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS users (
|
||||||
|
id BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
username VARCHAR(50) NULL UNIQUE,
|
||||||
|
password VARCHAR(255) NULL,
|
||||||
|
email VARCHAR(100) NULL UNIQUE,
|
||||||
|
firstName VARCHAR(50) NOT NULL,
|
||||||
|
lastName VARCHAR(50) NOT NULL,
|
||||||
|
fullName VARCHAR(100) NULL,
|
||||||
|
phone VARCHAR(20) NULL,
|
||||||
|
avatarUrl VARCHAR(255) NULL,
|
||||||
|
role VARCHAR(20) NOT NULL,
|
||||||
|
staffRole VARCHAR(50) NULL,
|
||||||
|
primaryStoreId BIGINT NULL,
|
||||||
|
loyaltyPoints INT NOT NULL DEFAULT 0,
|
||||||
|
active BOOLEAN NOT NULL DEFAULT TRUE,
|
||||||
|
tokenVersion INT NOT NULL DEFAULT 0,
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||||
|
CONSTRAINT fk_users_primary_store FOREIGN KEY (primaryStoreId) REFERENCES storeLocation(storeId) ON DELETE SET NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS supplier (
|
||||||
|
supId BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
supCompany VARCHAR(100) NOT NULL,
|
||||||
|
supContactFirstName VARCHAR(50) NOT NULL,
|
||||||
|
supContactLastName VARCHAR(50) NOT NULL,
|
||||||
|
supEmail VARCHAR(100) NOT NULL,
|
||||||
|
supPhone VARCHAR(20) NOT NULL,
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS category (
|
||||||
|
categoryId BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
categoryName VARCHAR(100) NOT NULL,
|
||||||
|
categoryType VARCHAR(50) NOT NULL,
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||||
|
CONSTRAINT uq_category_name_type UNIQUE (categoryName, categoryType)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS service (
|
||||||
|
serviceId BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
serviceName VARCHAR(100) NOT NULL,
|
||||||
|
serviceDesc TEXT NULL,
|
||||||
|
serviceDuration INT NOT NULL,
|
||||||
|
servicePrice DECIMAL(10, 2) NOT NULL,
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS service_species (
|
||||||
|
serviceId BIGINT NOT NULL,
|
||||||
|
species VARCHAR(50) NOT NULL,
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
PRIMARY KEY (serviceId, species),
|
||||||
|
CONSTRAINT fk_service_species_service FOREIGN KEY (serviceId) REFERENCES service(serviceId) ON DELETE CASCADE
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS product (
|
||||||
|
prodId BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
prodName VARCHAR(100) NOT NULL,
|
||||||
|
prodPrice DECIMAL(10, 2) NOT NULL,
|
||||||
|
categoryId BIGINT NOT NULL,
|
||||||
|
prodDesc TEXT NULL,
|
||||||
|
imageUrl VARCHAR(255) NULL,
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||||
|
CONSTRAINT fk_product_category FOREIGN KEY (categoryId) REFERENCES category(categoryId)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS inventory (
|
||||||
|
inventoryId BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
storeId BIGINT NOT NULL,
|
||||||
|
prodId BIGINT NOT NULL,
|
||||||
|
quantity INT NOT NULL DEFAULT 0,
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||||
|
CONSTRAINT uq_inventory_store_product UNIQUE (storeId, prodId),
|
||||||
|
CONSTRAINT fk_inventory_store FOREIGN KEY (storeId) REFERENCES storeLocation(storeId),
|
||||||
|
CONSTRAINT fk_inventory_product FOREIGN KEY (prodId) REFERENCES product(prodId)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS productSupplier (
|
||||||
|
supId BIGINT NOT NULL,
|
||||||
|
prodId BIGINT NOT NULL,
|
||||||
|
cost DECIMAL(10, 2) NOT NULL,
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||||
|
PRIMARY KEY (supId, prodId),
|
||||||
|
CONSTRAINT fk_product_supplier_supplier FOREIGN KEY (supId) REFERENCES supplier(supId),
|
||||||
|
CONSTRAINT fk_product_supplier_product FOREIGN KEY (prodId) REFERENCES product(prodId)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS purchaseOrder (
|
||||||
|
purchaseOrderId BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
supId BIGINT NOT NULL,
|
||||||
|
storeId BIGINT NOT NULL,
|
||||||
|
orderDate DATE NOT NULL,
|
||||||
|
status VARCHAR(50) NOT NULL,
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||||
|
CONSTRAINT fk_purchase_order_supplier FOREIGN KEY (supId) REFERENCES supplier(supId),
|
||||||
|
CONSTRAINT fk_purchase_order_store FOREIGN KEY (storeId) REFERENCES storeLocation(storeId)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS coupon (
|
||||||
|
couponId BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
couponCode VARCHAR(50) NOT NULL,
|
||||||
|
discountType VARCHAR(20) NOT NULL,
|
||||||
|
discountValue DECIMAL(10, 2) NOT NULL,
|
||||||
|
minOrderAmount DECIMAL(10, 2) NULL,
|
||||||
|
active BOOLEAN NOT NULL DEFAULT TRUE,
|
||||||
|
startsAt DATETIME NULL,
|
||||||
|
endsAt DATETIME NULL,
|
||||||
|
usageLimit INT NULL,
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||||
|
CONSTRAINT uq_coupon_code UNIQUE (couponCode)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS pet (
|
||||||
|
petId BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
petName VARCHAR(50) NOT NULL,
|
||||||
|
petSpecies VARCHAR(50) NOT NULL,
|
||||||
|
petBreed VARCHAR(50) NULL,
|
||||||
|
petAge INT NULL,
|
||||||
|
petStatus VARCHAR(20) NOT NULL,
|
||||||
|
petPrice DECIMAL(10, 2) NULL,
|
||||||
|
imageUrl VARCHAR(255) NULL,
|
||||||
|
ownerUserId BIGINT NULL,
|
||||||
|
storeId BIGINT NULL,
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||||
|
CONSTRAINT fk_pet_owner_user FOREIGN KEY (ownerUserId) REFERENCES users(id) ON DELETE SET NULL,
|
||||||
|
CONSTRAINT fk_pet_store FOREIGN KEY (storeId) REFERENCES storeLocation(storeId) ON DELETE SET NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS appointment (
|
||||||
|
appointmentId BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
serviceId BIGINT NOT NULL,
|
||||||
|
petId BIGINT NOT NULL,
|
||||||
|
customerId BIGINT NOT NULL,
|
||||||
|
storeId BIGINT NOT NULL,
|
||||||
|
employeeId BIGINT NOT NULL,
|
||||||
|
appointmentDate DATE NOT NULL,
|
||||||
|
appointmentTime TIME NOT NULL,
|
||||||
|
appointmentStatus VARCHAR(20) NOT NULL,
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||||
|
CONSTRAINT fk_appointment_service FOREIGN KEY (serviceId) REFERENCES service(serviceId),
|
||||||
|
CONSTRAINT fk_appointment_pet FOREIGN KEY (petId) REFERENCES pet(petId),
|
||||||
|
CONSTRAINT fk_appointment_customer FOREIGN KEY (customerId) REFERENCES users(id),
|
||||||
|
CONSTRAINT fk_appointment_store FOREIGN KEY (storeId) REFERENCES storeLocation(storeId),
|
||||||
|
CONSTRAINT fk_appointment_employee FOREIGN KEY (employeeId) REFERENCES users(id)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS adoption (
|
||||||
|
adoptionId BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
petId BIGINT NOT NULL,
|
||||||
|
customerId BIGINT NOT NULL,
|
||||||
|
employeeId BIGINT NOT NULL,
|
||||||
|
sourceStoreId BIGINT NOT NULL,
|
||||||
|
adoptionDate DATE NOT NULL,
|
||||||
|
adoptionStatus VARCHAR(20) NOT NULL,
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||||
|
CONSTRAINT fk_adoption_pet FOREIGN KEY (petId) REFERENCES pet(petId),
|
||||||
|
CONSTRAINT fk_adoption_customer FOREIGN KEY (customerId) REFERENCES users(id),
|
||||||
|
CONSTRAINT fk_adoption_employee FOREIGN KEY (employeeId) REFERENCES users(id),
|
||||||
|
CONSTRAINT fk_adoption_source_store FOREIGN KEY (sourceStoreId) REFERENCES storeLocation(storeId)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS cart (
|
||||||
|
cartId BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
userId BIGINT NOT NULL,
|
||||||
|
storeId BIGINT NULL,
|
||||||
|
couponId BIGINT NULL,
|
||||||
|
cartStatus VARCHAR(20) NOT NULL DEFAULT 'ACTIVE',
|
||||||
|
subtotalAmount DECIMAL(10, 2) NOT NULL DEFAULT 0.00,
|
||||||
|
discountAmount DECIMAL(10, 2) NOT NULL DEFAULT 0.00,
|
||||||
|
totalAmount DECIMAL(10, 2) NOT NULL DEFAULT 0.00,
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||||
|
CONSTRAINT fk_cart_user FOREIGN KEY (userId) REFERENCES users(id),
|
||||||
|
CONSTRAINT fk_cart_store FOREIGN KEY (storeId) REFERENCES storeLocation(storeId) ON DELETE SET NULL,
|
||||||
|
CONSTRAINT fk_cart_coupon FOREIGN KEY (couponId) REFERENCES coupon(couponId) ON DELETE SET NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS cart_item (
|
||||||
|
cartItemId BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
cartId BIGINT NOT NULL,
|
||||||
|
prodId BIGINT NOT NULL,
|
||||||
|
quantity INT NOT NULL,
|
||||||
|
unitPrice DECIMAL(10, 2) NOT NULL,
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||||
|
CONSTRAINT fk_cart_item_cart FOREIGN KEY (cartId) REFERENCES cart(cartId) ON DELETE CASCADE,
|
||||||
|
CONSTRAINT fk_cart_item_product FOREIGN KEY (prodId) REFERENCES product(prodId)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS sale (
|
||||||
|
saleId BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
saleDate DATETIME NOT NULL,
|
||||||
|
totalAmount DECIMAL(10, 2) NOT NULL,
|
||||||
|
paymentMethod VARCHAR(50) NOT NULL,
|
||||||
|
employeeId BIGINT NOT NULL,
|
||||||
|
storeId BIGINT NOT NULL,
|
||||||
|
customerId BIGINT NULL,
|
||||||
|
isRefund BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
|
originalSaleId BIGINT NULL,
|
||||||
|
channel VARCHAR(20) NOT NULL DEFAULT 'IN_STORE',
|
||||||
|
cartId BIGINT NULL,
|
||||||
|
couponId BIGINT NULL,
|
||||||
|
subtotalAmount DECIMAL(10, 2) NULL,
|
||||||
|
couponDiscountAmount DECIMAL(10, 2) NOT NULL DEFAULT 0.00,
|
||||||
|
employeeDiscountAmount DECIMAL(10, 2) NOT NULL DEFAULT 0.00,
|
||||||
|
pointsEarned INT NOT NULL DEFAULT 0,
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||||
|
CONSTRAINT fk_sale_employee FOREIGN KEY (employeeId) REFERENCES users(id),
|
||||||
|
CONSTRAINT fk_sale_store FOREIGN KEY (storeId) REFERENCES storeLocation(storeId),
|
||||||
|
CONSTRAINT fk_sale_customer FOREIGN KEY (customerId) REFERENCES users(id) ON DELETE SET NULL,
|
||||||
|
CONSTRAINT fk_sale_original_sale FOREIGN KEY (originalSaleId) REFERENCES sale(saleId),
|
||||||
|
CONSTRAINT fk_sale_cart FOREIGN KEY (cartId) REFERENCES cart(cartId) ON DELETE SET NULL,
|
||||||
|
CONSTRAINT fk_sale_coupon FOREIGN KEY (couponId) REFERENCES coupon(couponId) ON DELETE SET NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS saleItem (
|
||||||
|
saleItemId BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
saleId BIGINT NOT NULL,
|
||||||
|
prodId BIGINT NOT NULL,
|
||||||
|
quantity INT NOT NULL,
|
||||||
|
unitPrice DECIMAL(10, 2) NOT NULL,
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||||
|
CONSTRAINT fk_sale_item_sale FOREIGN KEY (saleId) REFERENCES sale(saleId) ON DELETE CASCADE,
|
||||||
|
CONSTRAINT fk_sale_item_product FOREIGN KEY (prodId) REFERENCES product(prodId)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS refund (
|
||||||
|
id BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
saleId BIGINT NOT NULL,
|
||||||
|
customerId BIGINT NOT NULL,
|
||||||
|
amount DECIMAL(10, 2) NOT NULL,
|
||||||
|
reason VARCHAR(500) NOT NULL,
|
||||||
|
status VARCHAR(20) NOT NULL,
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||||
|
CONSTRAINT fk_refund_sale FOREIGN KEY (saleId) REFERENCES sale(saleId),
|
||||||
|
CONSTRAINT fk_refund_customer FOREIGN KEY (customerId) REFERENCES users(id)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS refund_item (
|
||||||
|
id BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
refund_id BIGINT NOT NULL,
|
||||||
|
prod_id BIGINT NOT NULL,
|
||||||
|
quantity INT NOT NULL,
|
||||||
|
unit_price DECIMAL(10, 2) NOT NULL,
|
||||||
|
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||||
|
CONSTRAINT fk_refund_item_refund FOREIGN KEY (refund_id) REFERENCES refund(id) ON DELETE CASCADE,
|
||||||
|
CONSTRAINT fk_refund_item_product FOREIGN KEY (prod_id) REFERENCES product(prodId)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS conversation (
|
||||||
|
id BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
customerId BIGINT NOT NULL,
|
||||||
|
staffId BIGINT NULL,
|
||||||
|
status VARCHAR(20) NOT NULL DEFAULT 'OPEN',
|
||||||
|
mode VARCHAR(20) NOT NULL DEFAULT 'AUTOMATED',
|
||||||
|
humanRequestedAt TIMESTAMP NULL,
|
||||||
|
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||||
|
CONSTRAINT fk_conversation_customer FOREIGN KEY (customerId) REFERENCES users(id),
|
||||||
|
CONSTRAINT fk_conversation_staff FOREIGN KEY (staffId) REFERENCES users(id) ON DELETE SET NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS message (
|
||||||
|
id BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
conversationId BIGINT NOT NULL,
|
||||||
|
senderId BIGINT NOT NULL,
|
||||||
|
content TEXT NULL,
|
||||||
|
attachmentUrl VARCHAR(255) NULL,
|
||||||
|
attachmentName VARCHAR(255) NULL,
|
||||||
|
attachmentMimeType VARCHAR(100) NULL,
|
||||||
|
attachmentSizeBytes BIGINT NULL,
|
||||||
|
timestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
isRead BOOLEAN NOT NULL DEFAULT FALSE,
|
||||||
|
CONSTRAINT fk_message_conversation FOREIGN KEY (conversationId) REFERENCES conversation(id) ON DELETE CASCADE,
|
||||||
|
CONSTRAINT fk_message_sender FOREIGN KEY (senderId) REFERENCES users(id)
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE TABLE IF NOT EXISTS activityLog (
|
||||||
|
logId BIGINT AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
userId BIGINT NOT NULL,
|
||||||
|
storeId BIGINT NULL,
|
||||||
|
activity TEXT NOT NULL,
|
||||||
|
logTimestamp TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||||
|
CONSTRAINT fk_activity_log_user FOREIGN KEY (userId) REFERENCES users(id),
|
||||||
|
CONSTRAINT fk_activity_log_store FOREIGN KEY (storeId) REFERENCES storeLocation(storeId) ON DELETE SET NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX idx_users_primary_store ON users(primaryStoreId);
|
||||||
|
CREATE INDEX idx_users_role ON users(role);
|
||||||
|
CREATE INDEX idx_users_name ON users(lastName, firstName);
|
||||||
|
CREATE INDEX idx_service_species_species ON service_species(species);
|
||||||
|
CREATE INDEX idx_inventory_store ON inventory(storeId);
|
||||||
|
CREATE INDEX idx_inventory_product ON inventory(prodId);
|
||||||
|
CREATE INDEX idx_purchase_order_store ON purchaseOrder(storeId);
|
||||||
|
CREATE INDEX idx_pet_owner_user ON pet(ownerUserId);
|
||||||
|
CREATE INDEX idx_pet_store ON pet(storeId);
|
||||||
|
CREATE INDEX idx_pet_species ON pet(petSpecies);
|
||||||
|
CREATE INDEX idx_pet_name ON pet(petName);
|
||||||
|
CREATE INDEX idx_appointment_store ON appointment(storeId);
|
||||||
|
CREATE INDEX idx_appointment_employee ON appointment(employeeId);
|
||||||
|
CREATE INDEX idx_appointment_customer ON appointment(customerId);
|
||||||
|
CREATE INDEX idx_appointment_pet ON appointment(petId);
|
||||||
|
CREATE INDEX idx_appointment_date_status ON appointment(appointmentDate, appointmentStatus);
|
||||||
|
CREATE INDEX idx_adoption_store ON adoption(sourceStoreId);
|
||||||
|
CREATE INDEX idx_adoption_employee ON adoption(employeeId);
|
||||||
|
CREATE INDEX idx_sale_store ON sale(storeId);
|
||||||
|
CREATE INDEX idx_sale_employee ON sale(employeeId);
|
||||||
|
CREATE INDEX idx_sale_customer ON sale(customerId);
|
||||||
|
CREATE INDEX idx_sale_date ON sale(saleDate);
|
||||||
|
CREATE INDEX idx_cart_user ON cart(userId);
|
||||||
|
CREATE INDEX idx_conversation_customer ON conversation(customerId);
|
||||||
|
CREATE INDEX idx_conversation_staff ON conversation(staffId);
|
||||||
|
CREATE INDEX idx_activity_log_store ON activityLog(storeId);
|
||||||
1861
backend/src/main/resources/dev/final-target/final_target_seed.sql
Normal file
1861
backend/src/main/resources/dev/final-target/final_target_seed.sql
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user