<?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: Steve</title>
    <description>The latest articles on DEV Community by Steve (@swanny85).</description>
    <link>https://dev.to/swanny85</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%2F289778%2Fcdf70945-8a26-4e86-bdc4-5e54fb98a91f.jpg</url>
      <title>DEV Community: Steve</title>
      <link>https://dev.to/swanny85</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/swanny85"/>
    <language>en</language>
    <item>
      <title>Migrating a SQLite3 Database to PostgreSQL in Dokku</title>
      <dc:creator>Steve</dc:creator>
      <pubDate>Thu, 30 May 2024 17:35:36 +0000</pubDate>
      <link>https://dev.to/swanny85/migrating-a-sqlite3-database-to-postgresql-in-dokku-22j0</link>
      <guid>https://dev.to/swanny85/migrating-a-sqlite3-database-to-postgresql-in-dokku-22j0</guid>
      <description>&lt;p&gt;Migrating a SQLite3 database to PostgreSQL in a Dokku-managed environment involves several steps. This guide will walk you through the entire process, ensuring a smooth transition from SQLite3 to PostgreSQL.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Prerequisites&lt;/strong&gt;
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Dokku installed and running&lt;/li&gt;
&lt;li&gt;PostgreSQL service set up in Dokku&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;code&gt;pgloader&lt;/code&gt;&lt;/strong&gt; installed on your main server&lt;/li&gt;
&lt;li&gt;Access to your SQLite3 database file&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;Step-by-Step Guide&lt;/strong&gt;
&lt;/h2&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;1. Find the Location of the SQLite3 Database File&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;First, identify where the SQLite3 database file is stored. Use the following Dokku command to find the storage location:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;dokku storage:report &amp;lt;your_app_name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command will display information about the persistent storage used by your application. For example:&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="o"&gt;=====&amp;gt;&lt;/span&gt; webapp storage information
       Storage build mounts:
       Storage deploy mounts:         &lt;span class="nt"&gt;-v&lt;/span&gt; /var/lib/dokku/data/storage/webapp:/rails/storage
       Storage run mounts:            &lt;span class="nt"&gt;-v&lt;/span&gt; /var/lib/dokku/data/storage/webapp:/rails/storage
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the SQLite3 database file is located in &lt;strong&gt;&lt;code&gt;/var/lib/dokku/data/storage/webapp&lt;/code&gt;&lt;/strong&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;2. Install &lt;code&gt;pgloader&lt;/code&gt; on Your Main Server&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;If &lt;strong&gt;&lt;code&gt;pgloader&lt;/code&gt;&lt;/strong&gt; is not already installed, you can install it using the following command:&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;sudo &lt;/span&gt;apt-get update
&lt;span class="nb"&gt;sudo &lt;/span&gt;apt-get &lt;span class="nb"&gt;install &lt;/span&gt;pgloader
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;strong&gt;3. Retrieve PostgreSQL Connection Information&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Get the connection details for your PostgreSQL service. Run the following command to get the necessary information:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;dokku postgres:info &amp;lt;your_postgres_service_name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command will provide details including the DSN, internal IP, and port. For example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight swift"&gt;&lt;code&gt;&lt;span class="o"&gt;=====&amp;gt;&lt;/span&gt; &lt;span class="n"&gt;production&lt;/span&gt; &lt;span class="n"&gt;postgres&lt;/span&gt; &lt;span class="n"&gt;service&lt;/span&gt; &lt;span class="n"&gt;information&lt;/span&gt;
       &lt;span class="kt"&gt;Config&lt;/span&gt; &lt;span class="nv"&gt;dir&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;          &lt;span class="sr"&gt;/var/lib/dokku/services/postgres/production/&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;
       &lt;span class="kt"&gt;Data&lt;/span&gt; &lt;span class="nv"&gt;dir&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;            &lt;span class="sr"&gt;/var/lib/dokku/services/postgres/production/&lt;/span&gt;&lt;span class="n"&gt;data&lt;/span&gt;
       &lt;span class="kt"&gt;Dsn&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;                 &lt;span class="nv"&gt;postgres&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="c1"&gt;//postgres:&amp;lt;password&amp;gt;@dokku-postgres-production:5432/production&lt;/span&gt;
       &lt;span class="kt"&gt;Internal&lt;/span&gt; &lt;span class="nv"&gt;ip&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;         &lt;span class="mf"&gt;172.17&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="mf"&gt;0.6&lt;/span&gt;
       &lt;span class="kt"&gt;Status&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;              &lt;span class="n"&gt;running&lt;/span&gt;
       &lt;span class="kt"&gt;Version&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;             &lt;span class="nv"&gt;postgres&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="mf"&gt;16.2&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  &lt;strong&gt;4. Run &lt;code&gt;pgloader&lt;/code&gt;&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Use &lt;strong&gt;&lt;code&gt;pgloader&lt;/code&gt;&lt;/strong&gt; to migrate the SQLite3 database to PostgreSQL. Use the internal IP address instead of the hostname for the connection string.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;pgloader sqlite:///var/lib/dokku/data/storage/webapp/production.sqlite3 postgres://postgres:&amp;lt;password&amp;gt;@172.17.0.6:5432/production
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Replace &lt;strong&gt;&lt;code&gt;/var/lib/dokku/data/storage/webapp/production.sqlite3&lt;/code&gt;&lt;/strong&gt; with the path to your SQLite3 database file and &lt;strong&gt;&lt;code&gt;&amp;lt;password&amp;gt;&lt;/code&gt;&lt;/strong&gt; with the actual password.&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;strong&gt;5. Verify the Migration&lt;/strong&gt;
&lt;/h3&gt;

&lt;p&gt;Connect to your PostgreSQL database and verify that the data was imported correctly.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Connect to PostgreSQL&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;dokku postgres:connect &amp;lt;your_postgres_service_name&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;List Tables&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="err"&gt;\&lt;/span&gt;&lt;span class="n"&gt;dt&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Check Data in Specific Tables&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;To inspect the data in the &lt;strong&gt;&lt;code&gt;users&lt;/code&gt;&lt;/strong&gt; table, for example:&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight sql"&gt;&lt;code&gt;&lt;span class="k"&gt;SELECT&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="k"&gt;FROM&lt;/span&gt; &lt;span class="n"&gt;users&lt;/span&gt; &lt;span class="k"&gt;LIMIT&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;strong&gt;Check Data in the rails console.&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;dokku run webapp
bin/rails console
&lt;/code&gt;&lt;/pre&gt;

&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>dokku</category>
      <category>sqlite3</category>
      <category>postgres</category>
      <category>rails</category>
    </item>
    <item>
      <title>A couple things to think about when changing domains</title>
      <dc:creator>Steve</dc:creator>
      <pubDate>Wed, 15 Dec 2021 15:45:24 +0000</pubDate>
      <link>https://dev.to/swanny85/a-couple-things-to-think-about-when-changing-domains-243g</link>
      <guid>https://dev.to/swanny85/a-couple-things-to-think-about-when-changing-domains-243g</guid>
      <description>&lt;p&gt;My business is B2B and I was using the domain overdue.io for a while but wanted a .com.  overdue.com is for sale but the owner wants like $100k, I'd rather donate that to charity when I'm at the place where I can afford to drop that much on a domain name.  Regardless here are a couple things to think about when changing names.&lt;/p&gt;

&lt;p&gt;Are you keeping the old domain name and redirecting to the new one?  You're going to want to set that up to report a permanent redirect which I ended up doing in nginx.  &lt;/p&gt;

&lt;p&gt;But even before that think about the services that send information to your site.  Do you host an API?  Do you receive webhooks from Stripe, Postmark, or somewhere else?  Update those before you start redirecting as it will cause errors.  Stripe and many others will re-send the webhooks if they're unsuccessful.  &lt;/p&gt;

</description>
    </item>
    <item>
      <title>Well that was embarrassing.</title>
      <dc:creator>Steve</dc:creator>
      <pubDate>Sun, 08 Mar 2020 13:55:11 +0000</pubDate>
      <link>https://dev.to/swanny85/well-that-was-embarrassing-2ghg</link>
      <guid>https://dev.to/swanny85/well-that-was-embarrassing-2ghg</guid>
      <description>&lt;p&gt;The last few days I had been receiving errors when a new user would sign up to my site. It was a deserialization error that wasn't actually causing any problems.  Someone would sign up and &lt;code&gt;after_create&lt;/code&gt; they would receive a welcome message.  I decided to take a look at Google to see if I could find a fix for it.  &lt;/p&gt;

&lt;p&gt;What was happening was sidekiq was trying to complete the welcome message job so fast that it was running into errors as all of the information wasn't available in the database just yet. The fix I saw basically had the same explanation that made sense but I didn't look at the context of the original poster. They weren't sending welcome messages.  Their fix was to change &lt;code&gt;after_create&lt;/code&gt; to &lt;code&gt;after_commit&lt;/code&gt;.  As you may know, &lt;code&gt;after_create&lt;/code&gt; happens a total of once per user, &lt;code&gt;after_commit&lt;/code&gt; has no limits, it fires every time that user record is committed into the database.  DOH!&lt;/p&gt;

&lt;p&gt;The issue was found quickly and my users were apologized to and notified that this didn't affect any of their customers. It was definitely a reminder to slow down and take an extra few minutes to think about what you're about to deploy. Especially when you're the only check and balance and don't have a team to give you a quick "dummy check" as we called it in the Air Force. &lt;/p&gt;

&lt;p&gt;It's never fun messing something up, even if it was something that resulted in a customer needing to delete a few emails. Regardless it was a learning experience I thought I would share.&lt;/p&gt;

&lt;p&gt;Have an awesome week.&lt;/p&gt;

</description>
      <category>rails</category>
    </item>
    <item>
      <title>Rails 6 and ngrok</title>
      <dc:creator>Steve</dc:creator>
      <pubDate>Sat, 29 Feb 2020 15:18:15 +0000</pubDate>
      <link>https://dev.to/swanny85/rails-6-and-ngrok-219a</link>
      <guid>https://dev.to/swanny85/rails-6-and-ngrok-219a</guid>
      <description>&lt;p&gt;Long time lurker, first time caller.&lt;/p&gt;

&lt;p&gt;I just recently updated my failed payment application to Rails 6.  Went to use Ngrok to test some webhoooks and got an interesting little error.  Now, unless you specify a host in rails 6 everything except for localhost gets blocked.  Great new security feature.  Buuuut, what if I use ngrok regularly and don't have the paid version so I get a new address every time I run it? It's regex to the rescue.&lt;/p&gt;

&lt;p&gt;Simply open &lt;code&gt;config/environments/development.rb&lt;/code&gt; and then add &lt;code&gt;config.hosts &amp;lt;&amp;lt; /[a-z0-9]+\.ngrok\.io/&lt;/code&gt;super simple and awesome.&lt;/p&gt;

&lt;p&gt;Thought I'd keep it short.&lt;/p&gt;

&lt;p&gt;Have an awesome week.&lt;/p&gt;

</description>
      <category>rails</category>
      <category>ngrok</category>
      <category>ruby</category>
    </item>
  </channel>
</rss>
