This is the multi-page printable view of this section. Click here to print.
Using a Supabase Backend
- 1: Set up of a Deployment using Supabase
- 2: Correspondance of Data Structures between Logiak and Supabase
- 3: How to deploy a new version
- 4: Supabase Replication
- 5: Supabase Storage
- 6: Upload data to Supabase from a Google Sheet
- 7: Limits of the Supabase FREE Tier
- 8: How an end-user signs up to a Logiak App/Supabase Project
1 - Set up of a Deployment using Supabase
Supabase Backend set-up is easy
Setting up a Supabase Project and getting it work with Logiak could hardly be easier.
The Logiak UI supports the set up Step by Step, which involves copying and pasting, and clicking buttons, according to clear instructions, and this is illustrated from beginning to end by the video you will find below.
The only thing the video doesn’t show, which is of course a Precondition of doing an integration, is to get a Supabase Account. For that, it seems currently, you may need a GitHub account.
Supabase Set Up Illustrated
2 - Correspondance of Data Structures between Logiak and Supabase
Logiak Objects and Supabase Tables must align
The decoupling of Logiak and backends gives the user a lot of freedom and 100% control.
Success integration means though that a Logiak Project and a Supabase Project must be aligned when it comes to the definition of data structures.
Basically, to deploy a version of a Logiak Project succesfully, the Supabase Project must have a table corresponding to each Object (excepting State Objects) defined in the Logiak Project.
Objects/Tables tab automates the check
In a Supabase Deployment, there is a tab called Objects/Tables which gives the Logiak Project administrator good support in ensuring this alignment.
Before deploying a version, the administrator should visit this tab, select the Project version to be deployed, and let Logiak
- Query Supabase : find out what tables exist, and what columns they have
- Compare with Objects in the Logiak Project Version
- Show the administrator results of this comparison
- And offers the administrator buttons which will allow mismatches to be corrected in Supabase automatically.
Here is a video showing an example where Supabase contained no Project tables, and the administrator checks version 2 of the Project.
Logiak reports that four tables are missing.
The administrator clicks on a button, and the tables are defined in Supabase, with columns corresponding to Fields in the Logiak objects.
Mapping: Unique field -> Primary Key
Mapping: Relationship -> Foreign key
Type determined by primary key of customer table
Mapping: Date fields -> timestamp columns
Mapping: True/false fields -> bool columns
Mapping: Number and text fields -> numeric and text columns
3 - How to deploy a new version
Versioning is one way of maintaining control of a Project, and can be particularly important if you are working in a Team Space, building a Project with colleagues.
To take a Version is to take a snapshot of the whole project.
Choosing to deploy a new version is a separate step.
How to DEPLOY a new Version
4 - Supabase Replication
What is Replication?
From the Supabase docs: “Replication is a technique for copying the data from one database to another”
How Logiak uses Replication
Logiak has two main uses for Replication -
1. Remote deployment
Logiak supports the remote deployment of new versions of a Project.
To understand what is meant by this, consider:
- you have your users, and they are using a Logiak App you made
- you notice that your App needs some changes. you make the changes and take a new version.
- you deploy the new version
What we mean by “Remote deployment” here is that when you deploy the new version, you would like all devices to get notified, and let the users upgrade. You don’t want to always have to phone everyone, or send an email to everyone. Should be automatic.
Thanks to replication, it is.
- At setup, we create a logiak_version table.
- When you deploy a new version, a new row is created in the logiak_version table
- If Replication is enabled for the logiak_version table, then
- Supabase will automatically send a notification of the change in logiak_version.
- Devices will download the version
- Devices will show an upgrade button
2. Data sharing between devices
The second use Logiak Projects make of Replication is in data sharing between devices.
If Replication is turned on for all tables, not just logiak_version, then any database change on any device will be quickly reflected on all connected devices.
This is important for collaborative systems.
This data sharing is magic, but it is not flawless. A device can lack connectivity when Supabase sends notification of a change and there is not a queue where such notifications are stored for each device until they are back online.
In a database application, where it is important to keep reasonably in sync with the master copy of the data, this can be a big negative.
With Logiak , we have implemented a corrective mechanism at Login:
At Login, if an Object has an auto-fill modified field, if there is connectivity, Logiak will check at the master (Supabase ) for all rows of the corresponding table whose modified date is later than the latest in the database on the device, and retrieve those records.
5 - Supabase Storage
At the set up of a Supabase Deployment, we create a Storage Bucket.
The purpose of this is to hold any media which is created by use of your Project’s App(s).
Within Processes, you can be having users take photos, record videos, record audio.
These can be big files, which are not well stored in a normal database.
Instead, references to them are stored in the database, and the files themselves are uploaded to the Supabase Project’s Storage Bucket.
Free Tier Storage limits
500MB database & 1GB file storage
6 - Upload data to Supabase from a Google Sheet
Starting a Project with existing data
If you are starting a project which already has some associated data, you can incorporate that data into the Project in various ways.
If the data you have is static data - not primary data for the Project which you want to collect and change, but instead some reference / lookup data, then one option is to include it in your Project configuration via a Table Object.
Using Supabase SQL
Alternatively, if you now SQL, you could seed the data into Supabase by making use of the SQL Editor and running queries to insert data.
Using Logiak Upload
Another option is to make use of the Deployment’s Upload tab.
The following are required:
- The data must be in a Google Sheet, with the first row containing column headers/field names/column names
- The table structure must exist in Supabase
- (you can do ensure this automatically from Logiak Object definitions)
7 - Limits of the Supabase FREE Tier
The Supbase FREE plan has limits which you should be aware of.
Probably the most significant limitation of the FREE tier is possible pausing of your server!
This may happen if your project is not queried at least once every 7 days, so if your project is in continual use, you should be ok, but the only way to guarantee this wont happen is by upgrading.
The default rate limit for auth emails provided by Supabase is 30 new users per hour.
You may want to consider using your own mail credentials.
Up to 500MB database & 1GB file storage
8 - How an end-user signs up to a Logiak App/Supabase Project
End user accounts are those listed in the Supabase project
Without any special configuration, all end users in the Supabase project can login to Logiak Apps which are connected.
Two ways to CREATE end user accounts
There are two ways to create end user accounts
- Manually invite
- Let users sign-up
Invite end users
You can manually invite people to become end users by clicking the Invite button and entering an email address.
If you want to keep your project very secure, you could do this manual invite and configure the Login component in your App to not show a “sign-up” button.
Then the manual invite would be the only way someone could become an End User.
Permit people to Sign Up
By default, the Login component shows a Sign-up button.
Clicking Sign-up asks the user for an email and a password.
Then it does the following:
- it creates an End User in the Supabase project, awaiting validation
- sends the user an email to the address given with a link. Clicking on the link will validate the Supabase End User account.
- Feedback message appears to confirm Sign Up
Then the user has successfully signed up, and will be able to login to the App.
Here is that process illustrated:
For the above to work, the setup step which requires the copying and pasting of the Site URL must have been completed correctly.
If sign-up is not working, please go back to the Deployment’s Set Up tab and check this.