Preview:
CREATE TABLE identity_types (
    transaction_id UUID NOT NULL REFERENCES transaction_doctor(id) ON DELETE CASCADE,
    appointment_id UUID NOT NULL REFERENCES appointment(id) ON DELETE CASCADE,
    PRIMARY KEY (transaction_id, appointment_id),
    additional_attribute_1 TEXT NULL,
    additional_attribute_2 TEXT NULL,
    additional_attribute_3 TEXT NULL,
    additional_attribute_4 TEXT NULL,
    additional_attribute_5 TEXT NULL,
    created_at TIMESTAMPTZ NOT NULL DEFAULT NOW(),
    updated_at TIMESTAMPTZ NOT NULL DEFAULT NOW()
);

CREATE OR REPLACE FUNCTION trigger_set_timestamp()
    RETURNS TRIGGER AS $$
BEGIN
    NEW.updated_at = NOW();
    RETURN NEW;
END;
$$ LANGUAGE plpgsql;

CREATE TRIGGER set_timestamp
    BEFORE UPDATE ON identity_types
    FOR EACH ROW
EXECUTE PROCEDURE trigger_set_timestamp();
downloadDownload PNG downloadDownload JPEG downloadDownload SVG

Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!

Click to optimize width for Twitter