Create a Supabase Project with a Table and Example Data

Jon Meyers
InstructorJon Meyers
Share this video with your friends

Social Share Links

Send Tweet
Published 2 years ago
Updated 2 years ago

Supabase handles hosting a database, authentication, authorization, file storage, realtime, edge functions, database functions, triggers and webhooks - lots of ways to build apps and automate backend stuff.

In this lesson, we head over to database.new to create a new Supabase project. Additionally, we use the dashboard to easily create a new table for our messages. We talk through some different data types and constraints that can be applied to columns. Lastly, we populate our new table with some example messages.

Code Snippets

SQL code snippets can be run against your Supabase database by heading over to your project's SQL Editor, pasting them into a new query, and clicking RUN.

Create a messages table

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

Insert messages

insert into messages(content)
values
  ('first message'),
  ('second message');

Resources

Instructor: [0:00] Head over to database.new to create a new Supabase project. You may need to authenticate with GitHub if this is your first time using Supabase. I'm going to name my project Chatter and click this button to generate a secure password. [0:14] Make sure you click to copy this password to somewhere secure as this is the database password for your Postgres instance and the only time you'll see it. For region, I'm going to select Oceania Sydney as that is the closest region to me and then click create new project.

[0:30] Now, this will take a little bit of time to set up a new Supabase project. Now that we're up and running, I'm going to come across to the table editor and click new table. The name for our table is going to be messages. We're going to leave low-level security enabled and also leave real time disabled.

[0:47] For our columns, we want to change the data type of our ID to be UUID. And then click these three little dots for the default value and say we want to call this function to generate a new version for UUID any time we create a new row on this table.

[1:03] Now, since created that default value is now which will give us back a timestamp for the moment when we're creating this new row, it doesn't really make sense for this row to ever be . If we click this little cog, we can see some more options for our column and we can untick is nullable as this will always have a value.

[1:20] Now, we want to add a new column. The name of this column is going to be content. This will be the actual content that the user types in for each message, therefore, we want the type of this to be text. We don't want this to have a default value, but we also probably don't want this to be nullable as it doesn't really make sense for there to be a message with no content.

[1:42] Untick is nullable. Now when we click save, this will create that table along with those different columns. We can now insert some test data by clicking insert row and typing in the content for our first message, and click save to insert this new row into our database, which we can see there.

[2:00] Let's insert a second message and click save. Now, we have a new Supabase project with a table for our messages and two rows of example data.

ed leach
ed leach
~ 2 years ago

Looks very good. Thanks!

Markdown supported.
Become a member to join the discussionEnroll Today