Skip to content

Commit 7ab3e6e

Browse files
committed
Initial set
1 parent aed1b8f commit 7ab3e6e

File tree

7 files changed

+721
-24
lines changed

7 files changed

+721
-24
lines changed

Directory.Packages.props

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@
88
</ItemGroup>
99
<ItemGroup Label="Infrastructure">
1010
<PackageVersion Include="Azure.Storage.Blobs" Version="12.23.0" />
11-
<PackageVersion Include="Microsoft.EntityFrameworkCore" Version="8.0.10" />
12-
<PackageVersion Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.10" />
13-
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.10" />
11+
<PackageVersion Include="Microsoft.EntityFrameworkCore" Version="8.0.11" />
12+
<PackageVersion Include="Microsoft.EntityFrameworkCore.Sqlite" Version="8.0.11" />
13+
<PackageVersion Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.11" />
14+
<PackageVersion Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.11" />
1415
<PackageVersion Include="Microsoft.Extensions.Diagnostics.HealthChecks.Abstractions" Version="9.0.0" />
1516
<PackageVersion Include="MongoDB.Driver" Version="2.30.0" />
1617
<PackageVersion Include="Pomelo.EntityFrameworkCore.MySql" Version="8.0.2" />

MIGRATION.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,27 @@ This document describes the changes that need to be made to migrate from one ver
33

44
## 8.0 to 9.0
55

6+
### SQL - Entity Framework Migrations
7+
8+
Starting with `v9.0` the blog uses Entity Framework Migrations for all SQL providers. If you are already having a database you need to run the following script that creates the history table and the initial entry:
9+
```bash
10+
IF OBJECT_ID(N'[__EFMigrationsHistory]') IS NULL
11+
BEGIN
12+
CREATE TABLE [__EFMigrationsHistory] (
13+
[MigrationId] nvarchar(150) NOT NULL,
14+
[ProductVersion] nvarchar(32) NOT NULL,
15+
CONSTRAINT [PK___EFMigrationsHistory] PRIMARY KEY ([MigrationId])
16+
);
17+
END;
18+
GO
19+
20+
INSERT INTO [__EFMigrationsHistory] ([MigrationId], [ProductVersion])
21+
VALUES (N'20241128180004_Initial', N'8.0.11');
22+
GO
23+
```
24+
25+
Read more in the [documentation](docs/Storage/Readme.md).
26+
627
### Support / Donation section
728
If you used the sponsor/donation mechanism in the `appsettings.json` like this:
829
```json

docs/Storage/Readme.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,24 @@ For MySql use the following:
3131
"ConnectionString": "Server=YOURSERVER;User ID=YOURUSERID;Password=YOURPASSWORD;Database=YOURDATABASE"
3232
```
3333

34+
## Entity Framework Migrations
35+
36+
For the SQL providers (`SqlServer`, `Sqlite`, `MySql`), you can use Entity Framework Core Migrations to create and manage the database schema. The whole documentation can be found under [*"Entity Framework Core tools reference"*](https://learn.microsoft.com/en-us/ef/core/cli/dotnet). The short version is that you can use the following steps:
37+
38+
```bash
39+
dotnet ef database update --project src/LinkDotNet.Blog.Infrastructure --startup-project src/LinkDotNet.Blog.Web --connection "<ConnectionString>"
40+
```
41+
42+
The `--connection` parameter is optional - if you don't specify it, it will try to grab it from your `appsettings.json` file.
43+
The other options is to create a sql script you can execute against your database:
44+
45+
```bash
46+
dotnet ef migrations script --project src/LinkDotNet.Blog.Infrastructure --startup-project src/LinkDotNet.Blog.Web
47+
```
48+
49+
Here is the full documentation: [*"Applying Migrations"*](https://learn.microsoft.com/en-us/ef/core/managing-schemas/migrations/applying).
50+
51+
Alternatively, the blog calls `Database.EnsureCreated()` on startup, which creates the database schema if it does not exist. So you are not forced to use migrations.
52+
3453
## Considerations
3554
For most people a Sqlite database might be the best choice between convienence and ease of setup. As it runs "in-process" there are no additional dependencies or setup required (and therefore no additional cost). As the blog tries to cache many things, the load onto the database is not that big (performance considerations). The advantages of a "real" database like SqlServer or MySql are more in the realm of backups, replication, and other enterprise features (which are not needed often times for a simple blog).

src/LinkDotNet.Blog.Infrastructure/Migrations/20241128180004_Initial.Designer.cs

Lines changed: 244 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)