loic-sharma / BaGet

A lightweight NuGet and symbol server
https://loic-sharma.github.io/BaGet/
MIT License
2.61k stars 669 forks source link

relation "__EFMigrationsHistory" does not exist #695

Open craibuc opened 3 years ago

craibuc commented 3 years ago

Describe the bug

Attempting to use PostgreSQL (9.6.22) with BaGet Docker image.

To Reproduce

Steps to reproduce the behavior:

connect to Postgres and create BaGet-related DB objects

CREATE DATABASE baget;
CREATE USER baget WITH PASSWORD 'baget';
GRANT ALL ON DATABASE baget TO baget;

\connect baget;

CREATE SCHEMA baget;
GRANT USAGE ON SCHEMA baget TO baget;
GRANT CREATE ON SCHEMA baget TO **baget**;

create a .env file with this content:

Storage__Type=FileSystem
Storage__Path=/var/baget/packages
Database__Type=PostgreSql
Database__ConnectionString=Host=172.17.0.2;Port=5432;Database=baget;User ID=postgres;Password=[redacted]
Search__Type=Database

create the volume

docker volume create --name baget-data

start the container

docker run --rm --env-file .env --volume baget-data:/vol/baget loicsharma/baget

error

fail: Microsoft.EntityFrameworkCore.Database.Command[20102]
      Failed executing DbCommand (6ms) [Parameters=[], CommandType='Text', CommandTimeout='30']
      SELECT "MigrationId", "ProductVersion"
      FROM "__EFMigrationsHistory"
      ORDER BY "MigrationId";
Unhandled exception. Npgsql.PostgresException (0x80004005): 42P01: relation "__EFMigrationsHistory" does not exist
   at Npgsql.NpgsqlConnector.<>c__DisplayClass160_0.<<DoReadMessage>g__ReadMessageLong|0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at Npgsql.NpgsqlConnector.<>c__DisplayClass160_0.<<DoReadMessage>g__ReadMessageLong|0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at Npgsql.NpgsqlDataReader.NextResult(Boolean async, Boolean isConsuming)
   at Npgsql.NpgsqlCommand.ExecuteReaderAsync(CommandBehavior behavior, Boolean async, CancellationToken cancellationToken)
   at Npgsql.NpgsqlCommand.ExecuteDbDataReaderAsync(CommandBehavior behavior, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Storage.RelationalCommand.ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Migrations.HistoryRepository.GetAppliedMigrationsAsync(CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Migrations.Internal.Migrator.MigrateAsync(String targetMigration, CancellationToken cancellationToken)
   at BaGet.Core.AbstractContext`1.RunMigrationsAsync(CancellationToken cancellationToken) in /src/BaGet.Core/Entities/AbstractContext.cs:line 36
   at BaGet.Database.PostgreSql.PostgreSqlContext.RunMigrationsAsync(CancellationToken cancellationToken) in /src/BaGet.Database.PostgreSql/PostgreSqlContext.cs:line 38
   at BaGet.Web.IHostExtensions.RunMigrationsAsync(IHost host, CancellationToken cancellationToken) in /src/BaGet.Web/Extensions/IHostExtensions.cs:line 35
   at BaGet.Program.<>c__DisplayClass0_0.<<Main>b__1>d.MoveNext() in /src/BaGet/Program.cs:line 52
--- End of stack trace from previous location where exception was thrown ---
   at McMaster.Extensions.CommandLineUtils.CommandLineApplicationExtensions.<>c__DisplayClass9_0.<<OnExecuteAsync>b__0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at McMaster.Extensions.CommandLineUtils.CommandLineApplication.ExecuteAsync(String[] args, CancellationToken cancellationToken)
   at BaGet.Program.Main(String[] args) in /src/BaGet/Program.cs:line 55
   at BaGet.Program.<Main>(String[] args)
  Exception data:
    Severity: ERROR
    SqlState: 42P01
    MessageText: relation "__EFMigrationsHistory" does not exist
    Position: 45
    File: parse_relation.c
    Line: 1160
    Routine: parserOpenTable

Expected behavior

The BaGet server starts.