<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Leo Romanovsky on Medium]]></title>
        <description><![CDATA[Stories by Leo Romanovsky on Medium]]></description>
        <link>https://medium.com/@leoromanovsky?source=rss-5db039197fcb------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*hNlITkiyKqspvttP1g1hDA.jpeg</url>
            <title>Stories by Leo Romanovsky on Medium</title>
            <link>https://medium.com/@leoromanovsky?source=rss-5db039197fcb------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Mon, 23 Nov 2026 16:56:03 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@leoromanovsky/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Launching full support for Postgres Identity columns in TypeORM]]></title>
            <link>https://leoromanovsky.medium.com/launching-full-support-for-postgres-identity-columns-in-typeorm-24fa38a96b6c?source=rss-5db039197fcb------2</link>
            <guid isPermaLink="false">https://medium.com/p/24fa38a96b6c</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[typeorm]]></category>
            <category><![CDATA[open-source]]></category>
            <category><![CDATA[postgres]]></category>
            <category><![CDATA[nodejs]]></category>
            <dc:creator><![CDATA[Leo Romanovsky]]></dc:creator>
            <pubDate>Wed, 24 Nov 2021 00:00:00 GMT</pubDate>
            <atom:updated>2021-11-29T15:02:48.908Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*vhRNyvii1GLpa3jvx6G4fA.jpeg" /></figure><p>Over my career I’ve heard from colleagues that PostgreSQL was their favorite RDBMS and having recently launched a successful product on Postgres which made extensive use of its fuzzy search capabilities I was looking forward to learning more to qualify these endorsements.</p><p>A <a href="https://news.ycombinator.com/item?id=29163319">recent Hacker News post</a> called <a href="https://hakibenita.com/postgresql-unknown-features">Lesser-known Postgres features</a> made the front page had a lot of great advice and community discussion.</p><p><strong>One particular section described how to prevent setting the value of an auto generated key caught my eye</strong>: a few days earlier one of my projects had accidentally written to the primary key of a table and put it into a bad state, unable to write additional rows.</p><p>This project uses <a href="https://typeorm.io/">TypeORM</a> — the research I did, included chatting with the project’s maintainer, informed me that identity columns were not well supported. Some <a href="https://github.com/typeorm/typeorm/pull/7741">efforts had been added recently</a> but were not extensible enough to provide all possible identity column options that the community desired: notably it was still not possible create identity columns on non-primary keys nor to use the GENERATED ALWAYS style which is a powerful way to prevent users from writing to identity columns:</p><pre>db=# INSERT INTO sale (id, sold_at, amount) VALUES (2, now(), 1000);<br>ERROR:  cannot insert into column &quot;id&quot;<br>DETAIL:  Column &quot;id&quot; is an identity column defined as GENERATED ALWAYS.</pre><p><a href="https://www.postgresql.org/docs/10/sql-createtable.html">Postgres itself has had this feature</a> for many years and recommends all developers use it instead of serial types.</p><p>I decided to work on having this new functionality accepted!</p><p><strong>Contributing to open source projects, as with any other work, should be done with an emphatic attitude towards the maintainer’s time.</strong> To improve the chances of my efforts being quickly accepted, my goal was to put together a well researched Pull Request in-line with the project’s norms. I made a plan for how to implement the new API by chatting with another developer who had flagged the same concern and we created suitable API. This was done <a href="https://typeorm.slack.com/archives/CCTEVJC8G/p1636621370078900">over Slack and Discord</a> and was overall a really fun experience — IMO much more productive than message board chats.</p><p><strong>Implementing code to a spec is the easy part of the job — as software engineers we must understand how to best serve customers.</strong> Getting our interfaces and design decisions should take longer than expected; we need to couple this investment by working quickly on executing the implementation.</p><p>I’m happy to report that my diff was accepted and will be available in the next release of TypeORM — <a href="https://github.com/typeorm/typeorm/pull/8371">https://github.com/typeorm/typeorm/pull/8371</a></p><h3>The New API</h3><p>If you are wanting to create identity columns in Postgres two enhanced decorators are available:</p><ul><li>@PrimaryGeneratedColumn(&#39;identity&#39;...)</li><li>@Column({generated: &#39;identity&#39;, ...</li></ul><p>An example showing the various permutations and defaults:</p><pre>@Entity()<br>export class User {<br>  @PrimaryGeneratedColumn(&#39;identity&#39;, { generatedIdentity: &#39;ALWAYS&#39; })<br>  id: number;</pre><pre>@Column({<br>    type: &#39;bigint&#39;,<br>    generated: &#39;identity&#39;,<br>    generatedIdentity: &#39;ALWAYS&#39;,<br>  })<br>  secondId: number;</pre><pre>@Column({<br>    type: &#39;int&#39;,<br>    generated: &#39;identity&#39;,<br>    generatedIdentity: &#39;BY DEFAULT&#39;,<br>  })<br>  thirdId: number;</pre><pre>@Column({<br>    type: &#39;int&#39;,<br>    generated: &#39;identity&#39;,<br>  })<br>  fourthId: number;<br>}</pre><ul><li>You can chose any valid column type that Postgres allows for an identity column: smallint, int, bigint</li><li>Omitted a value for generatedIdentity defaults to BY DEFAULT to maintain the API contract of the previous implementation</li></ul><p>The model in the example generates this migration:</p><pre>CREATE TABLE &quot;user&quot; (<br>  &quot;id&quot; bigint GENERATED ALWAYS AS IDENTITY NOT NULL,<br>  &quot;secondId&quot; integer GENERATED ALWAYS AS IDENTITY NOT NULL,<br>  &quot;thirdId&quot; integer GENERATED BY DEFAULT AS IDENTITY NOT NULL,<br>  &quot;fourthId&quot; integer GENERATED BY DEFAULT AS IDENTITY NOT NULL,<br>CONSTRAINT &quot;PK_cace4a159ff9f2512dd42373760&quot; PRIMARY KEY (&quot;id&quot;))</pre><h3>How to migrate an existing model with serial columns</h3><p>If you are wishing to migrate any existing serial column to identity plan carefully for this change and reference this excellent answer on StackOverflow:</p><p><a href="https://stackoverflow.com/a/59233169">https://stackoverflow.com/a/59233169</a></p><h3>Next steps</h3><p>I’m excited to see the use of IDENTITY columns become more broadly used in TypeORM projects. Please reach out with improvements or questions.</p><p><em>Originally published at </em><a href="https://leoromanovsky.com/posts/postgres-identity-columns-in-typeorm"><em>https://leoromanovsky.com</em></a><em> on November 24, 2021.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=24fa38a96b6c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Blog without an Author: TypeORM creates confusion with required Columns and optional Foreign Keys]]></title>
            <link>https://leoromanovsky.medium.com/a-blog-without-an-author-typeorm-creates-confusion-with-required-columns-and-optional-foreign-keys-1a3f932d4e67?source=rss-5db039197fcb------2</link>
            <guid isPermaLink="false">https://medium.com/p/1a3f932d4e67</guid>
            <category><![CDATA[typeorm]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[orm]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Leo Romanovsky]]></dc:creator>
            <pubDate>Sat, 30 Oct 2021 18:06:43 GMT</pubDate>
            <atom:updated>2021-10-30T18:06:43.060Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ZVeYVL7pbbsm3UsyIPvnoQ.jpeg" /></figure><p>Storing data is one of the most critical choices we make when creating software and services.</p><p>We rely on our database schemas to enforce a service’s rules and a wrong column type or misconfiguration opens us up to subtle bugs, degrading our work in the eyes of customers.</p><p>Consider the case of a row with a foreign key but whose stored value is NULL - if accidental, the relationship between objects is forever lost.</p><p>From a customer’s perspective this manifests itself as storing an object, such as me hitting <strong>Publish</strong> on this blog, but later not being able to retrieve it.</p><h3>The problem with TypeORM models</h3><p>The <a href="https://typeorm.io/">most popular Javascript ORM in the Node ecosystem</a> surprised me recently with what I believe to be bad design choices.</p><p>Illustrating my findings interactively, below are two model definitions from the framework — I’d like you to guess what the table DDL will look like.</p><p>Pay particular attention to the required columns and foreign keys; scroll down for a deeper dive.</p><pre>@Entity()<br>export class User {<br>  @PrimaryGeneratedColumn()<br>  id: number;<br> <br>  @Column()<br>  firstName: string;<br> <br>  @Column({ nullable: false })<br>  lastName: string;<br> <br>  @Column({ nullable: true })<br>  birthDate: string;<br> <br>  @Column({ default: true })<br>  isActive: boolean;<br> <br>  @OneToMany(() =&gt; Post, (post) =&gt; post.user)<br>  posts: Post[];<br>}<br> <br>@Entity()<br>export class Post {<br>  @PrimaryGeneratedColumn()<br>  id: number;<br> <br>  @Column({ nullable: false })<br>  title: string;<br> <br>  @ManyToOne(() =&gt; User, {<br>    eager: true,<br>  })<br>  @JoinColumn({ name: &#39;user_id&#39; })<br>  user: User;<br>}</pre><p>The TypeORM migration program produces surprising output:</p><pre>CREATE TABLE &quot;user&quot; (<br>  &quot;id&quot; SERIAL NOT NULL, <br>  &quot;first_name&quot; character varying NOT NULL, # required!<br>  &quot;last_name&quot; character varying NOT NULL, <br>  &quot;birth_date&quot; character varying, <br>  &quot;is_active&quot; boolean NOT NULL DEFAULT true, <br>  CONSTRAINT &quot;PK_cace4a159ff9f2512dd42373760&quot;<br>  PRIMARY KEY (&quot;id&quot;)<br>)<br> <br>    <br>CREATE TABLE &quot;post&quot; (<br>  &quot;id&quot; SERIAL NOT NULL, <br>  &quot;title&quot; character varying NOT NULL, <br>  &quot;user_id&quot; integer, # not required!<br>  CONSTRAINT &quot;PK_be5fda3aac270b134ff9c21cdee&quot;<br>  PRIMARY KEY (&quot;id&quot;)<br>)<br> <br>ALTER TABLE &quot;post&quot;<br>ADD CONSTRAINT &quot;FK_52378a74ae3724bcab44036645b&quot;<br>FOREIGN KEY (&quot;user_id&quot;) <br>REFERENCES &quot;user&quot;(&quot;id&quot;) ON DELETE NO ACTION ON UPDATE NO ACTION</pre><ul><li>Did you expect firstName to be a required field? What about the model definition tipped you off?</li><li>Does it make sense for a Post not to have a User?</li></ul><h3>Unintuitive defaults lead to bugs</h3><p>In the code above we saw unexpected results when relying on TypeORM’s default parameters. Consider this application code that we would produce from it.</p><p><strong>Missing foreign key</strong></p><pre>const us = UserService.find(1)</pre><pre>const post = PostFactory.create(&#39;title&#39;, &#39;content&#39;)<br>await PostService.save(post)</pre><p>A critical bug created where the Post is disconnected from the User that owns it.</p><p><strong>Over-requirement of columns</strong></p><p>The developer only specified lastName as a required field so why is the code failing to save?</p><pre>const user = new User()<br>user.lastName = &#39;surname&#39;<br>user.save() # fails!</pre><p>The database will produce a failure to save the model since firstName is required as well.</p><h4><strong>The best code should not include any comments describing its behavior</strong></h4><p>A quick scan suffices to intuit how it fits into the larger picture.</p><p>Nowhere is this more important than how data is stored and accessed by your application.</p><p>I don’t think this is a case of “Read the Freaking Manual” — After working in a codebase for an extended period of time we do learn its peculiarities. It would be acceptable if TypeORM picked a path but <strong><em>my biggest gripe is the inconsistent behavior between regular and join columns</em></strong>.</p><p>I think that the TypeORM project made mistakes with their API; alas it has been downloaded millions of times. Is there any way it can be reversed?</p><p>For a tool we can’t control I’m going to focus on working with it — learning to mitigate its quirks.</p><h3>Ruby on Rails gets it right</h3><p>I used to work heavily in this framework and left feeling jaded. Looking back I recognize the hallmarks of a mature and well considered tool.</p><h3>Model definitions only include required fields</h3><pre># app/model/product.rb<br> <br>class Product &lt; ActiveRecord::Base<br>  validates :flag, :presence =&gt; true<br>end</pre><p>From looking just at the model, we can’t immediately tell what optional columns exist but we sure know which are necessary to save it. Rails expresses itself with brevity.</p><h3>Columns are nullable by default</h3><pre># migration ORM<br>create_table(:objects, primary_key: &#39;guid&#39;) do |t|<br>  t.column :name, :string, limit: 80<br>end</pre><pre># generated DDL<br>CREATE TABLE objects (<br>  guid bigint auto_increment PRIMARY KEY,<br>  name varchar(80)<br>)</pre><h3>Foreign keys are not nullable by default</h3><pre># migration ORM<br>create_join_table :products, :categories do |t|<br>  t.index :product_id<br>  t.index :category_id<br>end</pre><pre># generated DDL<br>CREATE TABLE products_categories (<br>  product_id int NOT NULL,<br>  category_id int NOT NULL,<br>)</pre><p>While Rails also exhibits inconsistent behavior I believe the defaults are more inline with what a developer would have picked anyways. In particular requiring the values of foreign keys to be populated avoids broken relationship between models.</p><h3>Moving forward with TypeORM</h3><p>I’ve been exploring <a href="https://www.prisma.io/docs/concepts/more/comparisons/prisma-and-typeorm">Prisma</a> and look forward to writing up my experiences in a future post.</p><p>For now I plan on explicitly calling out nullable on all my @Column and @JoinTable TypeORM decorators to make clear to myself and peers the intended usage of each attribute.</p><pre>@Entity()<br>export class User {<br>  @PrimaryGeneratedColumn()<br>  id: number;<br> <br>  @Column({ nullable: false })<br>  firstName: string;<br> <br>  @Column({ nullable: false })<br>  lastName: string;<br> <br>  @Column({ nullable: true })<br>  birthDate: string;<br> <br>  @Column({ default: true })<br>  isActive: boolean;<br> <br>  @OneToMany(() =&gt; Post, (post) =&gt; post.user)<br>  posts: Post[];<br>}<br> <br>@Entity()<br>export class Post {<br>  @PrimaryGeneratedColumn()<br>  id: number;<br> <br>  @Column({ nullable: false })<br>  title: string;<br> <br>  @ManyToOne(() =&gt; User, {<br>    eager: true,<br>    nullable: false,<br>  })<br>  @JoinColumn({ name: &#39;user_id&#39; })<br>  user: User;<br>}</pre><h3>Wrapping Up</h3><p>I was reminded this week that while I enjoy delivering quickly and not always sweating the details, our computer code is also a means of communication between current and future peers.</p><p>As your team and product grows, consider the APIs you create less as short-term necessities but as guardrails around acceptable and repeated usage.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1a3f932d4e67" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Joining Eppo]]></title>
            <link>https://leoromanovsky.medium.com/joining-eppo-55684f935b2d?source=rss-5db039197fcb------2</link>
            <guid isPermaLink="false">https://medium.com/p/55684f935b2d</guid>
            <category><![CDATA[announcements]]></category>
            <dc:creator><![CDATA[Leo Romanovsky]]></dc:creator>
            <pubDate>Mon, 23 Aug 2021 15:34:47 GMT</pubDate>
            <atom:updated>2021-08-23T15:34:47.878Z</atom:updated>
            <content:encoded><![CDATA[<p>I’m excited to announce that I’m joining Eppo to build the next generation of A/B experimentation tooling.</p><h3>Disconnect between large and small companies</h3><p>I’ve split my career between growing (Ticketfly, Strava) and mature (Uber, Slack) companies and have seen first hand the tremendous advantages businesses receive from their product teams quickly iterating with confidence knowing the key metrics are marching forward.</p><p>Head and <a href="https://eng.uber.com/experimentation-platform/">shoulders above others is Uber’s XP</a>— I still remember the awe I had the first time I tried merging code into their platform. Developers are guided through an A/B test proving the changes they request would have only positive impact on revenue, rider satisfaction and other factors. This kind of flywheel encourages constant experimentation and gives business leaders confidence that their organization is continuously improving.</p><h3>Companies are reinventing the wheel</h3><p>Having built the first iteration of Feature flagging tools at Strava, I saw the enormously cultural shift that happens at companies who move to iterating on their product offerings.</p><p><strong>However feature flagging is not enough</strong> — smaller firms still lack the confidence that their new changes are having a measurable positive impact on the business. The only possible solution is building a large team of analysts and developing in-house tools but they would be better served with a leading solution and focusing on their core business.</p><p>The end result is that only large companies have access to mature experimentation tools leaving an unleveled playing field and a gap that growing firms will struggle to breach.</p><h3>Early Team</h3><p>I’ve been thrilled with the<a href="https://www.notion.so/eppo/Why-I-started-Eppo-855f757c69da4a7db49b0d23e7e55b51"> team Che has built at Eppo so far</a>. I knew Carlin from our time working together at Strava and <a href="https://carlineng.medium.com/why-im-joining-eppo-fb2fecc890ba">followed his career to Sales at Snowflake</a> where he rounded out his engineering skills with a unique perspective.</p><p>Eppo is supported by investors at Amplify Partners and is among a portfolio of leading Data Tools companies.</p><p>If you’re interested in being part of a world-class team building the future of experimentation, visit us at <a href="https://www.geteppo.com/">geteppo.com</a>, or drop me a note at <a href="/service/mailto:leo@geteppo.com">leo@geteppo.com</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=55684f935b2d" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>