Bespoke Projects + Core Schema Versioning Strategy #304
Replies: 3 comments 4 replies
-
Hi Matthew! I hadn't thought of it, but it's a great idea 💡 Would you be interested in writing an introduction to SQL migrations for the official website? Currently we only have a few lines about it in the "getting started" guide, but I think it's a topic that would deserve a better guide in itself. I know @DSMejantel recently had issues with migrations and ended up manually moving data from an old schema to a new one for his production application. Having a guide with common pittfalls, tips and tricks, and examples would really help. |
Beta Was this translation helpful? Give feedback.
-
Hi, Your method looks interesting. |
Beta Was this translation helpful? Give feedback.
-
Hi, It's because I have removed the files on the migrations folder ! So, we have to keep all the migrations files on this folder. |
Beta Was this translation helpful? Give feedback.
-
Overview
While making multiple projects, I wanted to have an underlying "core schema" shared across projects. The core schema allows the inheriting of common resources that are probably stable across multiple bespoke projects (resources such as people, accounts, roles, permissions, etc). The core schema won't change from project to project, but it may get enhanced over time (such as adding a middle name to people). Maintaining a clear versioning system would be nice. So here's a straightforward approach I've come up with to ensure both compatibility and clarity.
Versioning Format
To keep track of migrations across different projects, we can adopt a simple naming convention consisting of six initial integers. These encode both our core schema and the project version:
xxxxxx_description.sql
:xxxxxx
represents a six-digit number:Examples
Initial Setup
A new project integrating the initial version of our core schema and adding initial project-specific migrations:
001000_core_schema.sql
- Installs version 1.0 of core schema.001001_create_users_table.sql
- Adds a 'users' table to the project.Subsequent Updates
Updating the core schema and adding further modifications:
002000_core_schema.sql
- Updates to version 2.0 of core schema.002001_add_logging_feature.sql
- Adds logging capabilities to the project (project is now version 2.001 -- inheriting core schema version 2.0).New Projects, Up-to-date Core Schema
New projects may now look like this:
001000_core_schema.sql
002000_core_schema.sql
003000_core_schema.sql
- Installs version 3 of core schema.003001_modify_users_table.sql
- Makes modifications to the 'users' table (project is now version 3.001 -- denotes a core version of 3, and project sub-version of 1).Benefits
This simple naming convention provides a few benefits:
Thoughts?
Let me know your thoughts! Have you run into similar versioning issues with bespoke projects and the desire to maintain a core schema across them? How have you handled it? I'd love to hear your thoughts and experiences!
Matthew
Beta Was this translation helpful? Give feedback.
All reactions