Planning schemas and contexts for a content site

This episode is an overview and planning session for a Phoenix CMS series:

  • Series Overview - Planning
  • Part 1 - Setting up schemas, contexts and ecto relations
  • Part 2 - Editing multiple tags at once as a list
  • Part 3 - Listing mixed forms of content together for topics
  • Part 4 - Setting up meta tags for SEO
  • Part 5 - Making content-specific markdown extensions
  • Part 6 - Using ETS to cache information and speed up the site

No coding this episode.

Instead we go through planning our schemas and contexts for a new Phoenix 1.3 site. As fun as it was making a minimal clone of the Phoenix Framework starting from a Cowboy Server, we need to move faster. Alchemist camp will be adding , and how to divide those schemas into Phoenix 1.3 contexts.

Controllers

  • user
  • auth (later moved into a Plugs directory)
  • session
  • page
  • episode
  • article
  • resource
  • topic

Schemas

  • user
    • name
    • username
    • referred_by
    • [lessons_viewed]
    • [subscription_plans]
    • is_admin
  • credentials
    • email
    • password_hash
    • user_id
    • stripe_id
    • growsurf_id
  • subscription_plan (obsoleted by Stripe Billing)
    • plan_id (generated by Stripe): string
    • name
    • amount: integer (in cents)
    • created
    • currency
    • interval (day|week|month|year)
    • interval_count
    • live_mode
    • metadata
    • statement_descriptor
    • trial_period_days
  • growsurf_contact
    • rank: int
    • id: string
    • fullName: string
    • winner: bool
    • referralCount: int
  • growsurf_contact_created_cb
    • campaign: growsurf_campaign
    • contact: growsurf_contact (just created one)
    • contacts: [growsurf_contact] (all)
  • entities
    • published
    • requires_login
    • is_premium
    • view_count
  • entity_plan (plans that grant access to entity)
    • entity_id
    • plan_id
  • entity_likes
    • entity_id
    • user_id
  • articles
    • title
    • slug
    • content
    • entity_id
  • episodes
    • title
    • slug
    • content
    • seconds_long
    • video_url
    • entity_id
  • resource_pages
    • name
    • slug
    • content
    • resource_url
    • entity_id
  • topics
    • text
  • entity_topics
    • topic_id
    • entity_id
  • pages (mostly default)
  • event
    • (id only)
  • view_event
    • href
    • user_id
    • user_agent
  • subscribe_event (internal)
    • user_id
    • plan_id
  • unsubscribe_event (internal)
    • user_id
    • plan_id
  • referral_event
    • referring_user_id
    • referred_user_id
    • meta
  • share_event
    • user_id
    • current_page
    • meta

As of the time of this writing, most of the above is implemented, except for various events, which are recorded only via logging and sending data to Keen. The main thing that was confusing for people, including myself, moving to Phoenix 1.3, was how to break apps up into contexts. That's really the focus of this episode. In the end, I went with this separation:

contexts

  • accounts
    • credential
    • user
  • affiliate
    • growsurf_campaign
    • growsurf_contact
  • analytics
    • event
  • billing
    • subscription_plan
  • content
    • article
    • entity
    • entity_like
    • entity_topic
    • episode
    • resource
    • topic

Hopefully this episode is useful! If you're looking for text-based resources, I suggest Shankar Devy's mini-book, Blueprint for Phoenix Context. I've since reached out to him and made an affiliate arrangement with him so if you use this link, you'll get the same price, and help support Alchemist Camp in the process.

Back to index

No Comments