<?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: Subodh Singh</title>
    <description>The latest articles on DEV Community by Subodh Singh (@subodh_singh_f89549296ce4).</description>
    <link>https://dev.to/subodh_singh_f89549296ce4</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4249332%2Ff948313e-3ea8-40f5-b34c-d7b3ba2a68b8.jpg</url>
      <title>DEV Community: Subodh Singh</title>
      <link>https://dev.to/subodh_singh_f89549296ce4</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/subodh_singh_f89549296ce4"/>
    <language>en</language>
    <item>
      <title>I Built a PostgreSQL Migration Linter to Catch Risky Schema Changes Before Deployment</title>
      <dc:creator>Subodh Singh</dc:creator>
      <pubDate>Tue, 17 Nov 2026 08:44:08 +0000</pubDate>
      <link>https://dev.to/subodh_singh_f89549296ce4/i-built-a-postgresql-migration-linter-to-catch-risky-schema-changes-before-deployment-2ffm</link>
      <guid>https://dev.to/subodh_singh_f89549296ce4/i-built-a-postgresql-migration-linter-to-catch-risky-schema-changes-before-deployment-2ffm</guid>
      <description>&lt;p&gt;PostgreSQL migrations can look harmless during code review but still cause problems when deployed to a busy production database.&lt;/p&gt;

&lt;p&gt;For example:&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;INDEX&lt;/span&gt; &lt;span class="n"&gt;idx_users_email&lt;/span&gt; &lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="nf"&gt;users&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;email&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This statement creates an index, but it can block writes while the index is being built.&lt;/p&gt;

&lt;p&gt;A safer alternative for many production workloads is:&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;INDEX&lt;/span&gt; &lt;span class="no"&gt;CONCURRENTLY&lt;/span&gt; &lt;span class="n"&gt;idx_users_email&lt;/span&gt; &lt;span class="k"&gt;ON&lt;/span&gt; &lt;span class="nf"&gt;users&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;email&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;However, developers must also ensure that concurrent index creation runs outside a transaction block.&lt;/p&gt;

&lt;h2&gt;
  
  
  Introducing pg-safe-migrate
&lt;/h2&gt;

&lt;p&gt;I built an open-source Node.js CLI called &lt;strong&gt;pg-safe-migrate&lt;/strong&gt; to identify common PostgreSQL migration risks before deployment.&lt;/p&gt;

&lt;p&gt;It uses PostgreSQL AST parsing through &lt;code&gt;libpg-query&lt;/code&gt;, rather than relying solely on regular expressions.&lt;/p&gt;

&lt;h3&gt;
  
  
  What it detects
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;PG001: CREATE INDEX without CONCURRENTLY&lt;/li&gt;
&lt;li&gt;PG002: DROP COLUMN&lt;/li&gt;
&lt;li&gt;PG003: ALTER COLUMN TYPE&lt;/li&gt;
&lt;li&gt;PG004: ADD COLUMN NOT NULL without DEFAULT&lt;/li&gt;
&lt;li&gt;PG005: ADD FOREIGN KEY without NOT VALID&lt;/li&gt;
&lt;li&gt;PG006: RENAME&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The CLI explains each finding and suggests a safer migration approach.&lt;/p&gt;

&lt;h2&gt;
  
  
  Try it yourself
&lt;/h2&gt;

&lt;p&gt;Install the package:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm install -D @subodh001/pg-safe-migrate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Run it against your migrations:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx pg-safe-migrate
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Or check changed SQL migrations:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx pg-safe-migrate --changed origin/main
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The tool supports Prisma, Drizzle, and raw SQL migration directories.&lt;/p&gt;

&lt;h2&gt;
  
  
  Why I built it
&lt;/h2&gt;

&lt;p&gt;I wanted a simple tool developers could run locally or in CI to catch potentially dangerous SQL changes before merging a pull request.&lt;/p&gt;

&lt;p&gt;The goal is not to replace database migration testing. It's to make common risks easier to notice during development.&lt;/p&gt;

&lt;h2&gt;
  
  
  Current limitations
&lt;/h2&gt;

&lt;p&gt;This is a static migration risk linter. It doesn't inspect live database state or guarantee zero downtime.&lt;/p&gt;

&lt;p&gt;The first public release includes six rules, Git-diff support, and GitHub Actions integration.&lt;/p&gt;

&lt;h2&gt;
  
  
  Open source
&lt;/h2&gt;

&lt;p&gt;GitHub: &lt;a href="https://github.com/subodhsingh001/pg-safe-migrate" rel="noopener noreferrer"&gt;https://github.com/subodhsingh001/pg-safe-migrate&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;npm: &lt;a href="https://www.npmjs.com/package/@subodh001/pg-safe-migrate" rel="noopener noreferrer"&gt;https://www.npmjs.com/package/@subodh001/pg-safe-migrate&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I'd appreciate feedback from PostgreSQL developers, particularly examples of false positives, missing safety rules, or ORM-specific migration problems.&lt;/p&gt;

</description>
      <category>cli</category>
      <category>database</category>
      <category>postgres</category>
      <category>sql</category>
    </item>
  </channel>
</rss>
