postgres-migrations icon indicating copy to clipboard operation
postgres-migrations copied to clipboard

Implementing on a new db

Open erasmuswill opened this issue 3 years ago • 11 comments

I am attempting to use this library to bootstrap a developer environment with GitPod. However, when I run the one script that sets up the entire db, I am getting this error:

Migrations error Error: Migration failed. Reason: An error occurred running 'rolledUp'. Rolled back this migration. No further migrations were run. Reason: relation "migrations" does not exist at /workspace/XXX/node_modules/postgres-migrations/dist/migrate.js:63:27 at processTicksAndRejections (internal/process/task_queues.js:93:5) at async /workspace/XXX/node_modules/postgres-migrations/dist/with-lock.js:25:28 at async /workspace/XXX/node_modules/postgres-migrations/dist/with-connection.js:16:28 at async /workspace/XXX/src/migrate.js:52:9 { cause: Error: An error occurred running 'rolledUp'. Rolled back this migration. No further migrations were run. Reason: relation "migrations" does not exist at /workspace/XXX/node_modules/postgres-migrations/dist/run-migration.js:36:15 at processTicksAndRejections (internal/process/task_queues.js:93:5) at async /workspace/XXX/node_modules/postgres-migrations/dist/migrate.js:54:32 at async /workspace/XXX/node_modules/postgres-migrations/dist/with-lock.js:25:28 at async /workspace/XXX/node_modules/postgres-migrations/dist/with-connection.js:16:28 at async /workspace/XXX/src/migrate.js:52:9 }

This is the code block where the error is originating:

const { createDb, migrate } = require("postgres-migrations");

        const database = 'XX';
        const cn = {
            database,
            user: "XXXX",
            password: "XXXXX",
            host: "localhost",
            port: 5432,
        };
    const dbConfig = { database, ...cn };

    try {
        await createDb(database, {
            ...dbConfig,
        })
        await migrate(dbConfig, "src/sql-migrations/").then(a => console.log("migrations applide", a)) // Line 52
    }
    catch (e) { console.error("Migrations error", e) }

erasmuswill avatar Mar 16 '21 09:03 erasmuswill

What can you tell me about your database setup?

Is it related to #33?

ThomWright avatar Mar 16 '21 12:03 ThomWright

It's a brand new, clean db. I doubt it's related to #33 , but it is possible. I am using a custom db name though

erasmuswill avatar Mar 17 '21 10:03 erasmuswill

Is it configured in any way, or is it 'out of the box' Postgres, for example from Dockerhub?

What Postgres version is it?

I assume you're using the latest version of this library?

Custom database name should be fine. There are plenty of tests for that.

ThomWright avatar Mar 17 '21 17:03 ThomWright

It's a Dockerfile based on the latest version of gitpod/workspace-postgres

erasmuswill avatar Mar 18 '21 09:03 erasmuswill

Are you able to provide a reproduction? I'm not sure there's much I can do otherwise.

I tried running the tests against gitpod/workspace-postgres but it looks like there's no port 5432 exposed.

ThomWright avatar Mar 18 '21 11:03 ThomWright

I am running across a similar issue.. I believe it would occur if the migrations folder is outside of the users current schema search path in postgres ..

in my case migrations is in the auth schema.. but if I check the users default search_path for the user connecting to the postgres instance .. it shows $user, public .. so it doesn't find the migrations table..

applying a simple

ALTER USER postgres SET search_path TO "$user", public, auth

solved the issue

ArieJones avatar May 29 '21 20:05 ArieJones

Even after ALTER USER postgres SET search_path TO "$user", public, auth I get the same error

How do I revert the ALTER USER .. statement?

I'm trying to use it with Supabase

CanRau avatar Sep 24 '22 22:09 CanRau

@CanRau Same. Any solution?

nickreese avatar Feb 24 '23 10:02 nickreese

Am using currently https://github.com/urbica/pg-migrate

CanRau avatar Feb 24 '23 10:02 CanRau

@CanRau Thanks

nickreese avatar Feb 24 '23 10:02 nickreese

Check your migration file ("rolledUp"). If it contains something like this:

SELECT pg_catalog.set_config('search_path', '', false);

try removing this line

neSpecc avatar Aug 15 '23 16:08 neSpecc