Tirsvad WebSite.DevTirsvadDk
Documentation
Tirsvad.WebSite.DevTirsvadDk
The website serves as a platform for sharing updates, features, and progress related to Tirsvad development and its affiliated projects. It provides a centralized location for developers, contributors, and users to stay informed about the latest developments, access resources, and engage with the Tirsvad community. Its content have quality requirements, and it is expected to be regularly updated with relevant information about Tirsvad and its ecosystem.
Table of Contents
- Configuration
- Entity Framework Core: Initialization & Updates
- Server-Side Setup
- MigrationRunner: Overview & Usage
- Publish & Deployment Workflow (WebUI and MigrationRunner)
Configuration
Environment variables
| Variable Name | Default value | Description |
|---|---|---|
| WWW_HOSTNAME | Overrides the hostname in GetHostFromNavigationManager(). | |
| PROJECTS_ROOT | Overrides the root path for the website. | |
| NUGET_LOCAL_HOST_PATH | Path to the local NuGet package source. Set in .env file. | |
| ConnectionStrings__DefaultConnection | Connection string for the default database connection. Set in appsettings.json or environment variables. |
Local NuGet Feed Setup
To use a local NuGet feed, set the environment variable in a .env file at the solution root:
NUGET_LOCAL_HOST_PATH=C:\path\to\local\nuget\feed
Configuration Management
This solution uses the standard ASP.NET Core configuration system. Configuration settings are managed via appsettings.json files, with overrides for each environment (e.g., appsettings.Development.json, appsettings.Production.json). Environment variables and user secrets (for development) are also supported.
- The configuration is loaded and made available via dependency injection.
- Access configuration in your services or components by injecting
IConfiguration. - Environment-specific settings are automatically selected based on the
ASPNETCORE_ENVIRONMENTvariable. - Sensitive data (like connection strings or API keys) should be stored in environment variables or user secrets, not in source control.
For more details, see the official Microsoft documentation.
Entity Framework Core: Initialization & Updates
Install EF Core Tools
Install EF Core CLI tools if not already present:
dotnet tool install --global dotnet-ef
Add a Migration
To create a new migration after updating your models or DbContext:
dotnet ef migrations add <MigrationName> --project src/Infrastructure --startup-project src/WebUI/WebUI
Update the Database
To apply migrations and update the database schema:
dotnet ef database update --project src/Infrastructure --startup-project src/WebUI/WebUI
Workflow
- Make changes to your models or
AppDbContextinsrc/Infrastructure/Persistents/. - Run the migration command to generate migration files.
- Apply migrations to update the database schema.
Server-Side Setup
Setup user and role management
-- Step 1: Create the role with login privilege and password
CREATE ROLE "exampleRole" LOGIN PASSWORD 'secr3t';
-- Step 2: (Optional) Grant privileges if needed
-- For example, allow the user to create databases:
ALTER ROLE "exampleRole" CREATEDB;
-- Step 3: Create a database owned by the new role
CREATE DATABASE "exampleDatabase" OWNER "exampleRole";
-- Step 4: Verify the role exists
\du
-- Step 5: Verify the database exists
\l
Troubleshooting
- Ensure your connection string is set in
src/WebUI/WebUI/appsettings.json. - Use
--verbosefor detailed output if errors occur.
For more details, see the official EF Core documentation.
MigrationRunner: Overview & Usage
What is MigrationRunner?
MigrationRunner is a migration management tool for .NET projects, typically used to apply, revert, and track database schema changes. It ensures your database stays in sync with your application models and supports versioned migrations for reliable deployments.
How to Use MigrationRunner
TODO: Provide specific commands and examples for using MigrationRunner in this project.
Best Practices
- Place migration classes in the Infrastructure project.
- Use versioned migration numbers for tracking.
- Test migrations in development before applying to production.
Publish & Deployment Workflow (WebUI and MigrationRunner)
Standard Publish & Deploy
- Publish both projects:
dotnet publish src/WebUI/WebUI -c Release -o g/publish/WebUI/release/ dotnet publish src/MigrationRunner/MigrationRunner -c Release -o g/publish/MigrationRunner/release/ - Deploy using
deploy.dev.tirsvad.dk.sh:- The script uploads both published folders to the server.
- MigrationRunner is executed remotely to update the database.
- Services are restarted.
Docker Workflow
- Build Docker images:
docker build -t devtirsvad-webui -f src/WebUI/WebUI/Dockerfile . docker build -t devtirsvad-migrationrunner -f src/MigrationRunner/MigrationRunner/Dockerfile . - Push images to your registry (if needed):
docker push <your-registry>/devtirsvad-webui docker push <your-registry>/devtirsvad-migrationrunner - Deploy using
docker-composeor Kubernetes. Exampledocker-compose.yml:version: '3.8' services: webui: image: devtirsvad-webui ports: - "80:80" depends_on: - migrationrunner migrationrunner: image: devtirsvad-migrationrunner command: ["dotnet", "MigrationRunner.dll"]