-- Add unique constraint for ON CONFLICT to work in CreateDevice query
ALTER TABLE devices
    ADD CONSTRAINT devices_user_id_device_token_uniq UNIQUE (user_id, device_token);

-- Add foreign key to users table for data integrity and cascade deletion
ALTER TABLE devices
    ADD CONSTRAINT devices_user_fk
    FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE;
