slightly improved .sh, moved migration code after sqlite wal pragma
Signed-off-by: Toastie <toastie@toastiet0ast.com>
This commit is contained in:
parent
c66968856d
commit
e97fbe64c5
2 changed files with 13 additions and 37 deletions
src/EllieBot
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue