mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2026-02-17 19:31:10 +00:00
1.add appointment feature; 2.add new api for creation,query and cancel. 3.add new table for appointment.
23 lines
No EOL
1 KiB
SQL
23 lines
No EOL
1 KiB
SQL
-- Create appointments table
|
|
CREATE TABLE appointments (
|
|
id INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
|
|
pet_id INTEGER NOT NULL,
|
|
owner_id INTEGER NOT NULL,
|
|
start_time TIMESTAMP NOT NULL,
|
|
end_time TIMESTAMP NOT NULL,
|
|
status VARCHAR(20) NOT NULL,
|
|
created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
|
version INTEGER DEFAULT 0
|
|
);
|
|
|
|
-- Add foreign key constraints
|
|
ALTER TABLE appointments ADD CONSTRAINT fk_appointments_pets FOREIGN KEY (pet_id) REFERENCES pets (id);
|
|
ALTER TABLE appointments ADD CONSTRAINT fk_appointments_owners FOREIGN KEY (owner_id) REFERENCES owners (id);
|
|
|
|
-- Create indexes for performance
|
|
CREATE INDEX appointments_pet_id ON appointments (pet_id);
|
|
CREATE INDEX appointments_start_time ON appointments (start_time);
|
|
CREATE INDEX appointments_pet_time_range ON appointments (pet_id, start_time, end_time);
|
|
|
|
-- Add check constraint to ensure end_time is after start_time
|
|
ALTER TABLE appointments ADD CONSTRAINT chk_appointment_time_order CHECK (end_time > start_time); |