Now that your Supabase project is up and running, it's time to build the foundation of your application: your database tables. Think of tables as organized collections of data, much like spreadsheets. Each row in a table represents a single record, and each column represents a specific piece of information about that record.
We'll start by creating a simple 'todos' table to store our to-do items. This table will have a few columns to keep track of each to-do.
Navigate to the 'Table editor' section in your Supabase project dashboard. You'll see a '+' button to create a new table. Click it!
You'll be presented with an interface to define your table schema. Let's add the following columns:
- id: This will be our primary key, a unique identifier for each to-do. We'll set it to be a UUID (Universally Unique Identifier) and auto-generate it. This ensures every to-do has a unique ID. For 'name', enter 'id'. For 'type', select 'UUID'. Under 'Default value', choose 'gen_random_uuid()'. Under 'Primary Key', check the box.
- task: This column will store the actual text of the to-do item. For 'name', enter 'task'. For 'type', select 'TEXT'. Check the 'Not Null' box, as every to-do should have a task description.
- is_complete: This will be a boolean (true/false) value indicating whether the to-do item has been completed. For 'name', enter 'is_complete'. For 'type', select 'BOOLEAN'. Set the 'Default value' to 'false', as new to-dos are not complete by default.
- created_at: This timestamp will record when the to-do item was created. For 'name', enter 'created_at'. For 'type', select 'TIMESTAMPTZ' (Timestamp with Time Zone). Under 'Default value', choose 'now()'. This will automatically populate the creation time.
Once you've defined these columns, give your table a name. Let's call it 'todos'. Click the 'Save' button.