-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add design time contexts. Add migrations.
- Loading branch information
Showing
19 changed files
with
4,253 additions
and
416 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.