Login
You're viewing the ruby.social public feed.
  • Nov 21, 2026, 9:49 PM

    You can add a constraint in two parts with PostgreSQL: one for new data being added (not valid) and then later you can do `alter table ... validate constraint` to ensure that historical data is validated.

    I would have loved this in MySQL for making fields UNIQUE, something that was extremely toil-filled when I worked at Shopify.

    Anyway, I've added those 9 as NOT VALID so that we don't add _new_ invalid data, to give me a chance to clean up.

    💬 1🔄 1⭐ 1

Replies

  • Nov 21, 2026, 9:51 PM

    I wrote a simple query to find the `media_attachments` which are referencing accounts that no longer exist on our server. This took a long time, so I went to Home Depot to buy stuff I need for an IRL project.

    I got a text message to my phone about the chassis being too warm 😅 -- when I came back an hour later it hadn't finished.

    Then I rewrote the `IN` to be a `LEFT JOIN` and it ran in 9 seconds. Still got it.

    Some tables are bigger so I'll be carrying on this evening; just thought I'd share.

    💬 1🔄 1⭐ 0
  • Nov 22, 2026, 4:00 AM

    And we're done. High five to 2023's @insom -- working across the years to fix the data I fucked up.

    ```
    postgres=> select count(*) from pg_constraint where not convalidated;
    count
    -------
    0
    (1 row)
    ```

    💬 0🔄 0⭐ 0