mirror of
https://github.com/bitwarden/server
synced 2025-12-15 15:53:59 +00:00
Document database projects and complete EDD support (#5855)
* Document database projects and complete EDD support * Remove an old remnant of a now-unused 'future' state * Sync finalization scripts * Fix conflict * Fix some script issues
This commit is contained in:
2
.github/CODEOWNERS
vendored
2
.github/CODEOWNERS
vendored
@@ -14,7 +14,7 @@
|
|||||||
.github/workflows/publish.yml @bitwarden/dept-bre
|
.github/workflows/publish.yml @bitwarden/dept-bre
|
||||||
|
|
||||||
## These are shared workflows ##
|
## These are shared workflows ##
|
||||||
.github/workflows/_move_finalization_db_scripts.yml
|
.github/workflows/_move_edd_db_scripts.yml
|
||||||
.github/workflows/release.yml
|
.github/workflows/release.yml
|
||||||
|
|
||||||
# Database Operations for database changes
|
# Database Operations for database changes
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
name: _move_finalization_db_scripts
|
name: _move_edd_db_scripts
|
||||||
run-name: Move finalization database scripts
|
run-name: Move EDD database scripts
|
||||||
|
|
||||||
on:
|
on:
|
||||||
workflow_call:
|
workflow_call:
|
||||||
@@ -17,7 +17,8 @@ jobs:
|
|||||||
id-token: write
|
id-token: write
|
||||||
outputs:
|
outputs:
|
||||||
migration_filename_prefix: ${{ steps.prefix.outputs.prefix }}
|
migration_filename_prefix: ${{ steps.prefix.outputs.prefix }}
|
||||||
copy_finalization_scripts: ${{ steps.check-finalization-scripts-existence.outputs.copy_finalization_scripts }}
|
copy_edd_scripts: ${{ steps.check-script-existence.outputs.copy_edd_scripts }}
|
||||||
|
|
||||||
steps:
|
steps:
|
||||||
- name: Log in to Azure
|
- name: Log in to Azure
|
||||||
uses: bitwarden/gh-actions/azure-login@main
|
uses: bitwarden/gh-actions/azure-login@main
|
||||||
@@ -45,17 +46,17 @@ jobs:
|
|||||||
id: prefix
|
id: prefix
|
||||||
run: echo "prefix=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT
|
run: echo "prefix=$(date +'%Y-%m-%d')" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
- name: Check if any files in DB finalization directory
|
- name: Check if any files in DB transition or finalization directories
|
||||||
id: check-finalization-scripts-existence
|
id: check-script-existence
|
||||||
run: |
|
run: |
|
||||||
if [ -f util/Migrator/DbScripts_finalization/* ]; then
|
if [ -f util/Migrator/DbScripts_transition/* -o -f util/Migrator/DbScripts_finalization/* ]; then
|
||||||
echo "copy_finalization_scripts=true" >> $GITHUB_OUTPUT
|
echo "copy_edd_scripts=true" >> $GITHUB_OUTPUT
|
||||||
else
|
else
|
||||||
echo "copy_finalization_scripts=false" >> $GITHUB_OUTPUT
|
echo "copy_edd_scripts=false" >> $GITHUB_OUTPUT
|
||||||
fi
|
fi
|
||||||
|
|
||||||
move-finalization-db-scripts:
|
move-scripts:
|
||||||
name: Move finalization database scripts
|
name: Move scripts
|
||||||
runs-on: ubuntu-22.04
|
runs-on: ubuntu-22.04
|
||||||
needs: setup
|
needs: setup
|
||||||
permissions:
|
permissions:
|
||||||
@@ -63,9 +64,9 @@ jobs:
|
|||||||
pull-requests: write
|
pull-requests: write
|
||||||
id-token: write
|
id-token: write
|
||||||
actions: read
|
actions: read
|
||||||
if: ${{ needs.setup.outputs.copy_finalization_scripts == 'true' }}
|
if: ${{ needs.setup.outputs.copy_edd_scripts == 'true' }}
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout
|
- name: Check out repo
|
||||||
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
@@ -74,23 +75,26 @@ jobs:
|
|||||||
id: branch_name
|
id: branch_name
|
||||||
env:
|
env:
|
||||||
PREFIX: ${{ needs.setup.outputs.migration_filename_prefix }}
|
PREFIX: ${{ needs.setup.outputs.migration_filename_prefix }}
|
||||||
run: echo "branch_name=move_finalization_db_scripts_$PREFIX" >> $GITHUB_OUTPUT
|
run: echo "branch_name=move_edd_db_scripts_$PREFIX" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
- name: "Create branch"
|
- name: "Create branch"
|
||||||
env:
|
env:
|
||||||
BRANCH: ${{ steps.branch_name.outputs.branch_name }}
|
BRANCH: ${{ steps.branch_name.outputs.branch_name }}
|
||||||
run: git switch -c $BRANCH
|
run: git switch -c $BRANCH
|
||||||
|
|
||||||
- name: Move DbScripts_finalization
|
- name: Move scripts and finalization database schema
|
||||||
id: move-files
|
id: move-files
|
||||||
env:
|
env:
|
||||||
PREFIX: ${{ needs.setup.outputs.migration_filename_prefix }}
|
PREFIX: ${{ needs.setup.outputs.migration_filename_prefix }}
|
||||||
run: |
|
run: |
|
||||||
src_dir="util/Migrator/DbScripts_finalization"
|
# scripts
|
||||||
|
moved_files="Migration scripts moved:\n\n"
|
||||||
|
|
||||||
|
src_dirs="util/Migrator/DbScripts_transition,util/Migrator/DbScripts_finalization"
|
||||||
dest_dir="util/Migrator/DbScripts"
|
dest_dir="util/Migrator/DbScripts"
|
||||||
i=0
|
i=0
|
||||||
|
|
||||||
moved_files=""
|
for src_dir in ${src_dirs//,/ }; do
|
||||||
for file in "$src_dir"/*; do
|
for file in "$src_dir"/*; do
|
||||||
filenumber=$(printf "%02d" $i)
|
filenumber=$(printf "%02d" $i)
|
||||||
|
|
||||||
@@ -98,11 +102,35 @@ jobs:
|
|||||||
new_filename="${PREFIX}_${filenumber}_${filename}"
|
new_filename="${PREFIX}_${filenumber}_${filename}"
|
||||||
dest_file="$dest_dir/$new_filename"
|
dest_file="$dest_dir/$new_filename"
|
||||||
|
|
||||||
|
# Replace any finalization references due to the move
|
||||||
|
sed -i -e 's/dbo_finalization/dbo/g' "$file"
|
||||||
|
|
||||||
mv "$file" "$dest_file"
|
mv "$file" "$dest_file"
|
||||||
moved_files="$moved_files \n $filename -> $new_filename"
|
moved_files="$moved_files \n $filename -> $new_filename"
|
||||||
|
|
||||||
i=$((i+1))
|
i=$((i+1))
|
||||||
done
|
done
|
||||||
|
done
|
||||||
|
|
||||||
|
# schema
|
||||||
|
moved_files="$moved_files\n\nFinalization scripts moved:\n\n"
|
||||||
|
|
||||||
|
src_dir="src/Sql/dbo_finalization"
|
||||||
|
dest_dir="src/Sql/dbo"
|
||||||
|
|
||||||
|
# sync finalization schema back to dbo, maintaining structure
|
||||||
|
rsync -r "$src_dir/" "$dest_dir/"
|
||||||
|
rm -rf $src_dir/*
|
||||||
|
|
||||||
|
# Replace any finalization references due to the move
|
||||||
|
find ./src/Sql/dbo -name "*.sql" -type f -exec sed -i \
|
||||||
|
-e 's/\[dbo_finalization\]/[dbo]/g' \
|
||||||
|
-e 's/dbo_finalization\./dbo./g' {} +
|
||||||
|
|
||||||
|
for file in "$src_dir"/**/*; do
|
||||||
|
moved_files="$moved_files \n $file"
|
||||||
|
done
|
||||||
|
|
||||||
echo "moved_files=$moved_files" >> $GITHUB_OUTPUT
|
echo "moved_files=$moved_files" >> $GITHUB_OUTPUT
|
||||||
|
|
||||||
- name: Log in to Azure
|
- name: Log in to Azure
|
||||||
@@ -139,7 +167,7 @@ jobs:
|
|||||||
git config --local user.name "bitwarden-devops-bot"
|
git config --local user.name "bitwarden-devops-bot"
|
||||||
if [ -n "$(git status --porcelain)" ]; then
|
if [ -n "$(git status --porcelain)" ]; then
|
||||||
git add .
|
git add .
|
||||||
git commit -m "Move DbScripts_finalization to DbScripts" -a
|
git commit -m "Move EDD database scripts" -a
|
||||||
git push -u origin ${{ steps.branch_name.outputs.branch_name }}
|
git push -u origin ${{ steps.branch_name.outputs.branch_name }}
|
||||||
echo "pr_needed=true" >> $GITHUB_OUTPUT
|
echo "pr_needed=true" >> $GITHUB_OUTPUT
|
||||||
else
|
else
|
||||||
@@ -155,16 +183,16 @@ jobs:
|
|||||||
BRANCH: ${{ steps.branch_name.outputs.branch_name }}
|
BRANCH: ${{ steps.branch_name.outputs.branch_name }}
|
||||||
GH_TOKEN: ${{ github.token }}
|
GH_TOKEN: ${{ github.token }}
|
||||||
MOVED_FILES: ${{ steps.move-files.outputs.moved_files }}
|
MOVED_FILES: ${{ steps.move-files.outputs.moved_files }}
|
||||||
TITLE: "Move finalization database scripts"
|
TITLE: "Move EDD database scripts"
|
||||||
run: |
|
run: |
|
||||||
PR_URL=$(gh pr create --title "$TITLE" \
|
PR_URL=$(gh pr create --title "$TITLE" \
|
||||||
--base "main" \
|
--base "main" \
|
||||||
--head "$BRANCH" \
|
--head "$BRANCH" \
|
||||||
--label "automated pr" \
|
--label "automated pr" \
|
||||||
--body "
|
--body "
|
||||||
## Automated movement of DbScripts_finalization to DbScripts
|
Automated movement of EDD database scripts.
|
||||||
|
|
||||||
## Files moved:
|
Files moved:
|
||||||
$(echo -e "$MOVED_FILES")
|
$(echo -e "$MOVED_FILES")
|
||||||
")
|
")
|
||||||
echo "pr_url=${PR_URL}" >> $GITHUB_OUTPUT
|
echo "pr_url=${PR_URL}" >> $GITHUB_OUTPUT
|
||||||
@@ -175,5 +203,5 @@ jobs:
|
|||||||
env:
|
env:
|
||||||
SLACK_WEBHOOK_URL: ${{ steps.retrieve-secrets.outputs.devops-alerts-slack-webhook-url }}
|
SLACK_WEBHOOK_URL: ${{ steps.retrieve-secrets.outputs.devops-alerts-slack-webhook-url }}
|
||||||
with:
|
with:
|
||||||
message: "Created PR for moving DbScripts_finalization to DbScripts: ${{ steps.create-pr.outputs.pr_url }}"
|
message: "Created PR for moving EDD database scripts: ${{ steps.create-pr.outputs.pr_url }}"
|
||||||
status: ${{ job.status }}
|
status: ${{ job.status }}
|
||||||
6
.github/workflows/repository-management.yml
vendored
6
.github/workflows/repository-management.yml
vendored
@@ -228,8 +228,8 @@ jobs:
|
|||||||
git switch --quiet --create $BRANCH_NAME
|
git switch --quiet --create $BRANCH_NAME
|
||||||
git push --quiet --set-upstream origin $BRANCH_NAME
|
git push --quiet --set-upstream origin $BRANCH_NAME
|
||||||
|
|
||||||
move_future_db_scripts:
|
move_edd_db_scripts:
|
||||||
name: Move finalization database scripts
|
name: Move EDD database scripts
|
||||||
needs: cut_branch
|
needs: cut_branch
|
||||||
uses: ./.github/workflows/_move_finalization_db_scripts.yml
|
uses: ./.github/workflows/_move_edd_db_scripts.yml
|
||||||
secrets: inherit
|
secrets: inherit
|
||||||
|
|||||||
@@ -11,8 +11,6 @@
|
|||||||
<TargetFrameworkProfile />
|
<TargetFrameworkProfile />
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Build Remove="dbo_future/**/*" />
|
|
||||||
|
|
||||||
<!-- Remove file just so we can add it back with some suppressions -->
|
<!-- Remove file just so we can add it back with some suppressions -->
|
||||||
<Build Remove="dbo/Stored Procedures/AzureSQLMaintenance.sql" />
|
<Build Remove="dbo/Stored Procedures/AzureSQLMaintenance.sql" />
|
||||||
<Build Include="dbo/Stored Procedures/AzureSQLMaintenance.sql">
|
<Build Include="dbo/Stored Procedures/AzureSQLMaintenance.sql">
|
||||||
|
|||||||
0
src/Sql/dbo_finalization/.gitkeep
Normal file
0
src/Sql/dbo_finalization/.gitkeep
Normal file
@@ -3,6 +3,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<EmbeddedResource Include="DbScripts\**\*.sql" />
|
<EmbeddedResource Include="DbScripts\**\*.sql" />
|
||||||
<EmbeddedResource Include="DbScripts_transition\**\*.sql" />
|
<EmbeddedResource Include="DbScripts_transition\**\*.sql" />
|
||||||
|
<EmbeddedResource Include="DbScripts_finalization\**\*.sql" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
|||||||
@@ -4,5 +4,5 @@ public static class MigratorConstants
|
|||||||
{
|
{
|
||||||
public const string SqlTableJournalName = "Migration";
|
public const string SqlTableJournalName = "Migration";
|
||||||
public const string DefaultMigrationsFolderName = "DbScripts";
|
public const string DefaultMigrationsFolderName = "DbScripts";
|
||||||
public const string TransitionMigrationsFolderName = "DbScripts_data_migration";
|
public const string TransitionMigrationsFolderName = "DbScripts_transition";
|
||||||
}
|
}
|
||||||
|
|||||||
7
util/Migrator/README.md
Normal file
7
util/Migrator/README.md
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
# Bitwarden Database Migrator
|
||||||
|
|
||||||
|
A class library leveraged by [utilities](../MsSqlMigratorUtility) and [hosted applications](/src/Admin/HostedServices/DatabaseMigrationHostedService.cs) to perform SQL database migrations. A [MSSQL migrator](./SqlServerDbMigrator.cs) exists here as the default use case.
|
||||||
|
|
||||||
|
In production environments the Migrator is typically executed during application startup or as part of CI/CD pipelines to ensure database schemas are up-to-date before application deployment.
|
||||||
|
|
||||||
|
See the [documentation on creating migrations](https://contributing.bitwarden.com/contributing/database-migrations/) for how to utilize the files seen here.
|
||||||
16
util/MsSqlMigratorUtility/README.md
Normal file
16
util/MsSqlMigratorUtility/README.md
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
# Bitwarden MSSQL Database Migrator Utility
|
||||||
|
|
||||||
|
A command-line utility for performing MSSQL database migrations for Bitwarden's self-hosted and cloud deployments.
|
||||||
|
|
||||||
|
## Overview
|
||||||
|
|
||||||
|
The MSSQL Migrator Utility is a specialized tool that leverages the [Migrator library](../Migrator) to handle MSSQL database migrations. The utility uses [DbUp](https://dbup.github.io/) to handle the execution and tracking of database migrations. It runs SQL scripts in order, tracking which scripts have been executed to avoid duplicate runs.
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
- Command-line interface for executing database migrations
|
||||||
|
- Integration with DbUp for reliable migration management
|
||||||
|
- Execution inside or outside of transactions for different application scenarios
|
||||||
|
- Script execution tracking to prevent duplicate migrations and support retries
|
||||||
|
|
||||||
|
See the [documentation](https://contributing.bitwarden.com/getting-started/server/database/mssql/#updating-the-database) for usage.
|
||||||
5
util/MySqlMigrations/README.md
Normal file
5
util/MySqlMigrations/README.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
# Bitwarden MySQL Database Migrator
|
||||||
|
|
||||||
|
A class library leveraged by [hosted applications](/src/Admin/HostedServices/DatabaseMigrationHostedService.cs) to perform MySQL database migrations via Entity Framework.
|
||||||
|
|
||||||
|
See the [documentation on creating migrations](https://contributing.bitwarden.com/contributing/database-migrations/) for how to utilize the files seen here.
|
||||||
5
util/PostgresMigrations/README.md
Normal file
5
util/PostgresMigrations/README.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
# Bitwarden PostgreSQL Database Migrator
|
||||||
|
|
||||||
|
A class library leveraged by [hosted applications](/src/Admin/HostedServices/DatabaseMigrationHostedService.cs) to perform PostgreSQL database migrations via Entity Framework.
|
||||||
|
|
||||||
|
See the [documentation on creating migrations](https://contributing.bitwarden.com/contributing/database-migrations/) for how to utilize the files seen here.
|
||||||
5
util/SqliteMigrations/README.md
Normal file
5
util/SqliteMigrations/README.md
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
# Bitwarden SQLite Database Migrator
|
||||||
|
|
||||||
|
A class library leveraged by [hosted applications](/src/Admin/HostedServices/DatabaseMigrationHostedService.cs) to perform SQLite database migrations via Entity Framework.
|
||||||
|
|
||||||
|
See the [documentation on creating migrations](https://contributing.bitwarden.com/contributing/database-migrations/) for how to utilize the files seen here.
|
||||||
Reference in New Issue
Block a user