Add db providers for secrets features (#6020)

* Add PostgreSql provider to Secrets

* Add SqlServer provider to Secrets

* fix sqlserver Method name

* resolve conflict Elsa.sln

* resolve conflict Elsa.sln

---------

Co-authored-by: Jérémie DEVILLARD <jdevillard@users.noreply.github.com>
This commit is contained in:
jdevillard 2024-10-14 21:03:39 +02:00 committed by GitHub
parent 121bc52b07
commit 9808020d57
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
19 changed files with 1745 additions and 937 deletions

1885
Elsa.sln

File diff suppressed because it is too large Load diff

View file

@ -11,7 +11,9 @@
<ProjectReference Include="..\..\modules\Elsa.MassTransit.AzureServiceBus\Elsa.MassTransit.AzureServiceBus.csproj"/>
<ProjectReference Include="..\..\modules\Elsa.OpenTelemetry\Elsa.OpenTelemetry.csproj" />
<ProjectReference Include="..\..\modules\Elsa.Secrets.Api\Elsa.Secrets.Api.csproj" />
<ProjectReference Include="..\..\modules\Elsa.Secrets.Persistence.EntityFrameworkCore.PostgreSql\Elsa.Secrets.Persistence.EntityFrameworkCore.PostgreSql.csproj" />
<ProjectReference Include="..\..\modules\Elsa.Secrets.Persistence.EntityFrameworkCore.Sqlite\Elsa.Secrets.Persistence.EntityFrameworkCore.Sqlite.csproj" />
<ProjectReference Include="..\..\modules\Elsa.Secrets.Persistence.EntityFrameworkCore.SqlServer\Elsa.Secrets.Persistence.EntityFrameworkCore.SqlServer.csproj" />
<ProjectReference Include="..\..\modules\Elsa.Secrets.Scripting\Elsa.Secrets.Scripting.csproj" />
<ProjectReference Include="..\..\modules\Elsa.Tenants.AspNetCore\Elsa.Tenants.AspNetCore.csproj" />
<ProjectReference Include="..\..\modules\Elsa\Elsa.csproj"/>

View file

@ -442,8 +442,17 @@ services
.UseSecrets()
.UseSecretsManagement(management =>
{
management.ConfigureOptions(options => configuration.GetSection("Secrets:Management").Bind(options));
management.UseEntityFrameworkCore(ef => ef.UseSqlite(sqliteConnectionString));
management.ConfigureOptions(options => configuration.GetSection("Secrets:Management").Bind(options));
if (sqlDatabaseProvider == SqlDatabaseProvider.PostgreSql)
management.UseEntityFrameworkCore(ef =>
ef.UseSqlServer(sqlServerConnectionString)
);
else if (sqlDatabaseProvider == SqlDatabaseProvider.PostgreSql)
management.UseEntityFrameworkCore(ef =>
ef.UsePostgreSql(postgresConnectionString)
);
else
management.UseEntityFrameworkCore(ef => ef.UseSqlite(sqliteConnectionString));
})
.UseSecretsApi()
.UseSecretsScripting()

View file

@ -0,0 +1,21 @@
using Elsa.EntityFrameworkCore.Common.Abstractions;
using Elsa.EntityFrameworkCore.Extensions;
using Elsa.EntityFrameworkCore.Modules.Alterations;
using Elsa.EntityFrameworkCore.Modules.Identity;
using Elsa.EntityFrameworkCore.Modules.Labels;
using Elsa.EntityFrameworkCore.Modules.Management;
using Elsa.EntityFrameworkCore.Modules.Runtime;
using Elsa.EntityFrameworkCore.PostgreSql;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore;
namespace Elsa.Secrets.Persistence.EntityFrameworkCore.PostgreSql;
[UsedImplicitly]
public class PostgreSqlSecretsDbContextFactory : PostgreSqlDesignTimeDbContextFactory<SecretsDbContext>
{
protected override void ConfigureBuilder(DbContextOptionsBuilder<SecretsDbContext> builder, string connectionString)
{
builder.UseElsaPostgreSql(GetType().Assembly, connectionString);
}
}

View file

@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Description>Provides PostgreSql persistence for the Elsa Secrets module using Entity Framework Core.</Description>
<PackageTags>elsa module secrets persistence efcore PostgreSql</PackageTags>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" PrivateAssets="all" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Elsa.Secrets.Persistence.EntityFrameworkCore\Elsa.Secrets.Persistence.EntityFrameworkCore.csproj" />
<ProjectReference Include="..\Elsa.EntityFrameworkCore.PostgreSql\Elsa.EntityFrameworkCore.PostgreSql.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="Migrations\" />
</ItemGroup>
</Project>

View file

@ -0,0 +1,3 @@
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
<ConfigureAwait />
</Weavers>

View file

@ -0,0 +1,111 @@
// <auto-generated />
using System;
using Elsa.Secrets.Persistence.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace Elsa.Secrets.Persistence.EntityFrameworkCore.PostgreSql.Migrations
{
[DbContext(typeof(SecretsDbContext))]
[Migration("20241011082142_V3_3")]
partial class V3_3
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasDefaultSchema("Elsa")
.HasAnnotation("ProductVersion", "7.0.20")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("Elsa.Secrets.Management.Secret", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<DateTimeOffset>("CreatedAt")
.HasColumnType("timestamp with time zone");
b.Property<string>("Description")
.IsRequired()
.HasColumnType("text");
b.Property<string>("EncryptedValue")
.IsRequired()
.HasColumnType("text");
b.Property<DateTimeOffset?>("ExpiresAt")
.HasColumnType("timestamp with time zone");
b.Property<TimeSpan?>("ExpiresIn")
.HasColumnType("interval");
b.Property<bool>("IsLatest")
.HasColumnType("boolean");
b.Property<DateTimeOffset?>("LastAccessedAt")
.HasColumnType("timestamp with time zone");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Owner")
.HasColumnType("text");
b.Property<string>("Scope")
.HasColumnType("text");
b.Property<string>("SecretId")
.IsRequired()
.HasColumnType("text");
b.Property<int>("Status")
.HasColumnType("integer");
b.Property<string>("TenantId")
.HasColumnType("text");
b.Property<DateTimeOffset>("UpdatedAt")
.HasColumnType("timestamp with time zone");
b.Property<int>("Version")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("ExpiresAt")
.HasDatabaseName("IX_Secret_ExpiresAt");
b.HasIndex("LastAccessedAt")
.HasDatabaseName("IX_Secret_LastAccessedAt");
b.HasIndex("Name")
.HasDatabaseName("IX_Secret_Name");
b.HasIndex("Scope")
.HasDatabaseName("IX_Secret_Scope");
b.HasIndex("Status")
.HasDatabaseName("IX_Secret_Status");
b.HasIndex("TenantId")
.HasDatabaseName("IX_Secret_TenantId");
b.HasIndex("Version")
.HasDatabaseName("IX_Secret_Version");
b.ToTable("Secrets", "Elsa");
});
#pragma warning restore 612, 618
}
}
}

View file

@ -0,0 +1,103 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Elsa.Secrets.Persistence.EntityFrameworkCore.PostgreSql.Migrations
{
/// <inheritdoc />
public partial class V3_3 : Migration
{
private readonly Elsa.EntityFrameworkCore.Common.Contracts.IElsaDbContextSchema _schema;
/// <inheritdoc />
public V3_3(Elsa.EntityFrameworkCore.Common.Contracts.IElsaDbContextSchema schema)
{
_schema = schema;
}
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.EnsureSchema(
name: _schema.Schema);
migrationBuilder.CreateTable(
name: "Secrets",
schema: _schema.Schema,
columns: table => new
{
Id = table.Column<string>(type: "text", nullable: false),
SecretId = table.Column<string>(type: "text", nullable: false),
Name = table.Column<string>(type: "text", nullable: false),
Scope = table.Column<string>(type: "text", nullable: true),
EncryptedValue = table.Column<string>(type: "text", nullable: false),
Description = table.Column<string>(type: "text", nullable: false),
Version = table.Column<int>(type: "integer", nullable: false),
IsLatest = table.Column<bool>(type: "boolean", nullable: false),
Status = table.Column<int>(type: "integer", nullable: false),
ExpiresIn = table.Column<TimeSpan>(type: "interval", nullable: true),
ExpiresAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
LastAccessedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: true),
TenantId = table.Column<string>(type: "text", nullable: true),
CreatedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
UpdatedAt = table.Column<DateTimeOffset>(type: "timestamp with time zone", nullable: false),
Owner = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Secrets", x => x.Id);
});
migrationBuilder.CreateIndex(
name: "IX_Secret_ExpiresAt",
schema: _schema.Schema,
table: "Secrets",
column: "ExpiresAt");
migrationBuilder.CreateIndex(
name: "IX_Secret_LastAccessedAt",
schema: _schema.Schema,
table: "Secrets",
column: "LastAccessedAt");
migrationBuilder.CreateIndex(
name: "IX_Secret_Name",
schema: _schema.Schema,
table: "Secrets",
column: "Name");
migrationBuilder.CreateIndex(
name: "IX_Secret_Scope",
schema: _schema.Schema,
table: "Secrets",
column: "Scope");
migrationBuilder.CreateIndex(
name: "IX_Secret_Status",
schema: _schema.Schema,
table: "Secrets",
column: "Status");
migrationBuilder.CreateIndex(
name: "IX_Secret_TenantId",
schema: _schema.Schema,
table: "Secrets",
column: "TenantId");
migrationBuilder.CreateIndex(
name: "IX_Secret_Version",
schema: _schema.Schema,
table: "Secrets",
column: "Version");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Secrets",
schema: _schema.Schema);
}
}
}

View file

@ -0,0 +1,108 @@
// <auto-generated />
using System;
using Elsa.Secrets.Persistence.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
#nullable disable
namespace Elsa.Secrets.Persistence.EntityFrameworkCore.PostgreSql.Migrations
{
[DbContext(typeof(SecretsDbContext))]
partial class SecretsDbContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasDefaultSchema("Elsa")
.HasAnnotation("ProductVersion", "7.0.20")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
modelBuilder.Entity("Elsa.Secrets.Management.Secret", b =>
{
b.Property<string>("Id")
.HasColumnType("text");
b.Property<DateTimeOffset>("CreatedAt")
.HasColumnType("timestamp with time zone");
b.Property<string>("Description")
.IsRequired()
.HasColumnType("text");
b.Property<string>("EncryptedValue")
.IsRequired()
.HasColumnType("text");
b.Property<DateTimeOffset?>("ExpiresAt")
.HasColumnType("timestamp with time zone");
b.Property<TimeSpan?>("ExpiresIn")
.HasColumnType("interval");
b.Property<bool>("IsLatest")
.HasColumnType("boolean");
b.Property<DateTimeOffset?>("LastAccessedAt")
.HasColumnType("timestamp with time zone");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("text");
b.Property<string>("Owner")
.HasColumnType("text");
b.Property<string>("Scope")
.HasColumnType("text");
b.Property<string>("SecretId")
.IsRequired()
.HasColumnType("text");
b.Property<int>("Status")
.HasColumnType("integer");
b.Property<string>("TenantId")
.HasColumnType("text");
b.Property<DateTimeOffset>("UpdatedAt")
.HasColumnType("timestamp with time zone");
b.Property<int>("Version")
.HasColumnType("integer");
b.HasKey("Id");
b.HasIndex("ExpiresAt")
.HasDatabaseName("IX_Secret_ExpiresAt");
b.HasIndex("LastAccessedAt")
.HasDatabaseName("IX_Secret_LastAccessedAt");
b.HasIndex("Name")
.HasDatabaseName("IX_Secret_Name");
b.HasIndex("Scope")
.HasDatabaseName("IX_Secret_Scope");
b.HasIndex("Status")
.HasDatabaseName("IX_Secret_Status");
b.HasIndex("TenantId")
.HasDatabaseName("IX_Secret_TenantId");
b.HasIndex("Version")
.HasDatabaseName("IX_Secret_Version");
b.ToTable("Secrets", "Elsa");
});
#pragma warning restore 612, 618
}
}
}

View file

@ -0,0 +1,23 @@
using System.Reflection;
using Elsa.EntityFrameworkCore.Common;
using Elsa.Secrets.Persistence.EntityFrameworkCore;
// ReSharper disable once CheckNamespace
namespace Elsa.EntityFrameworkCore.Extensions;
/// <summary>
/// Provides extensions to configure EF Core to use PostgreSql.
/// </summary>
public static class SecretsPostgreSqlProvidersExtensions
{
private static Assembly Assembly => typeof(SecretsPostgreSqlProvidersExtensions).Assembly;
/// <summary>
/// Configures the feature to use PostgreSql.
/// </summary>
public static EFCoreSecretPersistenceFeature UsePostgreSql(this EFCoreSecretPersistenceFeature feature, string connectionString, ElsaDbContextOptions? options = null)
{
feature.DbContextOptionsBuilder = (_, db) => db.UseElsaPostgreSql(Assembly, connectionString, options);
return feature;
}
}

View file

@ -0,0 +1 @@
ef-migration-runtime-schema --interface Elsa.EntityFrameworkCore.Common.Contracts.IElsaDbContextSchema --efOptions "migrations add V3_3 -c SecretsDbContext -o Migrations"

View file

@ -0,0 +1,21 @@
using Elsa.EntityFrameworkCore.Common.Abstractions;
using Elsa.EntityFrameworkCore.Extensions;
using Elsa.EntityFrameworkCore.Modules.Alterations;
using Elsa.EntityFrameworkCore.Modules.Identity;
using Elsa.EntityFrameworkCore.Modules.Labels;
using Elsa.EntityFrameworkCore.Modules.Management;
using Elsa.EntityFrameworkCore.Modules.Runtime;
using Elsa.EntityFrameworkCore.SqlServer;
using JetBrains.Annotations;
using Microsoft.EntityFrameworkCore;
namespace Elsa.Secrets.Persistence.EntityFrameworkCore.SqlServer;
[UsedImplicitly]
public class SqlServerSecretsDbContextFactory : SqlServerDesignTimeDbContextFactory<SecretsDbContext>
{
protected override void ConfigureBuilder(DbContextOptionsBuilder<SecretsDbContext> builder, string connectionString)
{
builder.UseElsaSqlServer(GetType().Assembly, connectionString);
}
}

View file

@ -0,0 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Description>Provides SqlServer persistence for the Elsa Secrets module using Entity Framework Core.</Description>
<PackageTags>elsa module secrets persistence efcore SqlServer</PackageTags>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" PrivateAssets="all" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Elsa.Secrets.Persistence.EntityFrameworkCore\Elsa.Secrets.Persistence.EntityFrameworkCore.csproj" />
<ProjectReference Include="..\Elsa.EntityFrameworkCore.SqlServer\Elsa.EntityFrameworkCore.SqlServer.csproj" />
</ItemGroup>
<ItemGroup>
<Folder Include="Migrations\" />
</ItemGroup>
</Project>

View file

@ -0,0 +1,3 @@
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd">
<ConfigureAwait />
</Weavers>

View file

@ -0,0 +1,111 @@
// <auto-generated />
using System;
using Elsa.Secrets.Persistence.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace Elsa.Secrets.Persistence.EntityFrameworkCore.SqlServer.Migrations
{
[DbContext(typeof(SecretsDbContext))]
[Migration("20241011092820_V3_3")]
partial class V3_3
{
/// <inheritdoc />
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasDefaultSchema("Elsa")
.HasAnnotation("ProductVersion", "7.0.20")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("Elsa.Secrets.Management.Secret", b =>
{
b.Property<string>("Id")
.HasColumnType("nvarchar(450)");
b.Property<DateTimeOffset>("CreatedAt")
.HasColumnType("datetimeoffset");
b.Property<string>("Description")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("EncryptedValue")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<DateTimeOffset?>("ExpiresAt")
.HasColumnType("datetimeoffset");
b.Property<TimeSpan?>("ExpiresIn")
.HasColumnType("time");
b.Property<bool>("IsLatest")
.HasColumnType("bit");
b.Property<DateTimeOffset?>("LastAccessedAt")
.HasColumnType("datetimeoffset");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(450)");
b.Property<string>("Owner")
.HasColumnType("nvarchar(max)");
b.Property<string>("Scope")
.HasColumnType("nvarchar(450)");
b.Property<string>("SecretId")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("Status")
.HasColumnType("int");
b.Property<string>("TenantId")
.HasColumnType("nvarchar(450)");
b.Property<DateTimeOffset>("UpdatedAt")
.HasColumnType("datetimeoffset");
b.Property<int>("Version")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("ExpiresAt")
.HasDatabaseName("IX_Secret_ExpiresAt");
b.HasIndex("LastAccessedAt")
.HasDatabaseName("IX_Secret_LastAccessedAt");
b.HasIndex("Name")
.HasDatabaseName("IX_Secret_Name");
b.HasIndex("Scope")
.HasDatabaseName("IX_Secret_Scope");
b.HasIndex("Status")
.HasDatabaseName("IX_Secret_Status");
b.HasIndex("TenantId")
.HasDatabaseName("IX_Secret_TenantId");
b.HasIndex("Version")
.HasDatabaseName("IX_Secret_Version");
b.ToTable("Secrets", "Elsa");
});
#pragma warning restore 612, 618
}
}
}

View file

@ -0,0 +1,103 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Elsa.Secrets.Persistence.EntityFrameworkCore.SqlServer.Migrations
{
/// <inheritdoc />
public partial class V3_3 : Migration
{
private readonly Elsa.EntityFrameworkCore.Common.Contracts.IElsaDbContextSchema _schema;
/// <inheritdoc />
public V3_3(Elsa.EntityFrameworkCore.Common.Contracts.IElsaDbContextSchema schema)
{
_schema = schema;
}
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.EnsureSchema(
name: _schema.Schema);
migrationBuilder.CreateTable(
name: "Secrets",
schema: _schema.Schema,
columns: table => new
{
Id = table.Column<string>(type: "nvarchar(450)", nullable: false),
SecretId = table.Column<string>(type: "nvarchar(max)", nullable: false),
Name = table.Column<string>(type: "nvarchar(450)", nullable: false),
Scope = table.Column<string>(type: "nvarchar(450)", nullable: true),
EncryptedValue = table.Column<string>(type: "nvarchar(max)", nullable: false),
Description = table.Column<string>(type: "nvarchar(max)", nullable: false),
Version = table.Column<int>(type: "int", nullable: false),
IsLatest = table.Column<bool>(type: "bit", nullable: false),
Status = table.Column<int>(type: "int", nullable: false),
ExpiresIn = table.Column<TimeSpan>(type: "time", nullable: true),
ExpiresAt = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: true),
LastAccessedAt = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: true),
TenantId = table.Column<string>(type: "nvarchar(450)", nullable: true),
CreatedAt = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: false),
UpdatedAt = table.Column<DateTimeOffset>(type: "datetimeoffset", nullable: false),
Owner = table.Column<string>(type: "nvarchar(max)", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_Secrets", x => x.Id);
});
migrationBuilder.CreateIndex(
name: "IX_Secret_ExpiresAt",
schema: _schema.Schema,
table: "Secrets",
column: "ExpiresAt");
migrationBuilder.CreateIndex(
name: "IX_Secret_LastAccessedAt",
schema: _schema.Schema,
table: "Secrets",
column: "LastAccessedAt");
migrationBuilder.CreateIndex(
name: "IX_Secret_Name",
schema: _schema.Schema,
table: "Secrets",
column: "Name");
migrationBuilder.CreateIndex(
name: "IX_Secret_Scope",
schema: _schema.Schema,
table: "Secrets",
column: "Scope");
migrationBuilder.CreateIndex(
name: "IX_Secret_Status",
schema: _schema.Schema,
table: "Secrets",
column: "Status");
migrationBuilder.CreateIndex(
name: "IX_Secret_TenantId",
schema: _schema.Schema,
table: "Secrets",
column: "TenantId");
migrationBuilder.CreateIndex(
name: "IX_Secret_Version",
schema: _schema.Schema,
table: "Secrets",
column: "Version");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "Secrets",
schema: _schema.Schema);
}
}
}

View file

@ -0,0 +1,108 @@
// <auto-generated />
using System;
using Elsa.Secrets.Persistence.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Infrastructure;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
#nullable disable
namespace Elsa.Secrets.Persistence.EntityFrameworkCore.SqlServer.Migrations
{
[DbContext(typeof(SecretsDbContext))]
partial class SecretsDbContextModelSnapshot : ModelSnapshot
{
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder
.HasDefaultSchema("Elsa")
.HasAnnotation("ProductVersion", "7.0.20")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
modelBuilder.Entity("Elsa.Secrets.Management.Secret", b =>
{
b.Property<string>("Id")
.HasColumnType("nvarchar(450)");
b.Property<DateTimeOffset>("CreatedAt")
.HasColumnType("datetimeoffset");
b.Property<string>("Description")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<string>("EncryptedValue")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<DateTimeOffset?>("ExpiresAt")
.HasColumnType("datetimeoffset");
b.Property<TimeSpan?>("ExpiresIn")
.HasColumnType("time");
b.Property<bool>("IsLatest")
.HasColumnType("bit");
b.Property<DateTimeOffset?>("LastAccessedAt")
.HasColumnType("datetimeoffset");
b.Property<string>("Name")
.IsRequired()
.HasColumnType("nvarchar(450)");
b.Property<string>("Owner")
.HasColumnType("nvarchar(max)");
b.Property<string>("Scope")
.HasColumnType("nvarchar(450)");
b.Property<string>("SecretId")
.IsRequired()
.HasColumnType("nvarchar(max)");
b.Property<int>("Status")
.HasColumnType("int");
b.Property<string>("TenantId")
.HasColumnType("nvarchar(450)");
b.Property<DateTimeOffset>("UpdatedAt")
.HasColumnType("datetimeoffset");
b.Property<int>("Version")
.HasColumnType("int");
b.HasKey("Id");
b.HasIndex("ExpiresAt")
.HasDatabaseName("IX_Secret_ExpiresAt");
b.HasIndex("LastAccessedAt")
.HasDatabaseName("IX_Secret_LastAccessedAt");
b.HasIndex("Name")
.HasDatabaseName("IX_Secret_Name");
b.HasIndex("Scope")
.HasDatabaseName("IX_Secret_Scope");
b.HasIndex("Status")
.HasDatabaseName("IX_Secret_Status");
b.HasIndex("TenantId")
.HasDatabaseName("IX_Secret_TenantId");
b.HasIndex("Version")
.HasDatabaseName("IX_Secret_Version");
b.ToTable("Secrets", "Elsa");
});
#pragma warning restore 612, 618
}
}
}

View file

@ -0,0 +1,23 @@
using System.Reflection;
using Elsa.EntityFrameworkCore.Common;
using Elsa.Secrets.Persistence.EntityFrameworkCore;
// ReSharper disable once CheckNamespace
namespace Elsa.EntityFrameworkCore.Extensions;
/// <summary>
/// Provides extensions to configure EF Core to use SqlServer.
/// </summary>
public static class SecretsSqlServerProvidersExtensions
{
private static Assembly Assembly => typeof(SecretsSqlServerProvidersExtensions).Assembly;
/// <summary>
/// Configures the feature to use SqlServer.
/// </summary>
public static EFCoreSecretPersistenceFeature UseSqlServer(this EFCoreSecretPersistenceFeature feature, string connectionString, ElsaDbContextOptions? options = null)
{
feature.UseSqlServer(Assembly, connectionString, options);
return feature;
}
}

View file

@ -0,0 +1 @@
ef-migration-runtime-schema --interface Elsa.EntityFrameworkCore.Common.Contracts.IElsaDbContextSchema --efOptions "migrations add V3_3 -c SecretsDbContext -o Migrations"