Skip to content

Conversation

Patrick-Pimentel-Bitwarden
Copy link
Contributor

🎟️ 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 & Details079bd54e-32f1-4e91-abc2-35df7b2d04df

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

Copy link
Contributor Author

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
Contributor Author

@Patrick-Pimentel-Bitwarden Patrick-Pimentel-Bitwarden Jan 3, 2025

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.

Copy link
Contributor Author

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: eb0c328
Status: ✅  Deploy successful!
Preview URL: https://c5013276.contributing-docs.pages.dev
Branch Preview URL: https://migration-clarification.contributing-docs.pages.dev

View logs

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.

Copy link
Contributor Author

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.


:::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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed with c5151e7

@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 need to manually write them to be performant and prevent accidental data loss.

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

withinfocus
withinfocus previously approved these changes Jan 7, 2025
@withinfocus
Copy link
Contributor

CF didn't deploy the latest so we might still have a trigger issue.

@Patrick-Pimentel-Bitwarden
Copy link
Contributor Author

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 need to manually write them to be performant and prevent accidental data loss.

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

Thank you so much for linking this information. I went and added this additional context.

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.

Hopefully the edits make sense. The pasted comment from Oscar needed adjustment.

:::info

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
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
intended and final state of the database at that time. This is crucial because this state of files
intended and final state of the database at that time. This is crucial because the state of database definitions

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.

Additionally, `src/Server` is a regular `sqlproj` as described in the
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
Additionally, `src/Server` is a regular `sqlproj` as described in the
Additionally, a [SQL database project](https://learn.microsoft.com/en-us/azure-data-studio/extensions/sql-database-project-extension-sdk-style-projects) is in place

maintain clarity and accuracy in the database schema management and synchronization processes.

Additionally, `src/Server` is a regular `sqlproj` as described in the
[SQL Database Project Extension SDK Style Projects](https://learn.microsoft.com/en-us/azure-data-studio/extensions/sql-database-project-extension-sdk-style-projects).
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
[SQL Database Project Extension SDK Style Projects](https://learn.microsoft.com/en-us/azure-data-studio/extensions/sql-database-project-extension-sdk-style-projects).


Additionally, `src/Server` is a regular `sqlproj` as described in the
[SQL Database Project Extension SDK Style Projects](https://learn.microsoft.com/en-us/azure-data-studio/extensions/sql-database-project-extension-sdk-style-projects).
However, instead of using the auto-generated migrations from DAC, as detailed in
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
However, instead of using the auto-generated migrations from DAC, as detailed in
however instead of 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)

Additionally, `src/Server` is a regular `sqlproj` as described in the
[SQL Database Project Extension SDK Style Projects](https://learn.microsoft.com/en-us/azure-data-studio/extensions/sql-database-project-extension-sdk-style-projects).
However, instead of using the auto-generated migrations from DAC, as detailed in
[Data-tier Applications](https://learn.microsoft.com/en-us/sql/relational-databases/data-tier-applications/data-tier-applications?view=sql-server-ver16),
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
[Data-tier Applications](https://learn.microsoft.com/en-us/sql/relational-databases/data-tier-applications/data-tier-applications?view=sql-server-ver16),

However, instead of using the auto-generated migrations from DAC, as detailed in
[Data-tier Applications](https://learn.microsoft.com/en-us/sql/relational-databases/data-tier-applications/data-tier-applications?view=sql-server-ver16),
we manually write migrations. This approach is chosen to enhance performance and prevent accidental
data loss. This is why there are both a `sqlproj` and standalone migrations.
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
data loss. This is why there are both a `sqlproj` and standalone migrations.
data loss, and is why there are both a `sqlproj` and standalone migrations.

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.

⛏️ on grammar.

separation helps maintain clarity and accuracy in database schema management and synchronization
processes.

Additionally, an
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
Additionally, an
Additionally, a

is in place; however, instead of 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 migrations. This approach is chosen to enhance performance and prevent accidental
data loss, which is why we have both an `sqlproj` and standalone migrations.
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
data loss, which is why we have both an `sqlproj` and standalone migrations.
data loss, which is why we have both a `sqlproj` and standalone migrations.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I suppose I'm an outlier how I pronounce it 😅

@Patrick-Pimentel-Bitwarden Patrick-Pimentel-Bitwarden merged commit 05ab1d9 into main Jan 9, 2025
9 checks passed
@Patrick-Pimentel-Bitwarden Patrick-Pimentel-Bitwarden deleted the migration-clarification branch January 9, 2025 18:35
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