An evening journey of renaming a database column

Before we start

Pre-requisites for following along the example are:

  • Docker and docker-compose
  • Postman (or similar)
  • Postgres compatible client (if you want to inspect the database)
  • Flyway
  • Go
  • Download the repo

Step 0

The first step is to have a look at what we have to work with.

Step 1

Next step is to run our first real migration, run flyway migrate -target=1.

Step 2

From now on we have an application reading from both columns and writing to both columns, great!. But now we need to transform our “pre app.v2 era” data rows so that name no longer is null. For this we can run a one time script/app, where we at our own pace can copy missing name data from the title column.

Step 3

This is the last step. Run the migration flyway migrate -target=3. This step has two parts, one is to drop the column title which should only be done when you are completely sure you never want to use the title column again.

Journeys end

There are several variations of this process to achieve the same result, some more use-case dependent than others. It comes down to details like the size of your dataset and so on, but I hope someone finds this little toy-example useful and interesting.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store