Spaces:
Running
Running
| using System.Text.Json; | |
| namespace BakeryErp.Infrastructure.Database; | |
| public sealed class DatabaseInitializer | |
| { | |
| private readonly DatabaseOptions _options; | |
| public DatabaseInitializer(DatabaseOptions options) | |
| { | |
| _options = options; | |
| } | |
| public void Initialize() | |
| { | |
| var directory = Path.GetDirectoryName(_options.DatabasePath); | |
| if (!string.IsNullOrWhiteSpace(directory)) | |
| { | |
| Directory.CreateDirectory(directory); | |
| } | |
| if (File.Exists(_options.DatabasePath)) | |
| { | |
| var existing = LocalDataStoreFile.Load(_options); | |
| existing.EnsureSeedData(); | |
| LocalDataStoreFile.Save(_options, existing); | |
| return; | |
| } | |
| var store = LocalDataStore.CreateSeed(); | |
| LocalDataStoreFile.Save(_options, store); | |
| } | |
| } | |