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

[Docs] migrator: shadow schema #434

Open
indeyets opened this issue Oct 19, 2024 · 3 comments
Open

[Docs] migrator: shadow schema #434

indeyets opened this issue Oct 19, 2024 · 3 comments

Comments

@indeyets
Copy link

I'm trying to migrate to pgkit/migrator from older slonik-based version. I'm mostly good except for understanding the usage of shadow database.

  • Is it a requirement or there's some way to work without it?
  • Our database servers are configured in a way where accounts do not have privileges to create new schemas in cluster. We can allow some hardcoded name for the "staging" probably. But then we need a way to specify this name via config.
  • Would be nice if migrator could detect this "misconfiguration" of database server and show friendly error instead of "scary" QueryError :)
@mmkal
Copy link
Owner

mmkal commented Oct 21, 2024

Thanks for trying it out. The shadow database is not a requirement, it's only used when you're trying to autogenerate changes. It's still possible to write everything by hand like in the previous version.

My setup is to use the shadow database features on a local db in order to speed up writing migrations etc. but only run up in prod.

I agree it should detect the misconfiguration and probably point to some docs about how you might want to change your workflow. I'll look into this. In the meantime which query exactly is your database setup rejecting?

@indeyets
Copy link
Author

It fails if I try "goto" or "check" commands (the second one is more interesting)

query: {
    parse: [Function: parse],
    name: 'create_d867d5c',
    sql: '\n' +
      '      create table if not exists $1:name(\n' +
      '        name text primary key,\n' +
      '        content text not null,\n' +
      '        status text,\n' +
      '        date timestamptz not null default now()\n' +
      '      )\n' +
      '    ',
    token: 'sql',
    values: [ 'migration' ],
    templateArgs: [Function: templateArgs]
  },
  result: undefined,
  [cause]: error: database "(redacted)-shadow_1729545545884_473647" does not exist

indeyets added a commit to indeyets/pgkit that referenced this issue Nov 7, 2024
connectionString is a URL, so it should be treated as such. regex didn't
handle more complex cases (such as "-" in the name of database).

And while it is possible to tweak regex for greater compatibility, using
actual URL-object guarantees proper result in ALL cases.

mmkal#434
@indeyets
Copy link
Author

indeyets commented Nov 7, 2024

@mmkal some of my issues were related to the fact that I use database name with dashes in it. #435 adds compatibility with such cases

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

2 participants