ConfigurationDatabase

Configuration

Supabase Setup

This project uses Supabase for the backend, which handles the database, authentication, etc.

  1. Create a new project in the [Supabase Dashboard].
  2. Go to Project Settings → API → Copy the URL and ANON_KEY
  3. Update the NEXT_PUBLIC_SUPABASE_URL and NEXT_PUBLIC_SUPABASE_ANON_KEY variables in the .env.local file:
.env.local
NEXT_PUBLIC_SUPABASE_URL=
NEXT_PUBLIC_SUPABASE_ANON_KEy=

Supabase Table Setup

To create all the required tables for the project, let’s start creating them using the Supabase SQL Editor:

  1. Go to Supabase DASHBOARDSQL EDITOR
  2. Copy all the SQL commands from the createTables.sql file below.
  3. Paste the copied SQL commands into the SQL Editor.
  4. Execute the SQL commands to create all necessary tables.
  5. Confirm that the tables were successfully created by checking the TABLE EDITOR tab in your Supabase Dashboard.
createTables.sql
CREATE TYPE SubscriptionStatusEnums AS ENUM ('ACTIVE', 'EXPIRED', 'NOT_PURCHASED');
CREATE TYPE FreeTrialStatusEnums AS ENUM ('ACTIVE', 'EXPIRED', 'NOT_STARTED');
CREATE TYPE SubscriptionTierEnums AS ENUM ('TIER_ZERO', 'TIER_ONE', 'TIER_TWO');
createTables.sql
CREATE TABLE users (
    id UUID PRIMARY KEY UNIQUE DEFAULT gen_random_uuid(),
    email TEXT,
    full_name TEXT,
    user_id UUID UNIQUE,
    created_at TIMESTAMPTZ,
    updated_at TIMESTAMPTZ
);
createTables.sql
CREATE TABLE products (
    id UUID PRIMARY KEY UNIQUE DEFAULT gen_random_uuid(),
    name TEXT,
    description TEXT,
    previous_price FLOAT8,
    current_price FLOAT8,
    stripe_price_id TEXT UNIQUE,
    is_highlighted BOOLEAN,
    is_active BOOLEAN,
    features JSONB,
    subscription_tier SubscriptionTierEnums,
    is_preorder BOOLEAN,
    created_at TIMESTAMPTZ,
    updated_at TIMESTAMPTZ
);
createTables.sql
CREATE TABLE free_trials (
    id UUID PRIMARY KEY UNIQUE DEFAULT gen_random_uuid(),
    start_date TIMESTAMPTZ,
    end_date TIMESTAMPTZ,
    stripe_price_id TEXT REFERENCES public.products(stripe_price_id) ON DELETE CASCADE,
    user_id UNIQUE UUID REFERENCES public.users(user_id) ON DELETE CASCADE,
    status FreeTrialStatusEnums
);
createTables.sql
CREATE TABLE purchased_subscriptions (
    id UUID PRIMARY KEY UNIQUE DEFAULT gen_random_uuid(),
    stripe_price_id TEXT REFERENCES public.products(stripe_price_id) ON DELETE CASCADE,
    user_id UNIQUE UUID REFERENCES public.users(user_id) ON DELETE CASCADE,
    status SubscriptionStatusEnums,
    subscription_tier SubscriptionTierEnums,
    created_at TIMESTAMPTZ,
    updated_at TIMESTAMPTZ
);

Here is the JSON data structure of the features column from the Products table:

[
    {
        "name": "Feature",
        "included": true
    },
    {
        "name": "Feature-02",
        "included": true
    },
    {
        "name": "Feature-03",
        "included": false
    },
    {
        "name": "Feature-04",
        "included": false
    },
    {
        "name": "Feature-05",
        "included": false
    }
]