Add design time contexts. Add migrations.

This commit is contained in:
Jared Goodwin 2024-02-20 17:10:28 -08:00
parent 8afdd97640
commit 05a434827d
19 changed files with 4202 additions and 365 deletions

View File

@ -10,10 +10,31 @@ public interface IAppDbFactory
AppDb GetContext();
}
public class AppDbFactory(IServiceProvider _services) : IAppDbFactory
public class AppDbFactory : IAppDbFactory
{
private readonly IConfiguration _configuration;
private readonly IWebHostEnvironment _hostEnv;
public AppDbFactory(
IConfiguration configuration,
IWebHostEnvironment hostEnv)
{
_configuration = configuration;
_hostEnv = hostEnv;
}
public AppDb GetContext()
{
return _services.GetRequiredService<AppDb>();
var dbProvider = _configuration["ApplicationOptions:DbProvider"]?.ToLower();
return dbProvider switch
{
"sqlite" => new SqliteDbContext(_configuration, _hostEnv),
"sqlserver" => new SqlServerDbContext(_configuration, _hostEnv),
"postgresql" => new PostgreSqlDbContext(_configuration, _hostEnv),
"inmemory" => new TestingDbContext(_hostEnv),
_ => throw new ArgumentException("Unknown DB provider."),
};
}
}
}

View File

@ -0,0 +1,70 @@
using Microsoft.EntityFrameworkCore.Design;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.FileProviders;
namespace Remotely.Server.Data;
public class SqliteDbContextDesignTime : IDesignTimeDbContextFactory<SqliteDbContext>
{
public SqliteDbContext CreateDbContext(string[] args)
{
var appSettings = new Dictionary<string, string?>
{
["ConnectionStrings:SQLite"] = "Data Source=remotely.db",
["ApplicationOptions:DbProvider"] = "sqlite"
};
var configuration = new ConfigurationBuilder()
.AddInMemoryCollection(appSettings)
.Build();
return new SqliteDbContext(configuration, new DesignTimeWebHostEnvironment());
}
}
public class SqlServerDbContextDesignTime : IDesignTimeDbContextFactory<SqlServerDbContext>
{
public SqlServerDbContext CreateDbContext(string[] args)
{
var appSettings = new Dictionary<string, string?>
{
["ConnectionStrings:SqlServer"] = "Server=(localdb)\\mssqllocaldb;Database=Remotely-Server-53bc9b9d-9d6a-45d4-8429-2a2761773502;Trusted_Connection=True;MultipleActiveResultSets=true",
["ApplicationOptions:DbProvider"] = "SqlServer"
};
var configuration = new ConfigurationBuilder()
.AddInMemoryCollection(appSettings)
.Build();
return new SqlServerDbContext(configuration, new DesignTimeWebHostEnvironment());
}
}
public class PostgreSqlDbContextDesignTime : IDesignTimeDbContextFactory<PostgreSqlDbContext>
{
public PostgreSqlDbContext CreateDbContext(string[] args)
{
var appSettings = new Dictionary<string, string?>
{
["ConnectionStrings:PostgreSql"] = "Host=localhost;Database=Remotely;Username=postgres;",
["ApplicationOptions:DbProvider"] = "PostgreSql"
};
var configuration = new ConfigurationBuilder()
.AddInMemoryCollection(appSettings)
.Build();
return new PostgreSqlDbContext(configuration, new DesignTimeWebHostEnvironment());
}
}
public class DesignTimeWebHostEnvironment : IWebHostEnvironment
{
public string WebRootPath { get; set; } = string.Empty;
public IFileProvider WebRootFileProvider { get; set; } = default!;
public string ApplicationName { get; set; } = string.Empty;
public IFileProvider ContentRootFileProvider { get; set; } = default!;
public string ContentRootPath { get; set; } = string.Empty;
public string EnvironmentName { get; set; } = "Development";
}

View File

@ -1,12 +1,4 @@
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Identity.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Diagnostics;
using Microsoft.Extensions.Configuration;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
namespace Remotely.Server.Data;
@ -25,4 +17,4 @@ public class SqliteDbContext : AppDb
options.UseSqlite(_configuration.GetConnectionString("SQLite"));
base.OnConfiguring(options);
}
}
}

View File

@ -2,116 +2,115 @@
#nullable disable
namespace Remotely.Server.Migrations.PostgreSql
namespace Remotely.Server.Migrations.PostgreSql;
/// <inheritdoc />
public partial class Remove_TitleBranding : Migration
{
/// <inheritdoc />
public partial class Remove_TitleBranding : Migration
protected override void Up(MigrationBuilder migrationBuilder)
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "ButtonForegroundBlue",
table: "BrandingInfos");
migrationBuilder.DropColumn(
name: "ButtonForegroundBlue",
table: "BrandingInfos");
migrationBuilder.DropColumn(
name: "ButtonForegroundGreen",
table: "BrandingInfos");
migrationBuilder.DropColumn(
name: "ButtonForegroundGreen",
table: "BrandingInfos");
migrationBuilder.DropColumn(
name: "ButtonForegroundRed",
table: "BrandingInfos");
migrationBuilder.DropColumn(
name: "ButtonForegroundRed",
table: "BrandingInfos");
migrationBuilder.DropColumn(
name: "TitleBackgroundBlue",
table: "BrandingInfos");
migrationBuilder.DropColumn(
name: "TitleBackgroundBlue",
table: "BrandingInfos");
migrationBuilder.DropColumn(
name: "TitleBackgroundGreen",
table: "BrandingInfos");
migrationBuilder.DropColumn(
name: "TitleBackgroundGreen",
table: "BrandingInfos");
migrationBuilder.DropColumn(
name: "TitleBackgroundRed",
table: "BrandingInfos");
migrationBuilder.DropColumn(
name: "TitleBackgroundRed",
table: "BrandingInfos");
migrationBuilder.DropColumn(
name: "TitleForegroundBlue",
table: "BrandingInfos");
migrationBuilder.DropColumn(
name: "TitleForegroundBlue",
table: "BrandingInfos");
migrationBuilder.DropColumn(
name: "TitleForegroundGreen",
table: "BrandingInfos");
migrationBuilder.DropColumn(
name: "TitleForegroundGreen",
table: "BrandingInfos");
migrationBuilder.DropColumn(
name: "TitleForegroundRed",
table: "BrandingInfos");
}
migrationBuilder.DropColumn(
name: "TitleForegroundRed",
table: "BrandingInfos");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<byte>(
name: "ButtonForegroundBlue",
table: "BrandingInfos",
type: "smallint",
nullable: false,
defaultValue: (byte)0);
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<byte>(
name: "ButtonForegroundBlue",
table: "BrandingInfos",
type: "smallint",
nullable: false,
defaultValue: (byte)0);
migrationBuilder.AddColumn<byte>(
name: "ButtonForegroundGreen",
table: "BrandingInfos",
type: "smallint",
nullable: false,
defaultValue: (byte)0);
migrationBuilder.AddColumn<byte>(
name: "ButtonForegroundGreen",
table: "BrandingInfos",
type: "smallint",
nullable: false,
defaultValue: (byte)0);
migrationBuilder.AddColumn<byte>(
name: "ButtonForegroundRed",
table: "BrandingInfos",
type: "smallint",
nullable: false,
defaultValue: (byte)0);
migrationBuilder.AddColumn<byte>(
name: "ButtonForegroundRed",
table: "BrandingInfos",
type: "smallint",
nullable: false,
defaultValue: (byte)0);
migrationBuilder.AddColumn<byte>(
name: "TitleBackgroundBlue",
table: "BrandingInfos",
type: "smallint",
nullable: false,
defaultValue: (byte)0);
migrationBuilder.AddColumn<byte>(
name: "TitleBackgroundBlue",
table: "BrandingInfos",
type: "smallint",
nullable: false,
defaultValue: (byte)0);
migrationBuilder.AddColumn<byte>(
name: "TitleBackgroundGreen",
table: "BrandingInfos",
type: "smallint",
nullable: false,
defaultValue: (byte)0);
migrationBuilder.AddColumn<byte>(
name: "TitleBackgroundGreen",
table: "BrandingInfos",
type: "smallint",
nullable: false,
defaultValue: (byte)0);
migrationBuilder.AddColumn<byte>(
name: "TitleBackgroundRed",
table: "BrandingInfos",
type: "smallint",
nullable: false,
defaultValue: (byte)0);
migrationBuilder.AddColumn<byte>(
name: "TitleBackgroundRed",
table: "BrandingInfos",
type: "smallint",
nullable: false,
defaultValue: (byte)0);
migrationBuilder.AddColumn<byte>(
name: "TitleForegroundBlue",
table: "BrandingInfos",
type: "smallint",
nullable: false,
defaultValue: (byte)0);
migrationBuilder.AddColumn<byte>(
name: "TitleForegroundBlue",
table: "BrandingInfos",
type: "smallint",
nullable: false,
defaultValue: (byte)0);
migrationBuilder.AddColumn<byte>(
name: "TitleForegroundGreen",
table: "BrandingInfos",
type: "smallint",
nullable: false,
defaultValue: (byte)0);
migrationBuilder.AddColumn<byte>(
name: "TitleForegroundGreen",
table: "BrandingInfos",
type: "smallint",
nullable: false,
defaultValue: (byte)0);
migrationBuilder.AddColumn<byte>(
name: "TitleForegroundRed",
table: "BrandingInfos",
type: "smallint",
nullable: false,
defaultValue: (byte)0);
}
migrationBuilder.AddColumn<byte>(
name: "TitleForegroundRed",
table: "BrandingInfos",
type: "smallint",
nullable: false,
defaultValue: (byte)0);
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,51 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Remotely.Server.Migrations.PostgreSql;
/// <inheritdoc />
public partial class Add_KeyValueRecords : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "Discriminator",
table: "RemotelyUsers",
type: "character varying(13)",
maxLength: 13,
nullable: false,
oldClrType: typeof(string),
oldType: "text");
migrationBuilder.CreateTable(
name: "KeyValueRecords",
columns: table => new
{
Key = table.Column<Guid>(type: "uuid", nullable: false),
Value = table.Column<string>(type: "text", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_KeyValueRecords", x => x.Key);
});
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "KeyValueRecords");
migrationBuilder.AlterColumn<string>(
name: "Discriminator",
table: "RemotelyUsers",
type: "text",
nullable: false,
oldClrType: typeof(string),
oldType: "character varying(13)",
oldMaxLength: 13);
}
}

View File

@ -17,7 +17,7 @@ namespace Remotely.Server.Migrations.PostgreSql
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.10")
.HasAnnotation("ProductVersion", "8.0.2")
.HasAnnotation("Relational:MaxIdentifierLength", 63);
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
@ -147,7 +147,8 @@ namespace Remotely.Server.Migrations.PostgreSql
b.Property<string>("Discriminator")
.IsRequired()
.HasColumnType("text");
.HasMaxLength(13)
.HasColumnType("character varying(13)");
b.Property<string>("Email")
.HasMaxLength(256)
@ -521,6 +522,20 @@ namespace Remotely.Server.Migrations.PostgreSql
b.ToTable("InviteLinks");
});
modelBuilder.Entity("Remotely.Shared.Entities.KeyValueRecord", b =>
{
b.Property<Guid>("Key")
.ValueGeneratedOnAdd()
.HasColumnType("uuid");
b.Property<string>("Value")
.HasColumnType("text");
b.HasKey("Key");
b.ToTable("KeyValueRecords");
});
modelBuilder.Entity("Remotely.Shared.Entities.Organization", b =>
{
b.Property<string>("ID")

View File

@ -2,116 +2,115 @@
#nullable disable
namespace Remotely.Server.Migrations.SqlServer
namespace Remotely.Server.Migrations.SqlServer;
/// <inheritdoc />
public partial class Remove_TitleBranding : Migration
{
/// <inheritdoc />
public partial class Remove_TitleBranding : Migration
protected override void Up(MigrationBuilder migrationBuilder)
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "ButtonForegroundBlue",
table: "BrandingInfos");
migrationBuilder.DropColumn(
name: "ButtonForegroundBlue",
table: "BrandingInfos");
migrationBuilder.DropColumn(
name: "ButtonForegroundGreen",
table: "BrandingInfos");
migrationBuilder.DropColumn(
name: "ButtonForegroundGreen",
table: "BrandingInfos");
migrationBuilder.DropColumn(
name: "ButtonForegroundRed",
table: "BrandingInfos");
migrationBuilder.DropColumn(
name: "ButtonForegroundRed",
table: "BrandingInfos");
migrationBuilder.DropColumn(
name: "TitleBackgroundBlue",
table: "BrandingInfos");
migrationBuilder.DropColumn(
name: "TitleBackgroundBlue",
table: "BrandingInfos");
migrationBuilder.DropColumn(
name: "TitleBackgroundGreen",
table: "BrandingInfos");
migrationBuilder.DropColumn(
name: "TitleBackgroundGreen",
table: "BrandingInfos");
migrationBuilder.DropColumn(
name: "TitleBackgroundRed",
table: "BrandingInfos");
migrationBuilder.DropColumn(
name: "TitleBackgroundRed",
table: "BrandingInfos");
migrationBuilder.DropColumn(
name: "TitleForegroundBlue",
table: "BrandingInfos");
migrationBuilder.DropColumn(
name: "TitleForegroundBlue",
table: "BrandingInfos");
migrationBuilder.DropColumn(
name: "TitleForegroundGreen",
table: "BrandingInfos");
migrationBuilder.DropColumn(
name: "TitleForegroundGreen",
table: "BrandingInfos");
migrationBuilder.DropColumn(
name: "TitleForegroundRed",
table: "BrandingInfos");
}
migrationBuilder.DropColumn(
name: "TitleForegroundRed",
table: "BrandingInfos");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<byte>(
name: "ButtonForegroundBlue",
table: "BrandingInfos",
type: "tinyint",
nullable: false,
defaultValue: (byte)0);
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<byte>(
name: "ButtonForegroundBlue",
table: "BrandingInfos",
type: "tinyint",
nullable: false,
defaultValue: (byte)0);
migrationBuilder.AddColumn<byte>(
name: "ButtonForegroundGreen",
table: "BrandingInfos",
type: "tinyint",
nullable: false,
defaultValue: (byte)0);
migrationBuilder.AddColumn<byte>(
name: "ButtonForegroundGreen",
table: "BrandingInfos",
type: "tinyint",
nullable: false,
defaultValue: (byte)0);
migrationBuilder.AddColumn<byte>(
name: "ButtonForegroundRed",
table: "BrandingInfos",
type: "tinyint",
nullable: false,
defaultValue: (byte)0);
migrationBuilder.AddColumn<byte>(
name: "ButtonForegroundRed",
table: "BrandingInfos",
type: "tinyint",
nullable: false,
defaultValue: (byte)0);
migrationBuilder.AddColumn<byte>(
name: "TitleBackgroundBlue",
table: "BrandingInfos",
type: "tinyint",
nullable: false,
defaultValue: (byte)0);
migrationBuilder.AddColumn<byte>(
name: "TitleBackgroundBlue",
table: "BrandingInfos",
type: "tinyint",
nullable: false,
defaultValue: (byte)0);
migrationBuilder.AddColumn<byte>(
name: "TitleBackgroundGreen",
table: "BrandingInfos",
type: "tinyint",
nullable: false,
defaultValue: (byte)0);
migrationBuilder.AddColumn<byte>(
name: "TitleBackgroundGreen",
table: "BrandingInfos",
type: "tinyint",
nullable: false,
defaultValue: (byte)0);
migrationBuilder.AddColumn<byte>(
name: "TitleBackgroundRed",
table: "BrandingInfos",
type: "tinyint",
nullable: false,
defaultValue: (byte)0);
migrationBuilder.AddColumn<byte>(
name: "TitleBackgroundRed",
table: "BrandingInfos",
type: "tinyint",
nullable: false,
defaultValue: (byte)0);
migrationBuilder.AddColumn<byte>(
name: "TitleForegroundBlue",
table: "BrandingInfos",
type: "tinyint",
nullable: false,
defaultValue: (byte)0);
migrationBuilder.AddColumn<byte>(
name: "TitleForegroundBlue",
table: "BrandingInfos",
type: "tinyint",
nullable: false,
defaultValue: (byte)0);
migrationBuilder.AddColumn<byte>(
name: "TitleForegroundGreen",
table: "BrandingInfos",
type: "tinyint",
nullable: false,
defaultValue: (byte)0);
migrationBuilder.AddColumn<byte>(
name: "TitleForegroundGreen",
table: "BrandingInfos",
type: "tinyint",
nullable: false,
defaultValue: (byte)0);
migrationBuilder.AddColumn<byte>(
name: "TitleForegroundRed",
table: "BrandingInfos",
type: "tinyint",
nullable: false,
defaultValue: (byte)0);
}
migrationBuilder.AddColumn<byte>(
name: "TitleForegroundRed",
table: "BrandingInfos",
type: "tinyint",
nullable: false,
defaultValue: (byte)0);
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,51 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Remotely.Server.Migrations.SqlServer;
/// <inheritdoc />
public partial class Add_KeyValueRecords : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.AlterColumn<string>(
name: "Discriminator",
table: "RemotelyUsers",
type: "nvarchar(13)",
maxLength: 13,
nullable: false,
oldClrType: typeof(string),
oldType: "nvarchar(max)");
migrationBuilder.CreateTable(
name: "KeyValueRecords",
columns: table => new
{
Key = table.Column<Guid>(type: "uniqueidentifier", nullable: false),
Value = table.Column<string>(type: "nvarchar(max)", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_KeyValueRecords", x => x.Key);
});
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "KeyValueRecords");
migrationBuilder.AlterColumn<string>(
name: "Discriminator",
table: "RemotelyUsers",
type: "nvarchar(max)",
nullable: false,
oldClrType: typeof(string),
oldType: "nvarchar(13)",
oldMaxLength: 13);
}
}

View File

@ -17,7 +17,7 @@ namespace Remotely.Server.Migrations.SqlServer
{
#pragma warning disable 612, 618
modelBuilder
.HasAnnotation("ProductVersion", "7.0.10")
.HasAnnotation("ProductVersion", "8.0.2")
.HasAnnotation("Relational:MaxIdentifierLength", 128);
SqlServerModelBuilderExtensions.UseIdentityColumns(modelBuilder);
@ -148,7 +148,8 @@ namespace Remotely.Server.Migrations.SqlServer
b.Property<string>("Discriminator")
.IsRequired()
.HasColumnType("nvarchar(max)");
.HasMaxLength(13)
.HasColumnType("nvarchar(13)");
b.Property<string>("Email")
.HasMaxLength(256)
@ -524,6 +525,20 @@ namespace Remotely.Server.Migrations.SqlServer
b.ToTable("InviteLinks");
});
modelBuilder.Entity("Remotely.Shared.Entities.KeyValueRecord", b =>
{
b.Property<Guid>("Key")
.ValueGeneratedOnAdd()
.HasColumnType("uniqueidentifier");
b.Property<string>("Value")
.HasColumnType("nvarchar(max)");
b.HasKey("Key");
b.ToTable("KeyValueRecords");
});
modelBuilder.Entity("Remotely.Shared.Entities.Organization", b =>
{
b.Property<string>("ID")

View File

@ -2,116 +2,115 @@
#nullable disable
namespace Remotely.Server.Migrations.Sqlite
namespace Remotely.Server.Migrations.Sqlite;
/// <inheritdoc />
public partial class Remove_TitleBranding : Migration
{
/// <inheritdoc />
public partial class Remove_TitleBranding : Migration
protected override void Up(MigrationBuilder migrationBuilder)
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropColumn(
name: "ButtonForegroundBlue",
table: "BrandingInfos");
migrationBuilder.DropColumn(
name: "ButtonForegroundBlue",
table: "BrandingInfos");
migrationBuilder.DropColumn(
name: "ButtonForegroundGreen",
table: "BrandingInfos");
migrationBuilder.DropColumn(
name: "ButtonForegroundGreen",
table: "BrandingInfos");
migrationBuilder.DropColumn(
name: "ButtonForegroundRed",
table: "BrandingInfos");
migrationBuilder.DropColumn(
name: "ButtonForegroundRed",
table: "BrandingInfos");
migrationBuilder.DropColumn(
name: "TitleBackgroundBlue",
table: "BrandingInfos");
migrationBuilder.DropColumn(
name: "TitleBackgroundBlue",
table: "BrandingInfos");
migrationBuilder.DropColumn(
name: "TitleBackgroundGreen",
table: "BrandingInfos");
migrationBuilder.DropColumn(
name: "TitleBackgroundGreen",
table: "BrandingInfos");
migrationBuilder.DropColumn(
name: "TitleBackgroundRed",
table: "BrandingInfos");
migrationBuilder.DropColumn(
name: "TitleBackgroundRed",
table: "BrandingInfos");
migrationBuilder.DropColumn(
name: "TitleForegroundBlue",
table: "BrandingInfos");
migrationBuilder.DropColumn(
name: "TitleForegroundBlue",
table: "BrandingInfos");
migrationBuilder.DropColumn(
name: "TitleForegroundGreen",
table: "BrandingInfos");
migrationBuilder.DropColumn(
name: "TitleForegroundGreen",
table: "BrandingInfos");
migrationBuilder.DropColumn(
name: "TitleForegroundRed",
table: "BrandingInfos");
}
migrationBuilder.DropColumn(
name: "TitleForegroundRed",
table: "BrandingInfos");
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<byte>(
name: "ButtonForegroundBlue",
table: "BrandingInfos",
type: "INTEGER",
nullable: false,
defaultValue: (byte)0);
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.AddColumn<byte>(
name: "ButtonForegroundBlue",
table: "BrandingInfos",
type: "INTEGER",
nullable: false,
defaultValue: (byte)0);
migrationBuilder.AddColumn<byte>(
name: "ButtonForegroundGreen",
table: "BrandingInfos",
type: "INTEGER",
nullable: false,
defaultValue: (byte)0);
migrationBuilder.AddColumn<byte>(
name: "ButtonForegroundGreen",
table: "BrandingInfos",
type: "INTEGER",
nullable: false,
defaultValue: (byte)0);
migrationBuilder.AddColumn<byte>(
name: "ButtonForegroundRed",
table: "BrandingInfos",
type: "INTEGER",
nullable: false,
defaultValue: (byte)0);
migrationBuilder.AddColumn<byte>(
name: "ButtonForegroundRed",
table: "BrandingInfos",
type: "INTEGER",
nullable: false,
defaultValue: (byte)0);
migrationBuilder.AddColumn<byte>(
name: "TitleBackgroundBlue",
table: "BrandingInfos",
type: "INTEGER",
nullable: false,
defaultValue: (byte)0);
migrationBuilder.AddColumn<byte>(
name: "TitleBackgroundBlue",
table: "BrandingInfos",
type: "INTEGER",
nullable: false,
defaultValue: (byte)0);
migrationBuilder.AddColumn<byte>(
name: "TitleBackgroundGreen",
table: "BrandingInfos",
type: "INTEGER",
nullable: false,
defaultValue: (byte)0);
migrationBuilder.AddColumn<byte>(
name: "TitleBackgroundGreen",
table: "BrandingInfos",
type: "INTEGER",
nullable: false,
defaultValue: (byte)0);
migrationBuilder.AddColumn<byte>(
name: "TitleBackgroundRed",
table: "BrandingInfos",
type: "INTEGER",
nullable: false,
defaultValue: (byte)0);
migrationBuilder.AddColumn<byte>(
name: "TitleBackgroundRed",
table: "BrandingInfos",
type: "INTEGER",
nullable: false,
defaultValue: (byte)0);
migrationBuilder.AddColumn<byte>(
name: "TitleForegroundBlue",
table: "BrandingInfos",
type: "INTEGER",
nullable: false,
defaultValue: (byte)0);
migrationBuilder.AddColumn<byte>(
name: "TitleForegroundBlue",
table: "BrandingInfos",
type: "INTEGER",
nullable: false,
defaultValue: (byte)0);
migrationBuilder.AddColumn<byte>(
name: "TitleForegroundGreen",
table: "BrandingInfos",
type: "INTEGER",
nullable: false,
defaultValue: (byte)0);
migrationBuilder.AddColumn<byte>(
name: "TitleForegroundGreen",
table: "BrandingInfos",
type: "INTEGER",
nullable: false,
defaultValue: (byte)0);
migrationBuilder.AddColumn<byte>(
name: "TitleForegroundRed",
table: "BrandingInfos",
type: "INTEGER",
nullable: false,
defaultValue: (byte)0);
}
migrationBuilder.AddColumn<byte>(
name: "TitleForegroundRed",
table: "BrandingInfos",
type: "INTEGER",
nullable: false,
defaultValue: (byte)0);
}
}

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,33 @@
using System;
using Microsoft.EntityFrameworkCore.Migrations;
#nullable disable
namespace Remotely.Server.Migrations.Sqlite;
/// <inheritdoc />
public partial class Add_KeyValueRecords : Migration
{
/// <inheritdoc />
protected override void Up(MigrationBuilder migrationBuilder)
{
migrationBuilder.CreateTable(
name: "KeyValueRecords",
columns: table => new
{
Key = table.Column<Guid>(type: "TEXT", nullable: false),
Value = table.Column<string>(type: "TEXT", nullable: true)
},
constraints: table =>
{
table.PrimaryKey("PK_KeyValueRecords", x => x.Key);
});
}
/// <inheritdoc />
protected override void Down(MigrationBuilder migrationBuilder)
{
migrationBuilder.DropTable(
name: "KeyValueRecords");
}
}

View File

@ -15,7 +15,7 @@ namespace Remotely.Server.Migrations.Sqlite
protected override void BuildModel(ModelBuilder modelBuilder)
{
#pragma warning disable 612, 618
modelBuilder.HasAnnotation("ProductVersion", "7.0.10");
modelBuilder.HasAnnotation("ProductVersion", "8.0.2");
modelBuilder.Entity("DeviceGroupRemotelyUser", b =>
{
@ -140,6 +140,7 @@ namespace Remotely.Server.Migrations.Sqlite
b.Property<string>("Discriminator")
.IsRequired()
.HasMaxLength(13)
.HasColumnType("TEXT");
b.Property<string>("Email")
@ -515,6 +516,20 @@ namespace Remotely.Server.Migrations.Sqlite
b.ToTable("InviteLinks");
});
modelBuilder.Entity("Remotely.Shared.Entities.KeyValueRecord", b =>
{
b.Property<Guid>("Key")
.ValueGeneratedOnAdd()
.HasColumnType("TEXT");
b.Property<string>("Value")
.HasColumnType("TEXT");
b.HasKey("Key");
b.ToTable("KeyValueRecords");
});
modelBuilder.Entity("Remotely.Shared.Entities.Organization", b =>
{
b.Property<string>("ID")

View File

@ -72,19 +72,6 @@ switch (dbProvider)
$"is set in appsettings.json or environment variables.");
}
if (dbProvider == "sqlite")
{
services.AddDbContext<AppDb, SqliteDbContext>();
}
else if (dbProvider == "sqlserver")
{
services.AddDbContext<AppDb, SqlServerDbContext>();
}
else if (dbProvider == "postgresql")
{
services.AddDbContext<AppDb, PostgreSqlDbContext>();
}
using AppDb appDb = dbProvider switch
{
"sqlite" => new SqliteDbContext(builder.Configuration, builder.Environment),
@ -227,7 +214,7 @@ else
{
services.AddScoped<IEmailSenderEx, EmailSenderEx>();
}
services.AddScoped<IAppDbFactory, AppDbFactory>();
services.AddSingleton<IAppDbFactory, AppDbFactory>();
services.AddTransient<IDataService, DataService>();
services.AddScoped<ApiAuthorizationFilter>();
services.AddScoped<LocalOnlyFilter>();

View File

@ -20,6 +20,6 @@
}
},
"ApplicationOptions": {
"DBProvider": "SQLite"
"DbProvider": "SQLite"
}
}
}

View File

@ -9,24 +9,6 @@ if (!$MigrationName) {
$ErrorActionPreference = "Stop"
function Replace-LineInFile($FilePath, $MatchPattern, $ReplaceLineWith, $MaxCount = -1){
$FullPath = (Get-Item -Path $FilePath).FullName
[string[]]$Content = Get-Content -Path $FullPath
$Count = 0
for ($i = 0; $i -lt $Content.Length; $i++)
{
if ($Content[$i] -ne $null -and $Content[$i].Contains($MatchPattern)) {
$Content[$i] = $ReplaceLineWith
$Count++
}
if ($MaxCount -gt 0 -and $Count -ge $MaxCount) {
break
}
}
[System.IO.File]::WriteAllLines($FullPath, $Content)
}
if ($PSScriptRoot) {
$Root = (Get-Item -Path $PSScriptRoot).Parent.FullName + "\Server"
}
@ -34,20 +16,10 @@ else {
$Root = (Get-Item -Path (Get-Location).Path).Parent.FullName + "\Server"
}
Push-Location "$Root"
Replace-LineInFile -FilePath "$Root\appsettings.json" -MatchPattern '"DBProvider":' -ReplaceLineWith ' "DBProvider": "SQLite",' -MaxCount 1
Push-Location $Root
dotnet ef migrations add $MigrationName --context "SqliteDbContext"
Replace-LineInFile -FilePath "$Root\appsettings.json" -MatchPattern '"DBProvider":' -ReplaceLineWith ' "DBProvider": "SQLServer",' -MaxCount 1
dotnet ef migrations add $MigrationName --context "SqlServerDbContext"
Replace-LineInFile -FilePath "$Root\appsettings.json" -MatchPattern '"DBProvider":' -ReplaceLineWith ' "DBProvider": "PostgreSQL",' -MaxCount 1
dotnet ef migrations add $MigrationName --context "PostgreSqlDbContext"
Replace-LineInFile -FilePath "$Root\appsettings.json" -MatchPattern '"DBProvider":' -ReplaceLineWith ' "DBProvider": "SQLite",' -MaxCount 1
Pop-Location

View File

@ -1,24 +1,5 @@
$ErrorActionPreference = "Stop"
function Replace-LineInFile($FilePath, $MatchPattern, $ReplaceLineWith, $MaxCount = -1){
$FullPath = (Get-Item -Path $FilePath).FullName
[string[]]$Content = Get-Content -Path $FullPath
$Count = 0
for ($i = 0; $i -lt $Content.Length; $i++)
{
if ($Content[$i] -ne $null -and $Content[$i].Contains($MatchPattern)) {
$Content[$i] = $ReplaceLineWith
$Count++
}
if ($MaxCount -gt 0 -and $Count -ge $MaxCount) {
break
}
}
[System.IO.File]::WriteAllLines($FullPath, $Content)
}
if ($PSScriptRoot) {
$Root = (Get-Item -Path $PSScriptRoot).Parent.FullName + "\Server"
}
@ -28,18 +9,8 @@ else {
Push-Location "$Root"
Replace-LineInFile -FilePath "$Root\appsettings.json" -MatchPattern '"DBProvider":' -ReplaceLineWith ' "DBProvider": "SQLite",' -MaxCount 1
dotnet ef migrations remove --context "SqliteDbContext"
Replace-LineInFile -FilePath "$Root\appsettings.json" -MatchPattern '"DBProvider":' -ReplaceLineWith ' "DBProvider": "SQLServer",' -MaxCount 1
dotnet ef migrations remove --context "SqlServerDbContext"
Replace-LineInFile -FilePath "$Root\appsettings.json" -MatchPattern '"DBProvider":' -ReplaceLineWith ' "DBProvider": "PostgreSQL",' -MaxCount 1
dotnet ef migrations remove --context "PostgreSqlDbContext"
Replace-LineInFile -FilePath "$Root\appsettings.json" -MatchPattern '"DBProvider":' -ReplaceLineWith ' "DBProvider": "SQLite",' -MaxCount 1
Pop-Location