Create a Supabase project

Jon Meyers
InstructorJon Meyers
Share this video with your friends

Social Share Links

Send Tweet
Published 2 years ago
Updated 2 years ago

Supabase is a suite of open-source tools wrapping a PostgreSQL database. It provides the building blocks of an app - database hosting, auth, file storage, realtime and edge functions - so we can focus on the thing that makes our app unique.

In this video, we sign up for a free Supabase account, create a basic schema for a blog, and populate it with test data.

Code Snippets

Create the table

create table if not exists articles (
  id uuid default uuid_generate_v4() primary key,
  created_at timestamp with time zone default timezone('utc'::text, now()) not null,
  title text not null,
  content text not null,
  is_published bool default false not null
);

Insert test data

insert into articles(title, content)
values
	('First blog', 'This is my very first blog'),
	('Second blog', 'I am really enjoying writing blogs'),
	('Third blog', 'Okay, this is getting hard to maintain');

Resources

Jon Meyers: [0:00] Head over to app.supabase.com to create a new project. If this is your first time using Supabase, you'll need to authenticate with GitHub to create an account and now we can create a new project. I'm going to create this in my Examples Organization. We need to give it a name, so I'm going to call mine Supabase at the Edge. [0:16] We now need a database password so I'm going to let Supabase generate a secure one for me and then I need to make sure that I copy this as it's the only time you'll be able to read this value. We need to select a region where our origin database is going to live. I'm going to select Sydney because it's geographically closest to my location, and now Create a new project.

[0:34] This will take a few minutes to create our project but once that's finished, we can come over to the Table Editor and click New table. The name of our table is going to be articles and then for our columns we have an id column here. We're going to change the type of this to be uuid.

[0:50] Then, if we click these three dots under Default Value, we want to call this uuid_generate_v4() function to automatically create an id for us.

[0:58] We then have our created_at timestamp which defaults to whenever we create a new row. If we click this little cog, we can see extra options and we want to untick Is Nullable because we should always have a created_at date.

[1:10] Now, we want to add a new column for our title which is going to be of type text. We also don't want this one to ever be null. We want a new column for content which will also be of type text. Again, it doesn't make sense for us to have an article without content, so we don't want that one to be nullable.

[1:29] Lastly, we want an is_published column, which is going to be of type bool. We want the default value for this to be false. Every time we create a new article, by default it is not yet published. Again, we want this to be not nullable.

[1:42] Let's click Save to create our table and those columns. If we come over to the SQL Editor and create a New query, we can paste in this block of SQL that you can find in the description for this video, which is inserting some new values into our articles table, where we're specifying title and content because the other columns are auto-generated.

[2:02] We're creating rows for our First, Second, and Third blog, and we can click RUN to execute this SQL. If we go back to the Table editor and click on our articles table, we can see our three articles have been inserted into our database.

~ a year ago

If you can't fetch data from new database in supabase or get an empty array like me. You need to set policy for your table by this SQL (you can run this in your supabase profile)

create policy "Public profiles are viewable by everyone."
on profiles for select
to authenticated, anon
using (
  true
);
~ a year ago

Instead of "profiles" in above SQL, you should paste your table name!

Jon Meyers
Jon Meyersinstructor
~ a year ago

Thanks for calling this one out 👍 We touch on RLS in this one and then go a little deeper here

Markdown supported.
Become a member to join the discussionEnroll Today