Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementing on a new db #59

Open
erasmuswill opened this issue Mar 16, 2021 · 11 comments
Open

Implementing on a new db #59

erasmuswill opened this issue Mar 16, 2021 · 11 comments

Comments

@erasmuswill
Copy link

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) }
@ThomWright
Copy link
Owner

What can you tell me about your database setup?

Is it related to #33?

@erasmuswill
Copy link
Author

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

@ThomWright
Copy link
Owner

ThomWright commented Mar 17, 2021

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.

@erasmuswill
Copy link
Author

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

@ThomWright
Copy link
Owner

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.

@ArieJones
Copy link

ArieJones commented May 29, 2021

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

@CanRau
Copy link

CanRau commented Sep 24, 2022

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

@nickreese
Copy link

@CanRau Same. Any solution?

@CanRau
Copy link

CanRau commented Feb 24, 2023

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

@nickreese
Copy link

@CanRau Thanks

@neSpecc
Copy link

neSpecc commented Aug 15, 2023

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

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

try removing this line

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants