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.
-- 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
);
Row level policy for habits table:
(auth.uid() = user_id)