Skip to content

Commit

Permalink
Merge pull request #127 from NoxOrg/feature/postgres_database_provider
Browse files Browse the repository at this point in the history
Feature/postgres database provider
  • Loading branch information
rochar authored Jul 5, 2023
2 parents b680148 + 5d0a4af commit f229551
Show file tree
Hide file tree
Showing 80 changed files with 837 additions and 1,503 deletions.
17 changes: 11 additions & 6 deletions .nox/design/sample.solution.nox.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -412,15 +412,20 @@ infrastructure:
name: SampleCurrencyDb

# Sql Server
serverUri: sqlserver.iwgplc.com
serverUri: localhost
provider: sqlServer
port: 1433
user: sqluser
password: sqlpassword
user: sa
password: Developer*123
options: Trusted_Connection=no;connection timeout=120;TrustServerCertificate=True;

### Postgres
# Postgres
#serverUri: localhost
#provider: postgres

#port: 54320
#user: sa
#password: Developer*123

### MySql
#provider: mySql

Expand All @@ -429,7 +434,7 @@ infrastructure:
provider: azureRedis
serverUri: redis.iwgplc.com
user: RedisUser
password: RedisPassword
password: RedisPassword*123

searchServer:
name: SampleSearch
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
version: '2.2'
version: '3.7'

volumes:
esdata:
driver: local

services:
apm-server:
container_name: apm-server
image: docker.elastic.co/apm/apm-server:7.17.10
depends_on:
elasticsearch:
Expand All @@ -22,25 +28,26 @@ services:
-E apm-server.kibana.host=kibana:5601
-E output.elasticsearch.hosts=["elasticsearch:9200"]
-E apm-server.kibana.username=elastic
-E apm-server.kibana.password=$ELASTIC_PASSWORD
-E apm-server.kibana.password=Developer*123
-E output.elasticsearch.username=elastic
-E output.elasticsearch.password=$ELASTIC_PASSWORD
-E output.elasticsearch.password=Developer*123
healthcheck:
interval: 10s
retries: 12
test: curl --write-out 'HTTP %{http_code}' --fail --silent --output /dev/null http://localhost:8200/

elasticsearch:
container_name: elasticsearch
image: docker.elastic.co/elasticsearch/elasticsearch:7.17.10
environment:
- bootstrap.memory_lock=true
- cluster.name=docker-cluster
- cluster.routing.allocation.disk.threshold_enabled=false
- discovery.type=single-node
- ES_JAVA_OPTS=-XX:UseAVX=2 -Xms1g -Xmx1g
- xpack.security.enabled=$ELASTIC_SECURITY
- xpack.security.enabled=true
- xpack.security.authc.api_key.enabled=true
- ELASTIC_PASSWORD=$ELASTIC_PASSWORD
- ELASTIC_PASSWORD=Developer*123
ulimits:
memlock:
hard: -1
Expand All @@ -57,6 +64,7 @@ services:
test: curl -s http://localhost:9200/_cluster/health | grep -vq '"status":"red"'

kibana:
container_name: kibana
image: docker.elastic.co/kibana/kibana:7.17.10
depends_on:
elasticsearch:
Expand All @@ -65,7 +73,7 @@ services:
ELASTICSEARCH_URL: http://elasticsearch:9200
ELASTICSEARCH_HOSTS: http://elasticsearch:9200
ELASTICSEARCH_USERNAME: elastic
ELASTICSEARCH_PASSWORD: $ELASTIC_PASSWORD
ELASTICSEARCH_PASSWORD: Developer*123
ports:
- 5601:5601
networks:
Expand All @@ -80,10 +88,6 @@ services:
timeout: 10s
retries: 120

volumes:
esdata:
driver: local

networks:
elastic:
driver: bridge
19 changes: 19 additions & 0 deletions docker-compose.postgres.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
version: '3.7'

volumes:
postgres:

services:
postgres:
container_name: postgres_container
image: postgres:14-alpine
restart: always
environment:
POSTGRES_DB: SampleCurrencyDb
POSTGRES_USER: "sa"
POSTGRES_PASSWORD: "Developer*123"
PGDATA: ./data
ports:
- "54320:5432"
volumes:
- postgres:/var/lib/postgresql/data
18 changes: 18 additions & 0 deletions docker-compose.sqlServer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
version: '3.7'

volumes:
sqlserver:

services:
sqlserver:
container_name: sqlserver_container
image: "mcr.microsoft.com/azure-sql-edge:latest"
user: root
ports:
- "1433:1433"
environment:
SA_PASSWORD: "Developer*123"
ACCEPT_EULA: "Y"
MSSQL_PID: "Developer"
volumes:
- sqlserver:/var/opt/mssql/data
122 changes: 122 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
version: '3.7'

volumes:
sqlserver:
postgres:
esdata:
driver: local

services:
sqlserver:
container_name: sqlserver_container
image: "mcr.microsoft.com/azure-sql-edge:latest"
user: root
ports:
- "1433:1433"
environment:
SA_PASSWORD: "Developer*123"
ACCEPT_EULA: "Y"
MSSQL_PID: "Developer"
volumes:
- sqlserver:/var/opt/mssql/data

postgres:
container_name: postgres_container
image: postgres:14-alpine
restart: always
environment:
POSTGRES_DB: SampleCurrencyDb
POSTGRES_USER: "sa"
POSTGRES_PASSWORD: "Developer*123"
PGDATA: ./data
ports:
- "54320:5432"
volumes:
- postgres:/var/lib/postgresql/data

apm-server:
container_name: apm-server
image: docker.elastic.co/apm/apm-server:7.17.10
depends_on:
elasticsearch:
condition: service_healthy
kibana:
condition: service_healthy
cap_add: ["CHOWN", "DAC_OVERRIDE", "SETGID", "SETUID"]
cap_drop: ["ALL"]
ports:
- 8200:8200
networks:
- elastic
command: >
apm-server -e
-E apm-server.rum.enabled=true
-E setup.kibana.host=kibana:5601
-E setup.template.settings.index.number_of_replicas=0
-E apm-server.kibana.enabled=true
-E apm-server.kibana.host=kibana:5601
-E output.elasticsearch.hosts=["elasticsearch:9200"]
-E apm-server.kibana.username=elastic
-E apm-server.kibana.password=Developer*123
-E output.elasticsearch.username=elastic
-E output.elasticsearch.password=Developer*123
healthcheck:
interval: 10s
retries: 12
test: curl --write-out 'HTTP %{http_code}' --fail --silent --output /dev/null http://localhost:8200/

elasticsearch:
container_name: elasticsearch
image: docker.elastic.co/elasticsearch/elasticsearch:7.17.10
environment:
- bootstrap.memory_lock=true
- cluster.name=docker-cluster
- cluster.routing.allocation.disk.threshold_enabled=false
- discovery.type=single-node
- ES_JAVA_OPTS=-XX:UseAVX=2 -Xms1g -Xmx1g
- xpack.security.enabled=true
- xpack.security.authc.api_key.enabled=true
- ELASTIC_PASSWORD=Developer*123
ulimits:
memlock:
hard: -1
soft: -1
volumes:
- esdata:/usr/share/elasticsearch/data
ports:
- 9200:9200
networks:
- elastic
healthcheck:
interval: 20s
retries: 10
test: curl -s http://localhost:9200/_cluster/health | grep -vq '"status":"red"'

kibana:
container_name: kibana
image: docker.elastic.co/kibana/kibana:7.17.10
depends_on:
elasticsearch:
condition: service_healthy
environment:
ELASTICSEARCH_URL: http://elasticsearch:9200
ELASTICSEARCH_HOSTS: http://elasticsearch:9200
ELASTICSEARCH_USERNAME: elastic
ELASTICSEARCH_PASSWORD: Developer*123
ports:
- 5601:5601
networks:
- elastic
healthcheck:
test:
[
"CMD-SHELL",
"curl -s -I http://localhost:5601 | grep -q 'HTTP/1.1 302 Found'",
]
interval: 10s
timeout: 10s
retries: 120

networks:
elastic:
driver: bridge

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Nox.Types.EntityFramework\Nox.Types.EntityFramework.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Npgsql.EntityFrameworkCore.PostgreSQL" Version="7.0.4" />
</ItemGroup>

</Project>
66 changes: 66 additions & 0 deletions src/Nox.EntityFramework.Postgres/PostgresDatabaseProvider.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
using Microsoft.EntityFrameworkCore;
using Nox.Solution;
using Nox.Types;
using Nox.Types.EntityFramework.Abstractions;
using Nox.Types.EntityFramework.Configurators;
using Npgsql;

namespace Nox.EntityFramework.Postgres;

public class PostgresDatabaseProvider: NoxDatabaseConfigurator, INoxDatabaseProvider
{
private string _connectionString = string.Empty;

private static readonly Dictionary<NoxType, INoxTypeDatabaseConfigurator> TypesConfiguration =
new()
{
{ NoxType.Text, new PostgresTextDatabaseConfiguration() }, //Use Postgres Implementation
{ NoxType.Number, new NumberDatabaseConfigurator() }, // use default implementation
{ NoxType.Money, new MoneyDatabaseConfigurator() } // use default implementation
};

public PostgresDatabaseProvider(): base(TypesConfiguration)
{

}

public string ConnectionString
{
get => _connectionString;
set => SetConnectionString(value);
}

public DbContextOptionsBuilder ConfigureDbContext(DbContextOptionsBuilder optionsBuilder, string applicationName, DatabaseServer dbServer)
{
var csb = new NpgsqlConnectionStringBuilder(dbServer.Options)
{
Host = dbServer.ServerUri,
Port = dbServer.Port ?? 5432,
Username = dbServer.User,
Password = dbServer.Password,
Database = dbServer.Name,
ApplicationName = applicationName,
};
SetConnectionString(csb.ConnectionString);

return optionsBuilder.UseNpgsql(_connectionString, opts =>
{
opts.MigrationsHistoryTable("MigrationsHistory", "migrations");
});
}

public string ToTableNameForSql(string table, string schema)
{
throw new NotImplementedException();
}

public string ToTableNameForSqlRaw(string table, string schema)
{
throw new NotImplementedException();
}

private void SetConnectionString(string connectionString)
{
_connectionString = connectionString;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Nox.Types.EntityFramework.vNext.Types;
using Nox.Types;
using Nox.Types.EntityFramework.Configurators;

namespace Nox.Types.EntityFramework.Postgres;
namespace Nox.EntityFramework.Postgres;

public class PostgresTextDatabaseConfiguration : TextDatabaseConfigurator
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Nox.Types.EntityFramework\Nox.Types.EntityFramework.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="7.0.8" />
</ItemGroup>

</Project>
Loading

0 comments on commit f229551

Please sign in to comment.