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

Update migrate.ps1 to support test database used by integration tests #5

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

Conversation

lizard-boy
Copy link

@lizard-boy lizard-boy commented Oct 19, 2024

🎟️ Tracking

https://bitwarden.atlassian.net/browse/PM-10863

📔 Objective

The integration tests for databases use different secrets.json properties than the ones used by locally running servers. This is to support not corrupting folk's local test data.

Currently these test databases are not supported by migrate.ps1 and other tooling. This PR updates migrate.ps1 with a --test switch, and adds logic for connecting to and migrating these databases.

The --all switch was modified to include running migrations against test databases as well.

🧮 Side Effects

As part of this work I had to modify an old MySql migration because of an error in its manually written logic. The script in question checks for the existence of a column from system tables before trying to drop it. This doesn't check for a specific databases, and so can cause false positives if you try to have multiple databases on the same server.

📸 Screenshots

In this demo I build fresh databases from scratch and run some migrations using migrate.ps1. It:

  1. starts with a pwsh migrate.ps1 --all command that skips test databases because no connection strings are found.
  2. Runs pwsh migrate.ps1 --all again, this time with connection strings set
  3. Shows examples of pwsh migrate.ps1 --test --{DATABASE} for targeting specific test databases.
  4. Shows the newly created databases in Azure Data Studio.
migrate.mov

⏰ 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

Greptile Summary

This PR updates the migrate.ps1 script to support test databases used in integration tests, enhancing the flexibility of the migration process for both development and test environments.

  • Added --test switch in dev/migrate.ps1 to handle test database migrations separately
  • Modified --all switch to include test database migrations
  • Updated connection string handling for MSSQL, MySQL, PostgreSQL, and SQLite in dev/migrate.ps1
  • Improved MySQL migration in util/MySqlMigrations/Migrations/20231214162533_GrantIdWithIndexes.cs to prevent issues with multiple databases on the same server
  • Enhanced 'Grant' table schema in MySQL, adding 'Id' column as primary key and creating indexes

Copy link

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

2 file(s) reviewed, 2 comment(s)
Edit PR Review Bot Settings | Greptile

# to ensure a valid json
return dotnet user-secrets list --json --project ../src/Api | Where-Object { $_ -notmatch "^//" } | ConvertFrom-Json
}
if ($all -or !$test) {
Copy link

Choose a reason for hiding this comment

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

style: Consider using if (!$test -or $all) for consistency with other sections

Set-Location "$currentDir/../util/$($item[2])/"
dotnet ef database update
if(!$test -or $all) {
Copy link

Choose a reason for hiding this comment

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

style: Use if (!$test -or $all) for consistency with the suggestion for line 37

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.

2 participants