1
0
mirror of https://github.com/bitwarden/server.git synced 2025-04-05 05:00:19 -05:00

Migration Fix (#1448)

* created stubs for missing ef provider methods

* fixed the initial postgres migration
This commit is contained in:
Addison Beck 2021-07-08 15:46:13 -04:00 committed by GitHub
parent b13dda2799
commit 4a828ad440
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 318 additions and 344 deletions

View File

@ -20,6 +20,11 @@ namespace Bit.Core.Repositories.EntityFramework
: base(serviceScopeFactory, mapper, (DatabaseContext context) => context.ProviderOrganizations)
{ }
public Task<ICollection<ProviderOrganization>> GetManyByUserIdAsync(Guid userId)
{
throw new NotImplementedException();
}
public async Task<ICollection<ProviderOrganizationOrganizationDetails>> GetManyDetailsByProviderAsync(Guid providerId)
{
using (var scope = ServiceScopeFactory.CreateScope())

View File

@ -140,5 +140,10 @@ namespace Bit.Core.Repositories.EntityFramework
return data;
}
}
public Task<IEnumerable<ProviderUserOrganizationDetails>> GetManyOrganizationDetailsByUserAsync(Guid userId, ProviderUserStatusType? status = null)
{
throw new NotImplementedException();
}
}
}

View File

@ -26,42 +26,15 @@ namespace MySqlMigrations
{
var globalSettings = GlobalSettingsFactory.GlobalSettings;
var optionsBuilder = new DbContextOptionsBuilder<DatabaseContext>();
var selectedDatabaseProvider = globalSettings.DatabaseProvider;
var provider = SupportedDatabaseProviders.Postgres;
var connectionString = string.Empty;
if (!string.IsNullOrWhiteSpace(selectedDatabaseProvider))
var connectionString = globalSettings.MySql?.ConnectionString;
if (string.IsNullOrWhiteSpace(connectionString))
{
switch (selectedDatabaseProvider.ToLowerInvariant())
{
case "postgres":
case "postgresql":
provider = SupportedDatabaseProviders.Postgres;
connectionString = globalSettings.PostgreSql.ConnectionString;
break;
case "mysql":
case "mariadb":
provider = SupportedDatabaseProviders.MySql;
connectionString = globalSettings.MySql.ConnectionString;
break;
default:
throw new Exception("No database provider selected");
break;
throw new Exception("No MySql connection string found.");
}
}
if (provider.Equals(SupportedDatabaseProviders.Postgres))
{
optionsBuilder.UseNpgsql(
connectionString,
b => b.MigrationsAssembly("PostgresMigrations"));
}
else if (provider.Equals(SupportedDatabaseProviders.MySql))
{
optionsBuilder.UseMySql(
connectionString,
ServerVersion.AutoDetect(connectionString),
b => b.MigrationsAssembly("MySqlMigrations"));
}
return new DatabaseContext(optionsBuilder.Options);
}
}

View File

@ -26,42 +26,14 @@ namespace MySqlMigrations
{
var globalSettings = GlobalSettingsFactory.GlobalSettings;
var optionsBuilder = new DbContextOptionsBuilder<DatabaseContext>();
var selectedDatabaseProvider = globalSettings.DatabaseProvider;
var provider = SupportedDatabaseProviders.Postgres;
var connectionString = string.Empty;
if (!string.IsNullOrWhiteSpace(selectedDatabaseProvider))
var connectionString = globalSettings.PostgreSql?.ConnectionString;
if (string.IsNullOrWhiteSpace(connectionString))
{
switch (selectedDatabaseProvider.ToLowerInvariant())
{
case "postgres":
case "postgresql":
provider = SupportedDatabaseProviders.Postgres;
connectionString = globalSettings.PostgreSql.ConnectionString;
break;
case "mysql":
case "mariadb":
provider = SupportedDatabaseProviders.MySql;
connectionString = globalSettings.MySql.ConnectionString;
break;
default:
throw new Exception("No database provider selected");
break;
throw new Exception("No Postgres connection string found.");
}
}
if (provider.Equals(SupportedDatabaseProviders.Postgres))
{
optionsBuilder.UseNpgsql(
connectionString,
b => b.MigrationsAssembly("PostgresMigrations"));
}
else if (provider.Equals(SupportedDatabaseProviders.MySql))
{
optionsBuilder.UseMySql(
connectionString,
ServerVersion.AutoDetect(connectionString),
b => b.MigrationsAssembly("MySqlMigrations"));
}
return new DatabaseContext(optionsBuilder.Options);
}
}

View File

@ -7,11 +7,11 @@ using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace Bit.EntityFrameworkMigrations.Migrations
namespace Bit.PostgresMigrations.Migrations
{
[DbContext(typeof(DatabaseContext))]
[Migration("20210617163014_Postgres_Init")]
partial class Postgres_Init
[Migration("20210708191531_Init")]
partial class Init
{
protected override void BuildTargetModel(ModelBuilder modelBuilder)
{
@ -699,6 +699,9 @@ namespace Bit.EntityFrameworkMigrations.Migrations
b.Property<byte>("Status")
.HasColumnType("smallint");
b.Property<bool>("UseEvents")
.HasColumnType("boolean");
b.HasKey("Id");
b.ToTable("Provider");

View File

@ -2,9 +2,9 @@
using Microsoft.EntityFrameworkCore.Migrations;
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
namespace Bit.EntityFrameworkMigrations.Migrations
namespace Bit.PostgresMigrations.Migrations
{
public partial class Postgres_Init : Migration
public partial class Init : Migration
{
protected override void Up(MigrationBuilder migrationBuilder)
{
@ -133,6 +133,7 @@ namespace Bit.EntityFrameworkMigrations.Migrations
BusinessTaxNumber = table.Column<string>(type: "text", nullable: true),
BillingEmail = table.Column<string>(type: "text", nullable: true),
Status = table.Column<byte>(type: "smallint", nullable: false),
UseEvents = table.Column<bool>(type: "boolean", nullable: false),
Enabled = table.Column<bool>(type: "boolean", nullable: false),
CreationDate = table.Column<DateTime>(type: "timestamp without time zone", nullable: false),
RevisionDate = table.Column<DateTime>(type: "timestamp without time zone", nullable: false)

View File

@ -107,6 +107,7 @@ CREATE TABLE "Provider" (
"BusinessTaxNumber" text NULL,
"BillingEmail" text NULL,
"Status" smallint NOT NULL,
"UseEvents" boolean NOT NULL,
"Enabled" boolean NOT NULL,
"CreationDate" timestamp without time zone NOT NULL,
"RevisionDate" timestamp without time zone NOT NULL,
@ -489,6 +490,8 @@ CREATE INDEX "IX_Transaction_UserId" ON "Transaction" ("UserId");
CREATE INDEX "IX_U2f_UserId" ON "U2f" ("UserId");
INSERT INTO "__EFMigrationsHistory" ("MigrationId", "ProductVersion")
VALUES ('20210617163014_Postgres_Init', '5.0.5');
VALUES ('20210708191531_Init', '5.0.5');
COMMIT;