Was thinking a bit about how a CMS could work with supabase.
One approach is to use a code generator.
All you’d need is a list of fields, and the code generator would do a bunch of work for you, like:
- Generating the SQL to create the tables.
- Adding the primary keys, foreign keys and common fields, like
id,user_id,status,inserted_at,updated_at,published_at. - Generating the security policies. Only
publisheddata should be accessible to the public, while creating and updating would require authentication. - Adding a trigger to set the
updated_attimestamp. - Adding a
*_versionstable and a trigger to capture each change.
We also get a few things for free:
- The content is accessible via the standard supabase API, ie
await supabase.from('table_name').select('*'). So no special API is needed. - It notifies whenever something changes via supabase’s
realtimeAPI.
In the future, it could provide:
- A visual editor for doing CRUD, publishing, scheduling, and archiving.
- A way to migrate the DB automatically, without copy & paste.
- The ability to Attach files to rows using Supabase Storage.
Code
https://svelte.dev/repl/58ad718676504e558f4a893e2ac050af?version=3.38.2
Demo
Notes
- Add default values for fields.
- When
scheduled_atis set, andstatus = 'scheduled'a CRON job should run to mark the postpublished, that will trigger realtime updates. - Should it support field validations?