<?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: Travis</title>
    <description>The latest articles on DEV Community by Travis (@travisv).</description>
    <link>https://dev.to/travisv</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%2F353786%2Fda63aaf2-5a09-4ab2-9318-66977318917e.jpg</url>
      <title>DEV Community: Travis</title>
      <link>https://dev.to/travisv</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/travisv"/>
    <language>en</language>
    <item>
      <title>Stop Supabase Projects From Being Paused</title>
      <dc:creator>Travis</dc:creator>
      <pubDate>Fri, 27 Sep 2024 22:10:18 +0000</pubDate>
      <link>https://dev.to/travisv/stop-supabase-projects-from-being-paused-36nf</link>
      <guid>https://dev.to/travisv/stop-supabase-projects-from-being-paused-36nf</guid>
      <description>&lt;h2&gt;
  
  
  Keep Your Supabase Projects Active with Supabase Inactive Fix and Supabase Pause Prevention
&lt;/h2&gt;

&lt;p&gt;Supabase is a powerful backend-as-a-service platform built on top of Postgres, providing developers with database hosting, authentication, and other essential services. However, if you're running multiple side projects on Supabase, you've probably encountered the dreaded inactivity pause: if 7 days pass without activity, your Supabase project is paused, and the database becomes inactive.&lt;/p&gt;

&lt;p&gt;To help you avoid this, I've created two GitHub projects that automate database activity to prevent pauses: &lt;a href="https://github.com/travisvn/supabase-inactive-fix" rel="noopener noreferrer"&gt;Supabase Inactive Fix&lt;/a&gt;, written in Python, and &lt;a href="https://github.com/travisvn/supabase-pause-prevention" rel="noopener noreferrer"&gt;Supabase Pause Prevention&lt;/a&gt;, designed for Next.js projects. In this post, I'll walk you through how to set up and use these tools to keep your side projects running smoothly without manual intervention.&lt;/p&gt;

&lt;h3&gt;
  
  
  Why Supabase Pauses Inactive Projects
&lt;/h3&gt;

&lt;p&gt;Supabase pauses any project that doesn't see activity for 7 consecutive days. While this is a great cost-saving measure, it can cause frustration for developers with side projects or apps that aren't accessed frequently. When a project is paused, it takes some time for the database to come back online when you need it, slowing down development and user experience.&lt;/p&gt;

&lt;p&gt;The good news is you can keep your databases active by making automated calls to your projects, ensuring that activity is logged before the 7-day window ends.&lt;/p&gt;

&lt;h3&gt;
  
  
  Supabase Inactive Fix: A Python-Based Solution (Recommended)
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Supabase Inactive Fix&lt;/strong&gt; is a Python script designed to prevent your Supabase databases from going inactive. It works by making unique calls to each Supabase Postgres database you configure it to watch, ensuring that the necessary activity is logged. You can easily set it up to run as a cron job on any server or computer.&lt;/p&gt;

&lt;h4&gt;
  
  
  Key Features:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Written in Python for flexibility and ease of use.&lt;/li&gt;
&lt;li&gt;Can be configured to watch multiple databases.&lt;/li&gt;
&lt;li&gt;Runs as a scheduled cron job to automate the process.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Note: Supabase Inactive Fix will keep any Supabase project active — it's not limited to Python projects by any means&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h4&gt;
  
  
  How to Set Up Supabase Inactive Fix:
&lt;/h4&gt;

&lt;h5&gt;
  
  
  1. Clone the repository:
&lt;/h5&gt;

&lt;p&gt;Start by cloning the &lt;a href="https://github.com/travisvn/supabase-inactive-fix" rel="noopener noreferrer"&gt;Supabase Inactive Fix GitHub repo&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;git clone https://github.com/travisvn/supabase-inactive-fix
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h5&gt;
  
  
  2. Install Dependencies:
&lt;/h5&gt;

&lt;p&gt;Navigate to the project folder and install the required dependencies using &lt;em&gt;pip&lt;/em&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;cd &lt;/span&gt;supabase-inactive-fix
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;python &lt;span class="nt"&gt;-m&lt;/span&gt; venv venv
&lt;span class="nb"&gt;source &lt;/span&gt;venv/bin/activate  &lt;span class="c"&gt;# On Windows use `venv\Scripts\activate`&lt;/span&gt;
pip &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-r&lt;/span&gt; requirements.txt
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h5&gt;
  
  
  3. Configure Your Databases:
&lt;/h5&gt;

&lt;p&gt;Inside the project, there's a configuration file &lt;em&gt;config.json&lt;/em&gt; where you can add the Supabase databases you want to keep active. You'll need your Supabase project URL and API keys.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Database1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"supabase_url"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"https://your-supabase-url-1.supabase.co"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"supabase_key_env"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"SUPABASE_KEY_1"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="err"&gt;//&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;Use&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;environment&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;variable&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;for&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;the&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;key&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"table_name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"KeepAlive"&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Database2"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"supabase_url"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"https://your-supabase-url-2.supabase.co"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"supabase_key"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"your-direct-supabase-key"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;  &lt;/span&gt;&lt;span class="err"&gt;//&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;Directly&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;define&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;the&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;key&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"table_name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"keep-alive"&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h5&gt;
  
  
  4. Set Up a Cron Job:
&lt;/h5&gt;

&lt;p&gt;To ensure your databases stay active, schedule the script to run at least once a week. If you're using a Linux or Mac system, you can set up a cron job like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;crontab &lt;span class="nt"&gt;-e&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add the following line to run the script every day at midnight:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;0 0 &lt;span class="k"&gt;*&lt;/span&gt; &lt;span class="k"&gt;*&lt;/span&gt; 1,4 &lt;span class="nb"&gt;cd&lt;/span&gt; /path/to/your/project &lt;span class="o"&gt;&amp;amp;&amp;amp;&lt;/span&gt; /path/to/your/project/venv/bin/python main.py &lt;span class="o"&gt;&amp;gt;&amp;gt;&lt;/span&gt; /path/to/your/project/logfile.log 2&amp;gt;&amp;amp;1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This ensures that your Supabase databases will always have activity within the 7-day window, keeping them from being paused.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/travisvn/supabase-inactive-fix?tab=readme-ov-file#supabase-inactive-fix" rel="noopener noreferrer"&gt;View the README for a detailed explanation and walkthrough&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Supabase Pause Prevention: An Alternative Using Next.js
&lt;/h2&gt;

&lt;p&gt;For those who prefer working with Next.js, &lt;a href="https://github.com/travisvn/supabase-pause-prevention" rel="noopener noreferrer"&gt;Supabase Pause Prevention&lt;/a&gt; is another option. While not as streamlined as the Python solution, it serves the same purpose by making calls to the APIs of other projects in your Supabase setup, ensuring that each project records activity.&lt;/p&gt;

&lt;h4&gt;
  
  
  Key Features:
&lt;/h4&gt;

&lt;ul&gt;
&lt;li&gt;Designed specifically for Next.js projects using Supabase.&lt;/li&gt;
&lt;li&gt;Prevents project pauses by making API calls to keep databases active.&lt;/li&gt;
&lt;li&gt;Easy integration with your existing Next.js setup.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  How to Set Up Supabase Pause Prevention:
&lt;/h3&gt;

&lt;h3&gt;
  
  
  Solution / How it works
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;Creating a &lt;em&gt;cron job&lt;/em&gt; (scheduled task) that makes a simple database call

&lt;ul&gt;
&lt;li&gt;&lt;em&gt;(This keeps your Supabase project active)&lt;/em&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Fetching &lt;code&gt;keep-alive.ts&lt;/code&gt; API endpoints for the other projects, as Vercel limits free-tier users to one cron job.&lt;/li&gt;

&lt;/ul&gt;

&lt;h2&gt;
  
  
  Getting Started
&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Super simple to add to your existing Supabase project!&lt;/strong&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Configure your main project
&lt;/h3&gt;

&lt;p&gt;&lt;em&gt;Only 3 files matter&lt;/em&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;a href="//app/api/keep-alive/route.ts"&gt;&lt;code&gt;/app/api/keep-alive/route.ts&lt;/code&gt;&lt;/a&gt; - API endpoint the cron job will execute&lt;/li&gt;
&lt;li&gt;
&lt;a href="//app/api/keep-alive/helper.ts"&gt;&lt;code&gt;/app/api/keep-alive/helper.ts&lt;/code&gt;&lt;/a&gt; - Helper functions called from &lt;code&gt;route.ts&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href="//config/keep-alive-config.ts"&gt;&lt;code&gt;/config/keep-alive-config.ts&lt;/code&gt;&lt;/a&gt; - Configuration for your setup&lt;/li&gt;
&lt;li&gt;
&lt;a href="//vercel.json"&gt;&lt;code&gt;/vercel.json&lt;/code&gt;&lt;/a&gt; - Directs Vercel to periodically run the &lt;code&gt;keep-alive&lt;/code&gt; endpoint&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code&gt;utils/supabase&lt;/code&gt; folder contains files provided in the Supabase docs for the &lt;a href="https://supabase.com/docs/guides/getting-started/tutorials/with-nextjs" rel="noopener noreferrer"&gt;Next.js Web App demo — Supabase&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Everything else is boilerplate from Next.js &lt;code&gt;create-next-app&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Configuring your other Supabase projects
&lt;/h3&gt;

&lt;p&gt;After selecting your primary project &lt;em&gt;(the one that implements the code provided in this repository)&lt;/em&gt;, you'll want to add an API endpoint to your other Supabase projects&lt;/p&gt;

&lt;p&gt;The only requirement is that this endpoint is reachable and makes a call to your Supabase database&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;API endpoint must make database call&lt;br&gt;&lt;br&gt;
Ensure the server doesn't cache this&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://github.com/travisvn/supabase-pause-prevention/#configuring-your-other-supabase-projects" rel="noopener noreferrer"&gt;Refer to the README for more details here&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Sample SQL
&lt;/h3&gt;

&lt;p&gt;Any table and column can be called, but if you'd rather go with a generic, here's a SQL query for a &lt;code&gt;keep-alive&lt;/code&gt; table&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;CREATE&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="nv"&gt;"keep-alive"&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
  &lt;span class="n"&gt;id&lt;/span&gt; &lt;span class="nb"&gt;BIGINT&lt;/span&gt; &lt;span class="k"&gt;generated&lt;/span&gt; &lt;span class="k"&gt;BY&lt;/span&gt; &lt;span class="k"&gt;DEFAULT&lt;/span&gt; &lt;span class="k"&gt;AS&lt;/span&gt; &lt;span class="k"&gt;IDENTITY&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;name&lt;/span&gt; &lt;span class="nb"&gt;text&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt; &lt;span class="k"&gt;DEFAULT&lt;/span&gt; &lt;span class="s1"&gt;''&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt; &lt;span class="nb"&gt;text&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="n"&gt;random&lt;/span&gt; &lt;span class="n"&gt;uuid&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt; &lt;span class="k"&gt;DEFAULT&lt;/span&gt; &lt;span class="n"&gt;gen_random_uuid&lt;/span&gt; &lt;span class="p"&gt;(),&lt;/span&gt;
  &lt;span class="k"&gt;CONSTRAINT&lt;/span&gt; &lt;span class="nv"&gt;"keep-alive_pkey"&lt;/span&gt; &lt;span class="k"&gt;PRIMARY&lt;/span&gt; &lt;span class="k"&gt;key&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;id&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="k"&gt;INSERT&lt;/span&gt; &lt;span class="k"&gt;INTO&lt;/span&gt;
  &lt;span class="nv"&gt;"keep-alive"&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="k"&gt;VALUES&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'placeholder'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt;
  &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'example'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;It is now &lt;strong&gt;strongly recommended&lt;/strong&gt; to use a &lt;code&gt;keep-alive&lt;/code&gt; table like the one above.&lt;br&gt;&lt;br&gt;
This is in light of the added features for &lt;em&gt;optional&lt;/em&gt; database insertion &amp;amp; deletion actions&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://github.com/travisvn/supabase-pause-prevention/?tab=readme-ov-file#supabase-pause-prevention" rel="noopener noreferrer"&gt;View the README for a detailed explanation and walkthrough&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrapping it up
&lt;/h2&gt;

&lt;p&gt;Whether you choose to use Python or integrate into your existing Next.js project, &lt;strong&gt;Supabase Inactive Fix&lt;/strong&gt; and &lt;strong&gt;Supabase Pause Prevention&lt;/strong&gt; are both excellent ways to keep your Supabase databases from being paused due to inactivity. With just a few steps, you can set up automated scripts to ensure your projects are always online and ready for use.&lt;/p&gt;

&lt;p&gt;Check out the repositories on GitHub:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://github.com/travisvn/supabase-inactive-fix" rel="noopener noreferrer"&gt;Supabase Inactive Fix (Python)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://github.com/travisvn/supabase-pause-prevention" rel="noopener noreferrer"&gt;Supabase Pause Prevention (Next.js)&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Both of these tools are easy to set up and will save you the hassle of manually unpausing your databases every week. &lt;/p&gt;

&lt;p&gt;If you have any questions, feel free to leave a comment!&lt;/p&gt;

</description>
      <category>nextjs</category>
      <category>sideprojects</category>
      <category>postgres</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
