-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
42d31bd
commit 50b7ae5
Showing
4 changed files
with
194 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<OutputType>Exe</OutputType> | ||
<TargetFramework>net7.0</TargetFramework> | ||
<ImplicitUsings>enable</ImplicitUsings> | ||
<Nullable>enable</Nullable> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.3" /> | ||
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="7.0.0" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="..\Maple2.Database\Maple2.Database.csproj" /> | ||
<ProjectReference Include="..\Maple2.Tools\Maple2.Tools.csproj" /> | ||
</ItemGroup> | ||
|
||
</Project> |
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,73 @@ | ||
using Maple2.Database.Context; | ||
using Maple2.Tools; | ||
using Microsoft.EntityFrameworkCore; | ||
using Microsoft.Extensions.Logging; | ||
using System.Diagnostics; | ||
|
||
DotEnv.Load(); | ||
|
||
string? server = Environment.GetEnvironmentVariable("DB_IP"); | ||
string? port = Environment.GetEnvironmentVariable("DB_PORT"); | ||
string? database = Environment.GetEnvironmentVariable("DATA_DB_NAME"); | ||
string? user = Environment.GetEnvironmentVariable("DB_USER"); | ||
string? password = Environment.GetEnvironmentVariable("DB_PASSWORD"); | ||
|
||
if (server == null || port == null || database == null || user == null || password == null) | ||
{ | ||
throw new ArgumentException("Database connection information was not set"); | ||
} | ||
|
||
string dataDbConnection = $"Server={server};Port={port};Database={database};User={user};Password={password};oldguids=true"; | ||
|
||
string worldServerDir = Path.Combine(Paths.SOLUTION_DIR, "Maple2.Server.World"); | ||
|
||
string cmdCommand = "cd " + worldServerDir + " && dotnet ef database update"; | ||
|
||
Console.WriteLine("Migrating..."); | ||
|
||
Process process = Process.Start("CMD.exe", "/C " + cmdCommand); | ||
|
||
process.WaitForExit(); | ||
|
||
Console.WriteLine("Migration complete!"); | ||
|
||
DbContextOptions options = new DbContextOptionsBuilder() | ||
.UseMySql(dataDbConnection, ServerVersion.AutoDetect(dataDbConnection)).Options; | ||
|
||
using var ms2Context = new Ms2Context(options); | ||
|
||
string[] seeds = | ||
{ | ||
"shops", "shop_items", "beauty_shops", "beauty_shop_items", "game_event", "system_banner", "premium_market_item" | ||
}; | ||
|
||
Console.WriteLine("Seeding..."); | ||
|
||
foreach (string seed in seeds) | ||
{ | ||
Seed(seed); | ||
} | ||
|
||
Console.WriteLine("Seeding complete!"); | ||
|
||
|
||
void Seed(string type) | ||
{ | ||
Stopwatch stopwatch = new(); | ||
|
||
Console.Write($"Seeding {type}... "); | ||
|
||
string fileLines = File.ReadAllText(Path.Combine(Paths.DB_SEEDS_DIR, $"{type}.sql")); | ||
ExecuteSqlFile(fileLines); | ||
|
||
Console.Write($"finished in {stopwatch.ElapsedMilliseconds}ms"); | ||
Console.WriteLine(); | ||
} | ||
|
||
void ExecuteSqlFile(string fileLines) | ||
{ | ||
fileLines = fileLines.Replace("\n", "").Replace("\r", "").Replace("\t", "").Replace("{", "{{").Replace("}", "}}"); | ||
|
||
ms2Context.Database.ExecuteSqlRaw(fileLines); | ||
} | ||
|
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