Pet owner and store
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
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';
|
||||
Reference in New Issue
Block a user