Skip to content

Commit

Permalink
feat: add postgresql configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
EnisMulic committed Nov 6, 2023
1 parent c4a12ed commit b864660
Show file tree
Hide file tree
Showing 8 changed files with 79 additions and 18 deletions.
38 changes: 33 additions & 5 deletions .template.config/template.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
{
"$schema": "http://json.schemastore.org/template",
"author": "Enis Mulic",
"classifications": ["Api", "Minimal Api", "Vertical Slice Architecture", "CQRS"],
"classifications": [
"Api",
"Minimal Api",
"Vertical Slice Architecture",
"CQRS"
],
"identity": "VerticalSliceMinimalApi",
"name": "Vertical Slice Minimal Api",
"shortName": "vsma",
Expand Down Expand Up @@ -48,7 +53,7 @@
"datatype": "choice",
"choices": [
{
"choice": "MSSql",
"choice": "MsSql",
"description": "Use Microsoft SQL or Azure SQL"
},
{
Expand All @@ -63,9 +68,9 @@
"defaultValue": "None",
"description": "The type of database to use"
},
"UseMSSql": {
"UseMsSql": {
"type": "computed",
"value": "(Database == \"MSSql\")"
"value": "(Database == \"MsSql\")"
},
"UsePostgreSql": {
"type": "computed",
Expand Down Expand Up @@ -96,8 +101,31 @@
{
"condition": "(!UseDatabase)",
"exclude": [
"src/Application/Infrastructure/Persistance/**"
"src/Application/Infrastructure/Persistance/**",
"appsettings.*.json"
]
},
{
"condition": "(UseMsSql)",
"exclude": [
"src/Api/appsettings.PostgreSql.json",
"docker-compose.postgresql.yml"
],
"rename": {
"appsettings.MsSql.json": "appsettings.Development.json",
"docker-compose.mssql.yml": "docker-compose.yml"
}
},
{
"condition": "(UsePostgreSql)",
"exclude": [
"src/Api/appsettings.MsSql.json",
"docker-compose.mssql.yml"
],
"rename": {
"appsettings.PostgreSql.json": "appsettings.Development.json",
"docker-compose.postgresql.yml": "docker-compose.yml"
}
}
]
}
Expand Down
12 changes: 7 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

[![Build](https://github.com/EnisMulic/VerticalSliceMinimalApi/actions/workflows/ci.yml/badge.svg)](https://github.com/EnisMulic/VerticalSliceMinimalApi/actions/workflows/ci.yml)

## Getting Started
## Getting Started

1. Clone the repository

Expand All @@ -19,10 +19,11 @@ dotnet new install ./VerticalSliceMinimalApi
3. Use the installed template to create your API

```sh
dotnet new vsma --name ProjectName
dotnet new vsma --name ProjectName
```

## Synopsis

```
dotnet new vsma --name [ProjectName]
[-gh|--git-host [Github|AzureDevOps|None]]
Expand All @@ -31,17 +32,18 @@ dotnet new vsma --name [ProjectName]

### Options

* `--name [ProjectName]`
- `--name [ProjectName]`
Specify the name of the project you are creating, this will replace all occurrences of `ProjectName` in the template with the name you pass in.

* `-gh|--git-host [Github|AzureDevOps|None]`
- `-gh|--git-host [Github|AzureDevOps|None]`
Choose the platform you will host your projects git repository, this will give you a base CI workflow, pull request template, and anything specific to the platform that might be of use. The default value is `None`.
* `-db|--database [MsSql|PostgreSql|None]`
- `-db|--database [MsSql|PostgreSql|None]`
Choose what database to use for your project. The default is `None`

## How to Run

To start the app run:

```sh
dotnet run --project src/Api
```
Expand Down
File renamed without changes.
10 changes: 10 additions & 0 deletions docker-compose.postgresql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
services:
postgres:
image: postgres:14-alpine
restart: unless-stopped
ports:
- 5432:5432
environment:
- POSTGRES_PASSWORD=QWElkj132!
- POSTGRES_USER=todos_user
- POSTGRES_DB=todos_db
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
{
"ConnectionStrings": {
"Default": "Server=.;Database=TodoDatabase;Trusted_Connection=True;MultipleActiveResultSets=true;TrustServerCertificate=True"
"Default": "Server=.;Database=TodoDatabase;MultipleActiveResultSets=true;TrustServerCertificate=True;User Id=sa;Password=QWElkj132!"
},
"Logging": {
"LogLevel": {
Expand All @@ -21,4 +21,4 @@
}
}
}
}
}
24 changes: 24 additions & 0 deletions src/Api/appsettings.PostgreSql.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"ConnectionStrings": {
"Default": "Host=localhost;Port=5432;Database=todos_db;Integrated Security=true;Pooling=true;Username=todos_user;Password=QWElkj132!"
},
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft.AspNetCore": "Warning"
}
},
"Authentication": {
"Schemes": {
"Bearer": {
"ValidAudiences": [
"http://localhost:44986",
"https://localhost:44337",
"http://localhost:5191",
"https://localhost:7079"
],
"ValidIssuer": "dotnet-user-jwts"
}
}
}
}
5 changes: 1 addition & 4 deletions src/Api/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,5 @@
}
}
},
"AllowedHosts": "*",
"ConnectionStrings": {
"Default": "Server=.;Database=TodoDatabase;Trusted_Connection=True;MultipleActiveResultSets=true;TrustServerCertificate=True"
}
"AllowedHosts": "*"
}
2 changes: 1 addition & 1 deletion src/Application/Infrastructure/ConfigureServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static IServiceCollection AddInfrastructureServices(this IServiceCollecti
{
options.AddInterceptors(sp.GetServices<ISaveChangesInterceptor>());
#if UseMSSql
#if UseMsSql
options.UseSqlServer(configuration.GetConnectionString("Default"),
builder => builder.MigrationsAssembly(typeof(ApplicationDbContext).Assembly.FullName));
#elif UsePostgreSql
Expand Down

0 comments on commit b864660

Please sign in to comment.