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

Ace migration commands failing when using the connection flag #947

Closed
pokedpeter opened this issue Aug 4, 2023 · 2 comments · Fixed by #983
Closed

Ace migration commands failing when using the connection flag #947

pokedpeter opened this issue Aug 4, 2023 · 2 comments · Fixed by #983
Labels
Status: Abandoned Dropped and not into consideration

Comments

@pokedpeter
Copy link
Contributor

pokedpeter commented Aug 4, 2023

I'm unable to run the following migration commands successfully: refresh, reset and fresh when providing a connection with the --connection flag

refresh and reset provide the same error:

node ace migration:refresh --connection=pg
[ error ]  """pg""" is not a valid connection name. Double check "config/database" file

While, fresh provides a different error:

node ace migration:fresh --connection=pg

   Exception: E_UNMANAGED_DB_CONNECTION: Cannot connect to unregistered connection "pg"

In contrast, the flag works with run, status and rollback commands

This is a minor issue as my current workaround for all these commands is to manually set the connection environment variable when calling the commands, eg:
DB_CONNECTION=pg node ace migration:refresh

Prerequisites

Package version

18.4.0

Node.js and npm version

Node: v18.16.0
npm: 9.5.1

Sample Code (to reproduce the issue)

  1. Obtain the connection key in database.ts. The default pg one is enough to replicate the issue.
...
  connections: {
    pg: { ... },
  }
...
  1. Run either the refresh or reset migration command with the --connection flag with the provided connection key pg and note the error
node ace migration:refresh --connection=pg
[ error ]  """pg""" is not a valid connection name. Double check "config/database" file

BONUS

A quick glance at the migration command files shows something in common with the working commands which the non-working ones lack:

  private instantiateMigrator() {
    const db = this.application.container.use('Adonis/Lucid/Database')
    const Migrator = this.application.container.resolveBinding('Adonis/Lucid/Migrator')

    this.migrator = new Migrator(db, this.application, {
      direction: 'up',
      connectionName: this.connection,
      dryRun: this.dryRun,
      disableLocks: this.disableLocks,
    })
  }

Can I attempt a fix?

Copy link

stale bot commented Dec 15, 2023

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the Status: Abandoned Dropped and not into consideration label Dec 15, 2023
@igortrinidad
Copy link

I'm facing the same issue, what about creating a PR to handle this @pokedpeter ?

pokedpeter added a commit to pokedpeter/lucid that referenced this issue Jan 16, 2024
When passing connection name parameter, connection name includes double quotes, so omit them

fix adonisjs#947
RomainLanz pushed a commit that referenced this issue Mar 8, 2024
When passing connection name parameter, connection name includes double quotes, so omit them

fix #947
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Abandoned Dropped and not into consideration
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants