feat: Add postgres instead of sql for write database

This commit is contained in:
meysamhadeli 2023-01-13 19:06:56 +03:30
parent 30b32b08bf
commit e96283d0e6
59 changed files with 1789 additions and 1557 deletions

View File

@ -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
#######################################################

View File

@ -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

View File

@ -14,8 +14,8 @@
<PackageReference Include="Asp.Versioning.Mvc.ApiExplorer" Version="7.0.0" />
<PackageReference Include="AspNetCore.HealthChecks.Elasticsearch" Version="6.0.2" />
<PackageReference Include="AspNetCore.HealthChecks.EventStore" Version="6.0.3" />
<PackageReference Include="AspNetCore.HealthChecks.NpgSql" Version="6.0.2" />
<PackageReference Include="AspNetCore.HealthChecks.Rabbitmq" Version="6.0.2" />
<PackageReference Include="AspNetCore.HealthChecks.SqlServer" Version="6.0.2" />
<PackageReference Include="AspNetCore.HealthChecks.UI.SQLite.Storage" Version="6.0.5" />
<PackageReference Include="Ben.BlockingDetector" Version="0.0.4" />
<PackageReference Include="EasyCaching.Core" Version="1.8.0" />

View File

@ -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)

View File

@ -1,6 +1,6 @@
namespace BuildingBlocks.EFCore;
public class DatabaseOptions
public class PostgresOptions
{
public string DefaultConnection { get; set; }
public string ConnectionString { get; set; }
}

View File

@ -17,18 +17,21 @@ public static class Extensions
this IServiceCollection services)
where TContext : DbContext, IDbContext
{
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
services.AddValidateOptions<DatabaseOptions>();
services.AddValidateOptions<PostgresOptions>();
services.AddDbContext<TContext>((sp, options) =>
{
var databaseOptions = services.GetOptions<DatabaseOptions>(nameof(DatabaseOptions));
var postgresOptions = sp.GetRequiredService<PostgresOptions>();
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<IDbContext>(provider => provider.GetService<TContext>());
@ -42,7 +45,9 @@ public static class Extensions
MigrateDatabaseAsync<TContext>(app.ApplicationServices).GetAwaiter().GetResult();
if (!env.IsEnvironment("test"))
{
SeedDataAsync(app.ApplicationServices).GetAwaiter().GetResult();
}
return app;
}

View File

@ -21,7 +21,7 @@ public static class Extensions
if (!healthOptions.Enabled) return services;
var appOptions = services.GetOptions<AppOptions>(nameof(AppOptions));
var sqlOptions = services.GetOptions<DatabaseOptions>(nameof(DatabaseOptions));
var postgresOptions = services.GetOptions<PostgresOptions>(nameof(PostgresOptions));
var rabbitMqOptions = services.GetOptions<RabbitMqOptions>(nameof(RabbitMqOptions));
var mongoOptions = services.GetOptions<MongoOptions>(nameof(MongoOptions));
var logOptions = services.GetOptions<LogOptions>(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 =>
{

View File

@ -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<PersistMessa
{
public void Configure(EntityTypeBuilder<PersistMessage> builder)
{
builder.ToTable("PersistMessage", AppDbContextBase.DefaultSchema);
builder.ToTable("persistMessage");
builder.HasKey(x => x.Id);
@ -16,27 +15,16 @@ public class PersistMessageConfiguration : IEntityTypeConfiguration<PersistMessa
.IsRequired().ValueGeneratedNever();
builder.Property(x => 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));
}
}

View File

@ -9,7 +9,8 @@ public class DesignTimeDbContextFactory : IDesignTimeDbContextFactory<PersistMes
{
var builder = new DbContextOptionsBuilder<PersistMessageDbContext>();
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);
}
}

View File

@ -1,64 +0,0 @@
// <auto-generated />
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
{
/// <inheritdoc />
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<long>("Id")
.HasColumnType("bigint");
b.Property<DateTime>("Created")
.HasColumnType("datetime2");
b.Property<string>("Data")
.HasColumnType("nvarchar(max)");
b.Property<string>("DataType")
.HasColumnType("nvarchar(max)");
b.Property<string>("DeliveryType")
.IsRequired()
.HasMaxLength(50)
.IsUnicode(false)
.HasColumnType("varchar(50)");
b.Property<string>("MessageStatus")
.IsRequired()
.HasMaxLength(50)
.IsUnicode(false)
.HasColumnType("varchar(50)");
b.Property<int>("RetryCount")
.HasColumnType("int");
b.HasKey("Id");
b.ToTable("PersistMessage", "dbo");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -1,44 +0,0 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace BuildingBlocks.PersistMessageProcessor.Data.Migrations
{
/// <inheritdoc />
public partial class initial : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.EnsureSchema(
name: "dbo");
migrationBuilder.CreateTable(
name: "PersistMessage",
schema: "dbo",
columns: table => new
{
Id = table.Column<long>(type: "bigint", nullable: false),
DataType = table.Column<string>(type: "nvarchar(max)", nullable: true),
Data = table.Column<string>(type: "nvarchar(max)", nullable: true),
Created = table.Column<DateTime>(type: "datetime2", nullable: false),
RetryCount = table.Column<int>(type: "int", nullable: false),
MessageStatus = table.Column<string>(type: "varchar(50)", unicode: false, maxLength: 50, nullable: false),
DeliveryType = table.Column<string>(type: "varchar(50)", unicode: false, maxLength: 50, nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_PersistMessage", x => x.Id);
});
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "PersistMessage",
schema: "dbo");
}
}
}

View File

@ -0,0 +1,72 @@
// <auto-generated />
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
{
/// <inheritdoc />
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<long>("Id")
.HasColumnType("bigint")
.HasColumnName("id");
b.Property<DateTime>("Created")
.HasColumnType("timestamp with time zone")
.HasColumnName("created");
b.Property<string>("Data")
.HasColumnType("text")
.HasColumnName("data");
b.Property<string>("DataType")
.HasColumnType("text")
.HasColumnName("data_type");
b.Property<string>("DeliveryType")
.IsRequired()
.ValueGeneratedOnAdd()
.HasColumnType("text")
.HasDefaultValue("Outbox")
.HasColumnName("delivery_type");
b.Property<string>("MessageStatus")
.IsRequired()
.ValueGeneratedOnAdd()
.HasColumnType("text")
.HasDefaultValue("InProgress")
.HasColumnName("message_status");
b.Property<int>("RetryCount")
.HasColumnType("integer")
.HasColumnName("retry_count");
b.HasKey("Id")
.HasName("pk_persist_message");
b.ToTable("persistMessage", (string)null);
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,39 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace BuildingBlocks.PersistMessageProcessor.Data.Migrations
{
/// <inheritdoc />
public partial class initial : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "persistMessage",
columns: table => new
{
id = table.Column<long>(type: "bigint", nullable: false),
datatype = table.Column<string>(name: "data_type", type: "text", nullable: true),
data = table.Column<string>(type: "text", nullable: true),
created = table.Column<DateTime>(type: "timestamp with time zone", nullable: false),
retrycount = table.Column<int>(name: "retry_count", type: "integer", nullable: false),
messagestatus = table.Column<string>(name: "message_status", type: "text", nullable: false, defaultValue: "InProgress"),
deliverytype = table.Column<string>(name: "delivery_type", type: "text", nullable: false, defaultValue: "Outbox")
},
constraints: table =>
{
table.PrimaryKey("pk_persist_message", x => x.id);
});
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "persistMessage");
}
}
}

View File

@ -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<long>("Id")
.HasColumnType("bigint");
.HasColumnType("bigint")
.HasColumnName("id");
b.Property<DateTime>("Created")
.HasColumnType("datetime2");
.HasColumnType("timestamp with time zone")
.HasColumnName("created");
b.Property<string>("Data")
.HasColumnType("nvarchar(max)");
.HasColumnType("text")
.HasColumnName("data");
b.Property<string>("DataType")
.HasColumnType("nvarchar(max)");
.HasColumnType("text")
.HasColumnName("data_type");
b.Property<string>("DeliveryType")
.IsRequired()
.HasMaxLength(50)
.IsUnicode(false)
.HasColumnType("varchar(50)");
.ValueGeneratedOnAdd()
.HasColumnType("text")
.HasDefaultValue("Outbox")
.HasColumnName("delivery_type");
b.Property<string>("MessageStatus")
.IsRequired()
.HasMaxLength(50)
.IsUnicode(false)
.HasColumnType("varchar(50)");
.ValueGeneratedOnAdd()
.HasColumnType("text")
.HasDefaultValue("InProgress")
.HasColumnName("message_status");
b.Property<int>("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
}

View File

@ -9,14 +9,21 @@ public static class Extensions
{
public static IServiceCollection AddPersistMessageProcessor(this IServiceCollection services)
{
AppContext.SetSwitch("Npgsql.EnableLegacyTimestampBehavior", true);
services.AddValidateOptions<PersistMessageOptions>();
services.AddDbContext<PersistMessageDbContext>(options =>
services.AddDbContext<PersistMessageDbContext>((sp, options) =>
{
var persistMessageOptions = services.GetOptions<PersistMessageOptions>(nameof(PersistMessageOptions));
var persistMessageOptions = sp.GetRequiredService<PersistMessageOptions>();
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<IPersistMessageDbContext>(provider => provider.GetService<PersistMessageDbContext>());

View File

@ -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<TEntryPoint> : IAsyncLifetime
where TEntryPoint : class
@ -41,8 +40,8 @@ public class TestFixture<TEntryPoint> : IAsyncLifetime
private int Timeout => 120; // Second
private ITestHarness TestHarness => ServiceProvider?.GetTestHarness();
private Action<IServiceCollection> 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<TEntryPoint> : 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<TEntryPoint> : IAsyncLifetime
{
configuration.AddInMemoryCollection(new KeyValuePair<string, string>[]
{
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<TEntryPoint> : 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<TEntryPoint> 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<TEntryPoint> : 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<DatabaseOptions>();
var postgresOptions = Fixture.ServiceProvider.GetRequiredService<PostgresOptions>();
var persistOptions = Fixture.ServiceProvider.GetRequiredService<PersistMessageOptions>();
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<TEntryPoint> : 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<TEntryPoint, TRContext> : TestFixtureCore<TEn
where TRContext : MongoDbContext
{
protected TestReadBase(
TestReadFixture<TEntryPoint, TRContext> integrationTestFixture, ITestOutputHelper outputHelper = null) : base(integrationTestFixture, outputHelper)
TestReadFixture<TEntryPoint, TRContext> integrationTestFixture, ITestOutputHelper outputHelper = null) : base(
integrationTestFixture, outputHelper)
{
Fixture = integrationTestFixture;
}
@ -569,7 +570,8 @@ public abstract class TestWriteBase<TEntryPoint, TWContext> : TestFixtureCore<TE
where TWContext : DbContext
{
protected TestWriteBase(
TestWriteFixture<TEntryPoint, TWContext> integrationTestFixture, ITestOutputHelper outputHelper = null) : base(integrationTestFixture, outputHelper)
TestWriteFixture<TEntryPoint, TWContext> integrationTestFixture, ITestOutputHelper outputHelper = null) : base(
integrationTestFixture, outputHelper)
{
Fixture = integrationTestFixture;
}
@ -584,7 +586,8 @@ public abstract class TestBase<TEntryPoint, TWContext, TRContext> : TestFixtureC
where TRContext : MongoDbContext
{
protected TestBase(
TestFixture<TEntryPoint, TWContext, TRContext> integrationTestFixture, ITestOutputHelper outputHelper = null) : base(integrationTestFixture, outputHelper)
TestFixture<TEntryPoint, TWContext, TRContext> integrationTestFixture, ITestOutputHelper outputHelper = null) :
base(integrationTestFixture, outputHelper)
{
Fixture = integrationTestFixture;
}

View File

@ -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<MsSqlTestcontainer>()
.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<MsSqlTestcontainer>()
.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<PostgreSqlTestcontainer>()
.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();

View File

@ -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",

View File

@ -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": "*"
}

View File

@ -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"
}
}

View File

@ -17,7 +17,7 @@ public class FakeFlightResponse : AutoFaker<FlightResponse>
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);
}
}

View File

@ -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": "*"
}

View File

@ -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

View File

@ -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"
}
}

View File

@ -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<Aircraft>
{
public void Configure(EntityTypeBuilder<Aircraft> builder)
{
builder.ToTable("Aircraft", AppDbContextBase.DefaultSchema);
builder.ToTable("aircraft");
builder.HasKey(r => r.Id);
builder.Property(r => r.Id).ValueGeneratedNever();
}

View File

@ -9,7 +9,7 @@ public class AirportConfiguration: IEntityTypeConfiguration<Airport>
{
public void Configure(EntityTypeBuilder<Airport> builder)
{
builder.ToTable("Airport", AppDbContextBase.DefaultSchema);
builder.ToTable("airport");
builder.HasKey(r => r.Id);
builder.Property(r => r.Id).ValueGeneratedNever();

View File

@ -6,11 +6,13 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace Flight.Data.Configurations;
using System;
public class FlightConfiguration : IEntityTypeConfiguration<Flights.Models.Flight>
{
public void Configure(EntityTypeBuilder<Flights.Models.Flight> 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<Flights.Models.Fligh
.HasForeignKey(d => 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 =>

View File

@ -5,11 +5,13 @@ using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace Flight.Data.Configurations;
using System;
public class SeatConfiguration : IEntityTypeConfiguration<Seat>
{
public void Configure(EntityTypeBuilder<Seat> 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<Seat>
.HasOne<Flights.Models.Flight>()
.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));
}
}

View File

@ -9,7 +9,8 @@ namespace Flight.Data
{
var builder = new DbContextOptionsBuilder<FlightDbContext>();
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);
}
}

View File

@ -1,232 +0,0 @@
// <auto-generated />
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
{
/// <inheritdoc />
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<long>("Id")
.HasColumnType("bigint");
b.Property<DateTime?>("CreatedAt")
.HasColumnType("datetime2");
b.Property<long?>("CreatedBy")
.HasColumnType("bigint");
b.Property<bool>("IsDeleted")
.HasColumnType("bit");
b.Property<DateTime?>("LastModified")
.HasColumnType("datetime2");
b.Property<long?>("LastModifiedBy")
.HasColumnType("bigint");
b.Property<int>("ManufacturingYear")
.HasColumnType("int");
b.Property<string>("Model")
.HasColumnType("nvarchar(max)");
b.Property<string>("Name")
.HasColumnType("nvarchar(max)");
b.Property<long>("Version")
.HasColumnType("bigint");
b.HasKey("Id");
b.ToTable("Aircraft", "dbo");
});
modelBuilder.Entity("Flight.Airports.Models.Airport", b =>
{
b.Property<long>("Id")
.HasColumnType("bigint");
b.Property<string>("Address")
.HasColumnType("nvarchar(max)");
b.Property<string>("Code")
.HasColumnType("nvarchar(max)");
b.Property<DateTime?>("CreatedAt")
.HasColumnType("datetime2");
b.Property<long?>("CreatedBy")
.HasColumnType("bigint");
b.Property<bool>("IsDeleted")
.HasColumnType("bit");
b.Property<DateTime?>("LastModified")
.HasColumnType("datetime2");
b.Property<long?>("LastModifiedBy")
.HasColumnType("bigint");
b.Property<string>("Name")
.HasColumnType("nvarchar(max)");
b.Property<long>("Version")
.HasColumnType("bigint");
b.HasKey("Id");
b.ToTable("Airport", "dbo");
});
modelBuilder.Entity("Flight.Flights.Models.Flight", b =>
{
b.Property<long>("Id")
.HasColumnType("bigint");
b.Property<long>("AircraftId")
.HasColumnType("bigint");
b.Property<long>("ArriveAirportId")
.HasColumnType("bigint");
b.Property<DateTime>("ArriveDate")
.HasColumnType("datetime2");
b.Property<DateTime?>("CreatedAt")
.HasColumnType("datetime2");
b.Property<long?>("CreatedBy")
.HasColumnType("bigint");
b.Property<long>("DepartureAirportId")
.HasColumnType("bigint");
b.Property<DateTime>("DepartureDate")
.HasColumnType("datetime2");
b.Property<decimal>("DurationMinutes")
.HasColumnType("decimal(18,2)");
b.Property<DateTime>("FlightDate")
.HasColumnType("datetime2");
b.Property<string>("FlightNumber")
.HasColumnType("nvarchar(max)");
b.Property<bool>("IsDeleted")
.HasColumnType("bit");
b.Property<DateTime?>("LastModified")
.HasColumnType("datetime2");
b.Property<long?>("LastModifiedBy")
.HasColumnType("bigint");
b.Property<decimal>("Price")
.HasColumnType("decimal(18,2)");
b.Property<int>("Status")
.HasColumnType("int");
b.Property<long>("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<long>("Id")
.HasColumnType("bigint");
b.Property<int>("Class")
.HasColumnType("int");
b.Property<DateTime?>("CreatedAt")
.HasColumnType("datetime2");
b.Property<long?>("CreatedBy")
.HasColumnType("bigint");
b.Property<long>("FlightId")
.HasColumnType("bigint");
b.Property<bool>("IsDeleted")
.HasColumnType("bit");
b.Property<DateTime?>("LastModified")
.HasColumnType("datetime2");
b.Property<long?>("LastModifiedBy")
.HasColumnType("bigint");
b.Property<string>("SeatNumber")
.HasColumnType("nvarchar(max)");
b.Property<int>("Type")
.HasColumnType("int");
b.Property<long>("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
}
}
}

View File

@ -1,169 +0,0 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Flight.Data.Migrations
{
/// <inheritdoc />
public partial class Initial : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.EnsureSchema(
name: "dbo");
migrationBuilder.CreateTable(
name: "Aircraft",
schema: "dbo",
columns: table => new
{
Id = table.Column<long>(type: "bigint", nullable: false),
Name = table.Column<string>(type: "nvarchar(max)", nullable: true),
Model = table.Column<string>(type: "nvarchar(max)", nullable: true),
ManufacturingYear = table.Column<int>(type: "int", nullable: false),
CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: true),
CreatedBy = table.Column<long>(type: "bigint", nullable: true),
LastModified = table.Column<DateTime>(type: "datetime2", nullable: true),
LastModifiedBy = table.Column<long>(type: "bigint", nullable: true),
IsDeleted = table.Column<bool>(type: "bit", nullable: false),
Version = table.Column<long>(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<long>(type: "bigint", nullable: false),
Name = table.Column<string>(type: "nvarchar(max)", nullable: true),
Address = table.Column<string>(type: "nvarchar(max)", nullable: true),
Code = table.Column<string>(type: "nvarchar(max)", nullable: true),
CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: true),
CreatedBy = table.Column<long>(type: "bigint", nullable: true),
LastModified = table.Column<DateTime>(type: "datetime2", nullable: true),
LastModifiedBy = table.Column<long>(type: "bigint", nullable: true),
IsDeleted = table.Column<bool>(type: "bit", nullable: false),
Version = table.Column<long>(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<long>(type: "bigint", nullable: false),
FlightNumber = table.Column<string>(type: "nvarchar(max)", nullable: true),
AircraftId = table.Column<long>(type: "bigint", nullable: false),
DepartureDate = table.Column<DateTime>(type: "datetime2", nullable: false),
DepartureAirportId = table.Column<long>(type: "bigint", nullable: false),
ArriveDate = table.Column<DateTime>(type: "datetime2", nullable: false),
ArriveAirportId = table.Column<long>(type: "bigint", nullable: false),
DurationMinutes = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
FlightDate = table.Column<DateTime>(type: "datetime2", nullable: false),
Status = table.Column<int>(type: "int", nullable: false),
Price = table.Column<decimal>(type: "decimal(18,2)", nullable: false),
CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: true),
CreatedBy = table.Column<long>(type: "bigint", nullable: true),
LastModified = table.Column<DateTime>(type: "datetime2", nullable: true),
LastModifiedBy = table.Column<long>(type: "bigint", nullable: true),
IsDeleted = table.Column<bool>(type: "bit", nullable: false),
Version = table.Column<long>(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<long>(type: "bigint", nullable: false),
SeatNumber = table.Column<string>(type: "nvarchar(max)", nullable: true),
Type = table.Column<int>(type: "int", nullable: false),
Class = table.Column<int>(type: "int", nullable: false),
FlightId = table.Column<long>(type: "bigint", nullable: false),
CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: true),
CreatedBy = table.Column<long>(type: "bigint", nullable: true),
LastModified = table.Column<DateTime>(type: "datetime2", nullable: true),
LastModifiedBy = table.Column<long>(type: "bigint", nullable: true),
IsDeleted = table.Column<bool>(type: "bit", nullable: false),
Version = table.Column<long>(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");
}
/// <inheritdoc />
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");
}
}
}

View File

@ -0,0 +1,299 @@
// <auto-generated />
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
{
/// <inheritdoc />
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<long>("Id")
.HasColumnType("bigint")
.HasColumnName("id");
b.Property<DateTime?>("CreatedAt")
.HasColumnType("timestamp with time zone")
.HasColumnName("created_at");
b.Property<long?>("CreatedBy")
.HasColumnType("bigint")
.HasColumnName("created_by");
b.Property<bool>("IsDeleted")
.HasColumnType("boolean")
.HasColumnName("is_deleted");
b.Property<DateTime?>("LastModified")
.HasColumnType("timestamp with time zone")
.HasColumnName("last_modified");
b.Property<long?>("LastModifiedBy")
.HasColumnType("bigint")
.HasColumnName("last_modified_by");
b.Property<int>("ManufacturingYear")
.HasColumnType("integer")
.HasColumnName("manufacturing_year");
b.Property<string>("Model")
.HasColumnType("text")
.HasColumnName("model");
b.Property<string>("Name")
.HasColumnType("text")
.HasColumnName("name");
b.Property<long>("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<long>("Id")
.HasColumnType("bigint")
.HasColumnName("id");
b.Property<string>("Address")
.HasColumnType("text")
.HasColumnName("address");
b.Property<string>("Code")
.HasColumnType("text")
.HasColumnName("code");
b.Property<DateTime?>("CreatedAt")
.HasColumnType("timestamp with time zone")
.HasColumnName("created_at");
b.Property<long?>("CreatedBy")
.HasColumnType("bigint")
.HasColumnName("created_by");
b.Property<bool>("IsDeleted")
.HasColumnType("boolean")
.HasColumnName("is_deleted");
b.Property<DateTime?>("LastModified")
.HasColumnType("timestamp with time zone")
.HasColumnName("last_modified");
b.Property<long?>("LastModifiedBy")
.HasColumnType("bigint")
.HasColumnName("last_modified_by");
b.Property<string>("Name")
.HasColumnType("text")
.HasColumnName("name");
b.Property<long>("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<long>("Id")
.HasColumnType("bigint")
.HasColumnName("id");
b.Property<long>("AircraftId")
.HasColumnType("bigint")
.HasColumnName("aircraft_id");
b.Property<long>("ArriveAirportId")
.HasColumnType("bigint")
.HasColumnName("arrive_airport_id");
b.Property<DateTime>("ArriveDate")
.HasColumnType("timestamp with time zone")
.HasColumnName("arrive_date");
b.Property<DateTime?>("CreatedAt")
.HasColumnType("timestamp with time zone")
.HasColumnName("created_at");
b.Property<long?>("CreatedBy")
.HasColumnType("bigint")
.HasColumnName("created_by");
b.Property<long>("DepartureAirportId")
.HasColumnType("bigint")
.HasColumnName("departure_airport_id");
b.Property<DateTime>("DepartureDate")
.HasColumnType("timestamp with time zone")
.HasColumnName("departure_date");
b.Property<decimal>("DurationMinutes")
.HasColumnType("numeric")
.HasColumnName("duration_minutes");
b.Property<DateTime>("FlightDate")
.HasColumnType("timestamp with time zone")
.HasColumnName("flight_date");
b.Property<string>("FlightNumber")
.HasColumnType("text")
.HasColumnName("flight_number");
b.Property<bool>("IsDeleted")
.HasColumnType("boolean")
.HasColumnName("is_deleted");
b.Property<DateTime?>("LastModified")
.HasColumnType("timestamp with time zone")
.HasColumnName("last_modified");
b.Property<long?>("LastModifiedBy")
.HasColumnType("bigint")
.HasColumnName("last_modified_by");
b.Property<decimal>("Price")
.HasColumnType("numeric")
.HasColumnName("price");
b.Property<string>("Status")
.IsRequired()
.ValueGeneratedOnAdd()
.HasColumnType("text")
.HasDefaultValue("Unknown")
.HasColumnName("status");
b.Property<long>("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<long>("Id")
.HasColumnType("bigint")
.HasColumnName("id");
b.Property<string>("Class")
.IsRequired()
.ValueGeneratedOnAdd()
.HasColumnType("text")
.HasDefaultValue("Unknown")
.HasColumnName("class");
b.Property<DateTime?>("CreatedAt")
.HasColumnType("timestamp with time zone")
.HasColumnName("created_at");
b.Property<long?>("CreatedBy")
.HasColumnType("bigint")
.HasColumnName("created_by");
b.Property<long>("FlightId")
.HasColumnType("bigint")
.HasColumnName("flight_id");
b.Property<bool>("IsDeleted")
.HasColumnType("boolean")
.HasColumnName("is_deleted");
b.Property<DateTime?>("LastModified")
.HasColumnType("timestamp with time zone")
.HasColumnName("last_modified");
b.Property<long?>("LastModifiedBy")
.HasColumnType("bigint")
.HasColumnName("last_modified_by");
b.Property<string>("SeatNumber")
.HasColumnType("text")
.HasColumnName("seat_number");
b.Property<string>("Type")
.IsRequired()
.ValueGeneratedOnAdd()
.HasColumnType("text")
.HasDefaultValue("Unknown")
.HasColumnName("type");
b.Property<long>("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
}
}
}

View File

@ -0,0 +1,152 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Flight.Data.Migrations
{
/// <inheritdoc />
public partial class Init : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "aircraft",
columns: table => new
{
id = table.Column<long>(type: "bigint", nullable: false),
name = table.Column<string>(type: "text", nullable: true),
model = table.Column<string>(type: "text", nullable: true),
manufacturingyear = table.Column<int>(name: "manufacturing_year", type: "integer", nullable: false),
createdat = table.Column<DateTime>(name: "created_at", type: "timestamp with time zone", nullable: true),
createdby = table.Column<long>(name: "created_by", type: "bigint", nullable: true),
lastmodified = table.Column<DateTime>(name: "last_modified", type: "timestamp with time zone", nullable: true),
lastmodifiedby = table.Column<long>(name: "last_modified_by", type: "bigint", nullable: true),
isdeleted = table.Column<bool>(name: "is_deleted", type: "boolean", nullable: false),
version = table.Column<long>(type: "bigint", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("pk_aircraft", x => x.id);
});
migrationBuilder.CreateTable(
name: "airport",
columns: table => new
{
id = table.Column<long>(type: "bigint", nullable: false),
name = table.Column<string>(type: "text", nullable: true),
address = table.Column<string>(type: "text", nullable: true),
code = table.Column<string>(type: "text", nullable: true),
createdat = table.Column<DateTime>(name: "created_at", type: "timestamp with time zone", nullable: true),
createdby = table.Column<long>(name: "created_by", type: "bigint", nullable: true),
lastmodified = table.Column<DateTime>(name: "last_modified", type: "timestamp with time zone", nullable: true),
lastmodifiedby = table.Column<long>(name: "last_modified_by", type: "bigint", nullable: true),
isdeleted = table.Column<bool>(name: "is_deleted", type: "boolean", nullable: false),
version = table.Column<long>(type: "bigint", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("pk_airport", x => x.id);
});
migrationBuilder.CreateTable(
name: "flight",
columns: table => new
{
id = table.Column<long>(type: "bigint", nullable: false),
flightnumber = table.Column<string>(name: "flight_number", type: "text", nullable: true),
aircraftid = table.Column<long>(name: "aircraft_id", type: "bigint", nullable: false),
departuredate = table.Column<DateTime>(name: "departure_date", type: "timestamp with time zone", nullable: false),
departureairportid = table.Column<long>(name: "departure_airport_id", type: "bigint", nullable: false),
arrivedate = table.Column<DateTime>(name: "arrive_date", type: "timestamp with time zone", nullable: false),
arriveairportid = table.Column<long>(name: "arrive_airport_id", type: "bigint", nullable: false),
durationminutes = table.Column<decimal>(name: "duration_minutes", type: "numeric", nullable: false),
flightdate = table.Column<DateTime>(name: "flight_date", type: "timestamp with time zone", nullable: false),
status = table.Column<string>(type: "text", nullable: false, defaultValue: "Unknown"),
price = table.Column<decimal>(type: "numeric", nullable: false),
createdat = table.Column<DateTime>(name: "created_at", type: "timestamp with time zone", nullable: true),
createdby = table.Column<long>(name: "created_by", type: "bigint", nullable: true),
lastmodified = table.Column<DateTime>(name: "last_modified", type: "timestamp with time zone", nullable: true),
lastmodifiedby = table.Column<long>(name: "last_modified_by", type: "bigint", nullable: true),
isdeleted = table.Column<bool>(name: "is_deleted", type: "boolean", nullable: false),
version = table.Column<long>(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<long>(type: "bigint", nullable: false),
seatnumber = table.Column<string>(name: "seat_number", type: "text", nullable: true),
type = table.Column<string>(type: "text", nullable: false, defaultValue: "Unknown"),
@class = table.Column<string>(name: "class", type: "text", nullable: false, defaultValue: "Unknown"),
flightid = table.Column<long>(name: "flight_id", type: "bigint", nullable: false),
createdat = table.Column<DateTime>(name: "created_at", type: "timestamp with time zone", nullable: true),
createdby = table.Column<long>(name: "created_by", type: "bigint", nullable: true),
lastmodified = table.Column<DateTime>(name: "last_modified", type: "timestamp with time zone", nullable: true),
lastmodifiedby = table.Column<long>(name: "last_modified_by", type: "bigint", nullable: true),
isdeleted = table.Column<bool>(name: "is_deleted", type: "boolean", nullable: false),
version = table.Column<long>(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");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "seat");
migrationBuilder.DropTable(
name: "flight");
migrationBuilder.DropTable(
name: "aircraft");
migrationBuilder.DropTable(
name: "airport");
}
}
}

View File

@ -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<long>("Id")
.HasColumnType("bigint");
.HasColumnType("bigint")
.HasColumnName("id");
b.Property<DateTime?>("CreatedAt")
.HasColumnType("datetime2");
.HasColumnType("timestamp with time zone")
.HasColumnName("created_at");
b.Property<long?>("CreatedBy")
.HasColumnType("bigint");
.HasColumnType("bigint")
.HasColumnName("created_by");
b.Property<bool>("IsDeleted")
.HasColumnType("bit");
.HasColumnType("boolean")
.HasColumnName("is_deleted");
b.Property<DateTime?>("LastModified")
.HasColumnType("datetime2");
.HasColumnType("timestamp with time zone")
.HasColumnName("last_modified");
b.Property<long?>("LastModifiedBy")
.HasColumnType("bigint");
.HasColumnType("bigint")
.HasColumnName("last_modified_by");
b.Property<int>("ManufacturingYear")
.HasColumnType("int");
.HasColumnType("integer")
.HasColumnName("manufacturing_year");
b.Property<string>("Model")
.HasColumnType("nvarchar(max)");
.HasColumnType("text")
.HasColumnName("model");
b.Property<string>("Name")
.HasColumnType("nvarchar(max)");
.HasColumnType("text")
.HasColumnName("name");
b.Property<long>("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<long>("Id")
.HasColumnType("bigint");
.HasColumnType("bigint")
.HasColumnName("id");
b.Property<string>("Address")
.HasColumnType("nvarchar(max)");
.HasColumnType("text")
.HasColumnName("address");
b.Property<string>("Code")
.HasColumnType("nvarchar(max)");
.HasColumnType("text")
.HasColumnName("code");
b.Property<DateTime?>("CreatedAt")
.HasColumnType("datetime2");
.HasColumnType("timestamp with time zone")
.HasColumnName("created_at");
b.Property<long?>("CreatedBy")
.HasColumnType("bigint");
.HasColumnType("bigint")
.HasColumnName("created_by");
b.Property<bool>("IsDeleted")
.HasColumnType("bit");
.HasColumnType("boolean")
.HasColumnName("is_deleted");
b.Property<DateTime?>("LastModified")
.HasColumnType("datetime2");
.HasColumnType("timestamp with time zone")
.HasColumnName("last_modified");
b.Property<long?>("LastModifiedBy")
.HasColumnType("bigint");
.HasColumnType("bigint")
.HasColumnName("last_modified_by");
b.Property<string>("Name")
.HasColumnType("nvarchar(max)");
.HasColumnType("text")
.HasColumnName("name");
b.Property<long>("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<long>("Id")
.HasColumnType("bigint");
.HasColumnType("bigint")
.HasColumnName("id");
b.Property<long>("AircraftId")
.HasColumnType("bigint");
.HasColumnType("bigint")
.HasColumnName("aircraft_id");
b.Property<long>("ArriveAirportId")
.HasColumnType("bigint");
.HasColumnType("bigint")
.HasColumnName("arrive_airport_id");
b.Property<DateTime>("ArriveDate")
.HasColumnType("datetime2");
.HasColumnType("timestamp with time zone")
.HasColumnName("arrive_date");
b.Property<DateTime?>("CreatedAt")
.HasColumnType("datetime2");
.HasColumnType("timestamp with time zone")
.HasColumnName("created_at");
b.Property<long?>("CreatedBy")
.HasColumnType("bigint");
.HasColumnType("bigint")
.HasColumnName("created_by");
b.Property<long>("DepartureAirportId")
.HasColumnType("bigint");
.HasColumnType("bigint")
.HasColumnName("departure_airport_id");
b.Property<DateTime>("DepartureDate")
.HasColumnType("datetime2");
.HasColumnType("timestamp with time zone")
.HasColumnName("departure_date");
b.Property<decimal>("DurationMinutes")
.HasColumnType("decimal(18,2)");
.HasColumnType("numeric")
.HasColumnName("duration_minutes");
b.Property<DateTime>("FlightDate")
.HasColumnType("datetime2");
.HasColumnType("timestamp with time zone")
.HasColumnName("flight_date");
b.Property<string>("FlightNumber")
.HasColumnType("nvarchar(max)");
.HasColumnType("text")
.HasColumnName("flight_number");
b.Property<bool>("IsDeleted")
.HasColumnType("bit");
.HasColumnType("boolean")
.HasColumnName("is_deleted");
b.Property<DateTime?>("LastModified")
.HasColumnType("datetime2");
.HasColumnType("timestamp with time zone")
.HasColumnName("last_modified");
b.Property<long?>("LastModifiedBy")
.HasColumnType("bigint");
.HasColumnType("bigint")
.HasColumnName("last_modified_by");
b.Property<decimal>("Price")
.HasColumnType("decimal(18,2)");
.HasColumnType("numeric")
.HasColumnName("price");
b.Property<int>("Status")
.HasColumnType("int");
b.Property<string>("Status")
.IsRequired()
.ValueGeneratedOnAdd()
.HasColumnType("text")
.HasDefaultValue("Unknown")
.HasColumnName("status");
b.Property<long>("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<long>("Id")
.HasColumnType("bigint");
.HasColumnType("bigint")
.HasColumnName("id");
b.Property<int>("Class")
.HasColumnType("int");
b.Property<string>("Class")
.IsRequired()
.ValueGeneratedOnAdd()
.HasColumnType("text")
.HasDefaultValue("Unknown")
.HasColumnName("class");
b.Property<DateTime?>("CreatedAt")
.HasColumnType("datetime2");
.HasColumnType("timestamp with time zone")
.HasColumnName("created_at");
b.Property<long?>("CreatedBy")
.HasColumnType("bigint");
.HasColumnType("bigint")
.HasColumnName("created_by");
b.Property<long>("FlightId")
.HasColumnType("bigint");
.HasColumnType("bigint")
.HasColumnName("flight_id");
b.Property<bool>("IsDeleted")
.HasColumnType("bit");
.HasColumnType("boolean")
.HasColumnName("is_deleted");
b.Property<DateTime?>("LastModified")
.HasColumnType("datetime2");
.HasColumnType("timestamp with time zone")
.HasColumnName("last_modified");
b.Property<long?>("LastModifiedBy")
.HasColumnType("bigint");
.HasColumnType("bigint")
.HasColumnName("last_modified_by");
b.Property<string>("SeatNumber")
.HasColumnType("nvarchar(max)");
.HasColumnType("text")
.HasColumnName("seat_number");
b.Property<int>("Type")
.HasColumnType("int");
b.Property<string>("Type")
.IsRequired()
.ValueGeneratedOnAdd()
.HasColumnType("text")
.HasDefaultValue("Unknown")
.HasColumnName("type");
b.Property<long>("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
}

View File

@ -10,7 +10,7 @@ public sealed class FakeCreateFlightCommand : AutoFaker<CreateFlightCommand>
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);

View File

@ -10,7 +10,7 @@ public sealed class FakeCreateFlightCommand : AutoFaker<CreateFlightCommand>
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);

View File

@ -12,7 +12,7 @@ public class FakeUpdateFlightCommand : AutoFaker<UpdateFlightCommand>
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);

View File

@ -10,7 +10,7 @@ public sealed class FakeCreateFlightCommand : AutoFaker<CreateFlightCommand>
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);

View File

@ -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",

View File

@ -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": "*"
}

View File

@ -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"
}
}

View File

@ -9,7 +9,8 @@ public class DesignTimeDbContextFactory : IDesignTimeDbContextFactory<IdentityCo
{
var builder = new DbContextOptionsBuilder<IdentityContext>();
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);
}
}

View File

@ -38,8 +38,26 @@ public sealed class IdentityContext : IdentityDbContext<ApplicationUser, Identit
// https://andrewlock.net/customising-asp-net-core-identity-ef-core-naming-conventions-for-postgresql/
foreach (var entity in builder.Model.GetEntityTypes())
{
// Replace schema
entity.SetSchema(AppDbContextBase.DefaultSchema);
// Replace table names
entity.SetTableName(entity.GetTableName()?.Underscore());
var identityObjectIdentifier = StoreObjectIdentifier.Table(entity.GetTableName()?.Underscore()!, entity.GetSchema());
// Replace column names
foreach (var property in entity.GetProperties())
{
property.SetColumnName(property.GetColumnName(identityObjectIdentifier)?.Underscore());
}
foreach (var key in entity.GetKeys())
{
key.SetName(key.GetName()?.Underscore());
}
foreach (var key in entity.GetForeignKeys())
{
key.SetConstraintName(key.GetConstraintName()?.Underscore());
}
}
builder.FilterSoftDeletedProperties();

View File

@ -1,291 +0,0 @@
// <auto-generated />
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
{
/// <inheritdoc />
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<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("bigint");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<long>("Id"));
b.Property<int>("AccessFailedCount")
.HasColumnType("int");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("nvarchar(max)");
b.Property<string>("Email")
.HasMaxLength(256)
.HasColumnType("nvarchar(256)");
b.Property<bool>("EmailConfirmed")
.HasColumnType("bit");
b.Property<string>("FirstName")
.HasColumnType("nvarchar(max)");
b.Property<string>("LastName")
.HasColumnType("nvarchar(max)");
b.Property<bool>("LockoutEnabled")
.HasColumnType("bit");
b.Property<DateTimeOffset?>("LockoutEnd")
.HasColumnType("datetimeoffset");
b.Property<string>("NormalizedEmail")
.HasMaxLength(256)
.HasColumnType("nvarchar(256)");
b.Property<string>("NormalizedUserName")
.HasMaxLength(256)
.HasColumnType("nvarchar(256)");
b.Property<string>("PassPortNumber")
.HasColumnType("nvarchar(max)");
b.Property<string>("PasswordHash")
.HasColumnType("nvarchar(max)");
b.Property<string>("PhoneNumber")
.HasColumnType("nvarchar(max)");
b.Property<bool>("PhoneNumberConfirmed")
.HasColumnType("bit");
b.Property<string>("SecurityStamp")
.HasColumnType("nvarchar(max)");
b.Property<bool>("TwoFactorEnabled")
.HasColumnType("bit");
b.Property<string>("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<long>", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("bigint");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<long>("Id"));
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("nvarchar(max)");
b.Property<string>("Name")
.HasMaxLength(256)
.HasColumnType("nvarchar(256)");
b.Property<string>("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<long>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("ClaimType")
.HasColumnType("nvarchar(max)");
b.Property<string>("ClaimValue")
.HasColumnType("nvarchar(max)");
b.Property<long>("RoleId")
.HasColumnType("bigint");
b.HasKey("Id");
b.HasIndex("RoleId");
b.ToTable("AspNetRoleClaims", "dbo");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<long>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
b.Property<string>("ClaimType")
.HasColumnType("nvarchar(max)");
b.Property<string>("ClaimValue")
.HasColumnType("nvarchar(max)");
b.Property<long>("UserId")
.HasColumnType("bigint");
b.HasKey("Id");
b.HasIndex("UserId");
b.ToTable("AspNetUserClaims", "dbo");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<long>", b =>
{
b.Property<string>("LoginProvider")
.HasColumnType("nvarchar(450)");
b.Property<string>("ProviderKey")
.HasColumnType("nvarchar(450)");
b.Property<string>("ProviderDisplayName")
.HasColumnType("nvarchar(max)");
b.Property<long>("UserId")
.HasColumnType("bigint");
b.HasKey("LoginProvider", "ProviderKey");
b.HasIndex("UserId");
b.ToTable("AspNetUserLogins", "dbo");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<long>", b =>
{
b.Property<long>("UserId")
.HasColumnType("bigint");
b.Property<long>("RoleId")
.HasColumnType("bigint");
b.HasKey("UserId", "RoleId");
b.HasIndex("RoleId");
b.ToTable("AspNetUserRoles", "dbo");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<long>", b =>
{
b.Property<long>("UserId")
.HasColumnType("bigint");
b.Property<string>("LoginProvider")
.HasColumnType("nvarchar(450)");
b.Property<string>("Name")
.HasColumnType("nvarchar(450)");
b.Property<string>("Value")
.HasColumnType("nvarchar(max)");
b.HasKey("UserId", "LoginProvider", "Name");
b.ToTable("AspNetUserTokens", "dbo");
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<long>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole<long>", null)
.WithMany()
.HasForeignKey("RoleId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<long>", b =>
{
b.HasOne("Identity.Identity.Models.ApplicationUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<long>", b =>
{
b.HasOne("Identity.Identity.Models.ApplicationUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<long>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole<long>", 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<long>", b =>
{
b.HasOne("Identity.Identity.Models.ApplicationUser", null)
.WithMany()
.HasForeignKey("UserId")
.OnDelete(DeleteBehavior.Cascade)
.IsRequired();
});
#pragma warning restore 612, 618
}
}
}

View File

@ -1,259 +0,0 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Identity.Data.Migrations
{
/// <inheritdoc />
public partial class initial : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.EnsureSchema(
name: "dbo");
migrationBuilder.CreateTable(
name: "AspNetRoles",
schema: "dbo",
columns: table => new
{
Id = table.Column<long>(type: "bigint", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
Name = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: true),
NormalizedName = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: true),
ConcurrencyStamp = table.Column<string>(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<long>(type: "bigint", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
FirstName = table.Column<string>(type: "nvarchar(max)", nullable: true),
LastName = table.Column<string>(type: "nvarchar(max)", nullable: true),
PassPortNumber = table.Column<string>(type: "nvarchar(max)", nullable: true),
UserName = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: true),
NormalizedUserName = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: true),
Email = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: true),
NormalizedEmail = table.Column<string>(type: "nvarchar(256)", maxLength: 256, nullable: true),
EmailConfirmed = table.Column<bool>(type: "bit", nullable: false),
PasswordHash = table.Column<string>(type: "nvarchar(max)", nullable: true),
SecurityStamp = table.Column<string>(type: "nvarchar(max)", nullable: true),
ConcurrencyStamp = table.Column<string>(type: "nvarchar(max)", nullable: true),
PhoneNumber = table.Column<string>(type: "nvarchar(max)", nullable: true),
PhoneNumberConfirmed = table.Column<bool>(type: "bit", nullable: false),
TwoFactorEnabled = table.Column<bool>(type: "bit", nullable: false),
LockoutEnd = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: true),
LockoutEnabled = table.Column<bool>(type: "bit", nullable: false),
AccessFailedCount = table.Column<int>(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<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
RoleId = table.Column<long>(type: "bigint", nullable: false),
ClaimType = table.Column<string>(type: "nvarchar(max)", nullable: true),
ClaimValue = table.Column<string>(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<int>(type: "int", nullable: false)
.Annotation("SqlServer:Identity", "1, 1"),
UserId = table.Column<long>(type: "bigint", nullable: false),
ClaimType = table.Column<string>(type: "nvarchar(max)", nullable: true),
ClaimValue = table.Column<string>(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<string>(type: "nvarchar(450)", nullable: false),
ProviderKey = table.Column<string>(type: "nvarchar(450)", nullable: false),
ProviderDisplayName = table.Column<string>(type: "nvarchar(max)", nullable: true),
UserId = table.Column<long>(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<long>(type: "bigint", nullable: false),
RoleId = table.Column<long>(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<long>(type: "bigint", nullable: false),
LoginProvider = table.Column<string>(type: "nvarchar(450)", nullable: false),
Name = table.Column<string>(type: "nvarchar(450)", nullable: false),
Value = table.Column<string>(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");
}
/// <inheritdoc />
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");
}
}
}

View File

@ -0,0 +1,346 @@
// <auto-generated />
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
{
/// <inheritdoc />
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<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("bigint")
.HasColumnName("id");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<long>("Id"));
b.Property<int>("AccessFailedCount")
.HasColumnType("integer")
.HasColumnName("access_failed_count");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("text")
.HasColumnName("concurrency_stamp");
b.Property<string>("Email")
.HasMaxLength(256)
.HasColumnType("character varying(256)")
.HasColumnName("email");
b.Property<bool>("EmailConfirmed")
.HasColumnType("boolean")
.HasColumnName("email_confirmed");
b.Property<string>("FirstName")
.HasColumnType("text")
.HasColumnName("first_name");
b.Property<string>("LastName")
.HasColumnType("text")
.HasColumnName("last_name");
b.Property<bool>("LockoutEnabled")
.HasColumnType("boolean")
.HasColumnName("lockout_enabled");
b.Property<DateTimeOffset?>("LockoutEnd")
.HasColumnType("timestamp with time zone")
.HasColumnName("lockout_end");
b.Property<string>("NormalizedEmail")
.HasMaxLength(256)
.HasColumnType("character varying(256)")
.HasColumnName("normalized_email");
b.Property<string>("NormalizedUserName")
.HasMaxLength(256)
.HasColumnType("character varying(256)")
.HasColumnName("normalized_user_name");
b.Property<string>("PassPortNumber")
.HasColumnType("text")
.HasColumnName("pass_port_number");
b.Property<string>("PasswordHash")
.HasColumnType("text")
.HasColumnName("password_hash");
b.Property<string>("PhoneNumber")
.HasColumnType("text")
.HasColumnName("phone_number");
b.Property<bool>("PhoneNumberConfirmed")
.HasColumnType("boolean")
.HasColumnName("phone_number_confirmed");
b.Property<string>("SecurityStamp")
.HasColumnType("text")
.HasColumnName("security_stamp");
b.Property<bool>("TwoFactorEnabled")
.HasColumnType("boolean")
.HasColumnName("two_factor_enabled");
b.Property<string>("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<long>", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("bigint")
.HasColumnName("id");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<long>("Id"));
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("text")
.HasColumnName("concurrency_stamp");
b.Property<string>("Name")
.HasMaxLength(256)
.HasColumnType("character varying(256)")
.HasColumnName("name");
b.Property<string>("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<long>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasColumnName("id");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ClaimType")
.HasColumnType("text")
.HasColumnName("claim_type");
b.Property<string>("ClaimValue")
.HasColumnType("text")
.HasColumnName("claim_value");
b.Property<long>("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<long>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("integer")
.HasColumnName("id");
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ClaimType")
.HasColumnType("text")
.HasColumnName("claim_type");
b.Property<string>("ClaimValue")
.HasColumnType("text")
.HasColumnName("claim_value");
b.Property<long>("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<long>", b =>
{
b.Property<string>("LoginProvider")
.HasColumnType("text")
.HasColumnName("login_provider");
b.Property<string>("ProviderKey")
.HasColumnType("text")
.HasColumnName("provider_key");
b.Property<string>("ProviderDisplayName")
.HasColumnType("text")
.HasColumnName("provider_display_name");
b.Property<long>("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<long>", b =>
{
b.Property<long>("UserId")
.HasColumnType("bigint")
.HasColumnName("user_id");
b.Property<long>("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<long>", b =>
{
b.Property<long>("UserId")
.HasColumnType("bigint")
.HasColumnName("user_id");
b.Property<string>("LoginProvider")
.HasColumnType("text")
.HasColumnName("login_provider");
b.Property<string>("Name")
.HasColumnType("text")
.HasColumnName("name");
b.Property<string>("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<long>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole<long>", 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<long>", 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<long>", 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<long>", b =>
{
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole<long>", 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<long>", 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
}
}
}

View File

@ -0,0 +1,228 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace Identity.Data.Migrations
{
/// <inheritdoc />
public partial class initial : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "asp_net_roles",
columns: table => new
{
id = table.Column<long>(type: "bigint", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
name = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: true),
normalizedname = table.Column<string>(name: "normalized_name", type: "character varying(256)", maxLength: 256, nullable: true),
concurrencystamp = table.Column<string>(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<long>(type: "bigint", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
firstname = table.Column<string>(name: "first_name", type: "text", nullable: true),
lastname = table.Column<string>(name: "last_name", type: "text", nullable: true),
passportnumber = table.Column<string>(name: "pass_port_number", type: "text", nullable: true),
username = table.Column<string>(name: "user_name", type: "character varying(256)", maxLength: 256, nullable: true),
normalizedusername = table.Column<string>(name: "normalized_user_name", type: "character varying(256)", maxLength: 256, nullable: true),
email = table.Column<string>(type: "character varying(256)", maxLength: 256, nullable: true),
normalizedemail = table.Column<string>(name: "normalized_email", type: "character varying(256)", maxLength: 256, nullable: true),
emailconfirmed = table.Column<bool>(name: "email_confirmed", type: "boolean", nullable: false),
passwordhash = table.Column<string>(name: "password_hash", type: "text", nullable: true),
securitystamp = table.Column<string>(name: "security_stamp", type: "text", nullable: true),
concurrencystamp = table.Column<string>(name: "concurrency_stamp", type: "text", nullable: true),
phonenumber = table.Column<string>(name: "phone_number", type: "text", nullable: true),
phonenumberconfirmed = table.Column<bool>(name: "phone_number_confirmed", type: "boolean", nullable: false),
twofactorenabled = table.Column<bool>(name: "two_factor_enabled", type: "boolean", nullable: false),
lockoutend = table.Column<DateTimeOffset>(name: "lockout_end", type: "timestamp with time zone", nullable: true),
lockoutenabled = table.Column<bool>(name: "lockout_enabled", type: "boolean", nullable: false),
accessfailedcount = table.Column<int>(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<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
roleid = table.Column<long>(name: "role_id", type: "bigint", nullable: false),
claimtype = table.Column<string>(name: "claim_type", type: "text", nullable: true),
claimvalue = table.Column<string>(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<int>(type: "integer", nullable: false)
.Annotation("Npgsql:ValueGenerationStrategy", NpgsqlValueGenerationStrategy.IdentityByDefaultColumn),
userid = table.Column<long>(name: "user_id", type: "bigint", nullable: false),
claimtype = table.Column<string>(name: "claim_type", type: "text", nullable: true),
claimvalue = table.Column<string>(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<string>(name: "login_provider", type: "text", nullable: false),
providerkey = table.Column<string>(name: "provider_key", type: "text", nullable: false),
providerdisplayname = table.Column<string>(name: "provider_display_name", type: "text", nullable: true),
userid = table.Column<long>(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<long>(name: "user_id", type: "bigint", nullable: false),
roleid = table.Column<long>(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<long>(name: "user_id", type: "bigint", nullable: false),
loginprovider = table.Column<string>(name: "login_provider", type: "text", nullable: false),
name = table.Column<string>(type: "text", nullable: false),
value = table.Column<string>(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);
}
/// <inheritdoc />
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");
}
}
}

View File

@ -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<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("bigint");
.HasColumnType("bigint")
.HasColumnName("id");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<long>("Id"));
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<long>("Id"));
b.Property<int>("AccessFailedCount")
.HasColumnType("int");
.HasColumnType("integer")
.HasColumnName("access_failed_count");
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("nvarchar(max)");
.HasColumnType("text")
.HasColumnName("concurrency_stamp");
b.Property<string>("Email")
.HasMaxLength(256)
.HasColumnType("nvarchar(256)");
.HasColumnType("character varying(256)")
.HasColumnName("email");
b.Property<bool>("EmailConfirmed")
.HasColumnType("bit");
.HasColumnType("boolean")
.HasColumnName("email_confirmed");
b.Property<string>("FirstName")
.HasColumnType("nvarchar(max)");
.HasColumnType("text")
.HasColumnName("first_name");
b.Property<string>("LastName")
.HasColumnType("nvarchar(max)");
.HasColumnType("text")
.HasColumnName("last_name");
b.Property<bool>("LockoutEnabled")
.HasColumnType("bit");
.HasColumnType("boolean")
.HasColumnName("lockout_enabled");
b.Property<DateTimeOffset?>("LockoutEnd")
.HasColumnType("datetimeoffset");
.HasColumnType("timestamp with time zone")
.HasColumnName("lockout_end");
b.Property<string>("NormalizedEmail")
.HasMaxLength(256)
.HasColumnType("nvarchar(256)");
.HasColumnType("character varying(256)")
.HasColumnName("normalized_email");
b.Property<string>("NormalizedUserName")
.HasMaxLength(256)
.HasColumnType("nvarchar(256)");
.HasColumnType("character varying(256)")
.HasColumnName("normalized_user_name");
b.Property<string>("PassPortNumber")
.HasColumnType("nvarchar(max)");
.HasColumnType("text")
.HasColumnName("pass_port_number");
b.Property<string>("PasswordHash")
.HasColumnType("nvarchar(max)");
.HasColumnType("text")
.HasColumnName("password_hash");
b.Property<string>("PhoneNumber")
.HasColumnType("nvarchar(max)");
.HasColumnType("text")
.HasColumnName("phone_number");
b.Property<bool>("PhoneNumberConfirmed")
.HasColumnType("bit");
.HasColumnType("boolean")
.HasColumnName("phone_number_confirmed");
b.Property<string>("SecurityStamp")
.HasColumnType("nvarchar(max)");
.HasColumnType("text")
.HasColumnName("security_stamp");
b.Property<bool>("TwoFactorEnabled")
.HasColumnType("bit");
.HasColumnType("boolean")
.HasColumnName("two_factor_enabled");
b.Property<string>("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<long>", b =>
{
b.Property<long>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("bigint");
.HasColumnType("bigint")
.HasColumnName("id");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<long>("Id"));
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<long>("Id"));
b.Property<string>("ConcurrencyStamp")
.IsConcurrencyToken()
.HasColumnType("nvarchar(max)");
.HasColumnType("text")
.HasColumnName("concurrency_stamp");
b.Property<string>("Name")
.HasMaxLength(256)
.HasColumnType("nvarchar(256)");
.HasColumnType("character varying(256)")
.HasColumnName("name");
b.Property<string>("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<long>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
.HasColumnType("integer")
.HasColumnName("id");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ClaimType")
.HasColumnType("nvarchar(max)");
.HasColumnType("text")
.HasColumnName("claim_type");
b.Property<string>("ClaimValue")
.HasColumnType("nvarchar(max)");
.HasColumnType("text")
.HasColumnName("claim_value");
b.Property<long>("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<long>", b =>
{
b.Property<int>("Id")
.ValueGeneratedOnAdd()
.HasColumnType("int");
.HasColumnType("integer")
.HasColumnName("id");
SqlServerPropertyBuilderExtensions.UseIdentityColumn(b.Property<int>("Id"));
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
b.Property<string>("ClaimType")
.HasColumnType("nvarchar(max)");
.HasColumnType("text")
.HasColumnName("claim_type");
b.Property<string>("ClaimValue")
.HasColumnType("nvarchar(max)");
.HasColumnType("text")
.HasColumnName("claim_value");
b.Property<long>("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<long>", b =>
{
b.Property<string>("LoginProvider")
.HasColumnType("nvarchar(450)");
.HasColumnType("text")
.HasColumnName("login_provider");
b.Property<string>("ProviderKey")
.HasColumnType("nvarchar(450)");
.HasColumnType("text")
.HasColumnName("provider_key");
b.Property<string>("ProviderDisplayName")
.HasColumnType("nvarchar(max)");
.HasColumnType("text")
.HasColumnName("provider_display_name");
b.Property<long>("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<long>", b =>
{
b.Property<long>("UserId")
.HasColumnType("bigint");
.HasColumnType("bigint")
.HasColumnName("user_id");
b.Property<long>("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<long>", b =>
{
b.Property<long>("UserId")
.HasColumnType("bigint");
.HasColumnType("bigint")
.HasColumnName("user_id");
b.Property<string>("LoginProvider")
.HasColumnType("nvarchar(450)");
.HasColumnType("text")
.HasColumnName("login_provider");
b.Property<string>("Name")
.HasColumnType("nvarchar(450)");
.HasColumnType("text")
.HasColumnName("name");
b.Property<string>("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<long>", 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<long>", 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<long>", 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<long>", 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<long>", 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
}

View File

@ -7,7 +7,7 @@ public class FakeRegisterNewUserCommand : AutoFaker<RegisterNewUserCommand>
{
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");

View File

@ -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",

View File

@ -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": "*"
}

View File

@ -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"
}
}

View File

@ -8,7 +8,7 @@ public class PassengerConfiguration: IEntityTypeConfiguration<Passengers.Models.
{
public void Configure(EntityTypeBuilder<Passengers.Models.Passenger> builder)
{
builder.ToTable("Passenger", AppDbContextBase.DefaultSchema);
builder.ToTable("passenger");
builder.HasKey(r => r.Id);
builder.Property(r => r.Id).ValueGeneratedNever();

View File

@ -9,7 +9,8 @@ public class DesignTimeDbContextFactory: IDesignTimeDbContextFactory<PassengerDb
{
var builder = new DbContextOptionsBuilder<PassengerDbContext>();
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);
}
}

View File

@ -1,70 +0,0 @@
// <auto-generated />
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
{
/// <inheritdoc />
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<long>("Id")
.HasColumnType("bigint");
b.Property<int>("Age")
.HasColumnType("int");
b.Property<DateTime?>("CreatedAt")
.HasColumnType("datetime2");
b.Property<long?>("CreatedBy")
.HasColumnType("bigint");
b.Property<bool>("IsDeleted")
.HasColumnType("bit");
b.Property<DateTime?>("LastModified")
.HasColumnType("datetime2");
b.Property<long?>("LastModifiedBy")
.HasColumnType("bigint");
b.Property<string>("Name")
.HasColumnType("nvarchar(max)");
b.Property<int>("PassengerType")
.HasColumnType("int");
b.Property<string>("PassportNumber")
.HasColumnType("nvarchar(max)");
b.Property<long>("Version")
.HasColumnType("bigint");
b.HasKey("Id");
b.ToTable("Passenger", "dbo");
});
#pragma warning restore 612, 618
}
}
}

View File

@ -1,48 +0,0 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Passenger.Data.Migrations
{
/// <inheritdoc />
public partial class initial : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.EnsureSchema(
name: "dbo");
migrationBuilder.CreateTable(
name: "Passenger",
schema: "dbo",
columns: table => new
{
Id = table.Column<long>(type: "bigint", nullable: false),
PassportNumber = table.Column<string>(type: "nvarchar(max)", nullable: true),
Name = table.Column<string>(type: "nvarchar(max)", nullable: true),
PassengerType = table.Column<int>(type: "int", nullable: false),
Age = table.Column<int>(type: "int", nullable: false),
CreatedAt = table.Column<DateTime>(type: "datetime2", nullable: true),
CreatedBy = table.Column<long>(type: "bigint", nullable: true),
LastModified = table.Column<DateTime>(type: "datetime2", nullable: true),
LastModifiedBy = table.Column<long>(type: "bigint", nullable: true),
IsDeleted = table.Column<bool>(type: "bit", nullable: false),
Version = table.Column<long>(type: "bigint", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("PK_Passenger", x => x.Id);
});
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Passenger",
schema: "dbo");
}
}
}

View File

@ -0,0 +1,82 @@
// <auto-generated />
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
{
/// <inheritdoc />
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<long>("Id")
.HasColumnType("bigint")
.HasColumnName("id");
b.Property<int>("Age")
.HasColumnType("integer")
.HasColumnName("age");
b.Property<DateTime?>("CreatedAt")
.HasColumnType("timestamp with time zone")
.HasColumnName("created_at");
b.Property<long?>("CreatedBy")
.HasColumnType("bigint")
.HasColumnName("created_by");
b.Property<bool>("IsDeleted")
.HasColumnType("boolean")
.HasColumnName("is_deleted");
b.Property<DateTime?>("LastModified")
.HasColumnType("timestamp with time zone")
.HasColumnName("last_modified");
b.Property<long?>("LastModifiedBy")
.HasColumnType("bigint")
.HasColumnName("last_modified_by");
b.Property<string>("Name")
.HasColumnType("text")
.HasColumnName("name");
b.Property<int>("PassengerType")
.HasColumnType("integer")
.HasColumnName("passenger_type");
b.Property<string>("PassportNumber")
.HasColumnType("text")
.HasColumnName("passport_number");
b.Property<long>("Version")
.HasColumnType("bigint")
.HasColumnName("version");
b.HasKey("Id")
.HasName("pk_passenger");
b.ToTable("passenger", (string)null);
});
#pragma warning restore 612, 618
}
}
}

View File

@ -0,0 +1,43 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Passenger.Data.Migrations
{
/// <inheritdoc />
public partial class initial : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "passenger",
columns: table => new
{
id = table.Column<long>(type: "bigint", nullable: false),
passportnumber = table.Column<string>(name: "passport_number", type: "text", nullable: true),
name = table.Column<string>(type: "text", nullable: true),
passengertype = table.Column<int>(name: "passenger_type", type: "integer", nullable: false),
age = table.Column<int>(type: "integer", nullable: false),
createdat = table.Column<DateTime>(name: "created_at", type: "timestamp with time zone", nullable: true),
createdby = table.Column<long>(name: "created_by", type: "bigint", nullable: true),
lastmodified = table.Column<DateTime>(name: "last_modified", type: "timestamp with time zone", nullable: true),
lastmodifiedby = table.Column<long>(name: "last_modified_by", type: "bigint", nullable: true),
isdeleted = table.Column<bool>(name: "is_deleted", type: "boolean", nullable: false),
version = table.Column<long>(type: "bigint", nullable: false)
},
constraints: table =>
{
table.PrimaryKey("pk_passenger", x => x.id);
});
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "passenger");
}
}
}

View File

@ -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<long>("Id")
.HasColumnType("bigint");
.HasColumnType("bigint")
.HasColumnName("id");
b.Property<int>("Age")
.HasColumnType("int");
.HasColumnType("integer")
.HasColumnName("age");
b.Property<DateTime?>("CreatedAt")
.HasColumnType("datetime2");
.HasColumnType("timestamp with time zone")
.HasColumnName("created_at");
b.Property<long?>("CreatedBy")
.HasColumnType("bigint");
.HasColumnType("bigint")
.HasColumnName("created_by");
b.Property<bool>("IsDeleted")
.HasColumnType("bit");
.HasColumnType("boolean")
.HasColumnName("is_deleted");
b.Property<DateTime?>("LastModified")
.HasColumnType("datetime2");
.HasColumnType("timestamp with time zone")
.HasColumnName("last_modified");
b.Property<long?>("LastModifiedBy")
.HasColumnType("bigint");
.HasColumnType("bigint")
.HasColumnName("last_modified_by");
b.Property<string>("Name")
.HasColumnType("nvarchar(max)");
.HasColumnType("text")
.HasColumnName("name");
b.Property<int>("PassengerType")
.HasColumnType("int");
.HasColumnType("integer")
.HasColumnName("passenger_type");
b.Property<string>("PassportNumber")
.HasColumnType("nvarchar(max)");
.HasColumnType("text")
.HasColumnName("passport_number");
b.Property<long>("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
}