-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve developing docs and bring in timeout migration (#256)
* Improve developing docs and bring in timeout migration * fix anon key example * type-gen * add codeowners * typo
- Loading branch information
Showing
4 changed files
with
132 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
@main/maintainers |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,9 +2,53 @@ | |
|
||
Local development of Playabl uses Docker to run a containerized version of the backend alongside a local copy of the UI. The Netlify service is also supported locally and can be run to test serverless functions. There is also some AWS in the codebase, but Netlify is typically preferred for serverless functions. | ||
|
||
## Supabase setup | ||
## Environment setup | ||
|
||
The local workflow is based on Supabase's guide for [local development](https://supabase.com/docs/guides/cli/local-development) with supabase CLI. | ||
_Note: these steps have only been tested on M1 Mac. If you want to develop on Linux or Windows you may need to alter these commands_ | ||
|
||
**Prereqs** | ||
|
||
- Docker | ||
- Node v20 or greater | ||
|
||
The local workflow is based on Supabase's guide for [local development](https://supabase.com/docs/guides/cli/local-development) with supabase CLI. It is **highly** recommended you read this guide and at least be familiar with its contents before starting. This guide has all the info you need for how to do various tasks like starting services, stopping services, resetting the DB, creating a migration, etc. | ||
|
||
**Install packages** | ||
|
||
`npm install` | ||
|
||
**Start supabase** | ||
|
||
`npx supabase start` | ||
|
||
This will pull the docker images and start the containers. At the end of it, you will be given an output of URLs and keys to use for local development. Some of these will need to be set in a `.env` file. Here is a sample output: | ||
|
||
``` | ||
Started supabase local development setup. | ||
API URL: http://127.0.0.1:54321 | ||
GraphQL URL: http://127.0.0.1:54321/graphql/v1 | ||
DB URL: postgresql://postgres:[email protected]:54322/postgres | ||
Studio URL: http://127.0.0.1:54323 | ||
Inbucket URL: http://127.0.0.1:54324 | ||
JWT secret: super-secret-jwt-token-with-at-least-32-characters-long | ||
anon key: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6ImFub24iLCJleHAiOjE5ODM4MTI5OTZ9.CRXP1A7WOeoJeXxjNni43kdQwgnWNReilDMblYTn_I0 | ||
service_role key: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJzdXBhYmFzZS1kZW1vIiwicm9sZSI6InNlcnZpY2Vfcm9sZSIsImV4cCI6MTk4MzgxMjk5Nn0.EGIM96RAZx35lJzdJsyH-qQwv8Hdp7fsn3W0YpN81IU | ||
``` | ||
|
||
**Set env variables** | ||
|
||
Set these values in a `.env` file at the root of the project: | ||
|
||
``` | ||
VITE_SUPABASE_URL=<API_URL> | ||
VITE_SUPABASE_ANON_KEY=<anon_key> | ||
SUPABASE_URL=<API_URL> | ||
SUPABASE_SERVICE_ROLE=<service_role_key> | ||
VITE_PLAYABL_URL=http://localhost:8888 | ||
``` | ||
|
||
You may see other environement variables in the code, but these aren't typically necessary for normal development. If you want to work on something that does require it, like AWS, I'll work with you to figure out the right values. | ||
|
||
### Storage (optional) | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
drop trigger if exists "send_notification" on "public"."notifications"; | ||
|
||
set check_function_bodies = off; | ||
|
||
CREATE OR REPLACE FUNCTION public.dispatch_unread_notifications_emails() | ||
RETURNS void | ||
LANGUAGE plpgsql | ||
SECURITY DEFINER | ||
AS $function$declare | ||
row record; | ||
begin | ||
for row in select p.id, n.email, p.username, count(n.email) | ||
from notifications n | ||
inner join profiles p | ||
on p.id = n.user_id | ||
and (p.email_preferences->>'email_enabled')::boolean is true | ||
and (p.email_preferences->>'unread_notifications_enabled')::boolean is true | ||
and n.read = false | ||
and n.created_at > current_timestamp - interval '1 day' | ||
group by (p.id, n.email, p.username) | ||
loop | ||
perform net.http_post( | ||
'https://app.playabl.io/.netlify/functions/unreadNotificationsEmail', | ||
jsonb_build_object( | ||
'user_id', | ||
row.id, | ||
'email', | ||
row.email, | ||
'username', | ||
row.username, | ||
'count', | ||
row.count | ||
), | ||
'{}', | ||
jsonb_build_object( | ||
'Content-Type', 'application/json', | ||
'Authorization', '2gCvGM1WXv2i5Y3LzDT6kZfUqzimkEzvmwn31CtiyWg2' | ||
), | ||
5000 | ||
); | ||
end loop; | ||
end;$function$ | ||
; | ||
|
||
CREATE TRIGGER send_notification AFTER INSERT ON public.notifications FOR EACH ROW EXECUTE FUNCTION supabase_functions.http_request('https://app.playabl.io/.netlify/functions/notify', 'POST', '{"Content-type":"application/json","Authorization":"2gCvGM1WXv2i5Y3LzDT6kZfUqzimkEzvmwn31CtiyWg2"}', '{}', '5000'); | ||
|
||
|