This repository was archived by the owner on Jul 28, 2025. It is now read-only.
generated from nhs-england-tools/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 1
feat: Docker Database-migration and DbContext creation #8
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
75d78ec
feat: migrations. docker, program and dbContext, csproj updated for …
Warren-Pitterson 6779b27
feat: db-setup no longer needed in compose
Warren-Pitterson d75f4dc
feat: connectionString no longer hardcoded
Warren-Pitterson de14772
chore: variable casing
Warren-Pitterson 2fd2c48
feat: logging added
Warren-Pitterson 42b2525
chore: tidy up
Warren-Pitterson a9729ae
chore: explicit directories
Warren-Pitterson 1ac6c1a
Merge branch 'main' into feat/Database-migration
Warren-Pitterson 6d6c015
feat: change targer from API to Mesh project
Warren-Pitterson fad274a
feat: refactor to target mesh, builds database with migrations,
Warren-Pitterson a1ef903
refactor: revert unnecessary API changes
Warren-Pitterson File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| #!/bin/bash | ||
| set -e | ||
|
|
||
| # Drop and recreate database for fresh start | ||
| echo "Checking if database exists..." | ||
| /opt/mssql-tools/bin/sqlcmd -S db -U "$DATABASE_USER" -P "$DATABASE_PASSWORD" -Q "IF NOT EXISTS (SELECT name FROM sys.databases WHERE name = N'$DATABASE_NAME') CREATE DATABASE $DATABASE_NAME" | ||
|
|
||
| # Run migrations | ||
| echo "Running migrations..." | ||
| /opt/mssql-tools/bin/sqlcmd -S db -d "$DATABASE_NAME" -U "$DATABASE_USER" -P "$DATABASE_PASSWORD" -i /database/migration.sql | ||
|
|
||
| echo "Migration completed successfully!" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| # Stage 1: Build & Generate EF Migration Script | ||
| FROM mcr.microsoft.com/dotnet/sdk:9.0 AS build-env | ||
|
|
||
| WORKDIR /src | ||
|
|
||
| RUN apt-get update && apt-get install -y git | ||
|
|
||
| COPY . . | ||
|
|
||
| RUN git submodule update --init --recursive | ||
|
|
||
| ARG DatabaseConnectionString | ||
| ENV DatabaseConnectionString=${DatabaseConnectionString} | ||
|
|
||
| RUN dotnet restore ./src/ServiceLayer.Mesh/ServiceLayer.Mesh.csproj && \ | ||
| dotnet build ./src/ServiceLayer.Mesh/ServiceLayer.Mesh.csproj && \ | ||
| dotnet tool install dotnet-ef --tool-path /tools | ||
|
|
||
| ENV PATH="/tools:$PATH" \ | ||
| DOTNET_CLI_HOME=/tmp \ | ||
| DOTNET_SKIP_FIRST_TIME_EXPERIENCE=true \ | ||
| DOTNET_NOLOGO=true | ||
|
|
||
| RUN mkdir -p /database && \ | ||
| dotnet ef migrations script \ | ||
| -o /database/migration.sql \ | ||
| --project ./src/ServiceLayer.Mesh/ | ||
|
|
||
| # Stage 2: Runtime - Apply Migration and Seed Data | ||
| FROM mcr.microsoft.com/mssql-tools:v1 AS migration-env | ||
|
|
||
| COPY --from=build-env /database/migration.sql /database/migration.sql | ||
| COPY scripts/database/migrate-and-seed.sh /scripts/database/migrate-and-seed.sh | ||
|
|
||
| RUN addgroup --system appgroup && \ | ||
| adduser --system --ingroup appgroup appuser && \ | ||
| chmod +x /scripts/database/migrate-and-seed.sh | ||
|
|
||
| USER appuser | ||
|
|
||
| ENTRYPOINT ["/scripts/database/migrate-and-seed.sh"] | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To take advantage of layer caching, it's better to copy the .csproj file first and run dotnet restore. After that, you can copy the source code and build the application.