From the course: Supabase Essential Training

Table columns

- [Instructor] Supabase provides a helpful dashboard for creating and modifying your Postgres database. Let's use this dashboard to create a table now. In Postgres databases you have access to several schemas. The one Supabase provides for the tables you define is called public. Any table you add to this schema becomes a part of the API that is automatically generated for your project. So since we're already in the public schema, I'm going to go ahead and click create new table, and then I'm going to start creating this table. This is going to be one that we use to track customers. So I'm going to name it customers. You can leave the description blank. And then there are a couple of settings. One is for row level security. I'm going to leave that enabled as it's recommended. And then there's also one for realtime. I'm going to leave this one unselected for now. The first column we have here is an ID field. By default, Supabase selects a big int type, otherwise known as int8 for the primary key. I prefer UUIDs. So I'm going to change this type to UUID, and tell you a little bit about UUIDs here. They are strings of a preset length with numbers, letters, and dashes. And I prefer these instead of sequential numbers because they're guaranteed to be unique across the database, the server and the world. It helps me prevent accidents. For instance, there have been times when I've had record number 12 in table A and then record number 12 in table B, And there have been times when I've confused this ID and wondered is this the 12 that goes to table A or table B? And then before you realize it, you've made some assumptions based on incorrect data. So this way, instead of using numbers a UUID makes it very easy to visually distinguish between the two. Next, there's this created at field. Supabase automatically adds this by default, and this is going to keep track of when the record is being created. Using a created at field like this is a great pattern because you can go back and debug to understand when a record was created. And now for this customer's table, I'm going to add one column and that column is going to be named name. And then I need to choose a type. For this name type, I'm going to select text, and that will allow us to track a customer. I'm also going to click here on the extra options, and I'm going to unselect is nullable. I want to require this field for every row. And now I'm going to click save. So now we have this customers table with an ID, created at, and name. Let's create another table. So here we're still in this public schema. I'm going to click new table, and I'm going to name this one items. I'm going to accept the same defaults, and then I'm also going to change the ID to UUID again. And this time I'm going to add two columns. One is going to be named name as well, and that's going to be a text field. And for this one, I'm also going to add a price cents. Whenever I deal with money, I always switch to an integer type, and this allows me to work with the data and avoid issues with floating point numbers. And then finally, I'm going to make both of these required. So I'm going to go to the options and deselect is knowable. And then finally I'm going to click save. And now we have a table with ID, created at, name and price cents for items. There are now two tables in this Postgres database's public schema, and these tables are now available in the API.

Contents