The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Adds some more guides for the database section
Paul Copplestonecae65fa1e292
diff --git a/web/docs/about.mdx b/web/docs/about.mdxindex ed445c88b30..610286ec914 100755--- a/web/docs/about.mdx+++ b/web/docs/about.mdx@@ -117,7 +117,7 @@ The documentation is divided into 3 sections.<Link class="card" to="/docs/guides" style={{ height: '100%' }}><div class="card__body"><h4>Guides</h4>- <p>In-depth explainations for each tool.</p>+ <p>In-depth explanations for each tool.</p></div></Link></div>diff --git a/web/docs/guides/database/intro.mdx b/web/docs/guides/database/intro.mdxnew file mode 100644index 00000000000..e505b948326--- /dev/null+++ b/web/docs/guides/database/intro.mdx@@ -0,0 +1,37 @@+---+id: introduction+title: "Introduction"+slug: introduction+---++import Tabs from '@theme/Tabs';+import TabItem from '@theme/TabItem';++Every Supabase project comes with a full Postgres database, a free and open source+database which is considered one of the world's most stable and advanced databases.+++## Postgres or PostgreSQL?+++The database was derived from the POSTGRES Project, a package written at the University of California at Berkeley in 1986.+This package included a query language called "PostQUEL".++In 1994, Postgres95 was built on top of POSTGRES code, adding an SQL language interpreter as a replacement for PostQUEL.+Eventually, Postgres95 was renamed to PostgreSQL to reflect the SQL query capability.++After this, many people refered to it as Postgres since it's less prone to confusion. Supabase is all about+simplicity, so we also refer to it as Postgres.++<!--++## Relational++Postgres is a Relational Database.++## SQL+++Postgres is a SQL database.++-->\ No newline at end of filediff --git a/web/docs/guides/database/managing-timezones.mdx b/web/docs/guides/database/managing-timezones.mdxnew file mode 100644index 00000000000..d3e47f0a77e--- /dev/null+++ b/web/docs/guides/database/managing-timezones.mdx@@ -0,0 +1,85 @@+---+id: managing-timezones+title: "Timezones"+slug: managing-timezones+description: How to change your database timezone.+---++import Tabs from '@theme/Tabs';+import TabItem from '@theme/TabItem';+++Every Supabase database is set to UTC timezone by default. We strongly recommend keeping it this way, even if your users are in a different location.+This is becuase it makes it much easier to calculate diffeneces between timezones if you adopt the mental model that "everything in my database is in UTC time".+++### Change timezone++++<Tabs+ defaultValue="sql"+ groupId="reference/postgres"+ values={[{ label: 'SQL', value: 'sql' }]}>++<TabItem value="sql">++```sql+alter database postgres+set timezone to 'America/New_York';+```+++</TabItem>++</Tabs>++### Full list of timezones++Get a full list of timezones supported by your database. This will return the following columns:++- `name`: Time zone name+- `abbrev`: Time zone abbreviation+- `utc_offset`: Offset from UTC (positive means east of Greenwich)+- `is_dst`: True if currently observing daylight savings+++<Tabs+ defaultValue="sql"+ groupId="reference/postgres"+ values={[{ label: 'SQL', value: 'sql' }]}>++<TabItem value="sql">++```sql+select name, abbrev, utc_offset, is_dst+from pg_timezone_names()+order by name;+```+++</TabItem>++</Tabs>++### Search for a specific timezone++Use `ilike` (case insensitive search) to find specific timezones.++<Tabs+ defaultValue="sql"+ groupId="reference/postgres"+ values={[{ label: 'SQL', value: 'sql' }]}>++<TabItem value="sql">++```sql+select *+from pg_timezone_names()+where name ilike '%york%';+```+++</TabItem>++</Tabs>\ No newline at end of filediff --git a/web/docs/guides/database/replication.mdx b/web/docs/guides/database/replication.mdxnew file mode 100644index 00000000000..b4c54ce0756--- /dev/null+++ b/web/docs/guides/database/replication.mdx@@ -0,0 +1,232 @@+---+id: replication+title: "Replication"+slug: replication+---++import Tabs from '@theme/Tabs';+import TabItem from '@theme/TabItem';+++Replication is technique for copying the data from one database to another. This is useful for:++- Spreading out the "load". For example, if your database has a lot of reads, you might want to split it between two databases.+- Reducing latency. For example, you may want one database in London to serve your European customers, and one in New York to serve the US.+- In Supabase's case, we use the built-in replication functionality to provide a real-time API.++++## Publications++Publications are a way of choosing which changes should be sent to other systems (usually another Postgres database).+++### Managing Publications++Supabase provides an interface for manaing your publications, or you can use SQL.++<Tabs+defaultValue="UI"+values={[+ {label: 'UI', value: 'UI'},+ {label: 'SQL', value: 'SQL'},+]}>+<TabItem value="UI">++```sh+1. Go to the "Database" section.+2. Click on "Replication" in the sidebar.+3. Control which database events are sent by toggling the Insert/Update/Delete toggles.+4. Control which tables broadcast changes by clicking into the "Source" and toggling the tables.+```++<video width="99%" muted playsInline controls="true">+<source src="/videos/api/api-realtime.mp4" type="video/mp4" muted playsInline />+</video>++</TabItem>+<TabItem value="SQL">++```sql+alter publication supabase_realtime add table products;+```++</TabItem>+</Tabs>++### Create a Publication++This publication will contain all changes to all tables.+++<Tabs+ defaultValue="sql"+ groupId="reference/postgres"+ values={[{ label: 'SQL', value: 'sql' }]}>++<TabItem value="sql">++```sql+create publication publication_name+for all tables;+```+++</TabItem>++</Tabs>++### Create a Publication which listens to individual tables++++<Tabs+ defaultValue="sql"+ groupId="reference/postgres"+ values={[{ label: 'SQL', value: 'sql' }]}>++<TabItem value="sql">++```sql+create publication publication_name+for table table_one, table_two;+```+++</TabItem>++</Tabs>++### Add tables to an existing publication++++<Tabs+ defaultValue="sql"+ groupId="reference/postgres"+ values={[{ label: 'SQL', value: 'sql' }]}>++<TabItem value="sql">++```sql+alter publication publication_name+add table table_name;+```+++</TabItem>++</Tabs>++### Listen to `insert`++++<Tabs+ defaultValue="sql"+ groupId="reference/postgres"+ values={[{ label: 'SQL', value: 'sql' }]}>++<TabItem value="sql">++```sql+create publication publication_name+for all tables+with (publish = 'insert');+```+++</TabItem>++</Tabs>++### Listen to `update`++++<Tabs+ defaultValue="sql"+ groupId="reference/postgres"+ values={[{ label: 'SQL', value: 'sql' }]}>++<TabItem value="sql">++```sql+create publication publication_name+for all tables+with (publish = 'update');+```+++</TabItem>++</Tabs>++### Listen to `delete`++++<Tabs+ defaultValue="sql"+ groupId="reference/postgres"+ values={[{ label: 'SQL', value: 'sql' }]}>++<TabItem value="sql">++```sql+create publication publication_name+for all tables+with (publish = 'delete');+```+++</TabItem>++</Tabs>++### Remove a Publication++++<Tabs+ defaultValue="sql"+ groupId="reference/postgres"+ values={[{ label: 'SQL', value: 'sql' }]}>++<TabItem value="sql">++```sql+drop publication if exists publication_name;+```+++</TabItem>++</Tabs>++### Recreate a Publication++If you are planning to re-create a publication, it's best to do it in a transaction to ensure the operation succeeds.+++<Tabs+ defaultValue="sql"+ groupId="reference/postgres"+ values={[{ label: 'SQL', value: 'sql' }]}>++<TabItem value="sql">++```sql+begin;+ -- remove the realtime publication+ drop publication if exists publication_name;++ -- re-create the publication but don't enable it for any tables+ create publication publication_name;+commit;+```+++</TabItem>++</Tabs>\ No newline at end of filediff --git a/web/sidebars.js b/web/sidebars.jsindex af85d54856e..51101c00bdc 100755--- a/web/sidebars.js+++ b/web/sidebars.js@@ -84,8 +84,24 @@ module.exports = {label: 'Database',collapsed: false,items: [+ 'guides/database/introduction','guides/database/tables','guides/database/full-text-search',+ // 'guides/database/json',+ // 'guides/database/arrays',+ // 'guides/database/sql-to-api',+ {+ type: 'category',+ label: 'Extensions',+ collapsed: true,+ items: [+ 'guides/database/extensions',+ // 'guides/database/extensions/pgtap',+ 'guides/database/extensions/plv8',+ 'guides/database/extensions/http',+ 'guides/database/extensions/uuid-ossp',+ ],+ },{type: 'category',label: 'Connecting to Postgres',@@ -96,23 +112,17 @@ module.exports = {'guides/database/connecting/connection-pooling',],},- // 'guides/database/arrays',- // 'guides/database/json',- // 'guides/database/managing-passwords',- // 'guides/database/sql-to-api',{type: 'category',- label: 'Extensions',+ label: 'Configuration',collapsed: true,items: [- 'guides/database/extensions',- // 'guides/database/extensions/pgtap',- 'guides/database/extensions/plv8',- 'guides/database/extensions/http',- 'guides/database/extensions/uuid-ossp',+ 'guides/database/timeouts',+ 'guides/database/replication',+ 'guides/database/managing-passwords',+ 'guides/database/managing-timezones',],},- 'guides/database/resource-management',],},{