<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Grover Sean Reyes</title>
    <description>The latest articles on DEV Community by Grover Sean Reyes (@yobyob).</description>
    <link>https://dev.to/yobyob</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F78793%2Fe97c734f-006b-4a60-be12-1cdf2ec6d864.png</url>
      <title>DEV Community: Grover Sean Reyes</title>
      <link>https://dev.to/yobyob</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/yobyob"/>
    <language>en</language>
    <item>
      <title>I tried to locally-host supabase and followed the production recommendations</title>
      <dc:creator>Grover Sean Reyes</dc:creator>
      <pubDate>Sat, 24 Dec 2022 22:55:54 +0000</pubDate>
      <link>https://dev.to/yobyob/i-tried-to-locally-host-supabase-and-followed-the-production-recommendations-7oe</link>
      <guid>https://dev.to/yobyob/i-tried-to-locally-host-supabase-and-followed-the-production-recommendations-7oe</guid>
      <description>&lt;p&gt;This is more like my experiences in setting up supabase and some docker configuration stuff... I'm just basically exploring some stuff.&lt;/p&gt;

&lt;p&gt;Supabase local-hosting basically uses docker to do &lt;br&gt;
everything...&lt;br&gt;
while I also use docker for local development, specifically the &lt;code&gt;devilbox&lt;/code&gt; instance. (which already has pgsql running)&lt;/p&gt;

&lt;p&gt;Anyways, Supabase recommend decoupling the pg-database&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;It is recommended that you decouple your database from the middleware so that you can upgrade the middleware without any downtime. The "middleware" is everything except Postgres, and it should work with any Postgres provider (such as AWS RDS), or your own Postgres cluster.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So I tried it,&lt;/p&gt;

&lt;p&gt;First thing I had to do was add this to my .env file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;## DB Connection to use Devilbox pgsql
POSTGRES_HOST=pgsql
POSTGRES_DB=supabase
POSTGRES_USER=postgres
POSTGRES_PASSWORD=1234
POSTGRES_PORT=5432
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;now I had to remove the entire &lt;code&gt;db&lt;/code&gt; section on the &lt;code&gt;docker-compose.yml&lt;/code&gt; file&lt;br&gt;
and replace it with a network config&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;networks:  
  devilbox_app_net:    
    external: true
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;this network configuration should allow supabase to connect to my devilbox docker bridge network&lt;/p&gt;

&lt;p&gt;With this added I had to add a networks config for every container that needs to connect to devilbox-pgsql&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;auth:
  ...
  networks:      
    - devilbox_app_net
  ...
rest:
  ...
  networks:      
    - devilbox_app_net
  ...
realtime:
  ...
  networks:      
    - devilbox_app_net
  ...
storage:
  ...
  networks:      
    - devilbox_app_net
  ...
meta:
  ...
  networks:      
    - devilbox_app_net
  ...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now I had to change all connection-url string that is used in the &lt;code&gt;docker-compose.yml&lt;/code&gt; file&lt;/p&gt;

&lt;p&gt;from &lt;code&gt;postgres://postgres:${POSTGRES_PASSWORD}@db:5432/postgres&lt;/code&gt;&lt;br&gt;
to &lt;code&gt;postgresql://${POSTGRES_USER}@${POSTGRES_HOST}:${POSTGRES_PORT}/${POSTGRES_DB}&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;I also had to change &lt;code&gt;realtime&lt;/code&gt; environments to use &lt;code&gt;POSTGRES_*&lt;/code&gt; environment values&lt;/p&gt;

&lt;p&gt;with all those stuff changed...&lt;/p&gt;

&lt;p&gt;I then need to manually install the pgsql extensions needed for supabase to run...&lt;/p&gt;

&lt;p&gt;&lt;a href="https://supabase.com/docs/guides/self-hosting#extensions" rel="noopener noreferrer"&gt;https://supabase.com/docs/guides/self-hosting#extensions&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;there was no problem installing &lt;code&gt;uuid-ossp&lt;/code&gt; and &lt;code&gt;pgcrypto&lt;/code&gt; because they are already in devilbox postgres container.&lt;br&gt;
the problem is &lt;code&gt;pgjwt&lt;/code&gt; because it's not... I had to manually copy the extension files from host machine to the container and make sure it's in the right directory which is &lt;br&gt;
&lt;code&gt;/usr/local/share/postgresql/extension&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;extension files can be found in this repository &lt;a href="https://github.com/michelp/pgjwt" rel="noopener noreferrer"&gt;https://github.com/michelp/pgjwt&lt;/a&gt; and the important files that I copied are the following:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;pgjwt--0.1.0--0.1.1.sql&lt;/li&gt;
&lt;li&gt;pgjwt--0.1.1--0.2.0.sql&lt;/li&gt;
&lt;li&gt;pgjwt--0.1.1.sql&lt;/li&gt;
&lt;li&gt;pgjwt.control&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;After copying those files I was finally able to install the last extension (&lt;code&gt;pgjwt&lt;/code&gt;)&lt;/p&gt;

&lt;p&gt;After making sure that all 3 extensions are properly installed in the devilbox postgres instance,&lt;/p&gt;

&lt;p&gt;I had to configure another thing again... &lt;/p&gt;

&lt;p&gt;the devilbox postgres should be configured to have a &lt;code&gt;wal_level&lt;/code&gt; of &lt;code&gt;logical&lt;/code&gt; because if not &lt;code&gt;supabase_realtime&lt;/code&gt; will scream at you. so I fixed that by putting this on my devilbox docker-compose.yml file, under the &lt;code&gt;pgsql&lt;/code&gt; container configurations.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;command: [ "postgres", "-c", "wal_level=logical" ]&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You might think I'm done!... but I'm not... I'm still stuck!&lt;/p&gt;

&lt;p&gt;I'm gettings this error from &lt;code&gt;supabase_realtime&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;could not access file "wal2json": No such file or directory&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;this means that I had to install a wal2json plugin for postgres... installing a plugin on a docker container instance that does not have a &lt;code&gt;make&lt;/code&gt; command is really hard, and up to this point, I got tired and just gave up...&lt;/p&gt;

&lt;p&gt;I know I'm almost there, but the fact the it took this much configuration to just change a database instance literally took me a whole night to research and find solutions.&lt;/p&gt;

&lt;p&gt;It's already 6:00 AM! and it's Christmas Morning, I need to sleep!&lt;/p&gt;

&lt;p&gt;PS. I started tinkering around 10:00 PM, also this is my first &lt;code&gt;Dev&lt;/code&gt; post&lt;/p&gt;

</description>
      <category>softwaredevelopment</category>
      <category>tooling</category>
    </item>
  </channel>
</rss>
