[backend/database] Increase migrations command timeout
This commit is contained in:
parent
dd7be34952
commit
f6847e9a3e
6 changed files with 44 additions and 6 deletions
|
@ -3,8 +3,10 @@ using EntityFramework.Exceptions.PostgreSQL;
|
||||||
using EntityFrameworkCore.Projectables.Infrastructure;
|
using EntityFrameworkCore.Projectables.Infrastructure;
|
||||||
using Iceshrimp.Backend.Core.Configuration;
|
using Iceshrimp.Backend.Core.Configuration;
|
||||||
using Iceshrimp.Backend.Core.Database.Tables;
|
using Iceshrimp.Backend.Core.Database.Tables;
|
||||||
|
using Iceshrimp.Backend.Core.Extensions;
|
||||||
using Microsoft.AspNetCore.DataProtection.EntityFrameworkCore;
|
using Microsoft.AspNetCore.DataProtection.EntityFrameworkCore;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Design;
|
||||||
using Npgsql;
|
using Npgsql;
|
||||||
|
|
||||||
namespace Iceshrimp.Backend.Core.Database;
|
namespace Iceshrimp.Backend.Core.Database;
|
||||||
|
@ -1011,3 +1013,20 @@ public class DatabaseContext(DbContextOptions<DatabaseContext> options)
|
||||||
public IQueryable<Note> NoteDescendants(Note note, int depth, int breadth)
|
public IQueryable<Note> NoteDescendants(Note note, int depth, int breadth)
|
||||||
=> FromExpression(() => NoteDescendants(note.Id, depth, breadth));
|
=> FromExpression(() => NoteDescendants(note.Id, depth, breadth));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[SuppressMessage("ReSharper", "UnusedType.Global",
|
||||||
|
Justification = "Constructed using reflection by the dotnet-ef CLI tool")]
|
||||||
|
public class DesignTimeDatabaseContextFactory : IDesignTimeDbContextFactory<DatabaseContext> {
|
||||||
|
DatabaseContext IDesignTimeDbContextFactory<DatabaseContext>.CreateDbContext(string[] args) {
|
||||||
|
var configuration = new ConfigurationBuilder()
|
||||||
|
.SetBasePath(Directory.GetCurrentDirectory())
|
||||||
|
.AddCustomConfiguration()
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
var config = configuration.GetSection("Database").Get<Config.DatabaseSection>();
|
||||||
|
var dataSource = DatabaseContext.GetDataSource(config);
|
||||||
|
var builder = new DbContextOptionsBuilder<DatabaseContext>();
|
||||||
|
DatabaseContext.Configure(builder, dataSource);
|
||||||
|
return new DatabaseContext(builder.Options);
|
||||||
|
}
|
||||||
|
}
|
|
@ -9,6 +9,9 @@ namespace Iceshrimp.Backend.Core.Database.Migrations
|
||||||
{
|
{
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override void Up(MigrationBuilder migrationBuilder) {
|
protected override void Up(MigrationBuilder migrationBuilder) {
|
||||||
|
Console.WriteLine("Fixing up note visibility enums, please hang tight!");
|
||||||
|
Console.WriteLine("This may take a long time (15-30 minutes), especially if your database is unusually large or you're running low end hardware.");
|
||||||
|
|
||||||
// We want to set all hidden notes to be specified notes that can only be seen by the author before we remove the enum
|
// We want to set all hidden notes to be specified notes that can only be seen by the author before we remove the enum
|
||||||
migrationBuilder.Sql("""
|
migrationBuilder.Sql("""
|
||||||
UPDATE "note" SET "visibleUserIds" = '{}', "mentions" = '{}', "visibility" = 'specified' WHERE "visibility" = 'hidden';
|
UPDATE "note" SET "visibleUserIds" = '{}', "mentions" = '{}', "visibility" = 'specified' WHERE "visibility" = 'hidden';
|
||||||
|
@ -27,6 +30,9 @@ namespace Iceshrimp.Backend.Core.Database.Migrations
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override void Down(MigrationBuilder migrationBuilder)
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
{
|
{
|
||||||
|
Console.WriteLine("Reverting changes to note visibility enums, please hang tight!");
|
||||||
|
Console.WriteLine("This may take a long time (15-30 minutes), especially if your database is unusually large or you're running low end hardware.");
|
||||||
|
|
||||||
migrationBuilder.Sql("""
|
migrationBuilder.Sql("""
|
||||||
ALTER TYPE "public"."note_visibility_enum" RENAME TO "note_visibility_enum_old";
|
ALTER TYPE "public"."note_visibility_enum" RENAME TO "note_visibility_enum_old";
|
||||||
ALTER TYPE "public"."poll_notevisibility_enum" RENAME TO "poll_notevisibility_enum_old";
|
ALTER TYPE "public"."poll_notevisibility_enum" RENAME TO "poll_notevisibility_enum_old";
|
||||||
|
|
|
@ -12,6 +12,9 @@ namespace Iceshrimp.Backend.Core.Database.Migrations
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override void Up(MigrationBuilder migrationBuilder)
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
{
|
{
|
||||||
|
Console.WriteLine("Fixing up note.mentionedRemoteUsers, please hang tight!");
|
||||||
|
Console.WriteLine("This may take a long time (15-30 minutes), especially if your database is unusually large or you're running low end hardware.");
|
||||||
|
|
||||||
migrationBuilder.Sql("""
|
migrationBuilder.Sql("""
|
||||||
ALTER TABLE "note" ALTER COLUMN "mentionedRemoteUsers" DROP DEFAULT;
|
ALTER TABLE "note" ALTER COLUMN "mentionedRemoteUsers" DROP DEFAULT;
|
||||||
ALTER TABLE "note" ALTER COLUMN "mentionedRemoteUsers" TYPE jsonb USING "mentionedRemoteUsers"::jsonb;
|
ALTER TABLE "note" ALTER COLUMN "mentionedRemoteUsers" TYPE jsonb USING "mentionedRemoteUsers"::jsonb;
|
||||||
|
@ -22,6 +25,9 @@ namespace Iceshrimp.Backend.Core.Database.Migrations
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
protected override void Down(MigrationBuilder migrationBuilder)
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
{
|
{
|
||||||
|
Console.WriteLine("Reverting changes to note.mentionedRemoteUsers, please hang tight!");
|
||||||
|
Console.WriteLine("This may take a long time (15-30 minutes), especially if your database is unusually large or you're running low end hardware.");
|
||||||
|
|
||||||
migrationBuilder.Sql("""
|
migrationBuilder.Sql("""
|
||||||
ALTER TABLE "note" ALTER COLUMN "mentionedRemoteUsers" DROP DEFAULT;
|
ALTER TABLE "note" ALTER COLUMN "mentionedRemoteUsers" DROP DEFAULT;
|
||||||
ALTER TABLE "note" ALTER COLUMN "mentionedRemoteUsers" TYPE text USING "mentionedRemoteUsers"::text;
|
ALTER TABLE "note" ALTER COLUMN "mentionedRemoteUsers" TYPE text USING "mentionedRemoteUsers"::text;
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
namespace Iceshrimp.Backend.Core.Extensions;
|
||||||
|
|
||||||
|
public static class ConfigurationBuilderExtensions {
|
||||||
|
public static IConfigurationBuilder AddCustomConfiguration(this IConfigurationBuilder configuration) {
|
||||||
|
return configuration.AddIniFile(Environment.GetEnvironmentVariable("ICESHRIMP_CONFIG") ?? "configuration.ini",
|
||||||
|
false, true)
|
||||||
|
.AddIniFile(Environment.GetEnvironmentVariable("ICESHRIMP_CONFIG_OVERRIDES") ?? "configuration.overrides.ini",
|
||||||
|
true, true);
|
||||||
|
}
|
||||||
|
}
|
|
@ -65,7 +65,9 @@ public static class WebApplicationExtensions {
|
||||||
|
|
||||||
if (args.Contains("--migrate") || args.Contains("--migrate-and-start")) {
|
if (args.Contains("--migrate") || args.Contains("--migrate-and-start")) {
|
||||||
app.Logger.LogInformation("Running migrations...");
|
app.Logger.LogInformation("Running migrations...");
|
||||||
|
context.Database.SetCommandTimeout(0);
|
||||||
await context.Database.MigrateAsync();
|
await context.Database.MigrateAsync();
|
||||||
|
context.Database.SetCommandTimeout(30);
|
||||||
if (args.Contains("--migrate")) Environment.Exit(0);
|
if (args.Contains("--migrate")) Environment.Exit(0);
|
||||||
}
|
}
|
||||||
else if ((await context.Database.GetPendingMigrationsAsync()).Any()) {
|
else if ((await context.Database.GetPendingMigrationsAsync()).Any()) {
|
||||||
|
|
|
@ -5,12 +5,7 @@ using Vite.AspNetCore.Extensions;
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
var builder = WebApplication.CreateBuilder(args);
|
||||||
|
|
||||||
builder.Configuration.Sources.Clear();
|
builder.Configuration.Sources.Clear();
|
||||||
builder.Configuration
|
builder.Configuration.AddCustomConfiguration();
|
||||||
.AddIniFile(Environment.GetEnvironmentVariable("ICESHRIMP_CONFIG") ?? "configuration.ini",
|
|
||||||
false, true);
|
|
||||||
builder.Configuration
|
|
||||||
.AddIniFile(Environment.GetEnvironmentVariable("ICESHRIMP_CONFIG_OVERRIDES") ?? "configuration.overrides.ini",
|
|
||||||
true, true);
|
|
||||||
|
|
||||||
builder.Services.AddControllers(options => { options.ModelBinderProviders.AddHybridBindingProvider(); })
|
builder.Services.AddControllers(options => { options.ModelBinderProviders.AddHybridBindingProvider(); })
|
||||||
.AddNewtonsoftJson() //TODO: remove once dotNetRdf switches to System.Text.Json (or we switch to LinkedData.NET)
|
.AddNewtonsoftJson() //TODO: remove once dotNetRdf switches to System.Text.Json (or we switch to LinkedData.NET)
|
||||||
|
|
Loading…
Add table
Reference in a new issue