codidact / core

The core Codidact Q&A software implementation
GNU Affero General Public License v3.0
259 stars 20 forks source link

Permission denied to create extension "adminpack". #90

Open asynts opened 4 years ago

asynts commented 4 years ago

I am not sure when this was introduced but the build is currently broken:

$ cd src/WebApp && dotnet run
fail: Microsoft.EntityFrameworkCore.Database.Command[20102]
      Failed executing DbCommand (2ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
      CREATE TYPE audit.history_activity_type AS ENUM ('CREATE', 'UPDATE_BEFORE', 'UPDATE_AFTER', 'DELETE');
      CREATE TYPE post_type AS ENUM ('question', 'answer', 'blog');
      CREATE EXTENSION IF NOT EXISTS adminpack;
fail: Codidact.Core.WebApp.Startup[0]
      Unable to apply database migrations. Check the connection string in your appsettings file.
crit: Microsoft.AspNetCore.Hosting.Diagnostics[6]
      Application startup exception
Npgsql.PostgresException (0x80004005): 42501: permission denied to create extension "adminpack"
   at Codidact.Core.WebApp.Startup.ApplyDatabaseMigrations(IApplicationBuilder app, ILogger logger) in /home/me/dev/codidact/core/src/WebApp/Startup.cs:line 163
   at Codidact.Core.WebApp.Startup.Configure(IApplicationBuilder app, IWebHostEnvironment env, ILogger`1 logger) in /home/me/dev/codidact/core/src/WebApp/Startup.cs:line 140
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at Microsoft.AspNetCore.Hosting.ConfigureBuilder.Invoke(Object instance, IApplicationBuilder builder)
   at Microsoft.AspNetCore.Hosting.ConfigureBuilder.<>c__DisplayClass4_0.<Build>b__0(IApplicationBuilder builder)
   at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.<>c__DisplayClass13_0.<UseStartup>b__2(IApplicationBuilder app)
   at Microsoft.AspNetCore.Mvc.Filters.MiddlewareFilterBuilderStartupFilter.<>c__DisplayClass0_0.<Configure>g__MiddlewareFilterBuilder|0(IApplicationBuilder builder)
   at Microsoft.AspNetCore.HostFilteringStartupFilter.<>c__DisplayClass0_0.<Configure>b__0(IApplicationBuilder app)
   at Microsoft.AspNetCore.Hosting.GenericWebHostService.StartAsync(CancellationToken cancellationToken)
  Exception data:
    Severity: ERROR
    SqlState: 42501
    MessageText: permission denied to create extension "adminpack"
    Hint: Must be superuser to create this extension.
    File: extension.c
    Line: 806
    Routine: execute_extension_script
Unhandled exception. Npgsql.PostgresException (0x80004005): 42501: permission denied to create extension "adminpack"
   at Codidact.Core.WebApp.Startup.ApplyDatabaseMigrations(IApplicationBuilder app, ILogger logger) in /home/me/dev/codidact/core/src/WebApp/Startup.cs:line 163
   at Codidact.Core.WebApp.Startup.Configure(IApplicationBuilder app, IWebHostEnvironment env, ILogger`1 logger) in /home/me/dev/codidact/core/src/WebApp/Startup.cs:line 140
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor, Boolean wrapExceptions)
   at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at Microsoft.AspNetCore.Hosting.ConfigureBuilder.Invoke(Object instance, IApplicationBuilder builder)
   at Microsoft.AspNetCore.Hosting.ConfigureBuilder.<>c__DisplayClass4_0.<Build>b__0(IApplicationBuilder builder)
   at Microsoft.AspNetCore.Hosting.GenericWebHostBuilder.<>c__DisplayClass13_0.<UseStartup>b__2(IApplicationBuilder app)
   at Microsoft.AspNetCore.Mvc.Filters.MiddlewareFilterBuilderStartupFilter.<>c__DisplayClass0_0.<Configure>g__MiddlewareFilterBuilder|0(IApplicationBuilder builder)
   at Microsoft.AspNetCore.HostFilteringStartupFilter.<>c__DisplayClass0_0.<Configure>b__0(IApplicationBuilder app)
   at Microsoft.AspNetCore.Hosting.GenericWebHostService.StartAsync(CancellationToken cancellationToken)
   at Microsoft.Extensions.Hosting.Internal.Host.StartAsync(CancellationToken cancellationToken)
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
   at Microsoft.Extensions.Hosting.HostingAbstractionsHostExtensions.RunAsync(IHost host, CancellationToken token)
   at Codidact.Core.WebApp.Program.Main(String[] args) in /home/me/dev/codidact/core/src/WebApp/Program.cs:line 13
   at Codidact.Core.WebApp.Program.<Main>(String[] args)
  Exception data:
    Severity: ERROR
    SqlState: 42501
    MessageText: permission denied to create extension "adminpack"
    Hint: Must be superuser to create this extension.
    File: extension.c
    Line: 806
    Routine: execute_extension_script

I remember having a discussion somewhere, that some of the generated code referenced the "adminpack" extension somewhere. It is mentioned in some of the database migrations.

We should remove this from the migrations and find the cause of this issue.

misha130 commented 4 years ago

This one: https://github.com/codidact/core/blob/ec407c4838586094da5956dada14a5ba354869cd/src/Infrastructure/Persistence/ApplicationDbContext.cs#L103

asynts commented 4 years ago

I tried removing that but that was not enough, still the same issue. I got it running by doing grep -r adminpack (Linux) and removing everything that had the word "adminpack" in it.

After removing it from the migrations it somehow worked, but I was very confused why this made a difference. If Entity Framework is presented with an empty database, it uses the dbcontext snapshot to initialize it, right? But removing it from there was not enough...