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

Put application tables in schema #201

Merged
merged 12 commits into from
Aug 14, 2024
2 changes: 1 addition & 1 deletion .azure/modules/postgreSql/AddAdministrationAccess.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ param appName string
param namePrefix string

resource database 'Microsoft.DBforPostgreSQL/flexibleServers@2022-12-01' existing = {
name: '${namePrefix}-pgflex'
name: '${namePrefix}-dbserver'
}
resource databaseAccess 'Microsoft.DBforPostgreSQL/flexibleServers/administrators@2022-12-01' = {
name: principalId
Expand Down
4 changes: 2 additions & 2 deletions .azure/modules/postgreSql/create.bicep
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ module saveMigrationConnectionString '../keyvault/upsertSecret.bicep' = {
params: {
destKeyVaultName: srcKeyVault.name
secretName: migrationConnectionStringName
secretValue: 'Host=${postgres.properties.fullyQualifiedDomainName};Database=${databaseName};Port=5432;Username=${databaseUser};Password=${administratorLoginPassword};'
secretValue: 'Host=${postgres.properties.fullyQualifiedDomainName};Database=${databaseName};Port=5432;Username=${databaseUser};Password=${administratorLoginPassword};options=-c role=azure_pg_admin;'
}
}

resource postgres 'Microsoft.DBforPostgreSQL/flexibleServers@2023-06-01-preview' = {
name: '${namePrefix}-pgflex'
name: '${namePrefix}-dbserver'
location: location
properties: {
version: '14'
Expand Down
2 changes: 1 addition & 1 deletion README-infrastructure.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ Cannot be automated as our deploying service principal does not have access to i

The database uses IP blocking for security reasons so to get access you need to add a firewall rule on the database server for your IP. You also need to set yourself as an AD administrator with access to the database.

1. Go to the database server in the Azure Portal (name ends in "-pgflex")
1. Go to the database server in the Azure Portal (name ends in "-dbserver")
2. Go Settings > Networking and click "Add current client IP address"
3. Go Security > Authentication and use "Add Microsoft Entra Admins" to add yourself.
4. After you have added yourself, you will see your AD user in the list of admins. Use the username from here and use an Azure Access token for password that can be generated using the CLI:
Expand Down
6 changes: 6 additions & 0 deletions src/Altinn.Correspondence.Persistence/Data/DatabaseContext.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Altinn.Correspondence.Core.Models;
using Azure.Identity;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.IdentityModel.Tokens;
using Npgsql;
using System.IdentityModel.Tokens.Jwt;
Expand Down Expand Up @@ -48,4 +49,9 @@ private bool IsAccessTokenValid()
SecurityToken token = tokenHandler.ReadToken(_accessToken);
return DateTime.UtcNow.AddSeconds(60) < token.ValidTo;
}

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.HasDefaultSchema("correspondence");
}
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading