Skip to content

Commit

Permalink
fix migrations
Browse files Browse the repository at this point in the history
  • Loading branch information
iammukeshm committed Nov 23, 2024
1 parent 5902fad commit d28a00c
Show file tree
Hide file tree
Showing 34 changed files with 457 additions and 962 deletions.
9 changes: 5 additions & 4 deletions src/api/framework/Infrastructure/Persistence/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@
namespace FSH.Framework.Infrastructure.Persistence;
public static class Extensions
{
private static readonly ILogger _logger = Log.ForContext(typeof(Extensions));
private static readonly ILogger Logger = Log.ForContext(typeof(Extensions));
internal static DbContextOptionsBuilder ConfigureDatabase(this DbContextOptionsBuilder builder, string dbProvider, string connectionString)
{
builder.ConfigureWarnings(warnings => warnings.Log(RelationalEventId.PendingModelChangesWarning));
return dbProvider.ToUpperInvariant() switch
{
DbProviders.PostgreSQL => builder.UseNpgsql(connectionString, e =>
Expand All @@ -31,9 +32,9 @@ public static WebApplicationBuilder ConfigureDatabase(this WebApplicationBuilder
.ValidateDataAnnotations()
.PostConfigure(config =>
{
_logger.Information("current db provider: {DatabaseProvider}", config.Provider);
_logger.Information("for documentations and guides, visit https://www.fullstackhero.net");
_logger.Information("to sponsor this project, visit https://opencollective.com/fullstackhero");
Logger.Information("current db provider: {DatabaseProvider}", config.Provider);
Logger.Information("for documentations and guides, visit https://www.fullstackhero.net");
Logger.Information("to sponsor this project, visit https://opencollective.com/fullstackhero");
});
builder.Services.AddScoped<ISaveChangesInterceptor, AuditInterceptor>();
return builder;
Expand Down
3 changes: 2 additions & 1 deletion src/api/framework/Infrastructure/Tenant/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ public static IServiceCollection ConfigureMultitenancy(this IServiceCollection s
// this was happening for every request earlier, leading to ineffeciency
config.Events.OnTenantResolveCompleted = async (context) =>
{
if (context.MultiTenantContext.StoreInfo!.StoreType != typeof(DistributedCacheStore<FshTenantInfo>))
if (context.MultiTenantContext.StoreInfo is null) return;
if (context.MultiTenantContext.StoreInfo.StoreType != typeof(DistributedCacheStore<FshTenantInfo>))
{
var sp = ((HttpContext)context.Context!).RequestServices;
var distributedCacheStore = sp
Expand Down

This file was deleted.

This file was deleted.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace FSH.Starter.WebApi.Migrations.MSSQL.Catalog
{
/// <inheritdoc />
public partial class AddCatalogSchema : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.EnsureSchema(
name: "catalog");

migrationBuilder.CreateTable(
name: "Brands",
schema: "catalog",
columns: table => new
{
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
Name = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false),
Description = table.Column<string>(type: "nvarchar(1000)", maxLength: 1000, nullable: true),
TenantId = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: false),
Created = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: false),
CreatedBy = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
LastModified = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: false),
LastModifiedBy = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
Deleted = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: true),
DeletedBy = table.Column<Guid>(type: "uniqueidentifier", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Brands", x => x.Id);
});

migrationBuilder.CreateTable(
name: "Products",
schema: "catalog",
columns: table => new
{
Id = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
Name = table.Column<string>(type: "nvarchar(100)", maxLength: 100, nullable: false),
Description = table.Column<string>(type: "nvarchar(1000)", maxLength: 1000, nullable: true),
Price = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
BrandId = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
TenantId = table.Column<string>(type: "nvarchar(64)", maxLength: 64, nullable: false),
Created = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: false),
CreatedBy = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
LastModified = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: false),
LastModifiedBy = table.Column<Guid>(type: "uniqueidentifier", nullable: true),
Deleted = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: true),
DeletedBy = table.Column<Guid>(type: "uniqueidentifier", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Products", x => x.Id);
table.ForeignKey(
name: "FK_Products_Brands_BrandId",
column: x => x.BrandId,
principalSchema: "catalog",
principalTable: "Brands",
principalColumn: "Id");
});

migrationBuilder.CreateIndex(
name: "IX_Products_BrandId",
schema: "catalog",
table: "Products",
column: "BrandId");
}

/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Products",
schema: "catalog");

migrationBuilder.DropTable(
name: "Brands",
schema: "catalog");
}
}
}
Loading

0 comments on commit d28a00c

Please sign in to comment.