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