Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add revisions table to Events #12

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions Application/Schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,17 @@ CREATE TABLE reservation_jobs (
ALTER TABLE events ADD CONSTRAINT events_ref_venue_id FOREIGN KEY (venue_id) REFERENCES venues (id) ON DELETE NO ACTION;
ALTER TABLE reservation_jobs ADD CONSTRAINT reservation_jobs_ref_reservation_id FOREIGN KEY (reservation_id) REFERENCES reservations (id) ON DELETE CASCADE;
ALTER TABLE reservations ADD CONSTRAINT reservations_ref_event_id FOREIGN KEY (event_id) REFERENCES events (id) ON DELETE NO ACTION;


CREATE TABLE events_revisions ( revision SERIAL NOT NULL) INHERITS (events);

CREATE OR REPLACE FUNCTION table_update() RETURNS TRIGGER AS $table_update$
BEGIN
INSERT INTO events_revisions SELECT NEW.*;
RETURN NEW;
END;
$table_update$ LANGUAGE plpgsql;

CREATE TRIGGER table_update
AFTER INSERT OR UPDATE ON events
FOR EACH ROW EXECUTE PROCEDURE table_update();