<?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: Andrey M.</title>
    <description>The latest articles on DEV Community by Andrey M. (@andrey_m).</description>
    <link>https://dev.to/andrey_m</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%2F4101118%2Fad70d9c9-9376-429a-bd93-f366bab3aa59.jpg</url>
      <title>DEV Community: Andrey M.</title>
      <link>https://dev.to/andrey_m</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/andrey_m"/>
    <language>en</language>
    <item>
      <title>A column changed type 8 days after I mapped it, and nothing told me</title>
      <dc:creator>Andrey M.</dc:creator>
      <pubDate>Sun, 30 Aug 2026 07:59:36 +0000</pubDate>
      <link>https://dev.to/andrey_m/a-column-changed-type-8-days-after-i-mapped-it-and-nothing-told-me-5a2n</link>
      <guid>https://dev.to/andrey_m/a-column-changed-type-8-days-after-i-mapped-it-and-nothing-told-me-5a2n</guid>
      <description>&lt;p&gt;I was rewriting a Java/Spring backend to Go. The database wasn't going anywhere — it&lt;br&gt;
already existed, with real data in it, and eighteen tables' worth of history behind it.&lt;br&gt;
The plan was simple: keep the schema, replace the service layer.&lt;/p&gt;

&lt;p&gt;Early on, &lt;code&gt;asset&lt;/code&gt; looked like this:&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;`asset`&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="nv"&gt;`id`&lt;/span&gt;    &lt;span class="nb"&gt;bigint&lt;/span&gt;       &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt; &lt;span class="n"&gt;AUTO_INCREMENT&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="p"&gt;...&lt;/span&gt;
    &lt;span class="nv"&gt;`value`&lt;/span&gt; &lt;span class="nb"&gt;int&lt;/span&gt;          &lt;span class="k"&gt;NOT&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;,&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="nv"&gt;`id`&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;I mapped it to a Go struct by hand, the way you do when you're moving fast and the table&lt;br&gt;
is right there on the screen:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="k"&gt;type&lt;/span&gt; &lt;span class="n"&gt;Asset&lt;/span&gt; &lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="n"&gt;ID&lt;/span&gt;    &lt;span class="kt"&gt;int64&lt;/span&gt;
    &lt;span class="n"&gt;Value&lt;/span&gt; &lt;span class="kt"&gt;int64&lt;/span&gt;
    &lt;span class="o"&gt;...&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Eight days later, a migration I wasn't looking at changed it:&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;ALTER&lt;/span&gt; &lt;span class="k"&gt;TABLE&lt;/span&gt; &lt;span class="nv"&gt;`asset`&lt;/span&gt;
    &lt;span class="n"&gt;CHANGE&lt;/span&gt; &lt;span class="nv"&gt;`value`&lt;/span&gt; &lt;span class="nv"&gt;`value`&lt;/span&gt; &lt;span class="nb"&gt;DECIMAL&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;19&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt; &lt;span class="k"&gt;DEFAULT&lt;/span&gt; &lt;span class="k"&gt;NULL&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;int NOT NULL&lt;/code&gt; became &lt;code&gt;decimal(19,2) NULL&lt;/code&gt;. Two changes at once, and my hand-written&lt;br&gt;
struct still said &lt;code&gt;int64&lt;/code&gt;, no pointer, no way to represent NULL. Nothing failed loudly —&lt;br&gt;
GORM will happily scan a decimal into an int64 and either round it or blow up on a NULL,&lt;br&gt;
depending on the day. It's the kind of bug that shows up as "why is this value off by a&lt;br&gt;
few cents" three weeks later, not as a compile error.&lt;/p&gt;

&lt;p&gt;That's when it clicked: I don't need a unit test for "does my Go struct still match the&lt;br&gt;
&lt;code&gt;asset&lt;/code&gt; table." I need something that reads the table and &lt;em&gt;tells&lt;/em&gt; me if it doesn't.&lt;/p&gt;

&lt;p&gt;So instead of writing the struct by hand, I pointed a small code generator I'd built for&lt;br&gt;
exactly this — reads live schema over JDBC, spits out Go structs — at the same database,&lt;br&gt;
and diffed the output against what I had. It caught &lt;code&gt;value&lt;/code&gt; immediately: wrong type,&lt;br&gt;
wrong nullability, no compile error to warn me.&lt;/p&gt;

&lt;p&gt;None of this is exotic. If you're doing DB-first Go with GORM, this is just what happens&lt;br&gt;
when the schema evolves and your structs are maintained by hand, by a human, on a Tuesday.&lt;br&gt;
The fix isn't "write more tests" — it's "stop hand-maintaining the mapping between a table&lt;br&gt;
and a struct, and regenerate it from the table instead." A unit test only catches what you&lt;br&gt;
thought to test. A schema read catches what actually changed.&lt;/p&gt;

&lt;p&gt;I ended up formalizing this into &lt;a href="https://github.com/panedrone/sqldalmaker" rel="noopener noreferrer"&gt;SQL DAL Maker&lt;/a&gt;&lt;br&gt;
— it reads live JDBC metadata and generates the DAO/model layer for Go (and a few other&lt;br&gt;
languages) from it, so the struct-vs-schema gap can't quietly reopen every time someone&lt;br&gt;
runs a migration. But the generator isn't really the point of this post. The point is:&lt;br&gt;
if your models are hand-typed and your schema isn't frozen, you already have this bug&lt;br&gt;
somewhere. You just haven't hit it yet.&lt;/p&gt;

</description>
      <category>go</category>
      <category>mysql</category>
      <category>gorm</category>
      <category>backend</category>
    </item>
  </channel>
</rss>
