Skip to content

Instantly share code, notes, and snippets.

@thedevdavid
Created July 26, 2023 09:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thedevdavid/940139aa8fb92a933a3135c77f6a689c to your computer and use it in GitHub Desktop.
Save thedevdavid/940139aa8fb92a933a3135c77f6a689c to your computer and use it in GitHub Desktop.
WWC Supabase DB Gen

Prompt:

Create a database. Create a habits table with an id, a habit name, an isCompletedToday flag, a userID foreign key relation, a color property, and a start_date. Create another table called users with userID, email. I need a third table for logging habit completions. Related to a habit ID, a completion date.

SQL:

-- Create a users table
create table users (
  user_id uuid primary key default uuid_generate_v4(),
  email text
);

-- Create a habits table
create table habits (
  id integer primary key generated always as identity,
  habit_name text,
  is_completed_today boolean,
  user_id uuid references users(user_id),
  color text,
  start_date date
);

-- Create a habit completions table
create table habit_completions (
  id integer primary key generated always as identity,
  habit_id integer references habits(id),
  completion_date date
);
@thedevdavid
Copy link
Author

Row level policy for habits table: (auth.uid() = user_id)

@thedevdavid
Copy link
Author

Flutterflow AIGen prompt:

habit dashboard page containing an appbar with title "dashboard", a floating action button with a plus icon and text "add habit", and a listview with list items containing a habit's name, description

@thedevdavid
Copy link
Author

Color1: #2B825B

@thedevdavid
Copy link
Author

Color2: #4D39F8

@thedevdavid
Copy link
Author

Here's the clonable project if you want to use it as a starting point or if you forgot to bring your laptop or anything.

Here, are some additional Row Level Security policies to make it just a bit more secure:

users table

code: (auth.uid() = user_id)
image

habits table

code:

(
  auth.uid () = (
    SELECT
      habits.user_id
    FROM
      habits
    WHERE
      (habits.id = habit_completions.habit_id)
  )
)

image

@thedevdavid
Copy link
Author

NOTE: the example Flutterflow project WILL NOT run because I've changed the Supabase credentials. Don't forget to update with your credentials after cloning.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment