Supa-Fast API(Supabase FastAPI): Setting up Database and Storage
Tags: database, sideprojects, tutorial
Published: 2022-01-07 18:58:42

>This tutorial is the First of a Three part series on Building a FastAPI with Supabase as the backend and Deploying it on deta.sh


***
**Supabase is an Open Source  Firebase Alternative**


In this tutorial, we will be setting up **_Supabase_** from scratch and there are going to be a **ton of screenshots** for reference ahead, so brace yourselves!!!

  

  
![Few ways you can use Print Screen Button](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/phjiqdhgncckxo149yhi.png)
 
 

---


## Getting Started with Supabase


  

Jump on to [Supabase](https://supabase.com/) ,click on Start your project and login with GitHub

  
![Supabase - Start your Project](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yz6pfy75jul7v1ryq2un.png)
 
![Supabase - Login with GitHub](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5gk6uis47s89fdgry20x.png)
 
Start a `New Project` and an empty database will be available for you to start adding tables.

  
![Create a New project](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2yjz178jjtabhtoaxuv5.png)
 
![Using Database and Storage Functionality](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ej7yojur5ajrwh3tuzrn.png)

> We will be using the **Database** and **Storage** functionality for this API as highlighted above and we'll start by adding a couple of tables in the Database.

Setting Up Database
-------------------

  

  

For reference ahead, we will be making the following relationship between our tables.

![database Mockup](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7739zcdz8wgx7lqrjkr4.png)
 
This mockup is made in [drawsql](https://drawsql.app/none-390/diagrams/supafast-api).





### themes Table
![Create a New table](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fp866fgo2apfsv4fif2r.png)
 
 

Start by creating a new table...

  

Here, in table named themes, we have enabled the _is Unique_ flag in the `monsterTheme` as we have to use the `monsterTheme` as a FOREIGN KEY in the `monsters` table as shown in the mockup above.

  

  




![Set the IsUnique as true](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/5rrvp3wmpeic2c8wah1x.png)
 
![Add New rows to themes table](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qpjmpka95fxym5x0vry9.png)
 

After inserting a few rows of Dummy/Demo data in the table `themes` like we did above, we can see a similar table in the Database.

  
![themes table overview](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/wbprc0cx7gs5rjlqt47v.png)
  

* * *

  

### monsters Table

![Using FOREIGN KEY in monsters table](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/7cun6bgd104eo60117oq.png)
   
A `FOREIGN KEY` can be added on the database by clicking on the link button which will open up the choices for the table and it's underlying columns.

  

We have the `themes` as the desired table and `monsterTheme` as the column which will act a `FOREIGN KEY` in the table `monsters` .
![Selecting the table and column for the Foreign Key](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/kq26b6nwr3565q1se12w.png)
 

  

Similar to themes, we will insert some Dummy data into the `monsters` table.

![Add New Row to monsters table](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/hkmxa253ubsbc9js2ll3.png)
   
 
![Monsters table Overview](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/9onmnkyg9qhhg85n6t13.png)
 


  

With the Databases set up with some initial dummy data, we can finally move on to the Supabase Storage.

  

Setting up Storage
------------------

  

Supabase Storage has 3 important keywords

*   **Files** : Any sort of media file
*   **Folder** : A way to organize the files in a more meaningful manner
*   **Bucket** : A Super Folder under which all related folders should be kept

  

  

We'll be creating a new Bucket named **supafast-api** for storing the `theme background` as well as the `monster images` .

  

We'll also be adding a number of Folders to structure these image so that we can retrieve them in the API easily.

  

  

Under Storage in the left menu bar, Create a new _public_ Bucket name `supafast-api.`

![Start with creating a New Bucket](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fqc3uxa20nasiodlo2zm.png)
 


  



  

Create a folder named `themes` and a folder for every theme name.

  

The themes folder contains images for the theme background whereas the theme names contain images for the underlying monsters.

 ![Folder and File structure in the storage bucket](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/drsdp3qxk9j9oyeo4isg.png)
  



And we are done with setting up the **Database** as well as the **Storage** for the database.

  

In the upcoming blogs of this series, we will look at building and deploying an API with [FastAPI](https://fastapi.tiangolo.com/) using the Supabase Client for Python.

***

  

**Below are the links for docs and products if you are more interesed.**

- [Supabase Docs](https://supabase.com/docs)

- Supabase also has an amazing [discord](https://discord.gg/dNgwGxwRRw) community to learn and have fun.

- [drawSql](https://drawsql.app/)

***


The API built in this series is used in the tabsMonster project. Everyone is more than welcome to checkout and contribute in this Open Source Project. 


{% github aUnicornDev/tabsMonster no-readme %}



***

### Thank you for reading this far

![Thank You](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/zje79bzb86jh3kciqbi0.png)