diff --git a/src/EllieBot/Db/EllieDbService.cs b/src/EllieBot/Db/EllieDbService.cs index f035a1d..a9f0781 100644 --- a/src/EllieBot/Db/EllieDbService.cs +++ b/src/EllieBot/Db/EllieDbService.cs @@ -27,20 +27,15 @@ public sealed class EllieDbService : DbService public override async Task SetupAsync() { - var dbType = DbType; - var connString = ConnString; - - await using var context = CreateRawDbContext(dbType, connString); - - await RunMigration(context); - + await using var context = CreateRawDbContext(DbType, ConnString); + // make sure sqlite db is in wal journal mode if (context is SqliteContext) { await context.Database.ExecuteSqlRawAsync("PRAGMA journal_mode=WAL"); } - - // await context.Database.MigrateAsync(); + + await RunMigration(context); } public override EllieContext CreateRawDbContext(string dbType, string connString) @@ -79,6 +74,7 @@ public sealed class EllieDbService : DbService public override EllieContext GetDbContext() => GetDbContextInternal(); + private static async Task RunMigration(DbContext ctx) { // if database doesn't exist, run the baseline migration @@ -101,7 +97,7 @@ public sealed class EllieDbService : DbService var lastApplied = applied.Last(); Log.Information("Last applied migration: {LastApplied}", lastApplied); - // apply all mirations with names greater than the last applied + // apply all migrations with names greater than the last applied foreach (var runnable in available) { if (string.Compare(lastApplied, runnable, StringComparison.Ordinal) < 0) diff --git a/src/EllieBot/migrate.sh b/src/EllieBot/migrate.sh index 1bce413..16699d2 100644 --- a/src/EllieBot/migrate.sh +++ b/src/EllieBot/migrate.sh @@ -43,35 +43,15 @@ fi echo "Cleaning up all migration files..." -# Step 3: Clean up migration files by removing everything except -for file in "Migrations/Sqlite"/*; do - - # Skip directories - if [[ ! -f "$file" ]]; then - continue - fi - - case "$file" in - *.cs) - echo "Deleting: $(basename "$file")" - rm -- "$file" - ;; - esac +# Step 3: Clean up migration files by removing everything +for file in "Migrations/Sqlite/"*.cs; do + echo "Deleting: $(basename "$file")" + rm -- "$file" done -for file in "Migrations/Postgresql"/*; do - - # Skip directories - if [[ ! -f "$file" ]]; then - continue - fi - - case "$file" in - *.cs) - echo "Deleting: $(basename "$file")" - rm -- "$file" - ;; - esac +for file in "Migrations/Postgresql/"*.cs; do + echo "Deleting: $(basename "$file")" + rm -- "$file" done # Step 4: Adding new initial migration