1

Im trying to use the example code from dbup converted to postgres.

Below is the code.

using System;
using System.Linq;
using System.Reflection;
using DbUp;

namespace GeoServerDbManager
{
    //"Host = 1.1.1.1; User Id = postgres; Password = postgres; Database = osmdev; Port = 5432"
    class Program
    {
        static int Main(string[] args)
        {
            var connectionString =
                args.FirstOrDefault()
                ?? "Host = 1.1.1.1; User Id = postgres; Password = postgres; Database = osmdev; Port = 5432";
            EnsureDatabase.For.PostgresqlDatabase(connectionString);
            var upgrader =
                DeployChanges.To
                    .PostgresqlDatabase(connectionString)
                    .WithScriptsEmbeddedInAssembly(Assembly.GetExecutingAssembly())
                    .LogToConsole()
                    .Build();

            var result = upgrader.PerformUpgrade();

            if (!result.Successful)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(result.Error);
                Console.ResetColor();
#if DEBUG
                Console.ReadLine();
#endif
                return -1;
            }

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("Success!");
            Console.ResetColor();
            return 0;
        }
    }
}

The database doesnt exist when I run this. I keep getting the error:

Script block number: 0; Message: 42P01: relation "schemaversions" does not exist
Npgsql.PostgresException (0x80004005): 42P01: relation "schemaversions" does not exist

The tables do get created and so does the schemaversions table but the schemaversions table is empty at the end of the script.

Tommie Jones
  • 957
  • 1
  • 16
  • 37
  • I came here with the same error but the fix was different so figured I would add a comment. I was doing a dump from PGAdmin, and using that for the create scripts for DBUp but saw this error. My issue was that PGAdmin added additional SQL statements that were technically correct for the source database, but different for target database so DBup was unhappy. In my case, I only kept the "CREATE TABLE..." and "INSERT ..." statements and it ran without issue. – Cullen D May 14 '22 at 04:04

1 Answers1

1

I know this is an old question but today I ran into the same problem and since there is no answer yet I'm answering for future reference:

I found that DbUp is trying to create a "schemaversions" but there is no default schema set. This results in the error:

Getting 'relation "schemaversions" does not exist error'

Setting the default schema fixed the problem for me:

builder.JournalToPostgresqlTable("SCHEMA_NAME", "schemaversions")

Mike Bovenlander
  • 5,236
  • 5
  • 28
  • 47