top | item 43574735

(no title)

efxhoy | 11 months ago

The best practice way to swap fullname for firstname, lastname would be to:

  1. Migration that adds firstname and lastname columns will all nulls
  2. Deploy application code change to start populating firstname and lastname alongside fullname, still reading fullname in the code.
  3. backfill the firstname and lastname values with a script/command/migration
  4. change app code to read firstname and lastname and stop writing fullname
  5. drop the fullname column
I don't think there's a safe way to do all that in a single migration unless all your app code also lives in the database so it can be atomically deployed. If you have multiple app servers and do rolling deploys with no downtime I think it has to be done in these 5 steps.

discuss

order

MrMcCall|11 months ago

  6. ensure there are no nulls in firstname and lastname
  7. alter the columns to be NOT NULL
Because no non-statistician uses nullable columns, right?

Of course, some dbs (SQLServer?) infer NULL from the empty string, or am I misremembering?

Always having the columns be NOT NULL is a fundamental cheat, after always having a PK, or is that too old school for 2025?

efxhoy|11 months ago

There's nothing wrong with nullable fields when it's appropriate. When kids are born they don't have names. Not all users want to tell you their names. A null value is data too.