DocHub
Custom course purchase records with email-based link tokens for course generation access

custom_course_purchases

What It Stores

Tracks purchases of custom (AI-generated) courses. The key feature is the link_token — a UUID sent via email that lets users access the course generation form without being logged into the app.

When Rows Are Created

Inserted by validate_purchase or admin tools when a custom course purchase is validated.

Columns

Column Type Required Default Description
id uuid Yes auto-generated Purchase record ID.
course_id uuid Yes Links to custom_courses.id.
purchase_id text Yes Store purchase/order ID.
purchase_token text Yes Store purchase token for validation.
source text Yes Purchase source (google_play, app_store).
link_token text Yes UUID token sent via email. User clicks this link to access the course generation form. Expires after 24 hours.
is_submitted boolean No false Has the user already submitted their course generation request? Prevents double submission.
status text No Purchase status: active, etc.
created_at timestamptz No now() Purchase time.
updated_at timestamptz No now() Last update.
  1. User purchases a custom course
  2. System generates a UUID link_token and emails it
  3. User clicks link → redirect-custom-course validates the token
  4. User fills in their preferences → submit-custom-course processes them
  5. is_submitted is set to true so the link can’t be reused

Key Relationships

  • custom_coursescourse_id links to the parent custom course

Who Can Access

Own rows only — authenticated users can SELECT if they own the linked custom_courses record.

Used By These Edge Functions

  • submit-custom-course — validates link token, marks as submitted
  • redirect-custom-course — validates token for deep link redirect
  • verify_gen_link — checks token validity and expiration
  • manage-regen-requests — manages regeneration for submitted purchases