Skip to content

Commit d28a00c

Browse files
committed
fix migrations
1 parent 5902fad commit d28a00c

34 files changed

+457
-962
lines changed

src/api/framework/Infrastructure/Persistence/Extensions.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,10 @@
1010
namespace FSH.Framework.Infrastructure.Persistence;
1111
public static class Extensions
1212
{
13-
private static readonly ILogger _logger = Log.ForContext(typeof(Extensions));
13+
private static readonly ILogger Logger = Log.ForContext(typeof(Extensions));
1414
internal static DbContextOptionsBuilder ConfigureDatabase(this DbContextOptionsBuilder builder, string dbProvider, string connectionString)
1515
{
16+
builder.ConfigureWarnings(warnings => warnings.Log(RelationalEventId.PendingModelChangesWarning));
1617
return dbProvider.ToUpperInvariant() switch
1718
{
1819
DbProviders.PostgreSQL => builder.UseNpgsql(connectionString, e =>
@@ -31,9 +32,9 @@ public static WebApplicationBuilder ConfigureDatabase(this WebApplicationBuilder
3132
.ValidateDataAnnotations()
3233
.PostConfigure(config =>
3334
{
34-
_logger.Information("current db provider: {DatabaseProvider}", config.Provider);
35-
_logger.Information("for documentations and guides, visit https://www.fullstackhero.net");
36-
_logger.Information("to sponsor this project, visit https://opencollective.com/fullstackhero");
35+
Logger.Information("current db provider: {DatabaseProvider}", config.Provider);
36+
Logger.Information("for documentations and guides, visit https://www.fullstackhero.net");
37+
Logger.Information("to sponsor this project, visit https://opencollective.com/fullstackhero");
3738
});
3839
builder.Services.AddScoped<ISaveChangesInterceptor, AuditInterceptor>();
3940
return builder;

src/api/framework/Infrastructure/Tenant/Extensions.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ public static IServiceCollection ConfigureMultitenancy(this IServiceCollection s
2929
// this was happening for every request earlier, leading to ineffeciency
3030
config.Events.OnTenantResolveCompleted = async (context) =>
3131
{
32-
if (context.MultiTenantContext.StoreInfo!.StoreType != typeof(DistributedCacheStore<FshTenantInfo>))
32+
if (context.MultiTenantContext.StoreInfo is null) return;
33+
if (context.MultiTenantContext.StoreInfo.StoreType != typeof(DistributedCacheStore<FshTenantInfo>))
3334
{
3435
var sp = ((HttpContext)context.Context!).RequestServices;
3536
var distributedCacheStore = sp

src/api/migrations/MSSQL/Catalog/20240605195930_Add Catalog Schema.Designer.cs

Lines changed: 0 additions & 73 deletions
This file was deleted.

src/api/migrations/MSSQL/Catalog/20240605195930_Add Catalog Schema.cs

Lines changed: 0 additions & 45 deletions
This file was deleted.

src/api/migrations/MSSQL/Catalog/20241123030623_Add Catalog Schema.Designer.cs

Lines changed: 138 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
using System;
2+
using Microsoft.EntityFrameworkCore.Migrations;
3+
4+
#nullable disable
5+
6+
namespace FSH.Starter.WebApi.Migrations.MSSQL.Catalog
7+
{
8+
/// <inheritdoc />
9+
public partial class AddCatalogSchema : Migration
10+
{
11+
/// <inheritdoc />
12+
protected override void Up(MigrationBuilder migrationBuilder)
13+
{
14+
migrationBuilder.EnsureSchema(
15+
name: "catalog");
16+
17+
migrationBuilder.CreateTable(
18+
name: "Brands",
19+
schema: "catalog",
20+
columns: table => new
21+
{
22+
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
23+
Name = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false),
24+
Description = table.Column<string>(type: "nvarchar(1000)", maxLength: 1000, nullable: true),
25+
TenantId = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: false),
26+
Created = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: false),
27+
CreatedBy = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
28+
LastModified = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: false),
29+
LastModifiedBy = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
30+
Deleted = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: true),
31+
DeletedBy = table.Column<Guid>(type: "uniqueidentifier", nullable: true)
32+
},
33+
constraints: table =>
34+
{
35+
table.PrimaryKey("PK_Brands", x => x.Id);
36+
});
37+
38+
migrationBuilder.CreateTable(
39+
name: "Products",
40+
schema: "catalog",
41+
columns: table => new
42+
{
43+
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
44+
Name = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false),
45+
Description = table.Column<string>(type: "nvarchar(1000)", maxLength: 1000, nullable: true),
46+
Price = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
47+
BrandId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
48+
TenantId = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: false),
49+
Created = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: false),
50+
CreatedBy = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
51+
LastModified = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: false),
52+
LastModifiedBy = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
53+
Deleted = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: true),
54+
DeletedBy = table.Column<Guid>(type: "uniqueidentifier", nullable: true)
55+
},
56+
constraints: table =>
57+
{
58+
table.PrimaryKey("PK_Products", x => x.Id);
59+
table.ForeignKey(
60+
name: "FK_Products_Brands_BrandId",
61+
column: x => x.BrandId,
62+
principalSchema: "catalog",
63+
principalTable: "Brands",
64+
principalColumn: "Id");
65+
});
66+
67+
migrationBuilder.CreateIndex(
68+
name: "IX_Products_BrandId",
69+
schema: "catalog",
70+
table: "Products",
71+
column: "BrandId");
72+
}
73+
74+
/// <inheritdoc />
75+
protected override void Down(MigrationBuilder migrationBuilder)
76+
{
77+
migrationBuilder.DropTable(
78+
name: "Products",
79+
schema: "catalog");
80+
81+
migrationBuilder.DropTable(
82+
name: "Brands",
83+
schema: "catalog");
84+
}
85+
}
86+
}

0 commit comments

Comments
 (0)