From e96283d0e61187fa2c94e4e7a2476cf8725389b4 Mon Sep 17 00:00:00 2001 From: meysamhadeli Date: Fri, 13 Jan 2023 19:06:56 +0330 Subject: [PATCH] feat: Add postgres instead of sql for write database --- .../docker-compose/docker-compose.yaml | 54 +-- .../docker-compose/infrastracture.yaml | 44 +-- src/BuildingBlocks/BuildingBlocks.csproj | 2 +- src/BuildingBlocks/EFCore/AppDbContextBase.cs | 11 +- src/BuildingBlocks/EFCore/DatabaseOptions.cs | 4 +- src/BuildingBlocks/EFCore/Extensions.cs | 13 +- src/BuildingBlocks/HealthCheck/Extensions.cs | 6 +- .../PersistMessageConfiguration.cs | 26 +- .../Data/DesignTimeDbContextFactory.cs | 3 +- .../20221206184130_initial.Designer.cs | 64 ---- .../Data/Migrations/20221206184130_initial.cs | 44 --- .../20230113134415_initial.Designer.cs | 72 ++++ .../Data/Migrations/20230113134415_initial.cs | 39 ++ .../PersistMessageDbContextModelSnapshot.cs | 42 ++- .../PersistMessageProcessor/Extensions.cs | 15 +- src/BuildingBlocks/TestBase/TestBase.cs | 63 ++-- src/BuildingBlocks/TestBase/TestContainers.cs | 29 +- .../src/Booking.Api/appsettings.docker.json | 2 +- .../Booking/src/Booking.Api/appsettings.json | 2 +- .../src/Booking.Api/appsettings.test.json | 2 +- .../Fakes/FakeFlightResponse.cs | 2 +- .../src/Flight.Api/appsettings.docker.json | 6 +- .../Flight/src/Flight.Api/appsettings.json | 6 +- .../src/Flight.Api/appsettings.test.json | 6 +- .../Configurations/AircraftConfiguration.cs | 3 +- .../Configurations/AirportConfiguration.cs | 2 +- .../Configurations/FlightConfiguration.cs | 11 +- .../Data/Configurations/SeatConfiguration.cs | 16 +- .../Flight/Data/DesignTimeDbContextFactory.cs | 3 +- .../20221206180723_Initial.Designer.cs | 232 ------------ .../Data/Migrations/20221206180723_Initial.cs | 169 --------- .../20230113134450_Init.Designer.cs | 299 +++++++++++++++ .../Data/Migrations/20230113134450_Init.cs | 152 ++++++++ .../FlightDbContextModelSnapshot.cs | 205 +++++++---- .../Fakes/FakeCreateFlightCommand.cs | 2 +- .../Fakes/FakeCreateFlightCommand.cs | 2 +- .../Fakes/FakeUpdateFlightCommand.cs | 2 +- .../UnitTest/Fakes/FakeCreateFlightCommand.cs | 2 +- .../src/Identity.Api/appsettings.docker.json | 6 +- .../src/Identity.Api/appsettings.json | 6 +- .../src/Identity.Api/appsettings.test.json | 6 +- .../Data/DesignTimeDbContextFactory.cs | 3 +- .../src/Identity/Data/IdentityContext.cs | 22 +- .../20221206180831_initial.Designer.cs | 291 --------------- .../Data/Migrations/20221206180831_initial.cs | 259 ------------- .../20230113134523_initial.Designer.cs | 346 ++++++++++++++++++ .../Data/Migrations/20230113134523_initial.cs | 228 ++++++++++++ .../IdentityContextModelSnapshot.cs | 207 +++++++---- .../Fakes/FakeRegisterNewUserCommand.cs | 2 +- .../src/Passenger.Api/appsettings.docker.json | 7 +- .../src/Passenger.Api/appsettings.json | 6 +- .../src/Passenger.Api/appsettings.test.json | 6 +- .../Configurations/PassengerConfiguration.cs | 2 +- .../Data/DesignTimeDbContextFactory.cs | 3 +- .../20221206180929_initial.Designer.cs | 70 ---- .../Data/Migrations/20221206180929_initial.cs | 48 --- .../20230113134610_initial.Designer.cs | 82 +++++ .../Data/Migrations/20230113134610_initial.cs | 43 +++ .../PassengerDbContextModelSnapshot.cs | 46 ++- 59 files changed, 1789 insertions(+), 1557 deletions(-) delete mode 100644 src/BuildingBlocks/PersistMessageProcessor/Data/Migrations/20221206184130_initial.Designer.cs delete mode 100644 src/BuildingBlocks/PersistMessageProcessor/Data/Migrations/20221206184130_initial.cs create mode 100644 src/BuildingBlocks/PersistMessageProcessor/Data/Migrations/20230113134415_initial.Designer.cs create mode 100644 src/BuildingBlocks/PersistMessageProcessor/Data/Migrations/20230113134415_initial.cs delete mode 100644 src/Services/Flight/src/Flight/Data/Migrations/20221206180723_Initial.Designer.cs delete mode 100644 src/Services/Flight/src/Flight/Data/Migrations/20221206180723_Initial.cs create mode 100644 src/Services/Flight/src/Flight/Data/Migrations/20230113134450_Init.Designer.cs create mode 100644 src/Services/Flight/src/Flight/Data/Migrations/20230113134450_Init.cs delete mode 100644 src/Services/Identity/src/Identity/Data/Migrations/20221206180831_initial.Designer.cs delete mode 100644 src/Services/Identity/src/Identity/Data/Migrations/20221206180831_initial.cs create mode 100644 src/Services/Identity/src/Identity/Data/Migrations/20230113134523_initial.Designer.cs create mode 100644 src/Services/Identity/src/Identity/Data/Migrations/20230113134523_initial.cs delete mode 100644 src/Services/Passenger/src/Passenger/Data/Migrations/20221206180929_initial.Designer.cs delete mode 100644 src/Services/Passenger/src/Passenger/Data/Migrations/20221206180929_initial.cs create mode 100644 src/Services/Passenger/src/Passenger/Data/Migrations/20230113134610_initial.Designer.cs create mode 100644 src/Services/Passenger/src/Passenger/Data/Migrations/20230113134610_initial.cs diff --git a/deployments/docker-compose/docker-compose.yaml b/deployments/docker-compose/docker-compose.yaml index 6ccfd71..bdf8f43 100644 --- a/deployments/docker-compose/docker-compose.yaml +++ b/deployments/docker-compose/docker-compose.yaml @@ -16,7 +16,7 @@ services: - "5001:80" - "5000:443" depends_on: - - sql + - postgres - rabbitmq - jaeger - elasticsearch @@ -47,7 +47,7 @@ services: - 5004:80 - 5003:443 depends_on: - - sql + - postgres - rabbitmq - jaeger - elasticsearch @@ -79,7 +79,7 @@ services: - 6005:80 - 5005:443 depends_on: - - sql + - postgres - rabbitmq - jaeger - elasticsearch @@ -110,7 +110,7 @@ services: - 6012:80 - 5012:443 depends_on: - - sql + - postgres - rabbitmq - jaeger - elasticsearch @@ -142,7 +142,7 @@ services: - 6010:80 - 5010:443 depends_on: - - sql + - postgres - rabbitmq - jaeger - eventstore @@ -160,36 +160,20 @@ services: - booking - ####################################################### - # SqlServer - ####################################################### - sql: - container_name: sql - image: mcr.microsoft.com/mssql/server:2022-latest - restart: unless-stopped - ports: - - "1433:1433" - environment: - SA_PASSWORD: "@Aa123456" - ACCEPT_EULA: "Y" - networks: - - booking - - -# ###################################################### -# # Postgres -# ###################################################### -# postgres: -# image: postgres:latest -# container_name: postgres -# restart: on-failure -# ports: -# - '5432:5432' -# environment: -# - POSTGRES_USER=postgres -# - POSTGRES_PASSWORD=postgres -# networks: -# - booking + ###################################################### + # Postgres + ###################################################### + postgres: + image: postgres:latest + container_name: postgres + restart: on-failure + ports: + - '5432:5432' + environment: + - POSTGRES_USER=postgres + - POSTGRES_PASSWORD=postgres + networks: + - booking ####################################################### diff --git a/deployments/docker-compose/infrastracture.yaml b/deployments/docker-compose/infrastracture.yaml index 10d4694..8dac1a1 100644 --- a/deployments/docker-compose/infrastracture.yaml +++ b/deployments/docker-compose/infrastracture.yaml @@ -15,36 +15,20 @@ services: - booking - ####################################################### - # SqlServer - ####################################################### - sql: - container_name: sql - image: mcr.microsoft.com/mssql/server:2022-latest - restart: unless-stopped - ports: - - "1433:1433" - environment: - SA_PASSWORD: "@Aa123456" - ACCEPT_EULA: "Y" - networks: - - booking - - -# ####################################################### -# # Postgres -# ###################################################### -# postgres: -# image: postgres:latest -# container_name: postgres -# restart: on-failure -# ports: -# - '5432:5432' -# environment: -# - POSTGRES_USER=postgres -# - POSTGRES_PASSWORD=postgres -# networks: -# - booking + ####################################################### + # Postgres + ###################################################### + postgres: + image: postgres:latest + container_name: postgres + restart: on-failure + ports: + - '5432:5432' + environment: + - POSTGRES_USER=postgres + - POSTGRES_PASSWORD=postgres + networks: + - booking ####################################################### # Jaeger diff --git a/src/BuildingBlocks/BuildingBlocks.csproj b/src/BuildingBlocks/BuildingBlocks.csproj index 8944ac0..fc9433b 100644 --- a/src/BuildingBlocks/BuildingBlocks.csproj +++ b/src/BuildingBlocks/BuildingBlocks.csproj @@ -14,8 +14,8 @@ + - diff --git a/src/BuildingBlocks/EFCore/AppDbContextBase.cs b/src/BuildingBlocks/EFCore/AppDbContextBase.cs index a2719ec..88db419 100644 --- a/src/BuildingBlocks/EFCore/AppDbContextBase.cs +++ b/src/BuildingBlocks/EFCore/AppDbContextBase.cs @@ -1,8 +1,6 @@ using System.Collections.Immutable; -using System.Data; using BuildingBlocks.Core.Event; using BuildingBlocks.Core.Model; -using BuildingBlocks.Utils; using BuildingBlocks.Web; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Storage; @@ -11,8 +9,6 @@ namespace BuildingBlocks.EFCore; public abstract class AppDbContextBase : DbContext, IDbContext { - public const string DefaultSchema = "dbo"; - private readonly ICurrentUserProvider _currentUserProvider; private IDbContextTransaction _currentTransaction; @@ -29,9 +25,12 @@ public abstract class AppDbContextBase : DbContext, IDbContext public async Task BeginTransactionAsync(CancellationToken cancellationToken = default) { - if (_currentTransaction != null) return; + if (_currentTransaction != null) + { + return; + } - _currentTransaction = await Database.BeginTransactionAsync(IsolationLevel.ReadCommitted, cancellationToken); + _currentTransaction ??= await Database.BeginTransactionAsync(cancellationToken); } public async Task CommitTransactionAsync(CancellationToken cancellationToken = default) diff --git a/src/BuildingBlocks/EFCore/DatabaseOptions.cs b/src/BuildingBlocks/EFCore/DatabaseOptions.cs index 90ef69d..aeaf85a 100644 --- a/src/BuildingBlocks/EFCore/DatabaseOptions.cs +++ b/src/BuildingBlocks/EFCore/DatabaseOptions.cs @@ -1,6 +1,6 @@ namespace BuildingBlocks.EFCore; -public class DatabaseOptions +public class PostgresOptions { - public string DefaultConnection { get; set; } + public string ConnectionString { get; set; } } diff --git a/src/BuildingBlocks/EFCore/Extensions.cs b/src/BuildingBlocks/EFCore/Extensions.cs index f61fe85..9f6c998 100644 --- a/src/BuildingBlocks/EFCore/Extensions.cs +++ b/src/BuildingBlocks/EFCore/Extensions.cs @@ -17,18 +17,21 @@ public static class Extensions this IServiceCollection services) where TContext : DbContext, IDbContext { + AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true); - services.AddValidateOptions(); + services.AddValidateOptions(); services.AddDbContext((sp, options) => { - var databaseOptions = services.GetOptions(nameof(DatabaseOptions)); + var postgresOptions = sp.GetRequiredService(); - options.UseSqlServer(databaseOptions?.DefaultConnection, + options.UseNpgsql(postgresOptions?.ConnectionString, dbOptions => { dbOptions.MigrationsAssembly(typeof(TContext).Assembly.GetName().Name); - }); + }) + // https://github.com/efcore/EFCore.NamingConventions + .UseSnakeCaseNamingConvention(); }); services.AddScoped(provider => provider.GetService()); @@ -42,7 +45,9 @@ public static class Extensions MigrateDatabaseAsync(app.ApplicationServices).GetAwaiter().GetResult(); if (!env.IsEnvironment("test")) + { SeedDataAsync(app.ApplicationServices).GetAwaiter().GetResult(); + } return app; } diff --git a/src/BuildingBlocks/HealthCheck/Extensions.cs b/src/BuildingBlocks/HealthCheck/Extensions.cs index fb43c9c..4bf9d5c 100644 --- a/src/BuildingBlocks/HealthCheck/Extensions.cs +++ b/src/BuildingBlocks/HealthCheck/Extensions.cs @@ -21,7 +21,7 @@ public static class Extensions if (!healthOptions.Enabled) return services; var appOptions = services.GetOptions(nameof(AppOptions)); - var sqlOptions = services.GetOptions(nameof(DatabaseOptions)); + var postgresOptions = services.GetOptions(nameof(PostgresOptions)); var rabbitMqOptions = services.GetOptions(nameof(RabbitMqOptions)); var mongoOptions = services.GetOptions(nameof(MongoOptions)); var logOptions = services.GetOptions(nameof(LogOptions)); @@ -35,8 +35,8 @@ public static class Extensions if (mongoOptions.ConnectionString is not null) healthChecksBuilder.AddMongoDb(mongoOptions.ConnectionString); - if (sqlOptions.DefaultConnection is not null) - healthChecksBuilder.AddSqlServer(sqlOptions.DefaultConnection); + if (postgresOptions.ConnectionString is not null) + healthChecksBuilder.AddNpgSql(postgresOptions.ConnectionString); services.AddHealthChecksUI(setup => { diff --git a/src/BuildingBlocks/PersistMessageProcessor/Data/Configurations/PersistMessageConfiguration.cs b/src/BuildingBlocks/PersistMessageProcessor/Data/Configurations/PersistMessageConfiguration.cs index 18c1281..6689f49 100644 --- a/src/BuildingBlocks/PersistMessageProcessor/Data/Configurations/PersistMessageConfiguration.cs +++ b/src/BuildingBlocks/PersistMessageProcessor/Data/Configurations/PersistMessageConfiguration.cs @@ -1,5 +1,4 @@ -using BuildingBlocks.EFCore; -using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; namespace BuildingBlocks.PersistMessageProcessor.Data.Configurations; @@ -8,7 +7,7 @@ public class PersistMessageConfiguration : IEntityTypeConfiguration builder) { - builder.ToTable("PersistMessage", AppDbContextBase.DefaultSchema); + builder.ToTable("persistMessage"); builder.HasKey(x => x.Id); @@ -16,27 +15,16 @@ public class PersistMessageConfiguration : IEntityTypeConfiguration x.DeliveryType) - .HasMaxLength(50) + .HasDefaultValue(MessageDeliveryType.Outbox) .HasConversion( - v => v.ToString(), - v => (MessageDeliveryType)Enum.Parse(typeof(MessageDeliveryType), v)) - .IsRequired() - .IsUnicode(false); + x => x.ToString(), + x => (MessageDeliveryType)Enum.Parse(typeof(MessageDeliveryType), x)); - builder.Property(x => x.DeliveryType) - .HasMaxLength(50) - .HasConversion( - v => v.ToString(), - v => (MessageDeliveryType)Enum.Parse(typeof(MessageDeliveryType), v)) - .IsRequired() - .IsUnicode(false); builder.Property(x => x.MessageStatus) - .HasMaxLength(50) + .HasDefaultValue(MessageStatus.InProgress) .HasConversion( v => v.ToString(), - v => (MessageStatus)Enum.Parse(typeof(MessageStatus), v)) - .IsRequired() - .IsUnicode(false); + v => (MessageStatus)Enum.Parse(typeof(MessageStatus), v)); } } diff --git a/src/BuildingBlocks/PersistMessageProcessor/Data/DesignTimeDbContextFactory.cs b/src/BuildingBlocks/PersistMessageProcessor/Data/DesignTimeDbContextFactory.cs index 6d0ae2f..5609afe 100644 --- a/src/BuildingBlocks/PersistMessageProcessor/Data/DesignTimeDbContextFactory.cs +++ b/src/BuildingBlocks/PersistMessageProcessor/Data/DesignTimeDbContextFactory.cs @@ -9,7 +9,8 @@ public class DesignTimeDbContextFactory : IDesignTimeDbContextFactory(); - builder.UseSqlServer("Server=localhost;Database=PersistMessageDB;User ID=sa;Password=@Aa123456;TrustServerCertificate=True"); + builder.UseNpgsql("Server=localhost;Port=5432;Database=persist_message;User Id=postgres;Password=postgres;Include Error Detail=true") + .UseSnakeCaseNamingConvention(); return new PersistMessageDbContext(builder.Options); } } diff --git a/src/BuildingBlocks/PersistMessageProcessor/Data/Migrations/20221206184130_initial.Designer.cs b/src/BuildingBlocks/PersistMessageProcessor/Data/Migrations/20221206184130_initial.Designer.cs deleted file mode 100644 index 4d44436..0000000 --- a/src/BuildingBlocks/PersistMessageProcessor/Data/Migrations/20221206184130_initial.Designer.cs +++ /dev/null @@ -1,64 +0,0 @@ -// -using System; -using BuildingBlocks.PersistMessageProcessor.Data; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace BuildingBlocks.PersistMessageProcessor.Data.Migrations -{ - [DbContext(typeof(PersistMessageDbContext))] - [Migration("20221206184130_initial")] - partial class initial - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "7.0.0") - .HasAnnotation("Relational:MaxIdentifierLength", 128); - - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - - modelBuilder.Entity("BuildingBlocks.PersistMessageProcessor.PersistMessage", b => - { - b.Property("Id") - .HasColumnType("bigint"); - - b.Property("Created") - .HasColumnType("datetime2"); - - b.Property("Data") - .HasColumnType("nvarchar(max)"); - - b.Property("DataType") - .HasColumnType("nvarchar(max)"); - - b.Property("DeliveryType") - .IsRequired() - .HasMaxLength(50) - .IsUnicode(false) - .HasColumnType("varchar(50)"); - - b.Property("MessageStatus") - .IsRequired() - .HasMaxLength(50) - .IsUnicode(false) - .HasColumnType("varchar(50)"); - - b.Property("RetryCount") - .HasColumnType("int"); - - b.HasKey("Id"); - - b.ToTable("PersistMessage", "dbo"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/src/BuildingBlocks/PersistMessageProcessor/Data/Migrations/20221206184130_initial.cs b/src/BuildingBlocks/PersistMessageProcessor/Data/Migrations/20221206184130_initial.cs deleted file mode 100644 index 3d3f92b..0000000 --- a/src/BuildingBlocks/PersistMessageProcessor/Data/Migrations/20221206184130_initial.cs +++ /dev/null @@ -1,44 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace BuildingBlocks.PersistMessageProcessor.Data.Migrations -{ - /// - public partial class initial : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.EnsureSchema( - name: "dbo"); - - migrationBuilder.CreateTable( - name: "PersistMessage", - schema: "dbo", - columns: table => new - { - Id = table.Column(type: "bigint", nullable: false), - DataType = table.Column(type: "nvarchar(max)", nullable: true), - Data = table.Column(type: "nvarchar(max)", nullable: true), - Created = table.Column(type: "datetime2", nullable: false), - RetryCount = table.Column(type: "int", nullable: false), - MessageStatus = table.Column(type: "varchar(50)", unicode: false, maxLength: 50, nullable: false), - DeliveryType = table.Column(type: "varchar(50)", unicode: false, maxLength: 50, nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_PersistMessage", x => x.Id); - }); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "PersistMessage", - schema: "dbo"); - } - } -} diff --git a/src/BuildingBlocks/PersistMessageProcessor/Data/Migrations/20230113134415_initial.Designer.cs b/src/BuildingBlocks/PersistMessageProcessor/Data/Migrations/20230113134415_initial.Designer.cs new file mode 100644 index 0000000..dd72190 --- /dev/null +++ b/src/BuildingBlocks/PersistMessageProcessor/Data/Migrations/20230113134415_initial.Designer.cs @@ -0,0 +1,72 @@ +// +using System; +using BuildingBlocks.PersistMessageProcessor.Data; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace BuildingBlocks.PersistMessageProcessor.Data.Migrations +{ + [DbContext(typeof(PersistMessageDbContext))] + [Migration("20230113134415_initial")] + partial class initial + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.1") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("BuildingBlocks.PersistMessageProcessor.PersistMessage", b => + { + b.Property("Id") + .HasColumnType("bigint") + .HasColumnName("id"); + + b.Property("Created") + .HasColumnType("timestamp with time zone") + .HasColumnName("created"); + + b.Property("Data") + .HasColumnType("text") + .HasColumnName("data"); + + b.Property("DataType") + .HasColumnType("text") + .HasColumnName("data_type"); + + b.Property("DeliveryType") + .IsRequired() + .ValueGeneratedOnAdd() + .HasColumnType("text") + .HasDefaultValue("Outbox") + .HasColumnName("delivery_type"); + + b.Property("MessageStatus") + .IsRequired() + .ValueGeneratedOnAdd() + .HasColumnType("text") + .HasDefaultValue("InProgress") + .HasColumnName("message_status"); + + b.Property("RetryCount") + .HasColumnType("integer") + .HasColumnName("retry_count"); + + b.HasKey("Id") + .HasName("pk_persist_message"); + + b.ToTable("persistMessage", (string)null); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/BuildingBlocks/PersistMessageProcessor/Data/Migrations/20230113134415_initial.cs b/src/BuildingBlocks/PersistMessageProcessor/Data/Migrations/20230113134415_initial.cs new file mode 100644 index 0000000..ee75b55 --- /dev/null +++ b/src/BuildingBlocks/PersistMessageProcessor/Data/Migrations/20230113134415_initial.cs @@ -0,0 +1,39 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace BuildingBlocks.PersistMessageProcessor.Data.Migrations +{ + /// + public partial class initial : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "persistMessage", + columns: table => new + { + id = table.Column(type: "bigint", nullable: false), + datatype = table.Column(name: "data_type", type: "text", nullable: true), + data = table.Column(type: "text", nullable: true), + created = table.Column(type: "timestamp with time zone", nullable: false), + retrycount = table.Column(name: "retry_count", type: "integer", nullable: false), + messagestatus = table.Column(name: "message_status", type: "text", nullable: false, defaultValue: "InProgress"), + deliverytype = table.Column(name: "delivery_type", type: "text", nullable: false, defaultValue: "Outbox") + }, + constraints: table => + { + table.PrimaryKey("pk_persist_message", x => x.id); + }); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "persistMessage"); + } + } +} diff --git a/src/BuildingBlocks/PersistMessageProcessor/Data/Migrations/PersistMessageDbContextModelSnapshot.cs b/src/BuildingBlocks/PersistMessageProcessor/Data/Migrations/PersistMessageDbContextModelSnapshot.cs index df9a1fb..74939c2 100644 --- a/src/BuildingBlocks/PersistMessageProcessor/Data/Migrations/PersistMessageDbContextModelSnapshot.cs +++ b/src/BuildingBlocks/PersistMessageProcessor/Data/Migrations/PersistMessageDbContextModelSnapshot.cs @@ -3,8 +3,8 @@ using System; using BuildingBlocks.PersistMessageProcessor.Data; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; #nullable disable @@ -17,43 +17,51 @@ namespace BuildingBlocks.PersistMessageProcessor.Data.Migrations { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "7.0.0") - .HasAnnotation("Relational:MaxIdentifierLength", 128); + .HasAnnotation("ProductVersion", "7.0.1") + .HasAnnotation("Relational:MaxIdentifierLength", 63); - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); modelBuilder.Entity("BuildingBlocks.PersistMessageProcessor.PersistMessage", b => { b.Property("Id") - .HasColumnType("bigint"); + .HasColumnType("bigint") + .HasColumnName("id"); b.Property("Created") - .HasColumnType("datetime2"); + .HasColumnType("timestamp with time zone") + .HasColumnName("created"); b.Property("Data") - .HasColumnType("nvarchar(max)"); + .HasColumnType("text") + .HasColumnName("data"); b.Property("DataType") - .HasColumnType("nvarchar(max)"); + .HasColumnType("text") + .HasColumnName("data_type"); b.Property("DeliveryType") .IsRequired() - .HasMaxLength(50) - .IsUnicode(false) - .HasColumnType("varchar(50)"); + .ValueGeneratedOnAdd() + .HasColumnType("text") + .HasDefaultValue("Outbox") + .HasColumnName("delivery_type"); b.Property("MessageStatus") .IsRequired() - .HasMaxLength(50) - .IsUnicode(false) - .HasColumnType("varchar(50)"); + .ValueGeneratedOnAdd() + .HasColumnType("text") + .HasDefaultValue("InProgress") + .HasColumnName("message_status"); b.Property("RetryCount") - .HasColumnType("int"); + .HasColumnType("integer") + .HasColumnName("retry_count"); - b.HasKey("Id"); + b.HasKey("Id") + .HasName("pk_persist_message"); - b.ToTable("PersistMessage", "dbo"); + b.ToTable("persistMessage", (string)null); }); #pragma warning restore 612, 618 } diff --git a/src/BuildingBlocks/PersistMessageProcessor/Extensions.cs b/src/BuildingBlocks/PersistMessageProcessor/Extensions.cs index ddcac04..eb52849 100644 --- a/src/BuildingBlocks/PersistMessageProcessor/Extensions.cs +++ b/src/BuildingBlocks/PersistMessageProcessor/Extensions.cs @@ -9,14 +9,21 @@ public static class Extensions { public static IServiceCollection AddPersistMessageProcessor(this IServiceCollection services) { + AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true); + services.AddValidateOptions(); - services.AddDbContext(options => + services.AddDbContext((sp, options) => { - var persistMessageOptions = services.GetOptions(nameof(PersistMessageOptions)); + var persistMessageOptions = sp.GetRequiredService(); - options.UseSqlServer(persistMessageOptions.ConnectionString, - x => x.MigrationsAssembly(typeof(PersistMessageDbContext).Assembly.GetName().Name)); + options.UseNpgsql(persistMessageOptions.ConnectionString, + dbOptions => + { + dbOptions.MigrationsAssembly(typeof(PersistMessageDbContext).Assembly.GetName().Name); + }) + // https://github.com/efcore/EFCore.NamingConventions + .UseSnakeCaseNamingConvention();; }); services.AddScoped(provider => provider.GetService()); diff --git a/src/BuildingBlocks/TestBase/TestBase.cs b/src/BuildingBlocks/TestBase/TestBase.cs index d2f4cf6..bb72ea9 100644 --- a/src/BuildingBlocks/TestBase/TestBase.cs +++ b/src/BuildingBlocks/TestBase/TestBase.cs @@ -14,14 +14,12 @@ using MediatR; using Microsoft.AspNetCore.Hosting; using Microsoft.AspNetCore.Http; using Microsoft.AspNetCore.Mvc.Testing; -using Microsoft.Data.SqlClient; using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using MongoDB.Driver; using NSubstitute; using Respawn; -using Respawn.Graph; using Serilog; using Xunit; using Xunit.Abstractions; @@ -32,7 +30,8 @@ using WebMotions.Fake.Authentication.JwtBearer; namespace BuildingBlocks.TestBase; - +using Npgsql; +using Exception = System.Exception; public class TestFixture : IAsyncLifetime where TEntryPoint : class @@ -41,8 +40,8 @@ public class TestFixture : IAsyncLifetime private int Timeout => 120; // Second private ITestHarness TestHarness => ServiceProvider?.GetTestHarness(); private Action TestRegistrationServices { get; set; } - private MsSqlTestcontainer MsSqlTestContainer; - private MsSqlTestcontainer MsSqlPersistTestContainer; + private PostgreSqlTestcontainer PostgresTestcontainer; + private PostgreSqlTestcontainer PostgresPersistTestContainer; public RabbitMqTestcontainer RabbitMqTestContainer; public MongoDbTestcontainer MongoDbTestContainer; @@ -239,21 +238,21 @@ public class TestFixture : IAsyncLifetime private async Task StartTestContainerAsync() { - MsSqlTestContainer = TestContainers.MsSqlTestContainer; - MsSqlPersistTestContainer = TestContainers.MsSqlPersistTestContainer; + PostgresTestcontainer = TestContainers.PostgresTestContainer; + PostgresPersistTestContainer = TestContainers.PostgresPersistTestContainer; RabbitMqTestContainer = TestContainers.RabbitMqTestContainer; MongoDbTestContainer = TestContainers.MongoTestContainer; await MongoDbTestContainer.StartAsync(); - await MsSqlTestContainer.StartAsync(); - await MsSqlPersistTestContainer.StartAsync(); + await PostgresTestcontainer.StartAsync(); + await PostgresPersistTestContainer.StartAsync(); await RabbitMqTestContainer.StartAsync(); } private async Task StopTestContainerAsync() { - await MsSqlTestContainer.StopAsync(); - await MsSqlPersistTestContainer.StopAsync(); + await PostgresTestcontainer.StopAsync(); + await PostgresPersistTestContainer.StopAsync(); await RabbitMqTestContainer.StopAsync(); await MongoDbTestContainer.StopAsync(); } @@ -262,8 +261,8 @@ public class TestFixture : IAsyncLifetime { configuration.AddInMemoryCollection(new KeyValuePair[] { - new("DatabaseOptions:DefaultConnection", MsSqlTestContainer.ConnectionString + "TrustServerCertificate=True"), - new("PersistMessageOptions:ConnectionString", MsSqlPersistTestContainer.ConnectionString + "TrustServerCertificate=True"), + new("PostgresOptions:ConnectionString", PostgresTestcontainer.ConnectionString), + new("PersistMessageOptions:ConnectionString", PostgresPersistTestContainer.ConnectionString), new("RabbitMqOptions:HostName", RabbitMqTestContainer.Hostname), new("RabbitMqOptions:UserName", RabbitMqTestContainer.Username), new("RabbitMqOptions:Password", RabbitMqTestContainer.Password), @@ -432,13 +431,13 @@ public class TestFixtureCore : IAsyncLifetime { private Respawner _reSpawnerDefaultDb; private Respawner _reSpawnerPersistDb; - private SqlConnection DefaultDbConnection { get; set; } - private SqlConnection PersistDbConnection { get; set; } + private NpgsqlConnection DefaultDbConnection { get; set; } + private NpgsqlConnection PersistDbConnection { get; set; } public TestFixtureCore(TestFixture integrationTestFixture, ITestOutputHelper outputHelper) { Fixture = integrationTestFixture; - integrationTestFixture.RegisterServices(services => RegisterTestsServices(services)); + integrationTestFixture.RegisterServices(RegisterTestsServices); integrationTestFixture.Logger = integrationTestFixture.CreateLogger(outputHelper); } @@ -447,43 +446,43 @@ public class TestFixtureCore : IAsyncLifetime public async Task InitializeAsync() { - await InitSqlAsync(); + await InitPostgresAsync(); } public async Task DisposeAsync() { - await ResetSqlAsync(); + await ResetPostgresAsync(); await ResetMongoAsync(); await ResetRabbitMqAsync(); } - private async Task InitSqlAsync() + private async Task InitPostgresAsync() { - var databaseOptions = Fixture.ServiceProvider.GetRequiredService(); + var postgresOptions = Fixture.ServiceProvider.GetRequiredService(); var persistOptions = Fixture.ServiceProvider.GetRequiredService(); if (!string.IsNullOrEmpty(persistOptions?.ConnectionString)) { - PersistDbConnection = new SqlConnection(persistOptions?.ConnectionString); + PersistDbConnection = new NpgsqlConnection(persistOptions.ConnectionString); await PersistDbConnection.OpenAsync(); _reSpawnerPersistDb = await Respawner.CreateAsync(PersistDbConnection, - new RespawnerOptions { TablesToIgnore = new Table[] { "__EFMigrationsHistory" }, }); + new RespawnerOptions { DbAdapter = DbAdapter.Postgres }); } - if (!string.IsNullOrEmpty(databaseOptions?.DefaultConnection)) + if (!string.IsNullOrEmpty(postgresOptions?.ConnectionString)) { - DefaultDbConnection = new SqlConnection(databaseOptions.DefaultConnection); + DefaultDbConnection = new NpgsqlConnection(postgresOptions.ConnectionString); await DefaultDbConnection.OpenAsync(); _reSpawnerDefaultDb = await Respawner.CreateAsync(DefaultDbConnection, - new RespawnerOptions { TablesToIgnore = new Table[] { "__EFMigrationsHistory" }, }); + new RespawnerOptions { DbAdapter = DbAdapter.Postgres }); await SeedDataAsync(); } } - private async Task ResetSqlAsync() + private async Task ResetPostgresAsync() { if (PersistDbConnection is not null) { @@ -514,7 +513,8 @@ public class TestFixtureCore : IAsyncLifetime { var port = Fixture.RabbitMqTestContainer?.GetMappedPublicPort(15672) ?? 15672; - var managementClient = new ManagementClient(Fixture.RabbitMqTestContainer?.Hostname, Fixture.RabbitMqTestContainer?.Username, + var managementClient = new ManagementClient(Fixture.RabbitMqTestContainer?.Hostname, + Fixture.RabbitMqTestContainer?.Username, Fixture.RabbitMqTestContainer?.Password, port); var bd = await managementClient.GetBindingsAsync(cancellationToken); @@ -555,7 +555,8 @@ public abstract class TestReadBase : TestFixtureCore integrationTestFixture, ITestOutputHelper outputHelper = null) : base(integrationTestFixture, outputHelper) + TestReadFixture integrationTestFixture, ITestOutputHelper outputHelper = null) : base( + integrationTestFixture, outputHelper) { Fixture = integrationTestFixture; } @@ -569,7 +570,8 @@ public abstract class TestWriteBase : TestFixtureCore integrationTestFixture, ITestOutputHelper outputHelper = null) : base(integrationTestFixture, outputHelper) + TestWriteFixture integrationTestFixture, ITestOutputHelper outputHelper = null) : base( + integrationTestFixture, outputHelper) { Fixture = integrationTestFixture; } @@ -584,7 +586,8 @@ public abstract class TestBase : TestFixtureC where TRContext : MongoDbContext { protected TestBase( - TestFixture integrationTestFixture, ITestOutputHelper outputHelper = null) : base(integrationTestFixture, outputHelper) + TestFixture integrationTestFixture, ITestOutputHelper outputHelper = null) : + base(integrationTestFixture, outputHelper) { Fixture = integrationTestFixture; } diff --git a/src/BuildingBlocks/TestBase/TestContainers.cs b/src/BuildingBlocks/TestBase/TestContainers.cs index 72826ed..e862091 100644 --- a/src/BuildingBlocks/TestBase/TestContainers.cs +++ b/src/BuildingBlocks/TestBase/TestContainers.cs @@ -16,27 +16,20 @@ public static class TestContainers Username = Guid.NewGuid().ToString("D") }) .WithImage("postgres:latest") + .WithPortBinding(5432, true) .WithCleanUp(true) .Build(); - - public static MsSqlTestcontainer MsSqlTestContainer = new TestcontainersBuilder() - .WithDatabase(new MsSqlTestcontainerConfiguration() - { - Password = Guid.NewGuid().ToString("D") - }) - .WithImage("mcr.microsoft.com/mssql/server:2022-latest") - .WithPortBinding(1433, true) - .WithCleanUp(true) - .Build(); - - public static MsSqlTestcontainer MsSqlPersistTestContainer = new TestcontainersBuilder() - .WithDatabase(new MsSqlTestcontainerConfiguration() - { - Password = Guid.NewGuid().ToString("D") - }) - .WithImage("mcr.microsoft.com/mssql/server:2022-latest") - .WithPortBinding(1433, true) + public static PostgreSqlTestcontainer PostgresPersistTestContainer => new TestcontainersBuilder() + .WithDatabase( + new PostgreSqlTestcontainerConfiguration + { + Database = Guid.NewGuid().ToString("D"), + Password = Guid.NewGuid().ToString("D"), + Username = Guid.NewGuid().ToString("D") + }) + .WithImage("postgres:latest") + .WithPortBinding(5432, true) .WithCleanUp(true) .Build(); diff --git a/src/Services/Booking/src/Booking.Api/appsettings.docker.json b/src/Services/Booking/src/Booking.Api/appsettings.docker.json index 1c95bd3..cb7fe4c 100644 --- a/src/Services/Booking/src/Booking.Api/appsettings.docker.json +++ b/src/Services/Booking/src/Booking.Api/appsettings.docker.json @@ -9,7 +9,7 @@ "PersistMessageOptions": { "Interval": 30, "Enabled": true, - "ConnectionString": "Server=sql;Database=PersistMessageDB;User ID=sa;Password=@Aa123456;TrustServerCertificate=True" + "ConnectionString": "Server=postgres;Port=5432;Database=persist_message;User Id=postgres;Password=postgres;Include Error Detail=true" }, "RabbitMqOptions": { "HostName": "rabbitmq", diff --git a/src/Services/Booking/src/Booking.Api/appsettings.json b/src/Services/Booking/src/Booking.Api/appsettings.json index da3ee97..cb80b35 100644 --- a/src/Services/Booking/src/Booking.Api/appsettings.json +++ b/src/Services/Booking/src/Booking.Api/appsettings.json @@ -49,7 +49,7 @@ "PersistMessageOptions": { "Interval": 30, "Enabled": true, - "ConnectionString": "Server=localhost;Database=PersistMessageDB;User ID=sa;Password=@Aa123456;TrustServerCertificate=True" + "ConnectionString": "Server=localhost;Port=5432;Database=persist_message;User Id=postgres;Password=postgres;Include Error Detail=true" }, "AllowedHosts": "*" } diff --git a/src/Services/Booking/src/Booking.Api/appsettings.test.json b/src/Services/Booking/src/Booking.Api/appsettings.test.json index 088abe0..5645ffb 100644 --- a/src/Services/Booking/src/Booking.Api/appsettings.test.json +++ b/src/Services/Booking/src/Booking.Api/appsettings.test.json @@ -24,6 +24,6 @@ "PersistMessageOptions": { "Interval": 30, "Enabled": true, - "ConnectionString": "Server=localhost;Database=PersistMessageDB_Test;User ID=sa;Password=@Aa123456;TrustServerCertificate=True" + "ConnectionString": "Server=localhost;Port=5432;Database=persist_message_test;User Id=postgres;Password=postgres;Include Error Detail=true" } } diff --git a/src/Services/Booking/tests/IntegrationTest/Fakes/FakeFlightResponse.cs b/src/Services/Booking/tests/IntegrationTest/Fakes/FakeFlightResponse.cs index 711d5d0..6e309c2 100644 --- a/src/Services/Booking/tests/IntegrationTest/Fakes/FakeFlightResponse.cs +++ b/src/Services/Booking/tests/IntegrationTest/Fakes/FakeFlightResponse.cs @@ -17,7 +17,7 @@ public class FakeFlightResponse : AutoFaker RuleFor(r => r.ArriveDate, _ => DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc).ToTimestamp()); RuleFor(r => r.DepartureDate, _ => DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc).ToTimestamp()); RuleFor(r => r.FlightDate, _ => DateTime.SpecifyKind(DateTime.Now, DateTimeKind.Utc).ToTimestamp()); - RuleFor(r => r.FlightNumber, _ => "121LP"); + RuleFor(r => r.FlightNumber, r => r.Random.Number(1000, 2000).ToString()); RuleFor(r => r.DepartureAirportId, _ => 2); } } diff --git a/src/Services/Flight/src/Flight.Api/appsettings.docker.json b/src/Services/Flight/src/Flight.Api/appsettings.docker.json index bfc897b..14bba68 100644 --- a/src/Services/Flight/src/Flight.Api/appsettings.docker.json +++ b/src/Services/Flight/src/Flight.Api/appsettings.docker.json @@ -6,8 +6,8 @@ "Microsoft.AspNetCore": "Warning" } }, - "DatabaseOptions": { - "DefaultConnection": "Server=sql;Database=FlightDB;User ID=sa;Password=@Aa123456;TrustServerCertificate=True" + "PostgresOptions": { + "ConnectionString": "Server=postgres;Port=5432;Database=flight;User Id=postgres;Password=postgres;Include Error Detail=true" }, "Jwt": { "Authority": "https://localhost:5005", @@ -23,7 +23,7 @@ "PersistMessageOptions": { "Interval": 30, "Enabled": true, - "ConnectionString": "Server=sql;Database=PersistMessageDB;User ID=sa;Password=@Aa123456;TrustServerCertificate=True" + "ConnectionString": "Server=postgres;Port=5432;Database=persist_message;User Id=postgres;Password=postgres;Include Error Detail=true" }, "AllowedHosts": "*" } diff --git a/src/Services/Flight/src/Flight.Api/appsettings.json b/src/Services/Flight/src/Flight.Api/appsettings.json index 43ca496..e69597f 100644 --- a/src/Services/Flight/src/Flight.Api/appsettings.json +++ b/src/Services/Flight/src/Flight.Api/appsettings.json @@ -21,8 +21,8 @@ "MinimumEventLevel": "error" } }, - "DatabaseOptions": { - "DefaultConnection": "Server=localhost;Database=FlightDB;User ID=sa;Password=@Aa123456;TrustServerCertificate=True" + "PostgresOptions": { + "ConnectionString": "Server=localhost;Port=5432;Database=flight;User Id=postgres;Password=postgres;Include Error Detail=true" }, "MongoOptions": { "ConnectionString": "mongodb://localhost:27017", @@ -42,7 +42,7 @@ "PersistMessageOptions": { "Interval": 30, "Enabled": true, - "ConnectionString": "Server=localhost;Database=PersistMessageDB;User ID=sa;Password=@Aa123456;TrustServerCertificate=True" + "ConnectionString": "Server=localhost;Port=5432;Database=persist_message;User Id=postgres;Password=postgres;Include Error Detail=true" }, "HealthOptions": { "Enabled": false diff --git a/src/Services/Flight/src/Flight.Api/appsettings.test.json b/src/Services/Flight/src/Flight.Api/appsettings.test.json index d1d3a72..9a7de5c 100644 --- a/src/Services/Flight/src/Flight.Api/appsettings.test.json +++ b/src/Services/Flight/src/Flight.Api/appsettings.test.json @@ -1,6 +1,6 @@ { - "DatabaseOptions": { - "DefaultConnection": "Server=localhost;Database=FlightDB_Test;User ID=sa;Password=@Aa123456;TrustServerCertificate=True" + "PostgresOptions": { + "ConnectionString": "Server=localhost;Port=5432;Database=flight_test;User Id=postgres;Password=postgres;Include Error Detail=true" }, "RabbitMqOptions": { "HostName": "localhost", @@ -20,6 +20,6 @@ "PersistMessageOptions": { "Interval": 2, "Enabled": true, - "ConnectionString": "Server=localhost;Database=PersistMessageDB_Test;User ID=sa;Password=@Aa123456;TrustServerCertificate=True" + "ConnectionString": "Server=localhost;Port=5432;Database=persist_message_test;User Id=postgres;Password=postgres;Include Error Detail=true" } } diff --git a/src/Services/Flight/src/Flight/Data/Configurations/AircraftConfiguration.cs b/src/Services/Flight/src/Flight/Data/Configurations/AircraftConfiguration.cs index b1410ea..c0ae112 100644 --- a/src/Services/Flight/src/Flight/Data/Configurations/AircraftConfiguration.cs +++ b/src/Services/Flight/src/Flight/Data/Configurations/AircraftConfiguration.cs @@ -1,4 +1,3 @@ -using BuildingBlocks.EFCore; using Flight.Aircrafts.Models; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; @@ -9,7 +8,7 @@ public class AircraftConfiguration : IEntityTypeConfiguration { public void Configure(EntityTypeBuilder builder) { - builder.ToTable("Aircraft", AppDbContextBase.DefaultSchema); + builder.ToTable("aircraft"); builder.HasKey(r => r.Id); builder.Property(r => r.Id).ValueGeneratedNever(); } diff --git a/src/Services/Flight/src/Flight/Data/Configurations/AirportConfiguration.cs b/src/Services/Flight/src/Flight/Data/Configurations/AirportConfiguration.cs index 18a5e6c..9561491 100644 --- a/src/Services/Flight/src/Flight/Data/Configurations/AirportConfiguration.cs +++ b/src/Services/Flight/src/Flight/Data/Configurations/AirportConfiguration.cs @@ -9,7 +9,7 @@ public class AirportConfiguration: IEntityTypeConfiguration { public void Configure(EntityTypeBuilder builder) { - builder.ToTable("Airport", AppDbContextBase.DefaultSchema); + builder.ToTable("airport"); builder.HasKey(r => r.Id); builder.Property(r => r.Id).ValueGeneratedNever(); diff --git a/src/Services/Flight/src/Flight/Data/Configurations/FlightConfiguration.cs b/src/Services/Flight/src/Flight/Data/Configurations/FlightConfiguration.cs index a5ea23c..a1aa491 100644 --- a/src/Services/Flight/src/Flight/Data/Configurations/FlightConfiguration.cs +++ b/src/Services/Flight/src/Flight/Data/Configurations/FlightConfiguration.cs @@ -6,11 +6,13 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders; namespace Flight.Data.Configurations; +using System; + public class FlightConfiguration : IEntityTypeConfiguration { public void Configure(EntityTypeBuilder builder) { - builder.ToTable("Flight", AppDbContextBase.DefaultSchema); + builder.ToTable("flight"); builder.HasKey(r => r.Id); builder.Property(r => r.Id).ValueGeneratedNever(); @@ -26,6 +28,13 @@ public class FlightConfiguration : IEntityTypeConfiguration d.DepartureAirportId) .HasForeignKey(a => a.ArriveAirportId); + + builder.Property(x => x.Status) + .HasDefaultValue(Flights.Enums.FlightStatus.Unknown) + .HasConversion( + x => x.ToString(), + x => (Flights.Enums.FlightStatus)Enum.Parse(typeof(Flights.Enums.FlightStatus), x)); + // // https://docs.microsoft.com/en-us/ef/core/modeling/shadow-properties // // https://docs.microsoft.com/en-us/ef/core/modeling/owned-entities // builder.OwnsMany(p => p.Seats, a => diff --git a/src/Services/Flight/src/Flight/Data/Configurations/SeatConfiguration.cs b/src/Services/Flight/src/Flight/Data/Configurations/SeatConfiguration.cs index 8033589..1e8404e 100644 --- a/src/Services/Flight/src/Flight/Data/Configurations/SeatConfiguration.cs +++ b/src/Services/Flight/src/Flight/Data/Configurations/SeatConfiguration.cs @@ -5,11 +5,13 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders; namespace Flight.Data.Configurations; +using System; + public class SeatConfiguration : IEntityTypeConfiguration { public void Configure(EntityTypeBuilder builder) { - builder.ToTable("Seat", AppDbContextBase.DefaultSchema); + builder.ToTable("seat"); builder.HasKey(r => r.Id); builder.Property(r => r.Id).ValueGeneratedNever(); @@ -18,5 +20,17 @@ public class SeatConfiguration : IEntityTypeConfiguration .HasOne() .WithMany() .HasForeignKey(p => p.FlightId); + + builder.Property(x => x.Class) + .HasDefaultValue(Seats.Enums.SeatClass.Unknown) + .HasConversion( + x => x.ToString(), + x => (Flight.Seats.Enums.SeatClass)Enum.Parse(typeof(Flight.Seats.Enums.SeatClass), x)); + + builder.Property(x => x.Type) + .HasDefaultValue(Seats.Enums.SeatType.Unknown) + .HasConversion( + x => x.ToString(), + x => (Flight.Seats.Enums.SeatType)Enum.Parse(typeof(Flight.Seats.Enums.SeatType), x)); } } diff --git a/src/Services/Flight/src/Flight/Data/DesignTimeDbContextFactory.cs b/src/Services/Flight/src/Flight/Data/DesignTimeDbContextFactory.cs index 3c9559b..6047782 100644 --- a/src/Services/Flight/src/Flight/Data/DesignTimeDbContextFactory.cs +++ b/src/Services/Flight/src/Flight/Data/DesignTimeDbContextFactory.cs @@ -9,7 +9,8 @@ namespace Flight.Data { var builder = new DbContextOptionsBuilder(); - builder.UseSqlServer("Server=localhost;Database=FlightDB;User ID=sa;Password=@Aa123456;TrustServerCertificate=True"); + builder.UseNpgsql("Server=localhost;Port=5432;Database=flight;User Id=postgres;Password=postgres;Include Error Detail=true") + .UseSnakeCaseNamingConvention(); return new FlightDbContext(builder.Options, null); } } diff --git a/src/Services/Flight/src/Flight/Data/Migrations/20221206180723_Initial.Designer.cs b/src/Services/Flight/src/Flight/Data/Migrations/20221206180723_Initial.Designer.cs deleted file mode 100644 index ba1c044..0000000 --- a/src/Services/Flight/src/Flight/Data/Migrations/20221206180723_Initial.Designer.cs +++ /dev/null @@ -1,232 +0,0 @@ -// -using System; -using Flight.Data; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace Flight.Data.Migrations -{ - [DbContext(typeof(FlightDbContext))] - [Migration("20221206180723_Initial")] - partial class Initial - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "7.0.0") - .HasAnnotation("Relational:MaxIdentifierLength", 128); - - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - - modelBuilder.Entity("Flight.Aircrafts.Models.Aircraft", b => - { - b.Property("Id") - .HasColumnType("bigint"); - - b.Property("CreatedAt") - .HasColumnType("datetime2"); - - b.Property("CreatedBy") - .HasColumnType("bigint"); - - b.Property("IsDeleted") - .HasColumnType("bit"); - - b.Property("LastModified") - .HasColumnType("datetime2"); - - b.Property("LastModifiedBy") - .HasColumnType("bigint"); - - b.Property("ManufacturingYear") - .HasColumnType("int"); - - b.Property("Model") - .HasColumnType("nvarchar(max)"); - - b.Property("Name") - .HasColumnType("nvarchar(max)"); - - b.Property("Version") - .HasColumnType("bigint"); - - b.HasKey("Id"); - - b.ToTable("Aircraft", "dbo"); - }); - - modelBuilder.Entity("Flight.Airports.Models.Airport", b => - { - b.Property("Id") - .HasColumnType("bigint"); - - b.Property("Address") - .HasColumnType("nvarchar(max)"); - - b.Property("Code") - .HasColumnType("nvarchar(max)"); - - b.Property("CreatedAt") - .HasColumnType("datetime2"); - - b.Property("CreatedBy") - .HasColumnType("bigint"); - - b.Property("IsDeleted") - .HasColumnType("bit"); - - b.Property("LastModified") - .HasColumnType("datetime2"); - - b.Property("LastModifiedBy") - .HasColumnType("bigint"); - - b.Property("Name") - .HasColumnType("nvarchar(max)"); - - b.Property("Version") - .HasColumnType("bigint"); - - b.HasKey("Id"); - - b.ToTable("Airport", "dbo"); - }); - - modelBuilder.Entity("Flight.Flights.Models.Flight", b => - { - b.Property("Id") - .HasColumnType("bigint"); - - b.Property("AircraftId") - .HasColumnType("bigint"); - - b.Property("ArriveAirportId") - .HasColumnType("bigint"); - - b.Property("ArriveDate") - .HasColumnType("datetime2"); - - b.Property("CreatedAt") - .HasColumnType("datetime2"); - - b.Property("CreatedBy") - .HasColumnType("bigint"); - - b.Property("DepartureAirportId") - .HasColumnType("bigint"); - - b.Property("DepartureDate") - .HasColumnType("datetime2"); - - b.Property("DurationMinutes") - .HasColumnType("decimal(18,2)"); - - b.Property("FlightDate") - .HasColumnType("datetime2"); - - b.Property("FlightNumber") - .HasColumnType("nvarchar(max)"); - - b.Property("IsDeleted") - .HasColumnType("bit"); - - b.Property("LastModified") - .HasColumnType("datetime2"); - - b.Property("LastModifiedBy") - .HasColumnType("bigint"); - - b.Property("Price") - .HasColumnType("decimal(18,2)"); - - b.Property("Status") - .HasColumnType("int"); - - b.Property("Version") - .HasColumnType("bigint"); - - b.HasKey("Id"); - - b.HasIndex("AircraftId"); - - b.HasIndex("ArriveAirportId"); - - b.ToTable("Flight", "dbo"); - }); - - modelBuilder.Entity("Flight.Seats.Models.Seat", b => - { - b.Property("Id") - .HasColumnType("bigint"); - - b.Property("Class") - .HasColumnType("int"); - - b.Property("CreatedAt") - .HasColumnType("datetime2"); - - b.Property("CreatedBy") - .HasColumnType("bigint"); - - b.Property("FlightId") - .HasColumnType("bigint"); - - b.Property("IsDeleted") - .HasColumnType("bit"); - - b.Property("LastModified") - .HasColumnType("datetime2"); - - b.Property("LastModifiedBy") - .HasColumnType("bigint"); - - b.Property("SeatNumber") - .HasColumnType("nvarchar(max)"); - - b.Property("Type") - .HasColumnType("int"); - - b.Property("Version") - .HasColumnType("bigint"); - - b.HasKey("Id"); - - b.HasIndex("FlightId"); - - b.ToTable("Seat", "dbo"); - }); - - modelBuilder.Entity("Flight.Flights.Models.Flight", b => - { - b.HasOne("Flight.Aircrafts.Models.Aircraft", null) - .WithMany() - .HasForeignKey("AircraftId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Flight.Airports.Models.Airport", null) - .WithMany() - .HasForeignKey("ArriveAirportId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Flight.Seats.Models.Seat", b => - { - b.HasOne("Flight.Flights.Models.Flight", null) - .WithMany() - .HasForeignKey("FlightId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/src/Services/Flight/src/Flight/Data/Migrations/20221206180723_Initial.cs b/src/Services/Flight/src/Flight/Data/Migrations/20221206180723_Initial.cs deleted file mode 100644 index 576d26f..0000000 --- a/src/Services/Flight/src/Flight/Data/Migrations/20221206180723_Initial.cs +++ /dev/null @@ -1,169 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace Flight.Data.Migrations -{ - /// - public partial class Initial : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.EnsureSchema( - name: "dbo"); - - migrationBuilder.CreateTable( - name: "Aircraft", - schema: "dbo", - columns: table => new - { - Id = table.Column(type: "bigint", nullable: false), - Name = table.Column(type: "nvarchar(max)", nullable: true), - Model = table.Column(type: "nvarchar(max)", nullable: true), - ManufacturingYear = table.Column(type: "int", nullable: false), - CreatedAt = table.Column(type: "datetime2", nullable: true), - CreatedBy = table.Column(type: "bigint", nullable: true), - LastModified = table.Column(type: "datetime2", nullable: true), - LastModifiedBy = table.Column(type: "bigint", nullable: true), - IsDeleted = table.Column(type: "bit", nullable: false), - Version = table.Column(type: "bigint", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Aircraft", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "Airport", - schema: "dbo", - columns: table => new - { - Id = table.Column(type: "bigint", nullable: false), - Name = table.Column(type: "nvarchar(max)", nullable: true), - Address = table.Column(type: "nvarchar(max)", nullable: true), - Code = table.Column(type: "nvarchar(max)", nullable: true), - CreatedAt = table.Column(type: "datetime2", nullable: true), - CreatedBy = table.Column(type: "bigint", nullable: true), - LastModified = table.Column(type: "datetime2", nullable: true), - LastModifiedBy = table.Column(type: "bigint", nullable: true), - IsDeleted = table.Column(type: "bit", nullable: false), - Version = table.Column(type: "bigint", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Airport", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "Flight", - schema: "dbo", - columns: table => new - { - Id = table.Column(type: "bigint", nullable: false), - FlightNumber = table.Column(type: "nvarchar(max)", nullable: true), - AircraftId = table.Column(type: "bigint", nullable: false), - DepartureDate = table.Column(type: "datetime2", nullable: false), - DepartureAirportId = table.Column(type: "bigint", nullable: false), - ArriveDate = table.Column(type: "datetime2", nullable: false), - ArriveAirportId = table.Column(type: "bigint", nullable: false), - DurationMinutes = table.Column(type: "decimal(18,2)", nullable: false), - FlightDate = table.Column(type: "datetime2", nullable: false), - Status = table.Column(type: "int", nullable: false), - Price = table.Column(type: "decimal(18,2)", nullable: false), - CreatedAt = table.Column(type: "datetime2", nullable: true), - CreatedBy = table.Column(type: "bigint", nullable: true), - LastModified = table.Column(type: "datetime2", nullable: true), - LastModifiedBy = table.Column(type: "bigint", nullable: true), - IsDeleted = table.Column(type: "bit", nullable: false), - Version = table.Column(type: "bigint", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Flight", x => x.Id); - table.ForeignKey( - name: "FK_Flight_Aircraft_AircraftId", - column: x => x.AircraftId, - principalSchema: "dbo", - principalTable: "Aircraft", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_Flight_Airport_ArriveAirportId", - column: x => x.ArriveAirportId, - principalSchema: "dbo", - principalTable: "Airport", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "Seat", - schema: "dbo", - columns: table => new - { - Id = table.Column(type: "bigint", nullable: false), - SeatNumber = table.Column(type: "nvarchar(max)", nullable: true), - Type = table.Column(type: "int", nullable: false), - Class = table.Column(type: "int", nullable: false), - FlightId = table.Column(type: "bigint", nullable: false), - CreatedAt = table.Column(type: "datetime2", nullable: true), - CreatedBy = table.Column(type: "bigint", nullable: true), - LastModified = table.Column(type: "datetime2", nullable: true), - LastModifiedBy = table.Column(type: "bigint", nullable: true), - IsDeleted = table.Column(type: "bit", nullable: false), - Version = table.Column(type: "bigint", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Seat", x => x.Id); - table.ForeignKey( - name: "FK_Seat_Flight_FlightId", - column: x => x.FlightId, - principalSchema: "dbo", - principalTable: "Flight", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateIndex( - name: "IX_Flight_AircraftId", - schema: "dbo", - table: "Flight", - column: "AircraftId"); - - migrationBuilder.CreateIndex( - name: "IX_Flight_ArriveAirportId", - schema: "dbo", - table: "Flight", - column: "ArriveAirportId"); - - migrationBuilder.CreateIndex( - name: "IX_Seat_FlightId", - schema: "dbo", - table: "Seat", - column: "FlightId"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "Seat", - schema: "dbo"); - - migrationBuilder.DropTable( - name: "Flight", - schema: "dbo"); - - migrationBuilder.DropTable( - name: "Aircraft", - schema: "dbo"); - - migrationBuilder.DropTable( - name: "Airport", - schema: "dbo"); - } - } -} diff --git a/src/Services/Flight/src/Flight/Data/Migrations/20230113134450_Init.Designer.cs b/src/Services/Flight/src/Flight/Data/Migrations/20230113134450_Init.Designer.cs new file mode 100644 index 0000000..89a56bf --- /dev/null +++ b/src/Services/Flight/src/Flight/Data/Migrations/20230113134450_Init.Designer.cs @@ -0,0 +1,299 @@ +// +using System; +using Flight.Data; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace Flight.Data.Migrations +{ + [DbContext(typeof(FlightDbContext))] + [Migration("20230113134450_Init")] + partial class Init + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.1") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("Flight.Aircrafts.Models.Aircraft", b => + { + b.Property("Id") + .HasColumnType("bigint") + .HasColumnName("id"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone") + .HasColumnName("created_at"); + + b.Property("CreatedBy") + .HasColumnType("bigint") + .HasColumnName("created_by"); + + b.Property("IsDeleted") + .HasColumnType("boolean") + .HasColumnName("is_deleted"); + + b.Property("LastModified") + .HasColumnType("timestamp with time zone") + .HasColumnName("last_modified"); + + b.Property("LastModifiedBy") + .HasColumnType("bigint") + .HasColumnName("last_modified_by"); + + b.Property("ManufacturingYear") + .HasColumnType("integer") + .HasColumnName("manufacturing_year"); + + b.Property("Model") + .HasColumnType("text") + .HasColumnName("model"); + + b.Property("Name") + .HasColumnType("text") + .HasColumnName("name"); + + b.Property("Version") + .HasColumnType("bigint") + .HasColumnName("version"); + + b.HasKey("Id") + .HasName("pk_aircraft"); + + b.ToTable("aircraft", (string)null); + }); + + modelBuilder.Entity("Flight.Airports.Models.Airport", b => + { + b.Property("Id") + .HasColumnType("bigint") + .HasColumnName("id"); + + b.Property("Address") + .HasColumnType("text") + .HasColumnName("address"); + + b.Property("Code") + .HasColumnType("text") + .HasColumnName("code"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone") + .HasColumnName("created_at"); + + b.Property("CreatedBy") + .HasColumnType("bigint") + .HasColumnName("created_by"); + + b.Property("IsDeleted") + .HasColumnType("boolean") + .HasColumnName("is_deleted"); + + b.Property("LastModified") + .HasColumnType("timestamp with time zone") + .HasColumnName("last_modified"); + + b.Property("LastModifiedBy") + .HasColumnType("bigint") + .HasColumnName("last_modified_by"); + + b.Property("Name") + .HasColumnType("text") + .HasColumnName("name"); + + b.Property("Version") + .HasColumnType("bigint") + .HasColumnName("version"); + + b.HasKey("Id") + .HasName("pk_airport"); + + b.ToTable("airport", (string)null); + }); + + modelBuilder.Entity("Flight.Flights.Models.Flight", b => + { + b.Property("Id") + .HasColumnType("bigint") + .HasColumnName("id"); + + b.Property("AircraftId") + .HasColumnType("bigint") + .HasColumnName("aircraft_id"); + + b.Property("ArriveAirportId") + .HasColumnType("bigint") + .HasColumnName("arrive_airport_id"); + + b.Property("ArriveDate") + .HasColumnType("timestamp with time zone") + .HasColumnName("arrive_date"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone") + .HasColumnName("created_at"); + + b.Property("CreatedBy") + .HasColumnType("bigint") + .HasColumnName("created_by"); + + b.Property("DepartureAirportId") + .HasColumnType("bigint") + .HasColumnName("departure_airport_id"); + + b.Property("DepartureDate") + .HasColumnType("timestamp with time zone") + .HasColumnName("departure_date"); + + b.Property("DurationMinutes") + .HasColumnType("numeric") + .HasColumnName("duration_minutes"); + + b.Property("FlightDate") + .HasColumnType("timestamp with time zone") + .HasColumnName("flight_date"); + + b.Property("FlightNumber") + .HasColumnType("text") + .HasColumnName("flight_number"); + + b.Property("IsDeleted") + .HasColumnType("boolean") + .HasColumnName("is_deleted"); + + b.Property("LastModified") + .HasColumnType("timestamp with time zone") + .HasColumnName("last_modified"); + + b.Property("LastModifiedBy") + .HasColumnType("bigint") + .HasColumnName("last_modified_by"); + + b.Property("Price") + .HasColumnType("numeric") + .HasColumnName("price"); + + b.Property("Status") + .IsRequired() + .ValueGeneratedOnAdd() + .HasColumnType("text") + .HasDefaultValue("Unknown") + .HasColumnName("status"); + + b.Property("Version") + .HasColumnType("bigint") + .HasColumnName("version"); + + b.HasKey("Id") + .HasName("pk_flight"); + + b.HasIndex("AircraftId") + .HasDatabaseName("ix_flight_aircraft_id"); + + b.HasIndex("ArriveAirportId") + .HasDatabaseName("ix_flight_arrive_airport_id"); + + b.ToTable("flight", (string)null); + }); + + modelBuilder.Entity("Flight.Seats.Models.Seat", b => + { + b.Property("Id") + .HasColumnType("bigint") + .HasColumnName("id"); + + b.Property("Class") + .IsRequired() + .ValueGeneratedOnAdd() + .HasColumnType("text") + .HasDefaultValue("Unknown") + .HasColumnName("class"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone") + .HasColumnName("created_at"); + + b.Property("CreatedBy") + .HasColumnType("bigint") + .HasColumnName("created_by"); + + b.Property("FlightId") + .HasColumnType("bigint") + .HasColumnName("flight_id"); + + b.Property("IsDeleted") + .HasColumnType("boolean") + .HasColumnName("is_deleted"); + + b.Property("LastModified") + .HasColumnType("timestamp with time zone") + .HasColumnName("last_modified"); + + b.Property("LastModifiedBy") + .HasColumnType("bigint") + .HasColumnName("last_modified_by"); + + b.Property("SeatNumber") + .HasColumnType("text") + .HasColumnName("seat_number"); + + b.Property("Type") + .IsRequired() + .ValueGeneratedOnAdd() + .HasColumnType("text") + .HasDefaultValue("Unknown") + .HasColumnName("type"); + + b.Property("Version") + .HasColumnType("bigint") + .HasColumnName("version"); + + b.HasKey("Id") + .HasName("pk_seat"); + + b.HasIndex("FlightId") + .HasDatabaseName("ix_seat_flight_id"); + + b.ToTable("seat", (string)null); + }); + + modelBuilder.Entity("Flight.Flights.Models.Flight", b => + { + b.HasOne("Flight.Aircrafts.Models.Aircraft", null) + .WithMany() + .HasForeignKey("AircraftId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired() + .HasConstraintName("fk_flight_aircraft_aircraft_id"); + + b.HasOne("Flight.Airports.Models.Airport", null) + .WithMany() + .HasForeignKey("ArriveAirportId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired() + .HasConstraintName("fk_flight_airport_airport_id"); + }); + + modelBuilder.Entity("Flight.Seats.Models.Seat", b => + { + b.HasOne("Flight.Flights.Models.Flight", null) + .WithMany() + .HasForeignKey("FlightId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired() + .HasConstraintName("fk_seat_flight_flight_id"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/Services/Flight/src/Flight/Data/Migrations/20230113134450_Init.cs b/src/Services/Flight/src/Flight/Data/Migrations/20230113134450_Init.cs new file mode 100644 index 0000000..12f07ac --- /dev/null +++ b/src/Services/Flight/src/Flight/Data/Migrations/20230113134450_Init.cs @@ -0,0 +1,152 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Flight.Data.Migrations +{ + /// + public partial class Init : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "aircraft", + columns: table => new + { + id = table.Column(type: "bigint", nullable: false), + name = table.Column(type: "text", nullable: true), + model = table.Column(type: "text", nullable: true), + manufacturingyear = table.Column(name: "manufacturing_year", type: "integer", nullable: false), + createdat = table.Column(name: "created_at", type: "timestamp with time zone", nullable: true), + createdby = table.Column(name: "created_by", type: "bigint", nullable: true), + lastmodified = table.Column(name: "last_modified", type: "timestamp with time zone", nullable: true), + lastmodifiedby = table.Column(name: "last_modified_by", type: "bigint", nullable: true), + isdeleted = table.Column(name: "is_deleted", type: "boolean", nullable: false), + version = table.Column(type: "bigint", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("pk_aircraft", x => x.id); + }); + + migrationBuilder.CreateTable( + name: "airport", + columns: table => new + { + id = table.Column(type: "bigint", nullable: false), + name = table.Column(type: "text", nullable: true), + address = table.Column(type: "text", nullable: true), + code = table.Column(type: "text", nullable: true), + createdat = table.Column(name: "created_at", type: "timestamp with time zone", nullable: true), + createdby = table.Column(name: "created_by", type: "bigint", nullable: true), + lastmodified = table.Column(name: "last_modified", type: "timestamp with time zone", nullable: true), + lastmodifiedby = table.Column(name: "last_modified_by", type: "bigint", nullable: true), + isdeleted = table.Column(name: "is_deleted", type: "boolean", nullable: false), + version = table.Column(type: "bigint", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("pk_airport", x => x.id); + }); + + migrationBuilder.CreateTable( + name: "flight", + columns: table => new + { + id = table.Column(type: "bigint", nullable: false), + flightnumber = table.Column(name: "flight_number", type: "text", nullable: true), + aircraftid = table.Column(name: "aircraft_id", type: "bigint", nullable: false), + departuredate = table.Column(name: "departure_date", type: "timestamp with time zone", nullable: false), + departureairportid = table.Column(name: "departure_airport_id", type: "bigint", nullable: false), + arrivedate = table.Column(name: "arrive_date", type: "timestamp with time zone", nullable: false), + arriveairportid = table.Column(name: "arrive_airport_id", type: "bigint", nullable: false), + durationminutes = table.Column(name: "duration_minutes", type: "numeric", nullable: false), + flightdate = table.Column(name: "flight_date", type: "timestamp with time zone", nullable: false), + status = table.Column(type: "text", nullable: false, defaultValue: "Unknown"), + price = table.Column(type: "numeric", nullable: false), + createdat = table.Column(name: "created_at", type: "timestamp with time zone", nullable: true), + createdby = table.Column(name: "created_by", type: "bigint", nullable: true), + lastmodified = table.Column(name: "last_modified", type: "timestamp with time zone", nullable: true), + lastmodifiedby = table.Column(name: "last_modified_by", type: "bigint", nullable: true), + isdeleted = table.Column(name: "is_deleted", type: "boolean", nullable: false), + version = table.Column(type: "bigint", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("pk_flight", x => x.id); + table.ForeignKey( + name: "fk_flight_aircraft_aircraft_id", + column: x => x.aircraftid, + principalTable: "aircraft", + principalColumn: "id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "fk_flight_airport_airport_id", + column: x => x.arriveairportid, + principalTable: "airport", + principalColumn: "id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "seat", + columns: table => new + { + id = table.Column(type: "bigint", nullable: false), + seatnumber = table.Column(name: "seat_number", type: "text", nullable: true), + type = table.Column(type: "text", nullable: false, defaultValue: "Unknown"), + @class = table.Column(name: "class", type: "text", nullable: false, defaultValue: "Unknown"), + flightid = table.Column(name: "flight_id", type: "bigint", nullable: false), + createdat = table.Column(name: "created_at", type: "timestamp with time zone", nullable: true), + createdby = table.Column(name: "created_by", type: "bigint", nullable: true), + lastmodified = table.Column(name: "last_modified", type: "timestamp with time zone", nullable: true), + lastmodifiedby = table.Column(name: "last_modified_by", type: "bigint", nullable: true), + isdeleted = table.Column(name: "is_deleted", type: "boolean", nullable: false), + version = table.Column(type: "bigint", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("pk_seat", x => x.id); + table.ForeignKey( + name: "fk_seat_flight_flight_id", + column: x => x.flightid, + principalTable: "flight", + principalColumn: "id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "ix_flight_aircraft_id", + table: "flight", + column: "aircraft_id"); + + migrationBuilder.CreateIndex( + name: "ix_flight_arrive_airport_id", + table: "flight", + column: "arrive_airport_id"); + + migrationBuilder.CreateIndex( + name: "ix_seat_flight_id", + table: "seat", + column: "flight_id"); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "seat"); + + migrationBuilder.DropTable( + name: "flight"); + + migrationBuilder.DropTable( + name: "aircraft"); + + migrationBuilder.DropTable( + name: "airport"); + } + } +} diff --git a/src/Services/Flight/src/Flight/Data/Migrations/FlightDbContextModelSnapshot.cs b/src/Services/Flight/src/Flight/Data/Migrations/FlightDbContextModelSnapshot.cs index 3c2ccf0..613d044 100644 --- a/src/Services/Flight/src/Flight/Data/Migrations/FlightDbContextModelSnapshot.cs +++ b/src/Services/Flight/src/Flight/Data/Migrations/FlightDbContextModelSnapshot.cs @@ -3,8 +3,8 @@ using System; using Flight.Data; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; #nullable disable @@ -17,187 +17,251 @@ namespace Flight.Data.Migrations { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "7.0.0") - .HasAnnotation("Relational:MaxIdentifierLength", 128); + .HasAnnotation("ProductVersion", "7.0.1") + .HasAnnotation("Relational:MaxIdentifierLength", 63); - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); modelBuilder.Entity("Flight.Aircrafts.Models.Aircraft", b => { b.Property("Id") - .HasColumnType("bigint"); + .HasColumnType("bigint") + .HasColumnName("id"); b.Property("CreatedAt") - .HasColumnType("datetime2"); + .HasColumnType("timestamp with time zone") + .HasColumnName("created_at"); b.Property("CreatedBy") - .HasColumnType("bigint"); + .HasColumnType("bigint") + .HasColumnName("created_by"); b.Property("IsDeleted") - .HasColumnType("bit"); + .HasColumnType("boolean") + .HasColumnName("is_deleted"); b.Property("LastModified") - .HasColumnType("datetime2"); + .HasColumnType("timestamp with time zone") + .HasColumnName("last_modified"); b.Property("LastModifiedBy") - .HasColumnType("bigint"); + .HasColumnType("bigint") + .HasColumnName("last_modified_by"); b.Property("ManufacturingYear") - .HasColumnType("int"); + .HasColumnType("integer") + .HasColumnName("manufacturing_year"); b.Property("Model") - .HasColumnType("nvarchar(max)"); + .HasColumnType("text") + .HasColumnName("model"); b.Property("Name") - .HasColumnType("nvarchar(max)"); + .HasColumnType("text") + .HasColumnName("name"); b.Property("Version") - .HasColumnType("bigint"); + .HasColumnType("bigint") + .HasColumnName("version"); - b.HasKey("Id"); + b.HasKey("Id") + .HasName("pk_aircraft"); - b.ToTable("Aircraft", "dbo"); + b.ToTable("aircraft", (string)null); }); modelBuilder.Entity("Flight.Airports.Models.Airport", b => { b.Property("Id") - .HasColumnType("bigint"); + .HasColumnType("bigint") + .HasColumnName("id"); b.Property("Address") - .HasColumnType("nvarchar(max)"); + .HasColumnType("text") + .HasColumnName("address"); b.Property("Code") - .HasColumnType("nvarchar(max)"); + .HasColumnType("text") + .HasColumnName("code"); b.Property("CreatedAt") - .HasColumnType("datetime2"); + .HasColumnType("timestamp with time zone") + .HasColumnName("created_at"); b.Property("CreatedBy") - .HasColumnType("bigint"); + .HasColumnType("bigint") + .HasColumnName("created_by"); b.Property("IsDeleted") - .HasColumnType("bit"); + .HasColumnType("boolean") + .HasColumnName("is_deleted"); b.Property("LastModified") - .HasColumnType("datetime2"); + .HasColumnType("timestamp with time zone") + .HasColumnName("last_modified"); b.Property("LastModifiedBy") - .HasColumnType("bigint"); + .HasColumnType("bigint") + .HasColumnName("last_modified_by"); b.Property("Name") - .HasColumnType("nvarchar(max)"); + .HasColumnType("text") + .HasColumnName("name"); b.Property("Version") - .HasColumnType("bigint"); + .HasColumnType("bigint") + .HasColumnName("version"); - b.HasKey("Id"); + b.HasKey("Id") + .HasName("pk_airport"); - b.ToTable("Airport", "dbo"); + b.ToTable("airport", (string)null); }); modelBuilder.Entity("Flight.Flights.Models.Flight", b => { b.Property("Id") - .HasColumnType("bigint"); + .HasColumnType("bigint") + .HasColumnName("id"); b.Property("AircraftId") - .HasColumnType("bigint"); + .HasColumnType("bigint") + .HasColumnName("aircraft_id"); b.Property("ArriveAirportId") - .HasColumnType("bigint"); + .HasColumnType("bigint") + .HasColumnName("arrive_airport_id"); b.Property("ArriveDate") - .HasColumnType("datetime2"); + .HasColumnType("timestamp with time zone") + .HasColumnName("arrive_date"); b.Property("CreatedAt") - .HasColumnType("datetime2"); + .HasColumnType("timestamp with time zone") + .HasColumnName("created_at"); b.Property("CreatedBy") - .HasColumnType("bigint"); + .HasColumnType("bigint") + .HasColumnName("created_by"); b.Property("DepartureAirportId") - .HasColumnType("bigint"); + .HasColumnType("bigint") + .HasColumnName("departure_airport_id"); b.Property("DepartureDate") - .HasColumnType("datetime2"); + .HasColumnType("timestamp with time zone") + .HasColumnName("departure_date"); b.Property("DurationMinutes") - .HasColumnType("decimal(18,2)"); + .HasColumnType("numeric") + .HasColumnName("duration_minutes"); b.Property("FlightDate") - .HasColumnType("datetime2"); + .HasColumnType("timestamp with time zone") + .HasColumnName("flight_date"); b.Property("FlightNumber") - .HasColumnType("nvarchar(max)"); + .HasColumnType("text") + .HasColumnName("flight_number"); b.Property("IsDeleted") - .HasColumnType("bit"); + .HasColumnType("boolean") + .HasColumnName("is_deleted"); b.Property("LastModified") - .HasColumnType("datetime2"); + .HasColumnType("timestamp with time zone") + .HasColumnName("last_modified"); b.Property("LastModifiedBy") - .HasColumnType("bigint"); + .HasColumnType("bigint") + .HasColumnName("last_modified_by"); b.Property("Price") - .HasColumnType("decimal(18,2)"); + .HasColumnType("numeric") + .HasColumnName("price"); - b.Property("Status") - .HasColumnType("int"); + b.Property("Status") + .IsRequired() + .ValueGeneratedOnAdd() + .HasColumnType("text") + .HasDefaultValue("Unknown") + .HasColumnName("status"); b.Property("Version") - .HasColumnType("bigint"); + .HasColumnType("bigint") + .HasColumnName("version"); - b.HasKey("Id"); + b.HasKey("Id") + .HasName("pk_flight"); - b.HasIndex("AircraftId"); + b.HasIndex("AircraftId") + .HasDatabaseName("ix_flight_aircraft_id"); - b.HasIndex("ArriveAirportId"); + b.HasIndex("ArriveAirportId") + .HasDatabaseName("ix_flight_arrive_airport_id"); - b.ToTable("Flight", "dbo"); + b.ToTable("flight", (string)null); }); modelBuilder.Entity("Flight.Seats.Models.Seat", b => { b.Property("Id") - .HasColumnType("bigint"); + .HasColumnType("bigint") + .HasColumnName("id"); - b.Property("Class") - .HasColumnType("int"); + b.Property("Class") + .IsRequired() + .ValueGeneratedOnAdd() + .HasColumnType("text") + .HasDefaultValue("Unknown") + .HasColumnName("class"); b.Property("CreatedAt") - .HasColumnType("datetime2"); + .HasColumnType("timestamp with time zone") + .HasColumnName("created_at"); b.Property("CreatedBy") - .HasColumnType("bigint"); + .HasColumnType("bigint") + .HasColumnName("created_by"); b.Property("FlightId") - .HasColumnType("bigint"); + .HasColumnType("bigint") + .HasColumnName("flight_id"); b.Property("IsDeleted") - .HasColumnType("bit"); + .HasColumnType("boolean") + .HasColumnName("is_deleted"); b.Property("LastModified") - .HasColumnType("datetime2"); + .HasColumnType("timestamp with time zone") + .HasColumnName("last_modified"); b.Property("LastModifiedBy") - .HasColumnType("bigint"); + .HasColumnType("bigint") + .HasColumnName("last_modified_by"); b.Property("SeatNumber") - .HasColumnType("nvarchar(max)"); + .HasColumnType("text") + .HasColumnName("seat_number"); - b.Property("Type") - .HasColumnType("int"); + b.Property("Type") + .IsRequired() + .ValueGeneratedOnAdd() + .HasColumnType("text") + .HasDefaultValue("Unknown") + .HasColumnName("type"); b.Property("Version") - .HasColumnType("bigint"); + .HasColumnType("bigint") + .HasColumnName("version"); - b.HasKey("Id"); + b.HasKey("Id") + .HasName("pk_seat"); - b.HasIndex("FlightId"); + b.HasIndex("FlightId") + .HasDatabaseName("ix_seat_flight_id"); - b.ToTable("Seat", "dbo"); + b.ToTable("seat", (string)null); }); modelBuilder.Entity("Flight.Flights.Models.Flight", b => @@ -206,13 +270,15 @@ namespace Flight.Data.Migrations .WithMany() .HasForeignKey("AircraftId") .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); + .IsRequired() + .HasConstraintName("fk_flight_aircraft_aircraft_id"); b.HasOne("Flight.Airports.Models.Airport", null) .WithMany() .HasForeignKey("ArriveAirportId") .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); + .IsRequired() + .HasConstraintName("fk_flight_airport_airport_id"); }); modelBuilder.Entity("Flight.Seats.Models.Seat", b => @@ -221,7 +287,8 @@ namespace Flight.Data.Migrations .WithMany() .HasForeignKey("FlightId") .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); + .IsRequired() + .HasConstraintName("fk_seat_flight_flight_id"); }); #pragma warning restore 612, 618 } diff --git a/src/Services/Flight/tests/EndToEndTest/Fakes/FakeCreateFlightCommand.cs b/src/Services/Flight/tests/EndToEndTest/Fakes/FakeCreateFlightCommand.cs index 0fe881e..2f64f78 100644 --- a/src/Services/Flight/tests/EndToEndTest/Fakes/FakeCreateFlightCommand.cs +++ b/src/Services/Flight/tests/EndToEndTest/Fakes/FakeCreateFlightCommand.cs @@ -10,7 +10,7 @@ public sealed class FakeCreateFlightCommand : AutoFaker public FakeCreateFlightCommand() { RuleFor(r => r.Id, _ => SnowFlakIdGenerator.NewId()); - RuleFor(r => r.FlightNumber, r => r.Random.String()); + RuleFor(r => r.FlightNumber, r => r.Random.Number(1000, 2000).ToString()); RuleFor(r => r.DepartureAirportId, _ => 1); RuleFor(r => r.ArriveAirportId, _ => 2); RuleFor(r => r.Status, _ => FlightStatus.Flying); diff --git a/src/Services/Flight/tests/IntegrationTest/Fakes/FakeCreateFlightCommand.cs b/src/Services/Flight/tests/IntegrationTest/Fakes/FakeCreateFlightCommand.cs index 87a0291..d3d93b7 100644 --- a/src/Services/Flight/tests/IntegrationTest/Fakes/FakeCreateFlightCommand.cs +++ b/src/Services/Flight/tests/IntegrationTest/Fakes/FakeCreateFlightCommand.cs @@ -10,7 +10,7 @@ public sealed class FakeCreateFlightCommand : AutoFaker public FakeCreateFlightCommand() { RuleFor(r => r.Id, _ => SnowFlakIdGenerator.NewId()); - RuleFor(r => r.FlightNumber, r => r.Random.String()); + RuleFor(r => r.FlightNumber, r => r.Random.Number(1000, 2000).ToString()); RuleFor(r => r.DepartureAirportId, _ => 1); RuleFor(r => r.ArriveAirportId, _ => 2); RuleFor(r => r.Status, _ => FlightStatus.Flying); diff --git a/src/Services/Flight/tests/IntegrationTest/Fakes/FakeUpdateFlightCommand.cs b/src/Services/Flight/tests/IntegrationTest/Fakes/FakeUpdateFlightCommand.cs index 196a206..b07f68d 100644 --- a/src/Services/Flight/tests/IntegrationTest/Fakes/FakeUpdateFlightCommand.cs +++ b/src/Services/Flight/tests/IntegrationTest/Fakes/FakeUpdateFlightCommand.cs @@ -12,7 +12,7 @@ public class FakeUpdateFlightCommand : AutoFaker RuleFor(r => r.DepartureAirportId, _ => flight.DepartureAirportId); RuleFor(r => r.ArriveAirportId, _ => flight.ArriveAirportId); RuleFor(r => r.AircraftId, _ => flight.AircraftId); - RuleFor(r => r.FlightNumber, _ => "12UU"); + RuleFor(r => r.FlightNumber, r => r.Random.Number(1000, 2000).ToString()); RuleFor(r => r.Price, _ => 800); RuleFor(r => r.Status, _ => flight.Status); RuleFor(r => r.ArriveDate, _ => flight.ArriveDate); diff --git a/src/Services/Flight/tests/UnitTest/Fakes/FakeCreateFlightCommand.cs b/src/Services/Flight/tests/UnitTest/Fakes/FakeCreateFlightCommand.cs index c34811c..3dc75bf 100644 --- a/src/Services/Flight/tests/UnitTest/Fakes/FakeCreateFlightCommand.cs +++ b/src/Services/Flight/tests/UnitTest/Fakes/FakeCreateFlightCommand.cs @@ -10,7 +10,7 @@ public sealed class FakeCreateFlightCommand : AutoFaker public FakeCreateFlightCommand() { RuleFor(r => r.Id, _ => SnowFlakIdGenerator.NewId()); - RuleFor(r => r.FlightNumber, r => r.Random.String()); + RuleFor(r => r.FlightNumber, r => r.Random.Number(1000, 2000).ToString()); RuleFor(r => r.DepartureAirportId, _ => 1); RuleFor(r => r.ArriveAirportId, _ => 2); RuleFor(r => r.AircraftId, _ => 1); diff --git a/src/Services/Identity/src/Identity.Api/appsettings.docker.json b/src/Services/Identity/src/Identity.Api/appsettings.docker.json index 5243321..895b198 100644 --- a/src/Services/Identity/src/Identity.Api/appsettings.docker.json +++ b/src/Services/Identity/src/Identity.Api/appsettings.docker.json @@ -1,12 +1,12 @@ { "App": "Identity-Service", - "DatabaseOptions": { - "DefaultConnection": "Server=sql;Database=IdentityDB;User ID=sa;Password=@Aa123456;TrustServerCertificate=True" + "PostgresOptions": { + "ConnectionString": "Server=postgres;Port=5432;Database=identity;User Id=postgres;Password=postgres;Include Error Detail=true" }, "PersistMessageOptions": { "Interval": 30, "Enabled": true, - "ConnectionString": "Server=sql;Database=PersistMessageDB;User ID=sa;Password=@Aa123456;TrustServerCertificate=True" + "ConnectionString": "Server=postgres;Port=5432;Database=persist_message;User Id=postgres;Password=postgres;Include Error Detail=true" }, "RabbitMqOptions": { "HostName": "rabbitmq", diff --git a/src/Services/Identity/src/Identity.Api/appsettings.json b/src/Services/Identity/src/Identity.Api/appsettings.json index 894d814..af84e36 100644 --- a/src/Services/Identity/src/Identity.Api/appsettings.json +++ b/src/Services/Identity/src/Identity.Api/appsettings.json @@ -2,8 +2,8 @@ "AppOptions": { "Name": "Identity-Service" }, - "DatabaseOptions": { - "DefaultConnection": "Server=localhost;Database=IdentityDB;User ID=sa;Password=@Aa123456;TrustServerCertificate=True" + "PostgresOptions": { + "ConnectionString": "Server=localhost;Port=5432;Database=identity;User Id=postgres;Password=postgres;Include Error Detail=true" }, "RabbitMqOptions": { "HostName": "localhost", @@ -41,7 +41,7 @@ "PersistMessageOptions": { "Interval": 30, "Enabled": true, - "ConnectionString": "Server=localhost;Database=PersistMessageDB;User ID=sa;Password=@Aa123456;TrustServerCertificate=True" + "ConnectionString": "Server=localhost;Port=5432;Database=persist_message;User Id=postgres;Password=postgres;Include Error Detail=true" }, "AllowedHosts": "*" } diff --git a/src/Services/Identity/src/Identity.Api/appsettings.test.json b/src/Services/Identity/src/Identity.Api/appsettings.test.json index 3d40033..2c6c220 100644 --- a/src/Services/Identity/src/Identity.Api/appsettings.test.json +++ b/src/Services/Identity/src/Identity.Api/appsettings.test.json @@ -1,6 +1,6 @@ { - "DatabaseOptions": { - "DefaultConnection": "Server=localhost;Database=IdentityDB_Test;User ID=sa;Password=@Aa123456;TrustServerCertificate=True" + "PostgresOptions": { + "ConnectionString": "Server=localhost;Port=5432;Database=identity_test;User Id=postgres;Password=postgres;Include Error Detail=true" }, "RabbitMqOptions": { "HostName": "localhost", @@ -20,6 +20,6 @@ "PersistMessageOptions": { "Interval": 30, "Enabled": true, - "ConnectionString": "Server=localhost;Database=PersistMessageDB_Test;User ID=sa;Password=@Aa123456;TrustServerCertificate=True" + "ConnectionString": "Server=localhost;Port=5432;Database=persist_message_test;User Id=postgres;Password=postgres;Include Error Detail=true" } } diff --git a/src/Services/Identity/src/Identity/Data/DesignTimeDbContextFactory.cs b/src/Services/Identity/src/Identity/Data/DesignTimeDbContextFactory.cs index f7dc16a..2fefae6 100644 --- a/src/Services/Identity/src/Identity/Data/DesignTimeDbContextFactory.cs +++ b/src/Services/Identity/src/Identity/Data/DesignTimeDbContextFactory.cs @@ -9,7 +9,8 @@ public class DesignTimeDbContextFactory : IDesignTimeDbContextFactory(); - builder.UseSqlServer("Server=localhost;Database=IdentityDB;User ID=sa;Password=@Aa123456;TrustServerCertificate=True"); + builder.UseNpgsql("Server=localhost;Port=5432;Database=identity;User Id=postgres;Password=postgres;Include Error Detail=true") + .UseSnakeCaseNamingConvention(); return new IdentityContext(builder.Options, null); } } diff --git a/src/Services/Identity/src/Identity/Data/IdentityContext.cs b/src/Services/Identity/src/Identity/Data/IdentityContext.cs index e512e2f..84b9b02 100644 --- a/src/Services/Identity/src/Identity/Data/IdentityContext.cs +++ b/src/Services/Identity/src/Identity/Data/IdentityContext.cs @@ -38,8 +38,26 @@ public sealed class IdentityContext : IdentityDbContext -using System; -using Identity.Data; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; - -#nullable disable - -namespace Identity.Data.Migrations -{ - [DbContext(typeof(IdentityContext))] - [Migration("20221206180831_initial")] - partial class initial - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "7.0.0") - .HasAnnotation("Relational:MaxIdentifierLength", 128); - - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - - modelBuilder.Entity("Identity.Identity.Models.ApplicationUser", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("bigint"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("AccessFailedCount") - .HasColumnType("int"); - - b.Property("ConcurrencyStamp") - .IsConcurrencyToken() - .HasColumnType("nvarchar(max)"); - - b.Property("Email") - .HasMaxLength(256) - .HasColumnType("nvarchar(256)"); - - b.Property("EmailConfirmed") - .HasColumnType("bit"); - - b.Property("FirstName") - .HasColumnType("nvarchar(max)"); - - b.Property("LastName") - .HasColumnType("nvarchar(max)"); - - b.Property("LockoutEnabled") - .HasColumnType("bit"); - - b.Property("LockoutEnd") - .HasColumnType("datetimeoffset"); - - b.Property("NormalizedEmail") - .HasMaxLength(256) - .HasColumnType("nvarchar(256)"); - - b.Property("NormalizedUserName") - .HasMaxLength(256) - .HasColumnType("nvarchar(256)"); - - b.Property("PassPortNumber") - .HasColumnType("nvarchar(max)"); - - b.Property("PasswordHash") - .HasColumnType("nvarchar(max)"); - - b.Property("PhoneNumber") - .HasColumnType("nvarchar(max)"); - - b.Property("PhoneNumberConfirmed") - .HasColumnType("bit"); - - b.Property("SecurityStamp") - .HasColumnType("nvarchar(max)"); - - b.Property("TwoFactorEnabled") - .HasColumnType("bit"); - - b.Property("UserName") - .HasMaxLength(256) - .HasColumnType("nvarchar(256)"); - - b.HasKey("Id"); - - b.HasIndex("NormalizedEmail") - .HasDatabaseName("EmailIndex"); - - b.HasIndex("NormalizedUserName") - .IsUnique() - .HasDatabaseName("UserNameIndex") - .HasFilter("[NormalizedUserName] IS NOT NULL"); - - b.ToTable("AspNetUsers", "dbo"); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("bigint"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ConcurrencyStamp") - .IsConcurrencyToken() - .HasColumnType("nvarchar(max)"); - - b.Property("Name") - .HasMaxLength(256) - .HasColumnType("nvarchar(256)"); - - b.Property("NormalizedName") - .HasMaxLength(256) - .HasColumnType("nvarchar(256)"); - - b.HasKey("Id"); - - b.HasIndex("NormalizedName") - .IsUnique() - .HasDatabaseName("RoleNameIndex") - .HasFilter("[NormalizedName] IS NOT NULL"); - - b.ToTable("AspNetRoles", "dbo"); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ClaimType") - .HasColumnType("nvarchar(max)"); - - b.Property("ClaimValue") - .HasColumnType("nvarchar(max)"); - - b.Property("RoleId") - .HasColumnType("bigint"); - - b.HasKey("Id"); - - b.HasIndex("RoleId"); - - b.ToTable("AspNetRoleClaims", "dbo"); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => - { - b.Property("Id") - .ValueGeneratedOnAdd() - .HasColumnType("int"); - - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); - - b.Property("ClaimType") - .HasColumnType("nvarchar(max)"); - - b.Property("ClaimValue") - .HasColumnType("nvarchar(max)"); - - b.Property("UserId") - .HasColumnType("bigint"); - - b.HasKey("Id"); - - b.HasIndex("UserId"); - - b.ToTable("AspNetUserClaims", "dbo"); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => - { - b.Property("LoginProvider") - .HasColumnType("nvarchar(450)"); - - b.Property("ProviderKey") - .HasColumnType("nvarchar(450)"); - - b.Property("ProviderDisplayName") - .HasColumnType("nvarchar(max)"); - - b.Property("UserId") - .HasColumnType("bigint"); - - b.HasKey("LoginProvider", "ProviderKey"); - - b.HasIndex("UserId"); - - b.ToTable("AspNetUserLogins", "dbo"); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => - { - b.Property("UserId") - .HasColumnType("bigint"); - - b.Property("RoleId") - .HasColumnType("bigint"); - - b.HasKey("UserId", "RoleId"); - - b.HasIndex("RoleId"); - - b.ToTable("AspNetUserRoles", "dbo"); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => - { - b.Property("UserId") - .HasColumnType("bigint"); - - b.Property("LoginProvider") - .HasColumnType("nvarchar(450)"); - - b.Property("Name") - .HasColumnType("nvarchar(450)"); - - b.Property("Value") - .HasColumnType("nvarchar(max)"); - - b.HasKey("UserId", "LoginProvider", "Name"); - - b.ToTable("AspNetUserTokens", "dbo"); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => - { - b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) - .WithMany() - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => - { - b.HasOne("Identity.Identity.Models.ApplicationUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => - { - b.HasOne("Identity.Identity.Models.ApplicationUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => - { - b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) - .WithMany() - .HasForeignKey("RoleId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - - b.HasOne("Identity.Identity.Models.ApplicationUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); - - modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => - { - b.HasOne("Identity.Identity.Models.ApplicationUser", null) - .WithMany() - .HasForeignKey("UserId") - .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/src/Services/Identity/src/Identity/Data/Migrations/20221206180831_initial.cs b/src/Services/Identity/src/Identity/Data/Migrations/20221206180831_initial.cs deleted file mode 100644 index 1c533e3..0000000 --- a/src/Services/Identity/src/Identity/Data/Migrations/20221206180831_initial.cs +++ /dev/null @@ -1,259 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace Identity.Data.Migrations -{ - /// - public partial class initial : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.EnsureSchema( - name: "dbo"); - - migrationBuilder.CreateTable( - name: "AspNetRoles", - schema: "dbo", - columns: table => new - { - Id = table.Column(type: "bigint", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - Name = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), - NormalizedName = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), - ConcurrencyStamp = table.Column(type: "nvarchar(max)", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_AspNetRoles", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "AspNetUsers", - schema: "dbo", - columns: table => new - { - Id = table.Column(type: "bigint", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - FirstName = table.Column(type: "nvarchar(max)", nullable: true), - LastName = table.Column(type: "nvarchar(max)", nullable: true), - PassPortNumber = table.Column(type: "nvarchar(max)", nullable: true), - UserName = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), - NormalizedUserName = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), - Email = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), - NormalizedEmail = table.Column(type: "nvarchar(256)", maxLength: 256, nullable: true), - EmailConfirmed = table.Column(type: "bit", nullable: false), - PasswordHash = table.Column(type: "nvarchar(max)", nullable: true), - SecurityStamp = table.Column(type: "nvarchar(max)", nullable: true), - ConcurrencyStamp = table.Column(type: "nvarchar(max)", nullable: true), - PhoneNumber = table.Column(type: "nvarchar(max)", nullable: true), - PhoneNumberConfirmed = table.Column(type: "bit", nullable: false), - TwoFactorEnabled = table.Column(type: "bit", nullable: false), - LockoutEnd = table.Column(type: "datetimeoffset", nullable: true), - LockoutEnabled = table.Column(type: "bit", nullable: false), - AccessFailedCount = table.Column(type: "int", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_AspNetUsers", x => x.Id); - }); - - migrationBuilder.CreateTable( - name: "AspNetRoleClaims", - schema: "dbo", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - RoleId = table.Column(type: "bigint", nullable: false), - ClaimType = table.Column(type: "nvarchar(max)", nullable: true), - ClaimValue = table.Column(type: "nvarchar(max)", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_AspNetRoleClaims", x => x.Id); - table.ForeignKey( - name: "FK_AspNetRoleClaims_AspNetRoles_RoleId", - column: x => x.RoleId, - principalSchema: "dbo", - principalTable: "AspNetRoles", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "AspNetUserClaims", - schema: "dbo", - columns: table => new - { - Id = table.Column(type: "int", nullable: false) - .Annotation("SqlServer:Identity", "1, 1"), - UserId = table.Column(type: "bigint", nullable: false), - ClaimType = table.Column(type: "nvarchar(max)", nullable: true), - ClaimValue = table.Column(type: "nvarchar(max)", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_AspNetUserClaims", x => x.Id); - table.ForeignKey( - name: "FK_AspNetUserClaims_AspNetUsers_UserId", - column: x => x.UserId, - principalSchema: "dbo", - principalTable: "AspNetUsers", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "AspNetUserLogins", - schema: "dbo", - columns: table => new - { - LoginProvider = table.Column(type: "nvarchar(450)", nullable: false), - ProviderKey = table.Column(type: "nvarchar(450)", nullable: false), - ProviderDisplayName = table.Column(type: "nvarchar(max)", nullable: true), - UserId = table.Column(type: "bigint", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_AspNetUserLogins", x => new { x.LoginProvider, x.ProviderKey }); - table.ForeignKey( - name: "FK_AspNetUserLogins_AspNetUsers_UserId", - column: x => x.UserId, - principalSchema: "dbo", - principalTable: "AspNetUsers", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "AspNetUserRoles", - schema: "dbo", - columns: table => new - { - UserId = table.Column(type: "bigint", nullable: false), - RoleId = table.Column(type: "bigint", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_AspNetUserRoles", x => new { x.UserId, x.RoleId }); - table.ForeignKey( - name: "FK_AspNetUserRoles_AspNetRoles_RoleId", - column: x => x.RoleId, - principalSchema: "dbo", - principalTable: "AspNetRoles", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - table.ForeignKey( - name: "FK_AspNetUserRoles_AspNetUsers_UserId", - column: x => x.UserId, - principalSchema: "dbo", - principalTable: "AspNetUsers", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateTable( - name: "AspNetUserTokens", - schema: "dbo", - columns: table => new - { - UserId = table.Column(type: "bigint", nullable: false), - LoginProvider = table.Column(type: "nvarchar(450)", nullable: false), - Name = table.Column(type: "nvarchar(450)", nullable: false), - Value = table.Column(type: "nvarchar(max)", nullable: true) - }, - constraints: table => - { - table.PrimaryKey("PK_AspNetUserTokens", x => new { x.UserId, x.LoginProvider, x.Name }); - table.ForeignKey( - name: "FK_AspNetUserTokens_AspNetUsers_UserId", - column: x => x.UserId, - principalSchema: "dbo", - principalTable: "AspNetUsers", - principalColumn: "Id", - onDelete: ReferentialAction.Cascade); - }); - - migrationBuilder.CreateIndex( - name: "IX_AspNetRoleClaims_RoleId", - schema: "dbo", - table: "AspNetRoleClaims", - column: "RoleId"); - - migrationBuilder.CreateIndex( - name: "RoleNameIndex", - schema: "dbo", - table: "AspNetRoles", - column: "NormalizedName", - unique: true, - filter: "[NormalizedName] IS NOT NULL"); - - migrationBuilder.CreateIndex( - name: "IX_AspNetUserClaims_UserId", - schema: "dbo", - table: "AspNetUserClaims", - column: "UserId"); - - migrationBuilder.CreateIndex( - name: "IX_AspNetUserLogins_UserId", - schema: "dbo", - table: "AspNetUserLogins", - column: "UserId"); - - migrationBuilder.CreateIndex( - name: "IX_AspNetUserRoles_RoleId", - schema: "dbo", - table: "AspNetUserRoles", - column: "RoleId"); - - migrationBuilder.CreateIndex( - name: "EmailIndex", - schema: "dbo", - table: "AspNetUsers", - column: "NormalizedEmail"); - - migrationBuilder.CreateIndex( - name: "UserNameIndex", - schema: "dbo", - table: "AspNetUsers", - column: "NormalizedUserName", - unique: true, - filter: "[NormalizedUserName] IS NOT NULL"); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "AspNetRoleClaims", - schema: "dbo"); - - migrationBuilder.DropTable( - name: "AspNetUserClaims", - schema: "dbo"); - - migrationBuilder.DropTable( - name: "AspNetUserLogins", - schema: "dbo"); - - migrationBuilder.DropTable( - name: "AspNetUserRoles", - schema: "dbo"); - - migrationBuilder.DropTable( - name: "AspNetUserTokens", - schema: "dbo"); - - migrationBuilder.DropTable( - name: "AspNetRoles", - schema: "dbo"); - - migrationBuilder.DropTable( - name: "AspNetUsers", - schema: "dbo"); - } - } -} diff --git a/src/Services/Identity/src/Identity/Data/Migrations/20230113134523_initial.Designer.cs b/src/Services/Identity/src/Identity/Data/Migrations/20230113134523_initial.Designer.cs new file mode 100644 index 0000000..098a6ae --- /dev/null +++ b/src/Services/Identity/src/Identity/Data/Migrations/20230113134523_initial.Designer.cs @@ -0,0 +1,346 @@ +// +using System; +using Identity.Data; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace Identity.Data.Migrations +{ + [DbContext(typeof(IdentityContext))] + [Migration("20230113134523_initial")] + partial class initial + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.1") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("Identity.Identity.Models.ApplicationUser", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint") + .HasColumnName("id"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("AccessFailedCount") + .HasColumnType("integer") + .HasColumnName("access_failed_count"); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("text") + .HasColumnName("concurrency_stamp"); + + b.Property("Email") + .HasMaxLength(256) + .HasColumnType("character varying(256)") + .HasColumnName("email"); + + b.Property("EmailConfirmed") + .HasColumnType("boolean") + .HasColumnName("email_confirmed"); + + b.Property("FirstName") + .HasColumnType("text") + .HasColumnName("first_name"); + + b.Property("LastName") + .HasColumnType("text") + .HasColumnName("last_name"); + + b.Property("LockoutEnabled") + .HasColumnType("boolean") + .HasColumnName("lockout_enabled"); + + b.Property("LockoutEnd") + .HasColumnType("timestamp with time zone") + .HasColumnName("lockout_end"); + + b.Property("NormalizedEmail") + .HasMaxLength(256) + .HasColumnType("character varying(256)") + .HasColumnName("normalized_email"); + + b.Property("NormalizedUserName") + .HasMaxLength(256) + .HasColumnType("character varying(256)") + .HasColumnName("normalized_user_name"); + + b.Property("PassPortNumber") + .HasColumnType("text") + .HasColumnName("pass_port_number"); + + b.Property("PasswordHash") + .HasColumnType("text") + .HasColumnName("password_hash"); + + b.Property("PhoneNumber") + .HasColumnType("text") + .HasColumnName("phone_number"); + + b.Property("PhoneNumberConfirmed") + .HasColumnType("boolean") + .HasColumnName("phone_number_confirmed"); + + b.Property("SecurityStamp") + .HasColumnType("text") + .HasColumnName("security_stamp"); + + b.Property("TwoFactorEnabled") + .HasColumnType("boolean") + .HasColumnName("two_factor_enabled"); + + b.Property("UserName") + .HasMaxLength(256) + .HasColumnType("character varying(256)") + .HasColumnName("user_name"); + + b.HasKey("Id") + .HasName("pk_asp_net_users"); + + b.HasIndex("NormalizedEmail") + .HasDatabaseName("EmailIndex"); + + b.HasIndex("NormalizedUserName") + .IsUnique() + .HasDatabaseName("UserNameIndex"); + + b.ToTable("asp_net_users", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("bigint") + .HasColumnName("id"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ConcurrencyStamp") + .IsConcurrencyToken() + .HasColumnType("text") + .HasColumnName("concurrency_stamp"); + + b.Property("Name") + .HasMaxLength(256) + .HasColumnType("character varying(256)") + .HasColumnName("name"); + + b.Property("NormalizedName") + .HasMaxLength(256) + .HasColumnType("character varying(256)") + .HasColumnName("normalized_name"); + + b.HasKey("Id") + .HasName("pk_asp_net_roles"); + + b.HasIndex("NormalizedName") + .IsUnique() + .HasDatabaseName("RoleNameIndex"); + + b.ToTable("asp_net_roles", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasColumnName("id"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ClaimType") + .HasColumnType("text") + .HasColumnName("claim_type"); + + b.Property("ClaimValue") + .HasColumnType("text") + .HasColumnName("claim_value"); + + b.Property("RoleId") + .HasColumnType("bigint") + .HasColumnName("role_id"); + + b.HasKey("Id") + .HasName("pk_asp_net_role_claims"); + + b.HasIndex("RoleId") + .HasDatabaseName("ix_asp_net_role_claims_role_id"); + + b.ToTable("asp_net_role_claims", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.Property("Id") + .ValueGeneratedOnAdd() + .HasColumnType("integer") + .HasColumnName("id"); + + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); + + b.Property("ClaimType") + .HasColumnType("text") + .HasColumnName("claim_type"); + + b.Property("ClaimValue") + .HasColumnType("text") + .HasColumnName("claim_value"); + + b.Property("UserId") + .HasColumnType("bigint") + .HasColumnName("user_id"); + + b.HasKey("Id") + .HasName("pk_asp_net_user_claims"); + + b.HasIndex("UserId") + .HasDatabaseName("ix_asp_net_user_claims_user_id"); + + b.ToTable("asp_net_user_claims", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.Property("LoginProvider") + .HasColumnType("text") + .HasColumnName("login_provider"); + + b.Property("ProviderKey") + .HasColumnType("text") + .HasColumnName("provider_key"); + + b.Property("ProviderDisplayName") + .HasColumnType("text") + .HasColumnName("provider_display_name"); + + b.Property("UserId") + .HasColumnType("bigint") + .HasColumnName("user_id"); + + b.HasKey("LoginProvider", "ProviderKey") + .HasName("pk_asp_net_user_logins"); + + b.HasIndex("UserId") + .HasDatabaseName("ix_asp_net_user_logins_user_id"); + + b.ToTable("asp_net_user_logins", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.Property("UserId") + .HasColumnType("bigint") + .HasColumnName("user_id"); + + b.Property("RoleId") + .HasColumnType("bigint") + .HasColumnName("role_id"); + + b.HasKey("UserId", "RoleId") + .HasName("pk_asp_net_user_roles"); + + b.HasIndex("RoleId") + .HasDatabaseName("ix_asp_net_user_roles_role_id"); + + b.ToTable("asp_net_user_roles", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.Property("UserId") + .HasColumnType("bigint") + .HasColumnName("user_id"); + + b.Property("LoginProvider") + .HasColumnType("text") + .HasColumnName("login_provider"); + + b.Property("Name") + .HasColumnType("text") + .HasColumnName("name"); + + b.Property("Value") + .HasColumnType("text") + .HasColumnName("value"); + + b.HasKey("UserId", "LoginProvider", "Name") + .HasName("pk_asp_net_user_tokens"); + + b.ToTable("asp_net_user_tokens", (string)null); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired() + .HasConstraintName("fk_asp_net_role_claims_asp_net_roles_role_id"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => + { + b.HasOne("Identity.Identity.Models.ApplicationUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired() + .HasConstraintName("fk_asp_net_user_claims_asp_net_users_user_id"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => + { + b.HasOne("Identity.Identity.Models.ApplicationUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired() + .HasConstraintName("fk_asp_net_user_logins_asp_net_users_user_id"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => + { + b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null) + .WithMany() + .HasForeignKey("RoleId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired() + .HasConstraintName("fk_asp_net_user_roles_asp_net_roles_role_id"); + + b.HasOne("Identity.Identity.Models.ApplicationUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired() + .HasConstraintName("fk_asp_net_user_roles_asp_net_users_user_id"); + }); + + modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => + { + b.HasOne("Identity.Identity.Models.ApplicationUser", null) + .WithMany() + .HasForeignKey("UserId") + .OnDelete(DeleteBehavior.Cascade) + .IsRequired() + .HasConstraintName("fk_asp_net_user_tokens_asp_net_users_user_id"); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/Services/Identity/src/Identity/Data/Migrations/20230113134523_initial.cs b/src/Services/Identity/src/Identity/Data/Migrations/20230113134523_initial.cs new file mode 100644 index 0000000..2fdc821 --- /dev/null +++ b/src/Services/Identity/src/Identity/Data/Migrations/20230113134523_initial.cs @@ -0,0 +1,228 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; + +#nullable disable + +namespace Identity.Data.Migrations +{ + /// + public partial class initial : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "asp_net_roles", + columns: table => new + { + id = table.Column(type: "bigint", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + name = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), + normalizedname = table.Column(name: "normalized_name", type: "character varying(256)", maxLength: 256, nullable: true), + concurrencystamp = table.Column(name: "concurrency_stamp", type: "text", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("pk_asp_net_roles", x => x.id); + }); + + migrationBuilder.CreateTable( + name: "asp_net_users", + columns: table => new + { + id = table.Column(type: "bigint", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + firstname = table.Column(name: "first_name", type: "text", nullable: true), + lastname = table.Column(name: "last_name", type: "text", nullable: true), + passportnumber = table.Column(name: "pass_port_number", type: "text", nullable: true), + username = table.Column(name: "user_name", type: "character varying(256)", maxLength: 256, nullable: true), + normalizedusername = table.Column(name: "normalized_user_name", type: "character varying(256)", maxLength: 256, nullable: true), + email = table.Column(type: "character varying(256)", maxLength: 256, nullable: true), + normalizedemail = table.Column(name: "normalized_email", type: "character varying(256)", maxLength: 256, nullable: true), + emailconfirmed = table.Column(name: "email_confirmed", type: "boolean", nullable: false), + passwordhash = table.Column(name: "password_hash", type: "text", nullable: true), + securitystamp = table.Column(name: "security_stamp", type: "text", nullable: true), + concurrencystamp = table.Column(name: "concurrency_stamp", type: "text", nullable: true), + phonenumber = table.Column(name: "phone_number", type: "text", nullable: true), + phonenumberconfirmed = table.Column(name: "phone_number_confirmed", type: "boolean", nullable: false), + twofactorenabled = table.Column(name: "two_factor_enabled", type: "boolean", nullable: false), + lockoutend = table.Column(name: "lockout_end", type: "timestamp with time zone", nullable: true), + lockoutenabled = table.Column(name: "lockout_enabled", type: "boolean", nullable: false), + accessfailedcount = table.Column(name: "access_failed_count", type: "integer", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("pk_asp_net_users", x => x.id); + }); + + migrationBuilder.CreateTable( + name: "asp_net_role_claims", + columns: table => new + { + id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + roleid = table.Column(name: "role_id", type: "bigint", nullable: false), + claimtype = table.Column(name: "claim_type", type: "text", nullable: true), + claimvalue = table.Column(name: "claim_value", type: "text", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("pk_asp_net_role_claims", x => x.id); + table.ForeignKey( + name: "fk_asp_net_role_claims_asp_net_roles_role_id", + column: x => x.roleid, + principalTable: "asp_net_roles", + principalColumn: "id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "asp_net_user_claims", + columns: table => new + { + id = table.Column(type: "integer", nullable: false) + .Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn), + userid = table.Column(name: "user_id", type: "bigint", nullable: false), + claimtype = table.Column(name: "claim_type", type: "text", nullable: true), + claimvalue = table.Column(name: "claim_value", type: "text", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("pk_asp_net_user_claims", x => x.id); + table.ForeignKey( + name: "fk_asp_net_user_claims_asp_net_users_user_id", + column: x => x.userid, + principalTable: "asp_net_users", + principalColumn: "id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "asp_net_user_logins", + columns: table => new + { + loginprovider = table.Column(name: "login_provider", type: "text", nullable: false), + providerkey = table.Column(name: "provider_key", type: "text", nullable: false), + providerdisplayname = table.Column(name: "provider_display_name", type: "text", nullable: true), + userid = table.Column(name: "user_id", type: "bigint", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("pk_asp_net_user_logins", x => new { x.loginprovider, x.providerkey }); + table.ForeignKey( + name: "fk_asp_net_user_logins_asp_net_users_user_id", + column: x => x.userid, + principalTable: "asp_net_users", + principalColumn: "id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "asp_net_user_roles", + columns: table => new + { + userid = table.Column(name: "user_id", type: "bigint", nullable: false), + roleid = table.Column(name: "role_id", type: "bigint", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("pk_asp_net_user_roles", x => new { x.userid, x.roleid }); + table.ForeignKey( + name: "fk_asp_net_user_roles_asp_net_roles_role_id", + column: x => x.roleid, + principalTable: "asp_net_roles", + principalColumn: "id", + onDelete: ReferentialAction.Cascade); + table.ForeignKey( + name: "fk_asp_net_user_roles_asp_net_users_user_id", + column: x => x.userid, + principalTable: "asp_net_users", + principalColumn: "id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateTable( + name: "asp_net_user_tokens", + columns: table => new + { + userid = table.Column(name: "user_id", type: "bigint", nullable: false), + loginprovider = table.Column(name: "login_provider", type: "text", nullable: false), + name = table.Column(type: "text", nullable: false), + value = table.Column(type: "text", nullable: true) + }, + constraints: table => + { + table.PrimaryKey("pk_asp_net_user_tokens", x => new { x.userid, x.loginprovider, x.name }); + table.ForeignKey( + name: "fk_asp_net_user_tokens_asp_net_users_user_id", + column: x => x.userid, + principalTable: "asp_net_users", + principalColumn: "id", + onDelete: ReferentialAction.Cascade); + }); + + migrationBuilder.CreateIndex( + name: "ix_asp_net_role_claims_role_id", + table: "asp_net_role_claims", + column: "role_id"); + + migrationBuilder.CreateIndex( + name: "RoleNameIndex", + table: "asp_net_roles", + column: "normalized_name", + unique: true); + + migrationBuilder.CreateIndex( + name: "ix_asp_net_user_claims_user_id", + table: "asp_net_user_claims", + column: "user_id"); + + migrationBuilder.CreateIndex( + name: "ix_asp_net_user_logins_user_id", + table: "asp_net_user_logins", + column: "user_id"); + + migrationBuilder.CreateIndex( + name: "ix_asp_net_user_roles_role_id", + table: "asp_net_user_roles", + column: "role_id"); + + migrationBuilder.CreateIndex( + name: "EmailIndex", + table: "asp_net_users", + column: "normalized_email"); + + migrationBuilder.CreateIndex( + name: "UserNameIndex", + table: "asp_net_users", + column: "normalized_user_name", + unique: true); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "asp_net_role_claims"); + + migrationBuilder.DropTable( + name: "asp_net_user_claims"); + + migrationBuilder.DropTable( + name: "asp_net_user_logins"); + + migrationBuilder.DropTable( + name: "asp_net_user_roles"); + + migrationBuilder.DropTable( + name: "asp_net_user_tokens"); + + migrationBuilder.DropTable( + name: "asp_net_roles"); + + migrationBuilder.DropTable( + name: "asp_net_users"); + } + } +} diff --git a/src/Services/Identity/src/Identity/Data/Migrations/IdentityContextModelSnapshot.cs b/src/Services/Identity/src/Identity/Data/Migrations/IdentityContextModelSnapshot.cs index fdf3fdf..d069e54 100644 --- a/src/Services/Identity/src/Identity/Data/Migrations/IdentityContextModelSnapshot.cs +++ b/src/Services/Identity/src/Identity/Data/Migrations/IdentityContextModelSnapshot.cs @@ -3,8 +3,8 @@ using System; using Identity.Data; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; #nullable disable @@ -17,219 +17,268 @@ namespace Identity.Data.Migrations { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "7.0.0") - .HasAnnotation("Relational:MaxIdentifierLength", 128); + .HasAnnotation("ProductVersion", "7.0.1") + .HasAnnotation("Relational:MaxIdentifierLength", 63); - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); modelBuilder.Entity("Identity.Identity.Models.ApplicationUser", b => { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("bigint"); + .HasColumnType("bigint") + .HasColumnName("id"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); b.Property("AccessFailedCount") - .HasColumnType("int"); + .HasColumnType("integer") + .HasColumnName("access_failed_count"); b.Property("ConcurrencyStamp") .IsConcurrencyToken() - .HasColumnType("nvarchar(max)"); + .HasColumnType("text") + .HasColumnName("concurrency_stamp"); b.Property("Email") .HasMaxLength(256) - .HasColumnType("nvarchar(256)"); + .HasColumnType("character varying(256)") + .HasColumnName("email"); b.Property("EmailConfirmed") - .HasColumnType("bit"); + .HasColumnType("boolean") + .HasColumnName("email_confirmed"); b.Property("FirstName") - .HasColumnType("nvarchar(max)"); + .HasColumnType("text") + .HasColumnName("first_name"); b.Property("LastName") - .HasColumnType("nvarchar(max)"); + .HasColumnType("text") + .HasColumnName("last_name"); b.Property("LockoutEnabled") - .HasColumnType("bit"); + .HasColumnType("boolean") + .HasColumnName("lockout_enabled"); b.Property("LockoutEnd") - .HasColumnType("datetimeoffset"); + .HasColumnType("timestamp with time zone") + .HasColumnName("lockout_end"); b.Property("NormalizedEmail") .HasMaxLength(256) - .HasColumnType("nvarchar(256)"); + .HasColumnType("character varying(256)") + .HasColumnName("normalized_email"); b.Property("NormalizedUserName") .HasMaxLength(256) - .HasColumnType("nvarchar(256)"); + .HasColumnType("character varying(256)") + .HasColumnName("normalized_user_name"); b.Property("PassPortNumber") - .HasColumnType("nvarchar(max)"); + .HasColumnType("text") + .HasColumnName("pass_port_number"); b.Property("PasswordHash") - .HasColumnType("nvarchar(max)"); + .HasColumnType("text") + .HasColumnName("password_hash"); b.Property("PhoneNumber") - .HasColumnType("nvarchar(max)"); + .HasColumnType("text") + .HasColumnName("phone_number"); b.Property("PhoneNumberConfirmed") - .HasColumnType("bit"); + .HasColumnType("boolean") + .HasColumnName("phone_number_confirmed"); b.Property("SecurityStamp") - .HasColumnType("nvarchar(max)"); + .HasColumnType("text") + .HasColumnName("security_stamp"); b.Property("TwoFactorEnabled") - .HasColumnType("bit"); + .HasColumnType("boolean") + .HasColumnName("two_factor_enabled"); b.Property("UserName") .HasMaxLength(256) - .HasColumnType("nvarchar(256)"); + .HasColumnType("character varying(256)") + .HasColumnName("user_name"); - b.HasKey("Id"); + b.HasKey("Id") + .HasName("pk_asp_net_users"); b.HasIndex("NormalizedEmail") .HasDatabaseName("EmailIndex"); b.HasIndex("NormalizedUserName") .IsUnique() - .HasDatabaseName("UserNameIndex") - .HasFilter("[NormalizedUserName] IS NOT NULL"); + .HasDatabaseName("UserNameIndex"); - b.ToTable("AspNetUsers", "dbo"); + b.ToTable("asp_net_users", (string)null); }); modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b => { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("bigint"); + .HasColumnType("bigint") + .HasColumnName("id"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); b.Property("ConcurrencyStamp") .IsConcurrencyToken() - .HasColumnType("nvarchar(max)"); + .HasColumnType("text") + .HasColumnName("concurrency_stamp"); b.Property("Name") .HasMaxLength(256) - .HasColumnType("nvarchar(256)"); + .HasColumnType("character varying(256)") + .HasColumnName("name"); b.Property("NormalizedName") .HasMaxLength(256) - .HasColumnType("nvarchar(256)"); + .HasColumnType("character varying(256)") + .HasColumnName("normalized_name"); - b.HasKey("Id"); + b.HasKey("Id") + .HasName("pk_asp_net_roles"); b.HasIndex("NormalizedName") .IsUnique() - .HasDatabaseName("RoleNameIndex") - .HasFilter("[NormalizedName] IS NOT NULL"); + .HasDatabaseName("RoleNameIndex"); - b.ToTable("AspNetRoles", "dbo"); + b.ToTable("asp_net_roles", (string)null); }); modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int"); + .HasColumnType("integer") + .HasColumnName("id"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); b.Property("ClaimType") - .HasColumnType("nvarchar(max)"); + .HasColumnType("text") + .HasColumnName("claim_type"); b.Property("ClaimValue") - .HasColumnType("nvarchar(max)"); + .HasColumnType("text") + .HasColumnName("claim_value"); b.Property("RoleId") - .HasColumnType("bigint"); + .HasColumnType("bigint") + .HasColumnName("role_id"); - b.HasKey("Id"); + b.HasKey("Id") + .HasName("pk_asp_net_role_claims"); - b.HasIndex("RoleId"); + b.HasIndex("RoleId") + .HasDatabaseName("ix_asp_net_role_claims_role_id"); - b.ToTable("AspNetRoleClaims", "dbo"); + b.ToTable("asp_net_role_claims", (string)null); }); modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => { b.Property("Id") .ValueGeneratedOnAdd() - .HasColumnType("int"); + .HasColumnType("integer") + .HasColumnName("id"); - SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property("Id")); + NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property("Id")); b.Property("ClaimType") - .HasColumnType("nvarchar(max)"); + .HasColumnType("text") + .HasColumnName("claim_type"); b.Property("ClaimValue") - .HasColumnType("nvarchar(max)"); + .HasColumnType("text") + .HasColumnName("claim_value"); b.Property("UserId") - .HasColumnType("bigint"); + .HasColumnType("bigint") + .HasColumnName("user_id"); - b.HasKey("Id"); + b.HasKey("Id") + .HasName("pk_asp_net_user_claims"); - b.HasIndex("UserId"); + b.HasIndex("UserId") + .HasDatabaseName("ix_asp_net_user_claims_user_id"); - b.ToTable("AspNetUserClaims", "dbo"); + b.ToTable("asp_net_user_claims", (string)null); }); modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => { b.Property("LoginProvider") - .HasColumnType("nvarchar(450)"); + .HasColumnType("text") + .HasColumnName("login_provider"); b.Property("ProviderKey") - .HasColumnType("nvarchar(450)"); + .HasColumnType("text") + .HasColumnName("provider_key"); b.Property("ProviderDisplayName") - .HasColumnType("nvarchar(max)"); + .HasColumnType("text") + .HasColumnName("provider_display_name"); b.Property("UserId") - .HasColumnType("bigint"); + .HasColumnType("bigint") + .HasColumnName("user_id"); - b.HasKey("LoginProvider", "ProviderKey"); + b.HasKey("LoginProvider", "ProviderKey") + .HasName("pk_asp_net_user_logins"); - b.HasIndex("UserId"); + b.HasIndex("UserId") + .HasDatabaseName("ix_asp_net_user_logins_user_id"); - b.ToTable("AspNetUserLogins", "dbo"); + b.ToTable("asp_net_user_logins", (string)null); }); modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => { b.Property("UserId") - .HasColumnType("bigint"); + .HasColumnType("bigint") + .HasColumnName("user_id"); b.Property("RoleId") - .HasColumnType("bigint"); + .HasColumnType("bigint") + .HasColumnName("role_id"); - b.HasKey("UserId", "RoleId"); + b.HasKey("UserId", "RoleId") + .HasName("pk_asp_net_user_roles"); - b.HasIndex("RoleId"); + b.HasIndex("RoleId") + .HasDatabaseName("ix_asp_net_user_roles_role_id"); - b.ToTable("AspNetUserRoles", "dbo"); + b.ToTable("asp_net_user_roles", (string)null); }); modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => { b.Property("UserId") - .HasColumnType("bigint"); + .HasColumnType("bigint") + .HasColumnName("user_id"); b.Property("LoginProvider") - .HasColumnType("nvarchar(450)"); + .HasColumnType("text") + .HasColumnName("login_provider"); b.Property("Name") - .HasColumnType("nvarchar(450)"); + .HasColumnType("text") + .HasColumnName("name"); b.Property("Value") - .HasColumnType("nvarchar(max)"); + .HasColumnType("text") + .HasColumnName("value"); - b.HasKey("UserId", "LoginProvider", "Name"); + b.HasKey("UserId", "LoginProvider", "Name") + .HasName("pk_asp_net_user_tokens"); - b.ToTable("AspNetUserTokens", "dbo"); + b.ToTable("asp_net_user_tokens", (string)null); }); modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim", b => @@ -238,7 +287,8 @@ namespace Identity.Data.Migrations .WithMany() .HasForeignKey("RoleId") .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); + .IsRequired() + .HasConstraintName("fk_asp_net_role_claims_asp_net_roles_role_id"); }); modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim", b => @@ -247,7 +297,8 @@ namespace Identity.Data.Migrations .WithMany() .HasForeignKey("UserId") .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); + .IsRequired() + .HasConstraintName("fk_asp_net_user_claims_asp_net_users_user_id"); }); modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin", b => @@ -256,7 +307,8 @@ namespace Identity.Data.Migrations .WithMany() .HasForeignKey("UserId") .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); + .IsRequired() + .HasConstraintName("fk_asp_net_user_logins_asp_net_users_user_id"); }); modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole", b => @@ -265,13 +317,15 @@ namespace Identity.Data.Migrations .WithMany() .HasForeignKey("RoleId") .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); + .IsRequired() + .HasConstraintName("fk_asp_net_user_roles_asp_net_roles_role_id"); b.HasOne("Identity.Identity.Models.ApplicationUser", null) .WithMany() .HasForeignKey("UserId") .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); + .IsRequired() + .HasConstraintName("fk_asp_net_user_roles_asp_net_users_user_id"); }); modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken", b => @@ -280,7 +334,8 @@ namespace Identity.Data.Migrations .WithMany() .HasForeignKey("UserId") .OnDelete(DeleteBehavior.Cascade) - .IsRequired(); + .IsRequired() + .HasConstraintName("fk_asp_net_user_tokens_asp_net_users_user_id"); }); #pragma warning restore 612, 618 } diff --git a/src/Services/Identity/tests/IntegrationTest/Fakes/FakeRegisterNewUserCommand.cs b/src/Services/Identity/tests/IntegrationTest/Fakes/FakeRegisterNewUserCommand.cs index afe7171..5582dde 100644 --- a/src/Services/Identity/tests/IntegrationTest/Fakes/FakeRegisterNewUserCommand.cs +++ b/src/Services/Identity/tests/IntegrationTest/Fakes/FakeRegisterNewUserCommand.cs @@ -7,7 +7,7 @@ public class FakeRegisterNewUserCommand : AutoFaker { public FakeRegisterNewUserCommand() { - RuleFor(r => r.Username, x => x.Random.Uuid().ToString()); + RuleFor(r => r.Username, x => "TestMyUser"); RuleFor(r => r.Password, _ => "Password@123"); RuleFor(r => r.ConfirmPassword, _ => "Password@123"); RuleFor(r => r.Email, _ => "test@test.com"); diff --git a/src/Services/Passenger/src/Passenger.Api/appsettings.docker.json b/src/Services/Passenger/src/Passenger.Api/appsettings.docker.json index d76441c..377e5a7 100644 --- a/src/Services/Passenger/src/Passenger.Api/appsettings.docker.json +++ b/src/Services/Passenger/src/Passenger.Api/appsettings.docker.json @@ -1,13 +1,12 @@ { "App": "Passenger-Service", - "DatabaseOptions": { - - "DefaultConnection": "Server=sql;Database=PassengerDB;User ID=sa;Password=@Aa123456;TrustServerCertificate=True" + "PostgresOptions": { + "ConnectionString": "Server=postgres;Port=5432;Database=passenger;User Id=postgres;Password=postgres;Include Error Detail=true" }, "PersistMessageOptions": { "Interval": 30, "Enabled": true, - "ConnectionString": "Server=sql;Database=PersistMessageDB;User ID=sa;Password=@Aa123456;TrustServerCertificate=True" + "ConnectionString": "Server=postgres;Port=5432;Database=persist_message;User Id=postgres;Password=postgres;Include Error Detail=true" }, "Jwt": { "Authority": "https://localhost:5005", diff --git a/src/Services/Passenger/src/Passenger.Api/appsettings.json b/src/Services/Passenger/src/Passenger.Api/appsettings.json index 8099f02..f73aaa3 100644 --- a/src/Services/Passenger/src/Passenger.Api/appsettings.json +++ b/src/Services/Passenger/src/Passenger.Api/appsettings.json @@ -2,8 +2,8 @@ "AppOptions": { "Name": "Passenger-Service" }, - "DatabaseOptions": { - "DefaultConnection": "Server=localhost;Database=PassengerDB;User ID=sa;Password=@Aa123456;TrustServerCertificate=True" + "PostgresOptions": { + "ConnectionString": "Server=localhost;Port=5432;Database=passenger;User Id=postgres;Password=postgres;Include Error Detail=true" }, "MongoOptions": { "ConnectionString": "mongodb://localhost:27017", @@ -45,7 +45,7 @@ "PersistMessageOptions": { "Interval": 30, "Enabled": true, - "ConnectionString": "Server=localhost;Database=PersistMessageDB;User ID=sa;Password=@Aa123456;TrustServerCertificate=True" + "ConnectionString": "Server=localhost;Port=5432;Database=persist_message;User Id=postgres;Password=postgres;Include Error Detail=true" }, "AllowedHosts": "*" } diff --git a/src/Services/Passenger/src/Passenger.Api/appsettings.test.json b/src/Services/Passenger/src/Passenger.Api/appsettings.test.json index 71ea34c..134759f 100644 --- a/src/Services/Passenger/src/Passenger.Api/appsettings.test.json +++ b/src/Services/Passenger/src/Passenger.Api/appsettings.test.json @@ -1,6 +1,6 @@ { - "DatabaseOptions": { - "DefaultConnection": "Server=localhost;Database=PassengerDB_Test;User ID=sa;Password=@Aa123456;TrustServerCertificate=True" + "PostgresOptions": { + "ConnectionString": "Server=localhost;Port=5432;Database=passenger_test;User Id=postgres;Password=postgres;Include Error Detail=true" }, "RabbitMqOptions": { "HostName": "localhost", @@ -20,6 +20,6 @@ "PersistMessageOptions": { "Interval": 30, "Enabled": true, - "ConnectionString": "Server=localhost;Database=PersistMessageDB_Test;User ID=sa;Password=@Aa123456;TrustServerCertificate=True" + "ConnectionString": "Server=localhost;Port=5432;Database=persist_message_test;User Id=postgres;Password=postgres;Include Error Detail=true" } } diff --git a/src/Services/Passenger/src/Passenger/Data/Configurations/PassengerConfiguration.cs b/src/Services/Passenger/src/Passenger/Data/Configurations/PassengerConfiguration.cs index 83733cc..6fea012 100644 --- a/src/Services/Passenger/src/Passenger/Data/Configurations/PassengerConfiguration.cs +++ b/src/Services/Passenger/src/Passenger/Data/Configurations/PassengerConfiguration.cs @@ -8,7 +8,7 @@ public class PassengerConfiguration: IEntityTypeConfiguration builder) { - builder.ToTable("Passenger", AppDbContextBase.DefaultSchema); + builder.ToTable("passenger"); builder.HasKey(r => r.Id); builder.Property(r => r.Id).ValueGeneratedNever(); diff --git a/src/Services/Passenger/src/Passenger/Data/DesignTimeDbContextFactory.cs b/src/Services/Passenger/src/Passenger/Data/DesignTimeDbContextFactory.cs index 950e3c2..87860fb 100644 --- a/src/Services/Passenger/src/Passenger/Data/DesignTimeDbContextFactory.cs +++ b/src/Services/Passenger/src/Passenger/Data/DesignTimeDbContextFactory.cs @@ -9,7 +9,8 @@ public class DesignTimeDbContextFactory: IDesignTimeDbContextFactory(); - builder.UseSqlServer("Server=localhost;Database=PassengerDB;User ID=sa;Password=@Aa123456;TrustServerCertificate=True"); + builder.UseNpgsql("Server=localhost;Port=5432;Database=passenger;User Id=postgres;Password=postgres;Include Error Detail=true") + .UseSnakeCaseNamingConvention(); return new PassengerDbContext(builder.Options, null); } } diff --git a/src/Services/Passenger/src/Passenger/Data/Migrations/20221206180929_initial.Designer.cs b/src/Services/Passenger/src/Passenger/Data/Migrations/20221206180929_initial.Designer.cs deleted file mode 100644 index 64ec17a..0000000 --- a/src/Services/Passenger/src/Passenger/Data/Migrations/20221206180929_initial.Designer.cs +++ /dev/null @@ -1,70 +0,0 @@ -// -using System; -using Microsoft.EntityFrameworkCore; -using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; -using Microsoft.EntityFrameworkCore.Migrations; -using Microsoft.EntityFrameworkCore.Storage.ValueConversion; -using Passenger.Data; - -#nullable disable - -namespace Passenger.Data.Migrations -{ - [DbContext(typeof(PassengerDbContext))] - [Migration("20221206180929_initial")] - partial class initial - { - /// - protected override void BuildTargetModel(ModelBuilder modelBuilder) - { -#pragma warning disable 612, 618 - modelBuilder - .HasAnnotation("ProductVersion", "7.0.0") - .HasAnnotation("Relational:MaxIdentifierLength", 128); - - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); - - modelBuilder.Entity("Passenger.Passengers.Models.Passenger", b => - { - b.Property("Id") - .HasColumnType("bigint"); - - b.Property("Age") - .HasColumnType("int"); - - b.Property("CreatedAt") - .HasColumnType("datetime2"); - - b.Property("CreatedBy") - .HasColumnType("bigint"); - - b.Property("IsDeleted") - .HasColumnType("bit"); - - b.Property("LastModified") - .HasColumnType("datetime2"); - - b.Property("LastModifiedBy") - .HasColumnType("bigint"); - - b.Property("Name") - .HasColumnType("nvarchar(max)"); - - b.Property("PassengerType") - .HasColumnType("int"); - - b.Property("PassportNumber") - .HasColumnType("nvarchar(max)"); - - b.Property("Version") - .HasColumnType("bigint"); - - b.HasKey("Id"); - - b.ToTable("Passenger", "dbo"); - }); -#pragma warning restore 612, 618 - } - } -} diff --git a/src/Services/Passenger/src/Passenger/Data/Migrations/20221206180929_initial.cs b/src/Services/Passenger/src/Passenger/Data/Migrations/20221206180929_initial.cs deleted file mode 100644 index 8730fb3..0000000 --- a/src/Services/Passenger/src/Passenger/Data/Migrations/20221206180929_initial.cs +++ /dev/null @@ -1,48 +0,0 @@ -using System; -using Microsoft.EntityFrameworkCore.Migrations; - -#nullable disable - -namespace Passenger.Data.Migrations -{ - /// - public partial class initial : Migration - { - /// - protected override void Up(MigrationBuilder migrationBuilder) - { - migrationBuilder.EnsureSchema( - name: "dbo"); - - migrationBuilder.CreateTable( - name: "Passenger", - schema: "dbo", - columns: table => new - { - Id = table.Column(type: "bigint", nullable: false), - PassportNumber = table.Column(type: "nvarchar(max)", nullable: true), - Name = table.Column(type: "nvarchar(max)", nullable: true), - PassengerType = table.Column(type: "int", nullable: false), - Age = table.Column(type: "int", nullable: false), - CreatedAt = table.Column(type: "datetime2", nullable: true), - CreatedBy = table.Column(type: "bigint", nullable: true), - LastModified = table.Column(type: "datetime2", nullable: true), - LastModifiedBy = table.Column(type: "bigint", nullable: true), - IsDeleted = table.Column(type: "bit", nullable: false), - Version = table.Column(type: "bigint", nullable: false) - }, - constraints: table => - { - table.PrimaryKey("PK_Passenger", x => x.Id); - }); - } - - /// - protected override void Down(MigrationBuilder migrationBuilder) - { - migrationBuilder.DropTable( - name: "Passenger", - schema: "dbo"); - } - } -} diff --git a/src/Services/Passenger/src/Passenger/Data/Migrations/20230113134610_initial.Designer.cs b/src/Services/Passenger/src/Passenger/Data/Migrations/20230113134610_initial.Designer.cs new file mode 100644 index 0000000..7657b3f --- /dev/null +++ b/src/Services/Passenger/src/Passenger/Data/Migrations/20230113134610_initial.Designer.cs @@ -0,0 +1,82 @@ +// +using System; +using Microsoft.EntityFrameworkCore; +using Microsoft.EntityFrameworkCore.Infrastructure; +using Microsoft.EntityFrameworkCore.Migrations; +using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; +using Passenger.Data; + +#nullable disable + +namespace Passenger.Data.Migrations +{ + [DbContext(typeof(PassengerDbContext))] + [Migration("20230113134610_initial")] + partial class initial + { + /// + protected override void BuildTargetModel(ModelBuilder modelBuilder) + { +#pragma warning disable 612, 618 + modelBuilder + .HasAnnotation("ProductVersion", "7.0.1") + .HasAnnotation("Relational:MaxIdentifierLength", 63); + + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); + + modelBuilder.Entity("Passenger.Passengers.Models.Passenger", b => + { + b.Property("Id") + .HasColumnType("bigint") + .HasColumnName("id"); + + b.Property("Age") + .HasColumnType("integer") + .HasColumnName("age"); + + b.Property("CreatedAt") + .HasColumnType("timestamp with time zone") + .HasColumnName("created_at"); + + b.Property("CreatedBy") + .HasColumnType("bigint") + .HasColumnName("created_by"); + + b.Property("IsDeleted") + .HasColumnType("boolean") + .HasColumnName("is_deleted"); + + b.Property("LastModified") + .HasColumnType("timestamp with time zone") + .HasColumnName("last_modified"); + + b.Property("LastModifiedBy") + .HasColumnType("bigint") + .HasColumnName("last_modified_by"); + + b.Property("Name") + .HasColumnType("text") + .HasColumnName("name"); + + b.Property("PassengerType") + .HasColumnType("integer") + .HasColumnName("passenger_type"); + + b.Property("PassportNumber") + .HasColumnType("text") + .HasColumnName("passport_number"); + + b.Property("Version") + .HasColumnType("bigint") + .HasColumnName("version"); + + b.HasKey("Id") + .HasName("pk_passenger"); + + b.ToTable("passenger", (string)null); + }); +#pragma warning restore 612, 618 + } + } +} diff --git a/src/Services/Passenger/src/Passenger/Data/Migrations/20230113134610_initial.cs b/src/Services/Passenger/src/Passenger/Data/Migrations/20230113134610_initial.cs new file mode 100644 index 0000000..9c98b8f --- /dev/null +++ b/src/Services/Passenger/src/Passenger/Data/Migrations/20230113134610_initial.cs @@ -0,0 +1,43 @@ +using System; +using Microsoft.EntityFrameworkCore.Migrations; + +#nullable disable + +namespace Passenger.Data.Migrations +{ + /// + public partial class initial : Migration + { + /// + protected override void Up(MigrationBuilder migrationBuilder) + { + migrationBuilder.CreateTable( + name: "passenger", + columns: table => new + { + id = table.Column(type: "bigint", nullable: false), + passportnumber = table.Column(name: "passport_number", type: "text", nullable: true), + name = table.Column(type: "text", nullable: true), + passengertype = table.Column(name: "passenger_type", type: "integer", nullable: false), + age = table.Column(type: "integer", nullable: false), + createdat = table.Column(name: "created_at", type: "timestamp with time zone", nullable: true), + createdby = table.Column(name: "created_by", type: "bigint", nullable: true), + lastmodified = table.Column(name: "last_modified", type: "timestamp with time zone", nullable: true), + lastmodifiedby = table.Column(name: "last_modified_by", type: "bigint", nullable: true), + isdeleted = table.Column(name: "is_deleted", type: "boolean", nullable: false), + version = table.Column(type: "bigint", nullable: false) + }, + constraints: table => + { + table.PrimaryKey("pk_passenger", x => x.id); + }); + } + + /// + protected override void Down(MigrationBuilder migrationBuilder) + { + migrationBuilder.DropTable( + name: "passenger"); + } + } +} diff --git a/src/Services/Passenger/src/Passenger/Data/Migrations/PassengerDbContextModelSnapshot.cs b/src/Services/Passenger/src/Passenger/Data/Migrations/PassengerDbContextModelSnapshot.cs index c5bb3b6..20ec96f 100644 --- a/src/Services/Passenger/src/Passenger/Data/Migrations/PassengerDbContextModelSnapshot.cs +++ b/src/Services/Passenger/src/Passenger/Data/Migrations/PassengerDbContextModelSnapshot.cs @@ -2,8 +2,8 @@ using System; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Infrastructure; -using Microsoft.EntityFrameworkCore.Metadata; using Microsoft.EntityFrameworkCore.Storage.ValueConversion; +using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata; using Passenger.Data; #nullable disable @@ -17,49 +17,61 @@ namespace Passenger.Data.Migrations { #pragma warning disable 612, 618 modelBuilder - .HasAnnotation("ProductVersion", "7.0.0") - .HasAnnotation("Relational:MaxIdentifierLength", 128); + .HasAnnotation("ProductVersion", "7.0.1") + .HasAnnotation("Relational:MaxIdentifierLength", 63); - SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder); + NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder); modelBuilder.Entity("Passenger.Passengers.Models.Passenger", b => { b.Property("Id") - .HasColumnType("bigint"); + .HasColumnType("bigint") + .HasColumnName("id"); b.Property("Age") - .HasColumnType("int"); + .HasColumnType("integer") + .HasColumnName("age"); b.Property("CreatedAt") - .HasColumnType("datetime2"); + .HasColumnType("timestamp with time zone") + .HasColumnName("created_at"); b.Property("CreatedBy") - .HasColumnType("bigint"); + .HasColumnType("bigint") + .HasColumnName("created_by"); b.Property("IsDeleted") - .HasColumnType("bit"); + .HasColumnType("boolean") + .HasColumnName("is_deleted"); b.Property("LastModified") - .HasColumnType("datetime2"); + .HasColumnType("timestamp with time zone") + .HasColumnName("last_modified"); b.Property("LastModifiedBy") - .HasColumnType("bigint"); + .HasColumnType("bigint") + .HasColumnName("last_modified_by"); b.Property("Name") - .HasColumnType("nvarchar(max)"); + .HasColumnType("text") + .HasColumnName("name"); b.Property("PassengerType") - .HasColumnType("int"); + .HasColumnType("integer") + .HasColumnName("passenger_type"); b.Property("PassportNumber") - .HasColumnType("nvarchar(max)"); + .HasColumnType("text") + .HasColumnName("passport_number"); b.Property("Version") - .HasColumnType("bigint"); + .HasColumnType("bigint") + .HasColumnName("version"); - b.HasKey("Id"); + b.HasKey("Id") + .HasName("pk_passenger"); - b.ToTable("Passenger", "dbo"); + b.ToTable("passenger", (string)null); }); #pragma warning restore 612, 618 }