-
Notifications
You must be signed in to change notification settings - Fork 16
/
supabase.saas.txt
1921 lines (1466 loc) · 89.9 KB
/
supabase.saas.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
SUPABASE
VERSION ==> #18-06-2023
BREAKING FEATURES ==> #New Supabase breaking features, or new Postgres versions
#Can:
# - pause then restart PROJECT (free only)
# - manually backup PROJECT, then create a new one, restoring backup
PRICING ==> #Free: 0$, Pro: 25$/month per PROJECT, Enterprise: custom
#Can set a spend cap
#Can see usage in UI
PAUSING ==> #Automatically done in free after 1 week inactivity
SUPPORT ==> #Pro only
SUMMARY ==> #Users: organizations, permissions, plan
#Projects: pausing, region
#Database: schemas, meta API, postgres CONF, compute add-on, extensions, wrappers, pgtap, lint
#Connection: SSL, network restrictions|bans, timeout, pgBouncer
#Role: anon|authenticated|service_role, dashboard_user, postgres, supabase_*, POLICY
#Backups: daily, PITR, manual
#Migrations: diff|manual, local|remote
#Postgrest: OpenAPI, REST, SQL FUNC, max ROWs, GraphQL
#Storage: CDN, buckets, images, metadata, signed URL, transform
#Edge functions: Deno, deploy, call, webhooks
#Realtime: channel, broadcast, postgres changes, presence
#Auth: email, one-time password, email templates, email server, SMS, MFA, OAuth, SAML, SSO, users, UI helpers
#Vector
#Encryption: secrets, vault, column encryption
#Logs: reports, edge, database, storage, functions, realtime, auth, prometheus
#API: keys, JWT expiry|refresh, management API, custom|vanity domains, self-hosting
#Clients: API, JavaScript, TypeScript types, CLI, local dev, UI, framework adapters, marketplace
/=+===============================+=\
/ : : \
)==: ORGANIZATION USERS :==(
\ :_______________________________: /
\=+===============================+=/
ORG ==> #Sets of USERs and PROJECTs
GET TOP_API_DOMAIN/organizations
supabase orgs list #List all ORGs
POST TOP_API_DOMAIN/organizations #Create an ORG
XORG.id #ORG_ID
XORG.name #'ORG_NAME'
USER ==> #Supabase direct users, not end-USERs
#Can have permissions:
# - billing only (read/write)
# - readonly: project read, PUBLIC_API_KEY read, database read, AUTH read, EDGE_FUNC read, logs, reports
# - developer: also API_KEYs, database write, STORAGE, AUTH write, READ_FUNC write
# - administrator: also user permissions, billing write, PROJECTs write
# - owner: also ORG, billing email address
#Unless Enterprise, only: owner, developer
/=+===============================+=\
/ : : \
)==: PROJECT :==(
\ :_______________________________: /
\=+===============================+=/
PROJECT #DATABASE + other Supabase features related to it
#Max: 2 (free), unlim (pro)
#There should be one per environment (production, staging, dev, etc.)
PROJECT_NAME #PROJECT human-friendly NAME
PROJECT_ID #PROJECT ID
CONF.project_id #Also called "reference ID"
CLOUD PROVIDER ==> #AWS. Can pick REGION
POST TOP_API_DOMAIN/projects
supabase projects
create PROJECT_NAME #
--interactive|-i #
--org-id #ORG_ID
--plan free|pro #
--region REGION #
GET TOP_API_DOMAIN/projects
supabase projects list #List all PROJECTs
XPROJECT.id #PROJECT_ID
XPROJECT.name #PROJECT_NAME
XPROJECT.organization_id #ORG_ID
XPROJECT.region #'REGION'
XPROJECT.created_at #'TIMESTAMPTZ'
/=+===============================+=\
/ : : \
)==: DATABASE :==(
\ :_______________________________: /
\=+===============================+=/
supabase/postgres #Docker image with Postgres
#On Ubuntu
#Meant to host on AWS
#Includes:
# - more EXTENSIONs
# - pgBouncer
# - postgrest
# - WAL-G
# - GoTrue
# - Kong
# - nginx
# - admin API and manager
# - Prometheus exporter
# - ROLEs, security, etc.
#Uses Ansible and Terraform
XPROJECT.database.version
CONFIG.db.major_version #NUM (def: 15, i.e. 15.1)
CLUSTER #'main'
DATABASE #'postgres'
CONFIG.api.schemas #"Exposed" SCHEMAs, i.e. available to public APIs
#Also full PRIVILEGEs with anon|authenticated|service_role ROLEs
#Def: public, graphql_public, storage
CONFIG.api.extra_search_path #'SCHEMA'_ARR (def: 'public')
ENVVAR search_path #"$user" + extra_search_path
#Also "extensions", if postgres ROLE
ENVVAR lc_collate|lc_ctype #'C.UTF-8'
ENVVAR lc_* #Others are 'en_US.UTF-8'
supabase/postgres-meta #CRUD API to execute DDL through SQL
#For ENTITYs: TABLE, COL, FUNC, TFUNC, ROLE, TYPE, SCHEMA, EXTENSION, PUBLICATION
#Can also use SQL query: execute, `explain`, format, parse
/=+===============================+=\
/ : : \
)==: PERFORMANCE :==(
\ :_______________________________: /
\=+===============================+=/
DATABASE SIZE ==> #40-60MB taken by Supabase utilities
#Pricing: max 500MB (free), 8GB then 1$/8GB
#Max:
# - self-serve: 200GB
# - from support: 64TB (pro), 1PB (enterprise)
#Autoscaling:
# - when reaching 90% of size
# - adds 50% more
# - max once per 6h
# - pro only
DATABASE EGRESS ==> #2GB/month (free), 50GB/month then 1$/10GB (pro)
EC2 INSTANCE TYPES ==> #Per PROJECT
#"Compute add-ons"
#
#Pricing per month ($): 0 5 50 100 200 400 950 1860 2790 3720
#Memory (GB): 1 2 4 8 16 32 64 128 192 256
#Max I/O (Mbps): 2606 2606 2606 4750 4750 4750 4750 9500 14250 19000
# (for 30min per day)
#Mean I/O (Mbps): 87 174 347 630 1188 2375 4750 9500 14250 19000
#Max IOPS (thousands) 12 12 12 20 20 20 20 40 50 80
# (for 30min per day)
#Mean IOPS (thousands) .5 1 2 4 6 12 20 40 50 80
#Max direct connections: 10 30 50 100 200 350 420 450 480 500
#Max pooled connections: 50 75 150 300 600 1200 2800 5600 8600 11600
#pgBouncer connections: 200 200 200 300 700 1500 3000 6000 9000 12000
#vCPUs: 2 2 2 2 4 8 16 32 48 64
#vCPUs shared: yes yes yes no no no no no no no
#
#Can see memory, I/O, vCPU, network usage in UI
POSTGRES CONF ==> #The following depends on EC2 instance type
#Below are figures for lowest one
work_mem #.004% of RAM
wal_buffers #.008% of RAM
shared_buffers #25% of RAM
shared_memory_size #40% of RAM
effective_cache_size #75% of RAM
max_slot_wal_keep_size #100% of RAM
min_wal_size #100% of RAM
max_wal_size #400% of RAM
effective_io_concurrency #200
max_connections #Max direct + pooled connections
max_worker_processes #4 (instead of 8)
max_parallel_workers #2 (instead of 8)
max_parallel_workers_per_gather #1 (instead of 2)
random_page_cost #1.1 (instead of 4)
supabase postgres-config update #Sets Postgres CONF VARs
--config VAR=VAL #Only for:
# - work_mem
# - shared_buffers
# - effective_cache_size
# - max_connections
# - max_worker_processes
# - max_parallel_workers
# - max_parallel_workers_per_gather
# - statement_timeout
# - maintenance_work_mem
# - max_parallel_maintenance_workers
# - session_replication_role
#Restarts the CLUSTER
--replace-existing-overrides #Erase previous calls to `update --config`
/=+===============================+=\
/ : : \
)==: EXTENSIONS :==(
\ :_______________________________: /
\=+===============================+=/
EXTENSIONS ==> #Automatically enabled:
# - uuid-ossp
# - pgjwt
# - pgcrypto, pgsodium
# - pg_safeupdate
# - supabase_vault
#Automatically enabled (not documented yet???):
# - pg_stat_statements
# - also shown in UI "Reports > Query performance"
# - pg_net
# - used by webhooks
# - pg_graphql
# - auto_explain
#Also available (on top of ones automatically available with Postgres):
# - pg_cron
# - pg_hashids
# - pg_jsonschema
# - wrappers
# - pgsql-http
# - supautils
#Also available (not documented yet???):
# - pgvector
# - plpgsql_check: PL/PGSQL linter
# - plv8: JavaScript LANGUAGE (V8)
# - plcoffee: CoffeeScript LANGUAGE
# - plls: LiveScript LANGUAGE
# - pg_tle: EXTENSIONs framework
# - pgtap: unit testing
# - pgaudit: security audit through logs
# - pg_stat_monitor: query performance monitoring
# - hypopg: create fake INDEXs, so they show up on `explain`, to see if worth creating them
# - pg_repack: like `cluster` or `vacuum full` for does not lock
# - rum: ACCESS_METHOD like gin but optimized for TSQUERY|TSVECTOR
# - postgis*: geometric operations
# - address_standardizer[_data_us]: part of PostGIS, normalize a shipping address
# - pgrouting: PostGIS routes
# - pgroonga[_database]: use Groonga, a text search database
# - timescaledb: Time series database
extensions #SCHEMA with some EXTENSIONs, e.g. pg_stat_statements
#Some EXTENSIONs have own SCHEMAs, e.g. pgbouncer, pgsodium, pgtle, vault, net
WRAPPERS ==> #See doc in Postgres
#Can create FDW|FSERVER|FTABLEs from the UI
/=+===============================+=\
/ : : \
)==: DATABASE TESTING :==(
\ :_______________________________: /
\=+===============================+=/
supabase test db #Run PGTAP pg_prove on all WORKDIR/tests/**/*.sql|pg
#PGTAP can also be added as PG extension
supabase test new "FILENAME" #Create dummy WORKDIR/tests/FILENAME.sql
--template|-t #Always 'pgtap'
supabase db lint #Lint for DDL errors in local database, including plpgsql_check
--level #'warning' (def) or 'error'
--schema|-s 'SCHEMA,...' #Def: all
--linked #Run on remote database instead
/=+===============================+=\
/ : : \
)==: CONNECTION :==(
\ :_______________________________: /
\=+===============================+=/
XPROJECT.database.host
PG_HOST #db.PROJECT_DOMAIN
CONFIG.api.port
PG_PORT #5432
ENVVAR SUPABASE_DB_PASSWORD #When logging to `postgres` ROLE
supabase link --password|-p STR #Prompted with CLI otherwise
supabase ... --password|-p STR #Many CLI commands can override it too
ENVVAR ssl_ca_file
ENVVAR ssl_cert_file
ENVVAR ssl_key_file #Server SSL is setup, i.e. encrypts query in-transit
supabase ssl-enforcement update
--enable|disable
-db-ssl-enforcement #Use LIBPQ.sslmode 'verify-full', i.e. require client SSL certificate
supabase ssl-enforcement get #
ENVVAR statement_timeout #Def: 8s if ROLE authenticated, 3s if ROLE anon
#Can be changed up to 2min
/=+===============================+=\
/ : : \
)==: NETWORK RESTRICTIONS :==(
\ :_______________________________: /
\=+===============================+=/
POST #Add NETWORK_RESTRICTIONS, i.e. IP restrictions for PGBouncer and Postgres database
API_DOMAIN/network-restrictions #Not for Rest|GraphQL, Storage, Realtime APIs
supabase network-restrictions #Does not work if an EDGE_FUNC needs to connect to the database
update #Def: none
--db-allow-cird ID[/MASK] #Can be 0.0.0.0/0 to remove any
GET
API_DOMAIN/network-restrictions
supabase network-restrictions get #Get NETWORK_RESTRICTIONS
XNETWORK_RESTRICTIONS.entitlement #'[dis]allowed'
XNETWORK_RESTRICTIONS.status #'stored|applied'
XNETWORK_RESTRICTIONS
.[old_]config.dbAllowedCidrs #'ID[/MARK]'_ARR
POST API_DOMAIN/network-bans
/retrieve
supabase network-bans get #See IP banned by Supabase
DELETE API_DOMAIN/network-bans
supabase network-bans remove
--db-unban-ip IP #Unban
XNETWORK_BANS
.banned_ipv4_addresses #'IP'_ARR
/=+===============================+=\
/ : : \
)==: PGBOUNCER :==(
\ :_______________________________: /
\=+===============================+=/
PGBOUNCER ==> #Is used to pool connections
#Runs on same credentials|URL, but port 6543
#Meant for connections opened|closed often, e.g. in serverless functions
#Document it ???
POOL MODE ==> #Of pgBouncer. Whether one connection per session, transaction, or statement
#Lower has better performance, but disables some PG features
pgbouncer_logs #SQL TABLE with logs for PGBouncer
PGBOUNCER_LOGS.id #'UUID'
PGBOUNCER_LOGS.timestamp #TIMESTAMPTZ
PGBOUNCER_LOGS.event_message #STR
/=+===============================+=\
/ : : \
)==: ROLES :==(
\ :_______________________________: /
\=+===============================+=/
AUTHENTICATION ==> #scram-sha-256 password
#Main one is for postgres, which can be set|reset
#Exception: anon|authenticated|service_role ROLEs
# - those have no `login` PRIVILEGE
# - they are set from initial session ROLE "authenticator"
# - they use API_KEYs instead
#dashboard_user ROLE also has no `login` PRIVILEGE, but I'm unsure how it is set
PRIVILEGES ==> #No ROLE has `admin option` PRIVILEGE
authenticator #Initial session ROLE in API requests
#Managed by Postgrest
#No `inherit` PRIVILEGE
anon #ROLE for anonymous API requests
#`usage` PRIVILEGEs on all SCHEMAs, except realtime|vault|supabase_migrations
authenticated #ROLE for authenticated API requests, for users
#`usage` PRIVILEGEs on all SCHEMAs, except realtime|vault|supabase_migrations
service_role #ROLE for privileged API requests, for users
#`usage` PRIVILEGEs on all SCHEMAs, except realtime|vault|supabase_migrations
dashboard_user #ROLE for API requests made through UI
#`createrole`, `createdb`, `replication` PRIVILEGEs
#Full PRIVILEGEs on DATABASE and on extensions|storage|auth SCHEMAs
#No PRIVILEGEs on other SCHEMAs
postgres #ROLE for programmatic access, for users
#Owner of DATABASE
#`createrole`, `createdb`, `replication`, `bypassrls` PRIVILEGEs
#Not superuser ROLE
#Full PRIVILEGEs on public|extensions|storage|auth|supabase_migrations SCHEMAs
#`usage` PRIVILEGEs on other SCHEMAs
#Can set itself to ROLEs: anon|authenticated|service_role or supabase_*_admin
supabase_* #ROLEs meant for support or built-in features
#Uses supautils EXTENSION to protect those (see its doc)
supabase_admin #Only superuser ROLE
#Full access to everything
supabase_read_only_user #ROLE member of pg_read_all_data
#`bypassrls` PRIVILEGE
supabase_auth_admin #ROLE owning auth SCHEMA|ENTITYs
#No `inherit` PRIVILEGE, but `createrole`
supabase_functions_admin #ROLE owning Edge functions SCHEMA|ENTITYs
#No `inherit` PRIVILEGE, but `createrole`
supabase_storage_admin #ROLE owning storage SCHEMA|ENTITYs
#No `inherit` PRIVILEGE, but `createrole`
#Can set itself to ROLEs: anon|authenticated|service_role
supabase_replication_admin #ROLE for logical replication features
#`replication` PRIVILEGE
POLICY #Row-level security enabled by default on TABLEs of exposed SCHEMAs
#`service_role` ROLE has `bypassrls` PRIVILEGE
/=+===============================+=\
/ : : \
)==: BACKUPS :==(
\ :_______________________________: /
\=+===============================+=/
DAILY BACKUPS ==> #pg_dumpall, once per day, last 7 days (pro only)
PITR BACKUPS ==> #Per-second backup
#Uses WAL physical replication, with WAL-G tool
#Threshold: either specific WAL file size, or 2 mins
#Keeps 7 days by default (can set it)
# - 100$ per 7d
#Cannot be used together with daily backups
supabase db dump #Runs pg_dump
#Excludes Supabase|EXTENSIONs managed SCHEMAs
--file|-f FILE #Def: stdout
--data-only #Include (only) data
--role-only #Include (only) ROLEs
--keep-comments #
/=+===============================+=\
/ : : \
)==: MIGRATIONS :==(
\ :_______________________________: /
\=+===============================+=/
MTIME #MIGRATION timestamp YYYYMMDDHHMMSS, used as identifier and to specify order
MNAME #MIGRATION name
supabase migration new MNAME #Create empty MIGRATION
#Can also set content from stdin
supabase db diff #Prints MIGRATION by diffing current local database and last MIGRATION
--file|-f MNAME #Create MIGRATION file
--use-migra #Smaller diff by using `migra` tool
--schema|-s 'SCHEMA,...' #Def: all
--linked #Apply remotely instead
supabase db remote commit #Add a new MIGRATION by diffing remote database and last MIGRATION
#Uses name "remote_commit"
--schema|-s 'SCHEMA,...' #Def: all
supabase db reset #Apply MIGRATIONs to local database, after resetting it
--linked #Apply remotely instead
supabase db up #Apply MIGRATIONs to local database, incrementally
supabase db push #Apply MIGRATIONs to remote database, incrementally
--dry-run #
supabase migration list #Print all local|remote MIGRATIONs names|timestamps
supabase migration repair MTIME #Fixes supabase_migrations.schema_migrations TABLE in remote database
--status #If:
# - 'reverted': delete ROW
# - 'applied': add ROW, using local MIGRATION
WORKDIR/migrations/MTIME_MNAME.sql#MIGRATION, i.e. SQL file describing DDL
#Including Postgres CONF, EXTENSIONs, FUNCs, POLICYs, PRIVILEGEs, etc.
#Only diff since last once
#Meant to be git committed
WORKDIR/seed.sql #Initial MIGRATION run only locally
#Meant for local dummy data
supabase_migrations #SCHEMA
supabase_migrations
.schema_migrations #TABLE with all MIGRATIONs
supabase_migrations
.schema_migrations.version #'MTIME'
supabase_migrations
.schema_migrations.statements #'SQL'. MIGRATION contents
auth|storage|supabase_functions
.migrations #TABLE with migrations done by Supabase on auth|storage|supabase_functions.*
/=+===============================+=\
/ : : \
)==: POSTGREST :==(
\ :_______________________________: /
\=+===============================+=/
REST_DOMAIN #PROJECT_DOMAIN/rest/v1
REST_DOMAIN/... #Proxies to postgREST routes (see its doc)
#Uses Cloudflare + Kong
#Can use HTTP/3
Content-Encoding: br [S] #
Strict-Transport-Security:
max-age=2592000;
includeSubDomains [S] #
REST_DOMAIN/ #/ route, i.e. OpenAPI as JSON
#OpenAPI as HTML also available when logged in the UI
REST_DOMAIN/TABLE #/TABLE route, i.e. REST CRUD
REST_DOMAIN/rpc/FUNC #/rpc/FUNC route, i.e. SQL FUNC
CLIENT.rest #@supabase/postgrest-js POSTGREST_CLIENT
CLIENT.* #Forwards to CLIENT.rest.*
COPTS.db.schema #Forwards to POPTS.schema
CONFIG.api.max_rows
POSTGREST_CONF.db-max-rows #Def: 1e3, max: 1e6
/=+===============================+=\
/ : : \
)==: GRAPHQL :==(
\ :_______________________________: /
\=+===============================+=/
DATABASE GRAPHQL ==> #Automatic GraphQL CRUD endpoints
#Includes introspection
#Uses PG extension "pg_graphql"
#The extension uses itself postgREST, i.e. similar features as REST API
graphql.resolve('QUERY'
[, $VARS_JSONB_OBJ[, 'OPNAME'
[, EXTENSIONS_JSONB]]])->JSONB #SQL FUNC resolving GraphQL query
GRAPHIQL ==> #Available in API docs
GRAPHQL_DOMAIN #'PROJECT_DOMAIN/graphql/v1'
query #Automatically populates foreign keys
query.TABLECollection.edges #Get ROWs of TABLE
#OBJ_ARR: node ROW_OBJ
graphql_public #SCHEMA with GraphQL???
graphql #SCHEMA with GraphQL???
https://github.com/supabase/pg_graphql ???
/=+===============================+=\
/ : : \
)==: STORAGE :==(
\ :_______________________________: /
\=+===============================+=/
STORAGE ==> #For big files
#Max: 1GB (free), 100GB then 1$/50GB (pro)
#Max egress: 2GB (free), 200GB then 1$/100GB (pro)
CDN ==> #S3 through Cloudflare
SMART CDN CACHING ==> #Automatically re-cache changed OBJECT on CDN
supabase/storage-api #Repository
STORAGE_DOMAIN #PROJECT_DOMAIN/storage/v1
INBUCKET ==> #Storage API
@supabase/storage-js #Version 2.5.4
new StorageClient
(STORAGE_DOMAIN[, OPTS]) #STORAGE
CLIENT.storage #new StorageClient()
OPTS.apikey #'API_KEY'
OPTS.Authorization #'Bearer API_KEY'
RES.data #VAL
RES.error #ERROR
storage #SCHEMA
/=+===============================+=\
/ : : \
)==: STORAGE BUCKETS :==(
\ :_______________________________: /
\=+===============================+=/
BUCKET #Main directory
SQL_BUCKET #ROW in storage.buckets TABLE
SQL_BUCKET|XBUCKET.id|name #'BUCKET'
SQL_BUCKET|XBUCKET.owner #REGROLE
SQL_BUCKET|XBUCKET
.created_at|updated_at #TIMESTAMPTZ
SQL_BUCKET|XBUCKET.public #BOOL. If false (def), can still download, but not create URL
SQL_BUCKET|XBUCKET
.allowed_mime_types #'MIME'_ARR (def: null). Can use *
CONFIG|SQL_BUCKET|XBUCKET
.file_size_limit #BIGINT (def: null)
SQL_BUCKET.avif_autodetection #BOOL (def: false)
FOLDER #Sub-directory
#Actually just prefix in OBJECT's name
FNAME #'[FOLDER/]NAME'
POST STORAGE_DOMAIN/bucket
STORAGE.createBucket
('BUCKET'[, OPTS])->RES #
OPTS.public #BOOL
OPTS.fileSizeLimit #NUM|null
OPTS.allowedMimeTypes #'MIME'_ARR|null
PUT STORAGE_DOMAIN/bucket/BUCKET
STORAGE.updateBucket
('BUCKET'[, OPTS])->RES #Same OPTS as createBucket()
GET STORAGE_DOMAIN/bucket/BUCKET
STORAGE.getBucket('BUCKET')->RES #
GET STORAGE_DOMAIN/bucket
STORAGE.listBuckets()->RES #
POST STORAGE_DOMAIN
/bucket/BUCKET/empty
STORAGE.emptyBucket('BUCKET')
->RES #
DELETE
STORAGE_DOMAIN/bucket/BUCKET
STORAGE.deleteBucket('BUCKET')
->RES #
/=+===============================+=\
/ : : \
)==: STORAGE OBJECTS :==(
\ :_______________________________: /
\=+===============================+=/
OBJECT #Single file
OBJECT_CONTENT #BLOB|FILE|FORMDATA|ARRBUFFER
#Max size: 50MB (free), 5GB (pro)
SQL_OBJECT #ROW in storage.objects TABLE
#Does not include OBJECT_CONTENTs
# - i.e. backups must manually download everything
SQL_OBJECT|XOBJECT.id #'UUID'
SQL_OBJECT|XOBJECT.bucket_id #SQL_BUCKET.id
XOBJECT.buckets #XBUCKET_ARR
SQL_OBJECT|XOBJECT.name #'FNAME'
SQL_OBJECT|XOBJECT.owner #REGROLE
SQL_OBJECT|XOBJECT.version #STR
storage.filename('FNAME')
->'NAME.EXT' #
storage.extension('FNAME')->'EXT' #
SQL_OBJECT.path_tokens #[...FOLDER, 'NAME']
storage.foldername('FNAME')
->[...FOLDER] #
SQL_OBJECT|XOBJECT
.created|updated_at #TIMESTAMPTZ
SQL_OBJECT|XOBJECT
.last_accessed_at #TIMESTAMPTZ
SQL_OBJECT|XOBJECT.metadata #OBJ_JSONB of METADATA
METADATA.size #NUM
METADATA.contentLength #NUM
METADATA.eTag #STR
METADATA.mimetype #'MIME'
METADATA.cacheControl #STR: HTTP Cache-Control [S]
METADATA.lastModified #'DATE'
METADATA.httpStatusCode #NUM
STORAGE.from('BUCKET')->STORAGE #Must be called before following methods
GET
STORAGE_DOMAIN/object/list/BUCKET
GET STORAGE_DOMAIN
/object/BUCKET/FNAME_GLOB
STORAGE.list
('BUCKET'[, OPTS][, OBJ])->RES #List OBJECTs
OPTS.search #STR. Search in FNAMEs
OPTS.sortBy.order #'asc' (def) or 'desc'
OPTS.sortBy.column #'COL'
OPTS.offset|limit #NUM
OBJ.signal #ABORT_SIGNAL
POST STORAGE_DOMAIN
/object/BUCKET/FNAME_GLOB
STORAGE.upload
('FNAME', OBJECT_CONTENT[, OPTS])
->RES #Add an OBJECT
OPTS.cacheControl #STR (def: 'max-age=3600')
#Can use query params for cache busting
OPTS.contentType #STR (def: 'text/plain;charset=UTF-8' for ARRBUFFER, guessed otherwise)
OPTS.upsert #BOOL (def: false)
OPTS.duplex #STR
POST
STORAGE_DOMAIN/upload/resumable
POST|PUT|PATCH STORAGE_DOMAIN
/upload/resumable/FNAME_GLOB #Streaming upload. See online doc
PUT STORAGE_DOMAIN
/object/BUCKET/FNAME_GLOB
STORAGE.update
('FNAME', OBJECT_CONTENT[, OPTS])#Replace an OBJECT
->RES #Same OPTS as upload()
POST STORAGE_DOMAIN/object/move
STORAGE.move('FNAME', 'FNAME2')
->RES #
POST STORAGE_DOMAIN/object/copy
STORAGE.copy('FNAME', 'FNAME2')
->RES #
DELETE STORAGE_DOMAIN
/object/BUCKET[/FNAME_GLOB]
STORAGE.remove('FNAME'_ARR)->RES #
GET STORAGE_DOMAIN/object[/info]
/authenticated/BUCKET/FNAME_GLOB
STORAGE.download('FNAME')->RES #Get an OBJECT
POST STORAGE_DOMAIN/object
/sign/BUCKET
STORAGE.getPublicUrl #Returns 'STORAGE_DOMAIN/object/public/BUCKET/FNAME', to get an OBJECT
('FNAME'[, OPTS])->RES #Only if BUCKET is public
OPTS.download #BOOL|'FILENAME' (def: false): set HTTP headers to make it downloadable
GET STORAGE_DOMAIN/object[/info]
/public/BUCKET/FNAME_GLOB #Use signed URL
POST STORAGE_DOMAIN/object #Same for a private BUCKET.
/sign/BUCKET/FNAME_GLOB #Includes a temporary private key.
STORAGE.createSignedUrl # - included in cache key, i.e. poorer caching
('FNAME', NUM[, OPTS])->RES #NUM is expiration in secs
GET STORAGE_DOMAIN/object
/sign/BUCKET/FNAME_GLOB #Use signed URL
POST STORAGE_DOMAIN/object
/sign/BUCKET
STORAGE.createSignedUrls
('FNAME'_ARR, NUM[, OPTS])->RES #Same for multiple URLs
POST STORAGE_DOMAIN/object/upload
/sign/BUCKET
STORAGE.createSignedUploadUrl #Same but allows uploads
('FNAME')->RES #Expiration is always 2h
PUT STORAGE_DOMAIN/object/upload
/sign/BUCKET
STORAGE.uploadToSignedUrl
('FNAME', 'TOKEN', OBJECT_CONTENT#Like upload() but with 'TOKEN' returned by createSignedUploadUrl()
[, OPTS])->RES #Same OPTS as upload()
/=+===============================+=\
/ : : \
)==: IMAGE TRANSFORM :==(
\ :_______________________________: /
\=+===============================+=/
GET STORAGE_DOMAIN/render/image
/public|authenticated|sign
/BUCKET/FNAME_GLOB #Like GET STORAGE_DOMAIN/object/... but for an image with transformation
OPTS.transform #Last argument of STORAGE.download|getPublicUrl()
#Transform image response
#For PNG|JPEG|WebP|AVIF|GIF|ICO|SVG|HEIC|BMP|TIFF
#Max 25MB
#Max 50 megapixels
#Max 100/month then 1$ per 200 transforms
#Pro only
#Uses a fork of `imgproxy`
TRANSFORM.height|width #1-2500
TRANSFORM.resize #'cover|contain|fill'
TRANSFORM.format #Unless set to 'origin', automatically convert to a better format,
#e.g. to WebP if client supports it
TRANSFORM.quality #20-100 (def: 80)
/=+===============================+=\
/ : : \
)==: EDGE FUNCTIONS :==(
\ :_______________________________: /
\=+===============================+=/
EDGE FUNCTION ==> #Built on Deno Subhosting
#Compared to SQL FUNC:
# - pros:
# - low latency
# - JavaScript
# - con: slower compute
#No access to filesystem nor npm:*
#Content-Type [S] cannot be text/html
#Max requests per month: 5e5 (free), 2e6 then 1$ per 5e5 (pro)
#Max size per EDGE_FUNC: 2MB (free), 10MB (pro)
#Max count: 10 (free), 100 then 1$ per 10 (pro)
supabase/functions-relay #Backend which proxies to Deno Subhosting
#Small Deno Oak API
#Meant to add: JWT verification, logging, rate limiting
supabase_functions #SCHEMA with Edge functions features
EDGE_FUNC #Edge function's name. Convention: hyphenated
XEDGE_FUNC.entrypoint_path
./functions/EDGE_FUNC/index.ts #Main file
./functions/_NOT_EDGE_FUNC #Helpers
supabase functions new EDGE_FUNC #Initializes ./functions/EDGE_FUNC/index.ts
DELETE
API_DOMAIN/functions/EDGE_FUNC
supabase functions
delete EDGE_FUNC #Delete remotely (not locally)
POST API_DOMAIN/functions
PATCH
API_DOMAIN/functions/EDGE_FUNC
supabase functions
deploy EDGE_FUNC #
GET API_DOMAIN/functions #List EDGE_FUNCs
GET API_DOMAIN/functions/EDGE_FUNC#
GET API_DOMAIN/functions
/EDGE_FUNC/body
supabase functions
download EDGE_FUNC #Download source code of EDGE_FUNC
supabase functions serve #Run EDGE_FUNCs locally
#FUNC_DOMAIN is http://localhost:54321/functions/v1
#Print stdout|stderr logs
#Hot reloading
XEDGE_FUNC.verify_jwt
CONFIG.functions.EDGE_FUNC
.verify_jwt
supabase functions deploy|serve
--no-verify-jwt #Unless specified, EDGE_FUNC requests must be authenticated with an API_KEY
XEDGE_FUNC.import_map[_path]
CONFIG.functions.EDGE_FUNC
.import_map
supabase functions deploy|serve
--import-map FILE #Deno import maps
#Def: ./functions/import_map.json
XEDGE_FUNC.id #ID
XEDGE_FUNC.slug #'EDGE_FUNC' slugified
XEDGE_FUNC.name #'EDGE_FUNC'
XEDGE_FUNC.version #NUM
XEDGE_FUNC.status #'ACTIVE|REMOVED|THROTTLED'
XEDGE_FUNC.created_at|updated_at #'DATE_NUM'
/=+===============================+=\
/ : : \
)==: EDGE FUNCTIONS CALL :==(
\ :_______________________________: /
\=+===============================+=/
FUNC_DOMAIN #https://PROJECT_ID.functions.supabase.co
FUNC_DOMAIN/EDGE_FUNC #Call EDGE_FUNC. Any HTTP method
@supabase/functions-js #Version 2.1.2
new FunctionsClient('URL'[, OPTS])#FUNCTIONS
OPTS.headers #OBJ
OPTS.customFetch #Def: globalThis.fetch, or `cross-fetch`
CLIENT.functions #new FunctionsClient(FUNC_DOMAIN)
FUNCTIONS.invoke
('EDGE_FUNC'[, OPTS])->>RES #
OPTS.method #'GET|POST|PUT|PATCH|DELETE' (def: 'POST')
OPTS.headers #OBJ
OPTS.body #Any supported by fetch(): STR|BLOB|ARRBUFFER|FORMDATA|RSTREAM
#Other values (e.g. OBJ|ARR) are serialized to JSON
# - unless Content-Type [C] set
RES.data #Response as is
#Automatically parses based on Content-Type [S]:
# - application/json: JSON
# - application/octet-stream: BLOB
# - multipart/form-data: FORMDATA
RES.error #ERROR|null
#Error classes:
# - FunctionsHttpError: 4**|5** response
# - FunctionsFetchError: while calling fetch(), i.e. network error
/=+===============================+=\
/ : : \
)==: WEBHOOKS :==(
\ :_______________________________: /
\=+===============================+=/
WEBHOOKS ==> #TFUNC on insert|update|delete of a given TABLE, calling either:
# - HTTP[S] request
# - GET|POST
# - EDGE_FUNC
# - i.e. POST request to it
#JSON payload OBJ:
# - type 'INSERT|UPDATE|DELETE'
# - schema 'SCHEMA'
# - table 'TABLE'
# - record VAL_ARR|null
# - old_record VAL_ARR|null
#Uses pg_net EXTENSION
supabase_functions.hooks #TABLE with all webhooks completed requests
supabase_functions.hooks
.request_id #INT8
supabase_functions.hooks.id #HOOK id
supabase_functions.hooks.hook_name#"HOOK" name
supabase_functions.hooks
.hook_table_id #TABLE.oid
supabase_functions.hooks
.created_at #TIMESTAMPTZ
/=+===============================+=\
/ : : \
)==: REALTIME :==(
\ :_______________________________: /
\=+===============================+=/
REALTIME ==> #Repository "supabase/realtime"
#Uses Elixir/Phoenix
realtime #SCHEMA with realtime features
CHANNEL #Namespace for events
#Max CHANNELs: 500 for all CLIENTs, 100 per CLIENT
#Number of CLIENTs (with >=1 CHANNEL): 200 (free), 500 then .01$ per CLIENT (pro)
EVENT_TYPE #'broadcast|postgres_changes|presence'
EVENT #Sub-type of EVENT_TYPE
PAYLOAD #Event payload OBJ
#Properties must be BOOL|NUM|STR|null|undefined
#Max size: 250KB (free), 3MB (pro)
# - 1MB for postgres_changes
#Max count: 2e6/month (free), 5e6 then 1$ per 4e5 (pro)
#Max per sec: 100 (free), 500 (pro)
ROPTS.params.eventsPerSecond #NUM (def: 10, max: 1000). Rate limit.
#10 times lower for EVENT_TYPE 'presence'
ROPTS.headers|params.apikey #API_KEY. Def: current one
#To change, must set on both headers|params
CLIENT.realtime.setAuth('API_KEY')#
/=+===============================+=\
/ : : \
)==: CHANNEL :==(
\ :_______________________________: /
\=+===============================+=/
@supabase/realtime-js #Version 2.7.3