Create a New Supabase Project and Basic PostgreSQL Schema

Jon Meyers
InstructorJon Meyers
Share this video with your friends

Social Share Links

Send Tweet
Published a year ago
Updated a year ago

Supabase is a collection of open source tools that wrap around a PostgreSQL database - Hosting, Auth, Realtime, File Storage, Edge Functions etc. In this lesson, we go to database.new to create a free Supabase project.

Additionally, we create a tweets table and populate it with some seed data.

Code Snippets

Create a tweets table

create table if not exists tweets (
  id uuid default gen_random_uuid() primary key,
  created_at timestamp with time zone default timezone('utc'::text, now()) not null,
  title text not null
);

Insert tweets

insert into tweets(title)
values
  ('first tweet'),
  ('second tweet'),
  ('third tweet');

Resources

Instructor: Head over to database.new to create a new Supabase project. Then I'm going to sign in with GitHub, enter my username and password, and click Sign in. You'll see this has selected my default organization. We're going to be building a Twitter clone. The name of my project is going to be Blue Bird.

I'm going to click this button here to generate a database password. Make sure you copy this value into something like a password manager as this is your database password and the only time you'll be able to read that value. For the region, I'm going to select Sydney as this is closest to my geographical location. You want this region to be close to your users for the best performance.

Everything we'll do in this course will be on the free plan. I'm going to click this button to create my new project. You'll see this will take a little bit of time to set up our project. Once that's finished, we want to come over to the Table Editor to create a new table to store our tweets.

I'm going to leave row level security, or RLS enabled, as this is recommended. For the structure of our table, we've already got an id, but I'm going to change the type of this from int8 to uuid, and then click these three dots to set the default value for this column to be a freshly generated random uuid.

We also have a created_at timestamp which has a default value set to the time that this row was created. Now, if we click this cog, we can see some more options for this column, and we'll see the value for this column can be set to NULL.

Since this timestamp is automatically generated for us and we're going to use it for sorting our tweets, we're always going to want this column to have a value. Let's untick Is Nullable, and then add a new column for the title of our tweet. The type for this one is going to be text. We won't have a default value for this one, but we always want our tweets to have a title.

Let's also untick Is Nullable, and then click Save to create our tweets table. Now we can insert a new row. Again, these two values will be generated for us. We just need a title, which is going to be, first tweet, and then click Save to insert that new row into the tweets table.

I'm going to magically add two more tweets. We can see we have our first, second and third tweet in our Supabase database.

egghead
egghead
~ 4 minutes ago

Member comments are a way for members to communicate, interact, and ask questions about a lesson.

The instructor or someone from the community might respond to your question Here are a few basic guidelines to commenting on egghead.io

Be on-Topic

Comments are for discussing a lesson. If you're having a general issue with the website functionality, please contact us at support@egghead.io.

Avoid meta-discussion

  • This was great!
  • This was horrible!
  • I didn't like this because it didn't match my skill level.
  • +1 It will likely be deleted as spam.

Code Problems?

Should be accompanied by code! Codesandbox or Stackblitz provide a way to share code and discuss it in context

Details and Context

Vague question? Vague answer. Any details and context you can provide will lure more interesting answers!

Markdown supported.
Become a member to join the discussionEnroll Today