mirror of
https://github.com/meysamhadeli/booking-microservices.git
synced 2026-04-29 01:04:56 +08:00
commit
efe5b6de06
1
.github/workflows/release-drafter.yml
vendored
1
.github/workflows/release-drafter.yml
vendored
@ -5,7 +5,6 @@
|
|||||||
on:
|
on:
|
||||||
push:
|
push:
|
||||||
branches:
|
branches:
|
||||||
- develop
|
|
||||||
- main
|
- main
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
|
|||||||
@ -152,6 +152,7 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Folder Include="Contracts" />
|
<Folder Include="Contracts" />
|
||||||
<Folder Include="EventStoreDB\BackgroundWorkers" />
|
<Folder Include="EventStoreDB\BackgroundWorkers" />
|
||||||
|
<Folder Include="PersistMessageProcessor\Data\Configurations" />
|
||||||
<Folder Include="PersistMessageProcessor\Data\Migrations" />
|
<Folder Include="PersistMessageProcessor\Data\Migrations" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
|||||||
@ -11,6 +11,9 @@ using Microsoft.Extensions.Hosting;
|
|||||||
|
|
||||||
namespace BuildingBlocks.EFCore;
|
namespace BuildingBlocks.EFCore;
|
||||||
|
|
||||||
|
using Humanizer;
|
||||||
|
using Microsoft.EntityFrameworkCore.Metadata;
|
||||||
|
|
||||||
public static class Extensions
|
public static class Extensions
|
||||||
{
|
{
|
||||||
public static IServiceCollection AddCustomDbContext<TContext>(
|
public static IServiceCollection AddCustomDbContext<TContext>(
|
||||||
@ -71,6 +74,35 @@ public static class Extensions
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//ref: https://andrewlock.net/customising-asp-net-core-identity-ef-core-naming-conventions-for-postgresql/
|
||||||
|
public static void ToSnakeCaseTables(this ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
foreach (var entity in modelBuilder.Model.GetEntityTypes())
|
||||||
|
{
|
||||||
|
// Replace table names
|
||||||
|
entity.SetTableName(entity.GetTableName()?.Underscore());
|
||||||
|
|
||||||
|
var tableObjectIdentifier = StoreObjectIdentifier.Table(entity.GetTableName()?.Underscore()!, entity.GetSchema());
|
||||||
|
|
||||||
|
// Replace column names
|
||||||
|
foreach (var property in entity.GetProperties())
|
||||||
|
{
|
||||||
|
property.SetColumnName(property.GetColumnName(tableObjectIdentifier)?.Underscore());
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var key in entity.GetKeys())
|
||||||
|
{
|
||||||
|
key.SetName(key.GetName()?.Underscore());
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var key in entity.GetForeignKeys())
|
||||||
|
{
|
||||||
|
key.SetConstraintName(key.GetConstraintName()?.Underscore());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static async Task MigrateDatabaseAsync<TContext>(IServiceProvider serviceProvider)
|
private static async Task MigrateDatabaseAsync<TContext>(IServiceProvider serviceProvider)
|
||||||
where TContext : DbContext, IDbContext
|
where TContext : DbContext, IDbContext
|
||||||
{
|
{
|
||||||
|
|||||||
@ -7,7 +7,7 @@ public class PersistMessageConfiguration : IEntityTypeConfiguration<PersistMessa
|
|||||||
{
|
{
|
||||||
public void Configure(EntityTypeBuilder<PersistMessage> builder)
|
public void Configure(EntityTypeBuilder<PersistMessage> builder)
|
||||||
{
|
{
|
||||||
builder.ToTable("persistMessage");
|
builder.ToTable(nameof(PersistMessage));
|
||||||
|
|
||||||
builder.HasKey(x => x.Id);
|
builder.HasKey(x => x.Id);
|
||||||
|
|
||||||
|
|||||||
@ -12,7 +12,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
|||||||
namespace BuildingBlocks.PersistMessageProcessor.Data.Migrations
|
namespace BuildingBlocks.PersistMessageProcessor.Data.Migrations
|
||||||
{
|
{
|
||||||
[DbContext(typeof(PersistMessageDbContext))]
|
[DbContext(typeof(PersistMessageDbContext))]
|
||||||
[Migration("20230113134415_initial")]
|
[Migration("20230113183839_initial")]
|
||||||
partial class initial
|
partial class initial
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
@ -64,7 +64,7 @@ namespace BuildingBlocks.PersistMessageProcessor.Data.Migrations
|
|||||||
b.HasKey("Id")
|
b.HasKey("Id")
|
||||||
.HasName("pk_persist_message");
|
.HasName("pk_persist_message");
|
||||||
|
|
||||||
b.ToTable("persistMessage", (string)null);
|
b.ToTable("persist_message", (string)null);
|
||||||
});
|
});
|
||||||
#pragma warning restore 612, 618
|
#pragma warning restore 612, 618
|
||||||
}
|
}
|
||||||
@ -12,7 +12,7 @@ namespace BuildingBlocks.PersistMessageProcessor.Data.Migrations
|
|||||||
protected override void Up(MigrationBuilder migrationBuilder)
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
{
|
{
|
||||||
migrationBuilder.CreateTable(
|
migrationBuilder.CreateTable(
|
||||||
name: "persistMessage",
|
name: "persist_message",
|
||||||
columns: table => new
|
columns: table => new
|
||||||
{
|
{
|
||||||
id = table.Column<long>(type: "bigint", nullable: false),
|
id = table.Column<long>(type: "bigint", nullable: false),
|
||||||
@ -33,7 +33,7 @@ namespace BuildingBlocks.PersistMessageProcessor.Data.Migrations
|
|||||||
protected override void Down(MigrationBuilder migrationBuilder)
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
{
|
{
|
||||||
migrationBuilder.DropTable(
|
migrationBuilder.DropTable(
|
||||||
name: "persistMessage");
|
name: "persist_message");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -61,7 +61,7 @@ namespace BuildingBlocks.PersistMessageProcessor.Data.Migrations
|
|||||||
b.HasKey("Id")
|
b.HasKey("Id")
|
||||||
.HasName("pk_persist_message");
|
.HasName("pk_persist_message");
|
||||||
|
|
||||||
b.ToTable("persistMessage", (string)null);
|
b.ToTable("persist_message", (string)null);
|
||||||
});
|
});
|
||||||
#pragma warning restore 612, 618
|
#pragma warning restore 612, 618
|
||||||
}
|
}
|
||||||
|
|||||||
@ -15,5 +15,6 @@ public class PersistMessageDbContext : AppDbContextBase, IPersistMessageDbContex
|
|||||||
{
|
{
|
||||||
builder.ApplyConfiguration(new PersistMessageConfiguration());
|
builder.ApplyConfiguration(new PersistMessageConfiguration());
|
||||||
base.OnModelCreating(builder);
|
base.OnModelCreating(builder);
|
||||||
|
builder.ToSnakeCaseTables();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -8,7 +8,7 @@ public class AircraftConfiguration : IEntityTypeConfiguration<Aircraft>
|
|||||||
{
|
{
|
||||||
public void Configure(EntityTypeBuilder<Aircraft> builder)
|
public void Configure(EntityTypeBuilder<Aircraft> builder)
|
||||||
{
|
{
|
||||||
builder.ToTable("aircraft");
|
builder.ToTable(nameof(Aircraft));
|
||||||
builder.HasKey(r => r.Id);
|
builder.HasKey(r => r.Id);
|
||||||
builder.Property(r => r.Id).ValueGeneratedNever();
|
builder.Property(r => r.Id).ValueGeneratedNever();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,4 +1,3 @@
|
|||||||
using BuildingBlocks.EFCore;
|
|
||||||
using Flight.Airports.Models;
|
using Flight.Airports.Models;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
using Microsoft.EntityFrameworkCore.Metadata.Builders;
|
||||||
@ -9,7 +8,7 @@ public class AirportConfiguration: IEntityTypeConfiguration<Airport>
|
|||||||
{
|
{
|
||||||
public void Configure(EntityTypeBuilder<Airport> builder)
|
public void Configure(EntityTypeBuilder<Airport> builder)
|
||||||
{
|
{
|
||||||
builder.ToTable("airport");
|
builder.ToTable(nameof(Airport));
|
||||||
|
|
||||||
builder.HasKey(r => r.Id);
|
builder.HasKey(r => r.Id);
|
||||||
builder.Property(r => r.Id).ValueGeneratedNever();
|
builder.Property(r => r.Id).ValueGeneratedNever();
|
||||||
|
|||||||
@ -12,7 +12,7 @@ public class FlightConfiguration : IEntityTypeConfiguration<Flights.Models.Fligh
|
|||||||
{
|
{
|
||||||
public void Configure(EntityTypeBuilder<Flights.Models.Flight> builder)
|
public void Configure(EntityTypeBuilder<Flights.Models.Flight> builder)
|
||||||
{
|
{
|
||||||
builder.ToTable("flight");
|
builder.ToTable(nameof(Flight));
|
||||||
|
|
||||||
builder.HasKey(r => r.Id);
|
builder.HasKey(r => r.Id);
|
||||||
builder.Property(r => r.Id).ValueGeneratedNever();
|
builder.Property(r => r.Id).ValueGeneratedNever();
|
||||||
|
|||||||
@ -11,7 +11,7 @@ public class SeatConfiguration : IEntityTypeConfiguration<Seat>
|
|||||||
{
|
{
|
||||||
public void Configure(EntityTypeBuilder<Seat> builder)
|
public void Configure(EntityTypeBuilder<Seat> builder)
|
||||||
{
|
{
|
||||||
builder.ToTable("seat");
|
builder.ToTable(nameof(Seat));
|
||||||
|
|
||||||
builder.HasKey(r => r.Id);
|
builder.HasKey(r => r.Id);
|
||||||
builder.Property(r => r.Id).ValueGeneratedNever();
|
builder.Property(r => r.Id).ValueGeneratedNever();
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
using BuildingBlocks.EFCore;
|
using BuildingBlocks.EFCore;
|
||||||
using BuildingBlocks.Utils;
|
|
||||||
using BuildingBlocks.Web;
|
using BuildingBlocks.Web;
|
||||||
using Flight.Aircrafts.Models;
|
using Flight.Aircrafts.Models;
|
||||||
using Flight.Airports.Models;
|
using Flight.Airports.Models;
|
||||||
@ -8,12 +7,14 @@ using Microsoft.EntityFrameworkCore;
|
|||||||
|
|
||||||
namespace Flight.Data;
|
namespace Flight.Data;
|
||||||
|
|
||||||
|
|
||||||
public sealed class FlightDbContext : AppDbContextBase
|
public sealed class FlightDbContext : AppDbContextBase
|
||||||
{
|
{
|
||||||
public FlightDbContext(DbContextOptions<FlightDbContext> options, ICurrentUserProvider currentUserProvider) : base(
|
public FlightDbContext(DbContextOptions<FlightDbContext> options, ICurrentUserProvider currentUserProvider) : base(
|
||||||
options, currentUserProvider)
|
options, currentUserProvider)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public DbSet<Flights.Models.Flight> Flights => Set<Flights.Models.Flight>();
|
public DbSet<Flights.Models.Flight> Flights => Set<Flights.Models.Flight>();
|
||||||
public DbSet<Airport> Airports => Set<Airport>();
|
public DbSet<Airport> Airports => Set<Airport>();
|
||||||
public DbSet<Aircraft> Aircraft => Set<Aircraft>();
|
public DbSet<Aircraft> Aircraft => Set<Aircraft>();
|
||||||
@ -24,5 +25,6 @@ public sealed class FlightDbContext : AppDbContextBase
|
|||||||
base.OnModelCreating(builder);
|
base.OnModelCreating(builder);
|
||||||
builder.FilterSoftDeletedProperties();
|
builder.FilterSoftDeletedProperties();
|
||||||
builder.ApplyConfigurationsFromAssembly(typeof(FlightRoot).Assembly);
|
builder.ApplyConfigurationsFromAssembly(typeof(FlightRoot).Assembly);
|
||||||
|
builder.ToSnakeCaseTables();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -12,7 +12,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
|||||||
namespace Flight.Data.Migrations
|
namespace Flight.Data.Migrations
|
||||||
{
|
{
|
||||||
[DbContext(typeof(FlightDbContext))]
|
[DbContext(typeof(FlightDbContext))]
|
||||||
[Migration("20230113134450_Init")]
|
[Migration("20230113183335_Init")]
|
||||||
partial class Init
|
partial class Init
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
@ -281,7 +281,7 @@ namespace Flight.Data.Migrations
|
|||||||
.HasForeignKey("ArriveAirportId")
|
.HasForeignKey("ArriveAirportId")
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasConstraintName("fk_flight_airport_airport_id");
|
.HasConstraintName("fk_flight_airport_arrive_airport_id");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("Flight.Seats.Models.Seat", b =>
|
modelBuilder.Entity("Flight.Seats.Models.Seat", b =>
|
||||||
@ -83,7 +83,7 @@ namespace Flight.Data.Migrations
|
|||||||
principalColumn: "id",
|
principalColumn: "id",
|
||||||
onDelete: ReferentialAction.Cascade);
|
onDelete: ReferentialAction.Cascade);
|
||||||
table.ForeignKey(
|
table.ForeignKey(
|
||||||
name: "fk_flight_airport_airport_id",
|
name: "fk_flight_airport_arrive_airport_id",
|
||||||
column: x => x.arriveairportid,
|
column: x => x.arriveairportid,
|
||||||
principalTable: "airport",
|
principalTable: "airport",
|
||||||
principalColumn: "id",
|
principalColumn: "id",
|
||||||
@ -278,7 +278,7 @@ namespace Flight.Data.Migrations
|
|||||||
.HasForeignKey("ArriveAirportId")
|
.HasForeignKey("ArriveAirportId")
|
||||||
.OnDelete(DeleteBehavior.Cascade)
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
.IsRequired()
|
.IsRequired()
|
||||||
.HasConstraintName("fk_flight_airport_airport_id");
|
.HasConstraintName("fk_flight_airport_arrive_airport_id");
|
||||||
});
|
});
|
||||||
|
|
||||||
modelBuilder.Entity("Flight.Seats.Models.Seat", b =>
|
modelBuilder.Entity("Flight.Seats.Models.Seat", b =>
|
||||||
|
|||||||
@ -34,33 +34,8 @@ public sealed class IdentityContext : IdentityDbContext<ApplicationUser, Identit
|
|||||||
{
|
{
|
||||||
builder.ApplyConfigurationsFromAssembly(Assembly.GetExecutingAssembly());
|
builder.ApplyConfigurationsFromAssembly(Assembly.GetExecutingAssembly());
|
||||||
base.OnModelCreating(builder);
|
base.OnModelCreating(builder);
|
||||||
|
|
||||||
// https://andrewlock.net/customising-asp-net-core-identity-ef-core-naming-conventions-for-postgresql/
|
|
||||||
foreach (var entity in builder.Model.GetEntityTypes())
|
|
||||||
{
|
|
||||||
// Replace table names
|
|
||||||
entity.SetTableName(entity.GetTableName()?.Underscore());
|
|
||||||
|
|
||||||
var identityObjectIdentifier = StoreObjectIdentifier.Table(entity.GetTableName()?.Underscore()!, entity.GetSchema());
|
|
||||||
|
|
||||||
// Replace column names
|
|
||||||
foreach (var property in entity.GetProperties())
|
|
||||||
{
|
|
||||||
property.SetColumnName(property.GetColumnName(identityObjectIdentifier)?.Underscore());
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var key in entity.GetKeys())
|
|
||||||
{
|
|
||||||
key.SetName(key.GetName()?.Underscore());
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach (var key in entity.GetForeignKeys())
|
|
||||||
{
|
|
||||||
key.SetConstraintName(key.GetConstraintName()?.Underscore());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
builder.FilterSoftDeletedProperties();
|
builder.FilterSoftDeletedProperties();
|
||||||
|
builder.ToSnakeCaseTables();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task BeginTransactionAsync(CancellationToken cancellationToken = default)
|
public async Task BeginTransactionAsync(CancellationToken cancellationToken = default)
|
||||||
|
|||||||
@ -12,7 +12,7 @@ using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
|||||||
namespace Identity.Data.Migrations
|
namespace Identity.Data.Migrations
|
||||||
{
|
{
|
||||||
[DbContext(typeof(IdentityContext))]
|
[DbContext(typeof(IdentityContext))]
|
||||||
[Migration("20230113134523_initial")]
|
[Migration("20230113183552_initial")]
|
||||||
partial class initial
|
partial class initial
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
@ -8,7 +8,7 @@ public class PassengerConfiguration: IEntityTypeConfiguration<Passengers.Models.
|
|||||||
{
|
{
|
||||||
public void Configure(EntityTypeBuilder<Passengers.Models.Passenger> builder)
|
public void Configure(EntityTypeBuilder<Passengers.Models.Passenger> builder)
|
||||||
{
|
{
|
||||||
builder.ToTable("passenger");
|
builder.ToTable(nameof(Passenger));
|
||||||
|
|
||||||
builder.HasKey(r => r.Id);
|
builder.HasKey(r => r.Id);
|
||||||
builder.Property(r => r.Id).ValueGeneratedNever();
|
builder.Property(r => r.Id).ValueGeneratedNever();
|
||||||
|
|||||||
@ -12,7 +12,7 @@ using Passenger.Data;
|
|||||||
namespace Passenger.Data.Migrations
|
namespace Passenger.Data.Migrations
|
||||||
{
|
{
|
||||||
[DbContext(typeof(PassengerDbContext))]
|
[DbContext(typeof(PassengerDbContext))]
|
||||||
[Migration("20230113134610_initial")]
|
[Migration("20230113183717_initial")]
|
||||||
partial class initial
|
partial class initial
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
@ -17,5 +17,6 @@ public sealed class PassengerDbContext : AppDbContextBase
|
|||||||
{
|
{
|
||||||
builder.ApplyConfigurationsFromAssembly(Assembly.GetExecutingAssembly());
|
builder.ApplyConfigurationsFromAssembly(Assembly.GetExecutingAssembly());
|
||||||
base.OnModelCreating(builder);
|
base.OnModelCreating(builder);
|
||||||
|
builder.ToSnakeCaseTables();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user