‹ BackHN Continuity

Thread

Is your Postgres migration safe or not safe?

138 points · 45 comments · vira28

  1. vira28 · · focus · HN ↗
    Author here: Adding some context. I led the Postgres platform team (2019-23) at Cloudflare and we were supporting 170+ growing product teams. One of the constant asks is schema migration review. We published a lot of best practices, added CI checks however, it was still hard to catch. Also, I tried to explain the internals of how the locking (rewrite) works, but I realized most of the devs just want the answer - Is it safe or not safe to run?

    Not sure if it rings a bell, the name is a reference to the Silicon Valley Jian Yang's hot dog or not hot dog app.

    Also, I understand the decision of safe vs not-safe depends heavily on data/histogram and edge cases, but still quite a lot of low-hanging issues can be easily caught with a deterministic rule engine. So I ported pg_savior[1] and used sql parser from libpg-query-node[2] which compiles as WASM, so it entirely runs on the browser. No telemetry, no login. Source attached [3]

    [1] <a href="https:&#x2F;&#x2F;github.com&#x2F;viggy28&#x2F;pg_savior" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;viggy28&#x2F;pg_savior [2] <a href="https:&#x2F;&#x2F;github.com&#x2F;constructive-io&#x2F;libpg-query-node" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;constructive-io&#x2F;libpg-query-node [3] <a href="https:&#x2F;&#x2F;github.com&#x2F;viggy28&#x2F;safe-not-safe" rel="nofollow">https:&#x2F;&#x2F;github.com&#x2F;viggy28&#x2F;safe-not-safe

    1. necovek · · focus · HN ↗
      Wow, great idea!

      It&#x27;s not immediately clear from the README, but is it easy to run with multiple profiles like &quot;backwards-compatible&quot;, &quot;revertable&quot; (both data and schema) and &quot;destructive&quot; for that final clean-up in multi-staged no-downtime migrations? Basically common subsets of &quot;safe-ness&quot; of the schema migration queries.

      I imagine it can be tuned, but I&#x27;d love this for all my projects.

      And since I am currently on a project doing MS SQL (gasp), that&#x27;d be cool too ;)

      I am familiar with an &quot;is it a hot dog&quot; app from back in the day, bit would have never made the connection :)

      1. vira28 · · focus · HN ↗
        Thanks you.

        Certainly, there is a lot of room to improve the README. Overall the project is very much alpha.

        You&#x27;re right. Currently, it&#x27;s very binary. The answer is more nuanced and it should classify it based on the profiles like you mentioned.

        Also, I noticed parsers for other databases that compiles to WASM. So, all running on client side.

    2. paol · · focus · HN ↗
      This looks extremely useful.

      If you continue working on this a good direction to go in would be to package it as a command line tool, so it can be integrated into testing and release processes.

      1. vira28 · · focus · HN ↗
        Appreciate it. Will definitely add a CLI option for it.
Open on Hacker News to reply ↗

Unofficial Hacker News client; not affiliated with Y Combinator.