Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added clarification for why the migrations are done the way they are … #508

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

Patrick-Pimentel-Bitwarden

🎟️ Tracking

📔 Objective

Added clarification explaining why the migrations are done the way they are done.

⏰ Reminders before review

  • Contributor guidelines followed
  • All formatters and local linters executed and passed
  • Written new unit and / or integration tests where applicable
  • Protected functional changes with optionality (feature flags)
  • Used internationalization (i18n) for all UI strings
  • CI builds passed
  • Communicated to DevOps any deployment requirements
  • Updated any necessary documentation (Confluence, contributing docs) or informed the documentation
    team

🦮 Reviewer guidelines

  • 👍 (:+1:) or similar for great changes
  • 📝 (:memo:) or ℹ️ (:information_source:) for notes or general info
  • ❓ (:question:) for questions
  • 🤔 (:thinking:) or 💭 (:thought_balloon:) for more open inquiry that's not quite a confirmed
    issue and could potentially benefit from discussion
  • 🎨 (:art:) for suggestions / improvements
  • ❌ (:x:) or ⚠️ (:warning:) for more significant problems or concerns needing attention
  • 🌱 (:seedling:) or ♻️ (:recycle:) for future improvements or indications of technical debt
  • ⛏ (:pick:) for minor or nitpick changes

Copy link

github-actions bot commented Jan 2, 2025

Logo
Checkmarx One – Scan Summary & Detailsfa869b17-cd66-4c8e-9b67-8b3b48f586f6

No New Or Fixed Issues Found

@Patrick-Pimentel-Bitwarden Patrick-Pimentel-Bitwarden marked this pull request as ready for review January 2, 2025 22:13
@Patrick-Pimentel-Bitwarden Patrick-Pimentel-Bitwarden requested a review from a team as a code owner January 2, 2025 22:13
Copy link
Contributor

@withinfocus withinfocus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's coverage of this at https://contributing.bitwarden.com/contributing/database-migrations/edd as well and I see it's linked right above this -- is this perhaps duplicative?

Also, not sure why CF Pages didn't deploy this for previewing, may need to check with BRE.


This directory is used for storing migration scripts that will be executed to transition the
database from its current state to the new state as defined in `src/Sql/dbo`. Each script must be
prefixed with the current date to ensure they are run in the correct order. These scripts are
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
prefixed with the current date to ensure they are run in the correct order. These scripts are
prefixed with the current date to ensure they are executed in the correct order. These scripts are

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I reread through edd link you sent again and I think I still feel like if someone asked: "Why do we create a separate stored procedure file in the src/Sql/.../dbo/Stored Procedures from the stored procedure in the migration file" I'm not sure what line/paragraph of that documentation I would quote or reference. I was aiming to add a line explaining/justifying why we do that explicitly. If I'm missing something would you mind pointing to what explains that?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I read the "Migrations" section on the EDD page it's covering what you briefly summarized in your expansion of step 2 here. Step 1's expanded content could probably be mentioned there as well, with the mention of "current state".

I think I reacted to this being related to EDD and the content there in part because of your language around "current" and "intended" -- those terms are true at the moment in time of the change. This is subtle but important, because what's in that (what I call "master") file today isn't what was in it when a migration a year ago was added. Additionally, we keep the master files to serve as a lint / validation step more than anything, to ensure migrations work as expected.

I might not be the best person to comment on this as I've had a lot to do with the migrations and EDD processes here though 😜 ... so maybe with just some wording tweaks and section-level links to the EDD content this is just fine; others should weigh in!

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"This is subtle but important, because what's in that (what I call "master") file today isn't what was in it when a migration a year ago was added. Additionally, we keep the master files to serve as a lint / validation step more than anything, to ensure migrations work as expected."

I think this would serve as a great addition to explicitly put somewhere. I did ping on the code channel and got some feedback as well. Between asking around the auth team/public channels it seems like there is a noticeable sentiment of ambiguity around the full reason why we do this so I was hoping to clarify that in the docs here. You are the third or forth person who has said "I might not be the best person to comment on this" or "This could also be being used in ways I don't know about though." or "This has also caused me pause... I do not know why though. I assume something to do with EDD..."

How does something like this sound:

Why separate stored procedure files?

The separate stored procedure files in src/Sql/.../dbo/Stored Procedures serve as a "master" reference for the current intended state of the database. This is crucial because the state of these files today may differ from when a migration was added a year ago. They act as a lint/validation step to ensure that migrations work as expected. This separation helps maintain clarity and accuracy in the database schema management process as well as there are build scripts to ensure they stay synced.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to wordsmith it a bit:

The separate database definitions in src/Sql/.../dbo serve as a "master" reference for the intended and final state of the database at that time. This is crucial because this state of files at the current moment may differ from when a migration was added in the past. These definitions act as a lint and validation step to ensure that migrations work as expected, and the separation helps maintain clarity and accuracy in the database schema management and synchronization processes.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works for me!

Copy link

cloudflare-workers-and-pages bot commented Jan 3, 2025

Deploying contributing-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: 6b18eea
Status: ✅  Deploy successful!
Preview URL: https://ebc2e651.contributing-docs.pages.dev
Branch Preview URL: https://migration-clarification.contributing-docs.pages.dev

View logs

@@ -54,6 +54,13 @@ required.
compatible with the changes to DbScripts. In order to achieve this we only keep a single
migration, which executes all backwards incompatible schema changes.

> **Note on creating migrations:** The separate database definitions in src/Sql/.../dbo serve as a
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎨 Pop this into a note or info box instead, higher up, probably right under the tip.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed with 6b18eead

Copy link
Contributor

@withinfocus withinfocus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⛏️y but really close.

@@ -27,6 +27,17 @@ Style][code-style-sql] first, since they have a major impact in how we write mig

:::

:::info

Note on creating migrations: The separate database definitions in src/Sql/.../dbo serve as a
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Note on creating migrations: The separate database definitions in src/Sql/.../dbo serve as a
The separate database definitions in src/Sql/.../dbo serve as a

@Hinton
Copy link
Member

Hinton commented Jan 7, 2025

Some useful context.

src/Server is a regular sqlproj, https://learn.microsoft.com/en-us/azure-data-studio/extensions/sql-database-project-extension-sdk-style-projects. But rather than using the auto generated migrations from DAC https://learn.microsoft.com/en-us/sql/relational-databases/data-tier-applications/data-tier-applications?view=sql-server-ver16 we manually write them in a more efficient manner.

This is why there are both a sqlproj and standalone migrations.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants