Constraints

46 Foreign Key Constraints

Constraint Name Child Column Parent Column Delete Rule
email_verification_codes_user_id_fkey
email_verification_codes.user_id
users.id
Cascade on delete
draw_results_box_id_fkey
draw_results.box_id
boxes.id
Cascade on delete
draw_results_performed_by_fkey
draw_results.performed_by
users.id
Null on delete
draw_pairs_draw_id_fkey
draw_pairs.draw_id
draw_results.id
Cascade on delete
draw_pairs_giver_participant_id_fkey
draw_pairs.giver_participant_id
box_participants.id
Cascade on delete
draw_pairs_receiver_participant_id_fkey
draw_pairs.receiver_participant_id
box_participants.id
Cascade on delete
team_members_user_id_fkey
team_members.user_id
users.id
Cascade on delete
team_members_team_id_fkey
team_members.team_id
teams.id
Cascade on delete
chat_rooms_participant2_id_fkey
chat_rooms.participant2_id
box_participants.id
Cascade on delete
chat_rooms_box_id_fkey
chat_rooms.box_id
boxes.id
Cascade on delete
chat_rooms_draw_id_fkey
chat_rooms.draw_id
draw_results.id
Cascade on delete
chat_rooms_participant1_id_fkey
chat_rooms.participant1_id
box_participants.id
Cascade on delete
team_invite_tokens_team_id_fkey
team_invite_tokens.team_id
teams.id
Cascade on delete
team_invite_tokens_invited_by_fkey
team_invite_tokens.invited_by
users.id
Cascade on delete
participant_exclusions_to_participant_id_fkey
participant_exclusions.to_participant_id
box_participants.id
Cascade on delete
participant_exclusions_from_participant_id_fkey
participant_exclusions.from_participant_id
box_participants.id
Cascade on delete
ownership_transfer_requests_from_user_id_fkey
ownership_transfer_requests.from_user_id
users.id
Cascade on delete
ownership_transfer_requests_to_user_id_fkey
ownership_transfer_requests.to_user_id
users.id
Cascade on delete
ownership_transfer_requests_team_id_fkey
ownership_transfer_requests.team_id
teams.id
Cascade on delete
votes_voter_id_fkey
votes.voter_id
users.id
Cascade on delete
votes_delivery_id_fkey
votes.delivery_id
deliveries.id
Cascade on delete
team_invites_created_by_fkey
team_invites.created_by
users.id
Cascade on delete
team_invites_team_id_fkey
team_invites.team_id
teams.id
Cascade on delete
anonymous_hints_wishlist_item_id_fkey
anonymous_hints.wishlist_item_id
wishlist_items.id
Cascade on delete
anonymous_hints_receiver_id_fkey
anonymous_hints.receiver_id
users.id
Cascade on delete
anonymous_hints_sender_id_fkey
anonymous_hints.sender_id
users.id
Cascade on delete
teams_owner_id_fkey
teams.owner_id
users.id
Restrict delete
notifications_user_id_fkey
notifications.user_id
users.id
Cascade on delete
refresh_tokens_user_id_fkey
refresh_tokens.user_id
users.id
Cascade on delete
boxes_team_id_fkey
boxes.team_id
teams.id
Cascade on delete
friendships_user_id_1_fkey
friendships.user_id_1
users.id
Cascade on delete
friendships_requester_id_fkey
friendships.requester_id
users.id
Restrict delete
friendships_user_id_2_fkey
friendships.user_id_2
users.id
Cascade on delete
dictionary_item_dictionary_id_fkey
dictionary_item.dictionary_id
dictionary.id
Cascade on delete
dictionary_item_parent_id_fkey
dictionary_item.parent_id
dictionary_item.id
Cascade on delete
wishlists_box_id_fkey
wishlists.box_id
boxes.id
Cascade on delete
wishlists_participant_id_fkey
wishlists.participant_id
box_participants.id
Cascade on delete
wishlist_items_wishlist_id_fkey
wishlist_items.wishlist_id
wishlists.id
Cascade on delete
email_2fa_codes_user_id_fkey
email_2fa_codes.user_id
users.id
Cascade on delete
deliveries_giver_participant_id_fkey
deliveries.giver_participant_id
box_participants.id
Cascade on delete
deliveries_box_id_fkey
deliveries.box_id
boxes.id
Cascade on delete
deliveries_receiver_participant_id_fkey
deliveries.receiver_participant_id
box_participants.id
Cascade on delete
box_participants_user_id_fkey
box_participants.user_id
users.id
Cascade on delete
box_participants_box_id_fkey
box_participants.box_id
boxes.id
Cascade on delete
user_consents_user_id_fkey
user_consents.user_id
users.id
Cascade on delete
password_reset_codes_user_id_fkey
password_reset_codes.user_id
users.id
Cascade on delete

Check Constraints

Table Constraint Name Constraint
email_verification_codes chk_verification_codes_expires (expires_at > created_at)
email_verification_codes chk_verification_codes_format ((code)::text ~ '^[0-9]{6}$'::text)
draw_results chk_draw_results_date (draw_date <= now())
draw_pairs chk_draw_pairs_different_participants (giver_participant_id <> receiver_participant_id)
team_members chk_team_members_different (team_id <> user_id)
chat_rooms chk_chat_participants_different (participant1_id <> participant2_id)
chat_rooms chk_chat_participants_order (participant1_id < participant2_id)
participant_exclusions chk_exclusions_different_participants (from_participant_id <> to_participant_id)
ownership_transfer_requests chk_ownership_transfer_expires (expires_at > created_at)
ownership_transfer_requests chk_ownership_transfer_status ((status)::text = ANY ((ARRAY['pending'::character varying, 'accepted'::character varying, 'declined'::character varying, 'expired'::character varying, 'cancelled'::character varying])::text[]))
votes chk_votes_type (vote_type = ANY (ARRAY['like'::text, 'super'::text, 'favorite'::text]))
team_invites chk_team_invites_expires (expires_at > created_at)
team_invites chk_team_invites_status ((status)::text = ANY ((ARRAY['pending'::character varying, 'accepted'::character varying, 'expired'::character varying, 'revoked'::character varying])::text[]))
teams chk_teams_invite_code_length (char_length(invite_code) >= 32)
teams chk_teams_name_length ((char_length(name) >= 2) AND (char_length(name) <= 200))
dictionary chk_dictionary_code_format (code ~ '^[a-z][a-z0-9_]*$'::text)
notifications chk_notifications_type ((type)::text = ANY ((ARRAY['email'::character varying, 'draw_result'::character varying, 'invite'::character varying, 'message'::character varying, 'gift_sent'::character varying, 'gift_received'::character varying, 'vote'::character varying])::text[]))
refresh_tokens chk_refresh_tokens_expires (expires_at > now())
boxes chk_boxes_budget ((budget_min IS NULL) OR (budget_max IS NULL) OR (budget_min <= budget_max))
boxes chk_boxes_budget_positive ((budget_min IS NULL) OR (budget_min >= (0)::numeric))
boxes chk_boxes_dates ((draw_date IS NULL) OR (start_date IS NULL) OR (draw_date >= start_date))
boxes chk_boxes_delivery_deadline ((delivery_deadline IS NULL) OR (draw_date IS NULL) OR (delivery_deadline >= draw_date))
boxes chk_boxes_max_items ((max_wishlist_items > 0) AND (max_wishlist_items <= 100))
boxes chk_boxes_name_length ((char_length(name) >= 2) AND (char_length(name) <= 200))
dictionary_item chk_dictionary_item_code_format (code ~ '^[a-z][a-z0-9_]*$'::text)
wishlist_items chk_wishlist_items_name_length ((char_length(name) >= 1) AND (char_length(name) <= 500))
wishlist_items chk_wishlist_items_price ((price IS NULL) OR (price >= (0)::numeric))
wishlist_items chk_wishlist_items_priority ((priority >= '-100'::integer) AND (priority <= 100))
email_2fa_codes chk_email_2fa_codes_expires (expires_at > created_at)
email_2fa_codes chk_email_2fa_codes_format ((code)::text ~ '^[0-9a-f]{6}$'::text)
deliveries chk_deliveries_dates ((shipped_at IS NULL) OR (delivered_at IS NULL) OR (delivered_at >= shipped_at))
deliveries chk_deliveries_different_participants (giver_participant_id <> receiver_participant_id)
deliveries chk_deliveries_tracking_format ((tracking_number IS NULL) OR ((char_length(tracking_number) >= 5) AND (char_length(tracking_number) <= 100)))
users chk_users_email_format (email ~* '^[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}$'::text)
users chk_users_phone_format ((phone IS NULL) OR (phone ~ '^\+?[0-9\s\-\(\)]+$'::text))
password_reset_codes chk_password_reset_codes_expires (expires_at > created_at)
password_reset_codes chk_password_reset_codes_format ((code)::text ~ '^[0-9a-f]{6}$'::text)