<?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: Leo Blondel</title>
    <description>The latest articles on Forem by Leo Blondel (@leo_blondel_7428307667096).</description>
    <link>https://forem.com/leo_blondel_7428307667096</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%2F3725917%2F3c5c6e22-b8d7-4034-921b-2b1511fb0862.png</url>
      <title>Forem: Leo Blondel</title>
      <link>https://forem.com/leo_blondel_7428307667096</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/leo_blondel_7428307667096"/>
    <language>en</language>
    <item>
      <title>Squashing AdonisJS Migrations: A Tool I Built</title>
      <dc:creator>Leo Blondel</dc:creator>
      <pubDate>Thu, 22 Jan 2026 10:37:16 +0000</pubDate>
      <link>https://forem.com/leo_blondel_7428307667096/squashing-adonisjs-migrations-a-tool-i-built-444h</link>
      <guid>https://forem.com/leo_blondel_7428307667096/squashing-adonisjs-migrations-a-tool-i-built-444h</guid>
      <description>&lt;h2&gt;
  
  
  The Problem
&lt;/h2&gt;

&lt;p&gt;After years of development, AdonisJS projects often accumulate hundreds of migration files:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;🐌 Slow fresh deployments (running 100+ migrations)&lt;/li&gt;
&lt;li&gt;📂 Cluttered migration folders&lt;/li&gt;
&lt;li&gt;🔍 Hard to understand current schema&lt;/li&gt;
&lt;li&gt;🧹 No official way to consolidate like Django's &lt;code&gt;squashmigrations&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  The Solution
&lt;/h2&gt;

&lt;p&gt;I built &lt;strong&gt;&lt;a href="https://github.com/the-alien-club/adonis-lucid-migration-squash" rel="noopener noreferrer"&gt;adonis-lucid-migration-squash&lt;/a&gt;&lt;/strong&gt; to solve this!&lt;/p&gt;

&lt;h3&gt;
  
  
  What it does:
&lt;/h3&gt;

&lt;p&gt;Takes your PostgreSQL schema dump and converts it to a &lt;strong&gt;clean, single Knex migration&lt;/strong&gt; with:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;✅ Smart enum detection&lt;/li&gt;
&lt;li&gt;✅ Proper foreign keys &amp;amp; constraints&lt;/li&gt;
&lt;li&gt;✅ Automated verification&lt;/li&gt;
&lt;li&gt;✅ Complete up() and down() methods&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Quick Start:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="c"&gt;# 1. Dump your production schema&lt;/span&gt;
pg_dump &lt;span class="nt"&gt;-s&lt;/span&gt; &lt;span class="nt"&gt;--no-owner&lt;/span&gt; &lt;span class="nt"&gt;--no-acl&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; schema.sql

&lt;span class="c"&gt;# 2. Convert to Knex migration&lt;/span&gt;
python &lt;span class="nt"&gt;-m&lt;/span&gt; pg_to_knex schema.sql baseline_migration.ts

&lt;span class="c"&gt;# 3. Archive old migrations, use the baseline!&lt;/span&gt;
&lt;span class="nb"&gt;mv &lt;/span&gt;database/migrations/&lt;span class="k"&gt;*&lt;/span&gt;.ts database/archive/
&lt;span class="nb"&gt;mv &lt;/span&gt;baseline.ts database/migrations/1_baseline.ts
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Example Output:&lt;br&gt;
Instead of raw SQL, you get clean Knex code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;up&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;knex&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Knex&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nx"&gt;knex&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;schema&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createTable&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;users&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;table&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;table&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;uuid&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;id&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;primary&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="nx"&gt;table&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;string&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;email&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nf"&gt;notNullable&lt;/span&gt;&lt;span class="p"&gt;().&lt;/span&gt;&lt;span class="nf"&gt;unique&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
    &lt;span class="nx"&gt;table&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;enum&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;role&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;admin&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;user&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]).&lt;/span&gt;&lt;span class="nf"&gt;defaultTo&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;user&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
    &lt;span class="nx"&gt;table&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;timestamps&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="p"&gt;)&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;h2&gt;
  
  
  When to use it?
&lt;/h2&gt;

&lt;p&gt;✅ Before major version releases&lt;br&gt;
✅ When you have 50+ migrations&lt;br&gt;
✅ Creating a clean foundation&lt;br&gt;
✅ All environments are on the same version&lt;/p&gt;

&lt;h2&gt;
  
  
  Check it out!
&lt;/h2&gt;

&lt;p&gt;🔗 &lt;strong&gt;&lt;a href="https://github.com/the-alien-club/adonis-lucid-migration-squash" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt;&lt;/strong&gt; Would love to hear feedback from the AdonisJS community! 🚀 #adonisjs #nodejs #typescript #database #migrations&lt;/p&gt;

</description>
      <category>adonisjs</category>
      <category>typescript</category>
      <category>webdev</category>
      <category>database</category>
    </item>
  </channel>
</rss>
