Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/sql server #71

Open
wants to merge 13 commits into
base: main
Choose a base branch
from
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ A .NET Core REST API project template 👷 Built with a sense of peace and tranq

### Prerequisites

- PostgreSQL
[https://www.postgresql.org/](https://www.postgresql.org/)
- SQL Server
[https://www.microsoft.com/en-gb/sql-server/sql-server-2022](https://www.microsoft.com/en-gb/sql-server/sql-server-2022)
- RabbitMQ
[https://www.rabbitmq.com/](https://www.rabbitmq.com/)
- Redis
Expand All @@ -60,7 +60,7 @@ In the `src/Halcyon.Api` directory of the project, create a new `appsettings.Dev
```
{
"ConnectionStrings": {
"Database": "Host=localhost;Port=5432;Database=halcyon;Username=postgres;Password=password",
"Database": "Server=localhost;Database=Halcyon;User Id=sa;Password=Pass@word;TrustServerCertificate=true;MultipleActiveResultSets=true;",
"RabbitMq": "amqp://guest:guest@localhost:5672",
"Redis": "localhost"
},
Expand All @@ -73,7 +73,7 @@ In the `src/Halcyon.Api` directory of the project, create a new `appsettings.Dev
"NoReplyAddress": "[email protected]",
"CdnUrl": "http://localhost:3000"
},
"Jwt": {
"Jwt": {
"SecurityKey": "super_secret_key_that_should_be_changed",
"Issuer": "HalcyonApi",
"Audience": "HalcyonClient",
Expand Down
25 changes: 13 additions & 12 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ services:
ASPNETCORE_ENVIRONMENT: Development
ASPNETCORE_HTTP_PORTS: 8080
ASPNETCORE_HTTPS_PORTS: 8081
ConnectionStrings__Database: Host=host.docker.internal;Port=5432;Database=halcyon;Username=postgres;Password=password
ConnectionStrings__Database: Server=host.docker.internal;Database=Halcyon;User Id=sa;Password=Pass@word;TrustServerCertificate=true;MultipleActiveResultSets=true;
ConnectionStrings__RabbitMq: amqp://guest:[email protected]:5672
ConnectionStrings__Redis: host.docker.internal
Email__SmtpServer: host.docker.internal
Expand All @@ -27,25 +27,26 @@ services:
- ${APPDATA}/Microsoft/UserSecrets:/home/app/.microsoft/usersecrets:ro
- ${APPDATA}/ASP.NET/Https:/home/app/.aspnet/https:ro
depends_on:
postgres:
mssql:
condition: service_healthy
rabbitmq:
condition: service_healthy
redis:
condition: service_healthy

postgres:
image: postgres:17.0
user: postgres
mssql:
image: ghcr.io/chrispoulter/mssql-2022-full-text:latest
# image: mcr.microsoft.com/mssql/server:2022-latest
environment:
POSTGRES_PASSWORD: password
ACCEPT_EULA: Y
MSSQL_SA_PASSWORD: Pass@word
ports:
- 5432:5432
- 1433:1433
volumes:
- postgres:/var/lib/postgresql/data
- mssql:/var/opt/mssql
restart: always
healthcheck:
test: [ 'CMD', 'pg_isready' ]
test: /opt/mssql-tools18/bin/sqlcmd -U sa -P "$${MSSQL_SA_PASSWORD}" -C -Q "SELECT 1" -b -o /dev/null
interval: 10s
timeout: 5s
retries: 3
Expand Down Expand Up @@ -101,13 +102,13 @@ services:
restart: always

volumes:
postgres:
name: halcyon-postgres
mssql:
name: halcyon-mssql
rabbitmq:
name: halcyon-rabbitmq
redis:
name: halcyon-redis
maildev:
name: halcyon-maildev
seq:
name: halcyon-seq
name: halcyon-seq
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using Halcyon.Api.Data;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Npgsql;

namespace Halcyon.Api.Common.Infrastructure;

Expand All @@ -16,21 +15,15 @@ string connectionName
builder.Services.AddDbContext<HalcyonDbContext>(
(provider, options) =>
options
.UseNpgsql(
.UseSqlServer(
builder.Configuration.GetConnectionString(connectionName),
builder => builder.EnableRetryOnFailure()
)
.UseSnakeCaseNamingConvention()
.AddInterceptors(provider.GetServices<IInterceptor>())
);

builder.Services.AddHealthChecks().AddDbContextCheck<TContext>();

builder
.Services.AddOpenTelemetry()
.WithTracing(tracing => tracing.AddNpgsql())
.WithMetrics(metrics => metrics.AddNpgsqlInstrumentation());

return builder;
}
}
5 changes: 1 addition & 4 deletions src/Halcyon.Api/Data/Users/User.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Halcyon.Api.Common.Events;
using NpgsqlTypes;

namespace Halcyon.Api.Data.Users;

Expand All @@ -23,7 +22,5 @@ public class User : IEntity

public List<string> Roles { get; set; }

public uint Version { get; }

public NpgsqlTsVector SearchVector { get; }
public byte[] Version { get; set; }
}
12 changes: 0 additions & 12 deletions src/Halcyon.Api/Data/Users/UserConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,7 @@ public void Configure(EntityTypeBuilder<User> builder)
builder.Property(u => u.FirstName).IsRequired();
builder.Property(u => u.LastName).IsRequired();
builder.Property(u => u.DateOfBirth).IsRequired();
builder.Property(u => u.Roles).HasColumnType("text[]");
builder.Property(u => u.IsLockedOut).HasDefaultValue(false);
builder.Property(u => u.Version).IsRowVersion();

builder.HasGeneratedTsVectorColumn(
u => u.SearchVector,
"english",
u => new
{
u.FirstName,
u.LastName,
u.EmailAddress,
}
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ private static async Task<IResult> HandleAsync(
);
}

if (request.Version is not null && request.Version != user.Version)
if (request.Version is not null && !request.Version.SequenceEqual(user.Version))
{
return Results.Problem(
statusCode: StatusCodes.Status409Conflict,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ private static async Task<IResult> HandleAsync(
);
}

if (request?.Version is not null && request.Version != user.Version)
if (request.Version is not null && !request.Version.SequenceEqual(user.Version))
{
return Results.Problem(
statusCode: StatusCodes.Status409Conflict,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ public class GetProfileResponse

public DateOnly DateOfBirth { get; set; }

public uint Version { get; set; }
public byte[] Version { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ private static async Task<IResult> HandleAsync(
);
}

if (request.Version is not null && request.Version != user.Version)
if (request.Version is not null && !request.Version.SequenceEqual(user.Version))
{
return Results.Problem(
statusCode: StatusCodes.Status409Conflict,
Expand Down
2 changes: 1 addition & 1 deletion src/Halcyon.Api/Features/UpdateRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@

public class UpdateRequest
{
public uint? Version { get; set; }
public byte[] Version { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ private static async Task<IResult> HandleAsync(
);
}

if (request?.Version is not null && request.Version != user.Version)
if (request.Version is not null && !request.Version.SequenceEqual(user.Version))
{
return Results.Problem(
statusCode: StatusCodes.Status409Conflict,
Expand Down
2 changes: 1 addition & 1 deletion src/Halcyon.Api/Features/Users/GetUser/GetUserResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,5 @@ public class GetUserResponse

public List<string> Roles { get; set; }

public uint Version { get; set; }
public byte[] Version { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ private static async Task<IResult> HandleAsync(
);
}

if (request?.Version is not null && request.Version != user.Version)
if (request.Version is not null && !request.Version.SequenceEqual(user.Version))
{
return Results.Problem(
statusCode: StatusCodes.Status409Conflict,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,14 @@ private static async Task<IResult> HandleAsync(

if (!string.IsNullOrEmpty(request.Search))
{
query = query.Where(u =>
u.SearchVector.Matches(EF.Functions.PhraseToTsQuery("english", request.Search))
);
query = query.Where(u => EF.Functions.FreeText(u.EmailAddress, request.Search));

//query = query.Where(u =>
// EF.Functions.Like(
// u.FirstName + " " + u.LastName + " " + u.EmailAddress,
// $"%{request.Search}%"
// )
//);
}

var count = await query.CountAsync(cancellationToken);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ private static async Task<IResult> HandleAsync(
);
}

if (request?.Version is not null && request.Version != user.Version)
if (request.Version is not null && !request.Version.SequenceEqual(user.Version))
{
return Results.Problem(
statusCode: StatusCodes.Status409Conflict,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ private static async Task<IResult> HandleAsync(
);
}

if (request.Version is not null && request.Version != user.Version)
if (request.Version is not null && !request.Version.SequenceEqual(user.Version))
{
return Results.Problem(
statusCode: StatusCodes.Status409Conflict,
Expand Down
4 changes: 1 addition & 3 deletions src/Halcyon.Api/Halcyon.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="EFCore.NamingConventions" Version="9.0.0" />
<PackageReference Include="FluentValidation" Version="11.11.0" />
<PackageReference Include="FluentValidation.AspNetCore" Version="11.3.0" />
<PackageReference Include="MailKit" Version="4.9.0" />
Expand All @@ -24,12 +23,11 @@
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="9.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="9.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Relational" Version="9.0.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Caching.Hybrid" Version="9.0.0-preview.7.24406.2" />
<PackageReference Include="Microsoft.Extensions.Caching.StackExchangeRedis" Version="9.0.0" />
<PackageReference Include="Microsoft.Extensions.Diagnostics.HealthChecks.EntityFrameworkCore" Version="9.0.0" />
<PackageReference Include="Microsoft.VisualStudio.Azure.Containers.Tools.Targets" Version="1.21.0" />
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="9.0.2" />
<PackageReference Include="Npgsql.OpenTelemetry" Version="9.0.2" />
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.10.0" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.10.0" />
<PackageReference Include="OpenTelemetry.Instrumentation.AspNetCore" Version="1.10.1" />
Expand Down

This file was deleted.

Loading
Loading