<?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>Forem: Andrey Karchevsky</title>
    <description>The latest articles on Forem by Andrey Karchevsky (@realkarych).</description>
    <link>https://forem.com/realkarych</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%2F3131029%2Fb05cc6c7-c67f-4195-828a-760ff6f0f19a.png</url>
      <title>Forem: Andrey Karchevsky</title>
      <link>https://forem.com/realkarych</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/realkarych"/>
    <language>en</language>
    <item>
      <title>Time to test our migrations! — Seqwall</title>
      <dc:creator>Andrey Karchevsky</dc:creator>
      <pubDate>Tue, 06 May 2025 20:39:25 +0000</pubDate>
      <link>https://forem.com/realkarych/time-to-test-our-migrations-3mf1</link>
      <guid>https://forem.com/realkarych/time-to-test-our-migrations-3mf1</guid>
      <description>&lt;p&gt;A few months ago, I started wondering: &lt;em&gt;“How should we actually test database migrations?”&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;(Yes, that thing no one really does.)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Well — sometimes people do test them, to be fair. The standard approach usually involves writing integration tests and checking how the application behaves with the new schema version.&lt;/p&gt;

&lt;p&gt;But honestly, that’s not nearly enough to ensure the migration itself is correct.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;A lot can go wrong:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;code&gt;ALTER TABLE&lt;/code&gt; &lt;em&gt;suddenly&lt;/em&gt; takes an &lt;code&gt;EXCLUSIVE ACCESS lock&lt;/code&gt; and production freezes until it’s done.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;An index works on your local machine — but silently &lt;em&gt;fails&lt;/em&gt; on prod.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;A migration wipes out data (someone forgot to delete a &lt;code&gt;DROP TABLE&lt;/code&gt; used for debugging), and the last dump was from the Mesozoic era.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;…&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There are many hypothetical issues like this — enough material for several talks.&lt;/p&gt;

&lt;p&gt;I decided to focus on something simple and fundamental:&lt;/p&gt;

&lt;p&gt;How do we validate that a migration is correct in terms of schema state?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;My reasoning&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A valid migration should:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;apply cleanly;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;be reversible (a downgrade should work);&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;be idempotent (you can apply/rollback it as many times as needed);&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;and most importantly — after a up + down, the schema should match the original, semantically.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;That led me to build a CLI tool that tests your migrations for schema correctness.&lt;/p&gt;

&lt;p&gt;You can read more about the methodology in the project’s repository.&lt;/p&gt;

&lt;p&gt;So I’d really appreciate your help: bug reports, issues, PRs — all welcome.&lt;/p&gt;

&lt;p&gt;👉 Seqwall on GitHub: &lt;a href="https://github.com/realkarych/seqwall" rel="noopener noreferrer"&gt;https://github.com/realkarych/seqwall&lt;/a&gt;&lt;/p&gt;

</description>
      <category>postgres</category>
      <category>database</category>
      <category>migrations</category>
      <category>go</category>
    </item>
  </channel>
</rss>
