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()
|
public override async Task SetupAsync()
|
||||||
{
|
{
|
||||||
var dbType = DbType;
|
await using var context = CreateRawDbContext(DbType, ConnString);
|
||||||
var connString = ConnString;
|
|
||||||
|
|
||||||
await using var context = CreateRawDbContext(dbType, connString);
|
|
||||||
|
|
||||||
await RunMigration(context);
|
|
||||||
|
|
||||||
// make sure sqlite db is in wal journal mode
|
// make sure sqlite db is in wal journal mode
|
||||||
if (context is SqliteContext)
|
if (context is SqliteContext)
|
||||||
{
|
{
|
||||||
await context.Database.ExecuteSqlRawAsync("PRAGMA journal_mode=WAL");
|
await context.Database.ExecuteSqlRawAsync("PRAGMA journal_mode=WAL");
|
||||||
}
|
}
|
||||||
|
|
||||||
// await context.Database.MigrateAsync();
|
await RunMigration(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override EllieContext CreateRawDbContext(string dbType, string connString)
|
public override EllieContext CreateRawDbContext(string dbType, string connString)
|
||||||
|
@ -79,6 +74,7 @@ public sealed class EllieDbService : DbService
|
||||||
public override EllieContext GetDbContext()
|
public override EllieContext GetDbContext()
|
||||||
=> GetDbContextInternal();
|
=> GetDbContextInternal();
|
||||||
|
|
||||||
|
|
||||||
private static async Task RunMigration(DbContext ctx)
|
private static async Task RunMigration(DbContext ctx)
|
||||||
{
|
{
|
||||||
// if database doesn't exist, run the baseline migration
|
// if database doesn't exist, run the baseline migration
|
||||||
|
@ -101,7 +97,7 @@ public sealed class EllieDbService : DbService
|
||||||
var lastApplied = applied.Last();
|
var lastApplied = applied.Last();
|
||||||
Log.Information("Last applied migration: {LastApplied}", lastApplied);
|
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)
|
foreach (var runnable in available)
|
||||||
{
|
{
|
||||||
if (string.Compare(lastApplied, runnable, StringComparison.Ordinal) < 0)
|
if (string.Compare(lastApplied, runnable, StringComparison.Ordinal) < 0)
|
||||||
|
|
|
@ -43,35 +43,15 @@ fi
|
||||||
|
|
||||||
echo "Cleaning up all migration files..."
|
echo "Cleaning up all migration files..."
|
||||||
|
|
||||||
# Step 3: Clean up migration files by removing everything except
|
# Step 3: Clean up migration files by removing everything
|
||||||
for file in "Migrations/Sqlite"/*; do
|
for file in "Migrations/Sqlite/"*.cs; do
|
||||||
|
echo "Deleting: $(basename "$file")"
|
||||||
# Skip directories
|
rm -- "$file"
|
||||||
if [[ ! -f "$file" ]]; then
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
|
|
||||||
case "$file" in
|
|
||||||
*.cs)
|
|
||||||
echo "Deleting: $(basename "$file")"
|
|
||||||
rm -- "$file"
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
done
|
done
|
||||||
|
|
||||||
for file in "Migrations/Postgresql"/*; do
|
for file in "Migrations/Postgresql/"*.cs; do
|
||||||
|
echo "Deleting: $(basename "$file")"
|
||||||
# Skip directories
|
rm -- "$file"
|
||||||
if [[ ! -f "$file" ]]; then
|
|
||||||
continue
|
|
||||||
fi
|
|
||||||
|
|
||||||
case "$file" in
|
|
||||||
*.cs)
|
|
||||||
echo "Deleting: $(basename "$file")"
|
|
||||||
rm -- "$file"
|
|
||||||
;;
|
|
||||||
esac
|
|
||||||
done
|
done
|
||||||
|
|
||||||
# Step 4: Adding new initial migration
|
# Step 4: Adding new initial migration
|
||||||
|
|
Loading…
Add table
Reference in a new issue