Home / Companies / Octopus Deploy / Blog / Post Details
Content Deep Dive

Database migrations lessons learned

Blog post from Octopus Deploy

Post Details
Company
Date Published
Author
Frank Lin
Word Count
967
Language
English
Hacker News Points
-
Summary

Database migrations, also known as schema migrations or script-based updates, are essential in keeping application databases up-to-date with minimal risk, as demonstrated by Octopus Deploy's extensive experience. These migrations involve using scripts to ensure the persisted data's structure evolves consistently with application changes, thus preventing the application code from managing every possible version of the data. Various frameworks, such as NodeJS, Django, and Ruby on Rails, support migration scripts, often with rollback capabilities. Key lessons from Octopus Deploy's decade-long experience include isolating migration scripts from production code to prevent future dependencies, avoiding deserialization to simplify the process, and rigorously testing individual scripts to ensure reliability. Running long migrations online can reduce downtime, though it introduces challenges in maintaining database consistency across different states. Additionally, versioning documents separately from schema changes can offer flexibility, especially for teams using object-relational mappers or document databases.