adonisjs / lucid

AdonisJS SQL ORM. Supports PostgreSQL, MySQL, MSSQL, Redshift, SQLite and many more
https://lucid.adonisjs.com/
MIT License
1.03k stars 189 forks source link

db:wipe, migration:fresh... Not successful when using postgres with other schema than public #926

Closed rbartholomay closed 6 months ago

rbartholomay commented 1 year ago

Package version

"@adonisjs/lucid": "^18.3.0",

Node.js and npm version

node v16.19.0 npm 9.4.2

Sample Code (to reproduce the issue)

config/database.ts

    pg: {
      client: 'pg',
      connection: {
        host: Env.get('PG_HOST'),
        port: Env.get('PG_PORT'),
        user: Env.get('PG_USER'),
        password: Env.get('PG_PASSWORD', ''),
        database: Env.get('PG_DB_NAME'),
      },
      migrations: {
        naturalSort: true,
      },
      healthCheck: true,
      debug: Env.get('PG_DEBUG'),
      searchPath: Env.get('PG_DB_SCHEMA').split(',') || ['PUBLIC'],
    },

.env

PG_HOST=localhost
PG_PORT=5432
PG_USER=dummy-user
PG_PASSWORD=dummy-password
PG_DB_NAME=mydb
PG_DB_SCHEMA=my-schema

When runninig the command the defined searchPath in the postgres config will be ignored:

node ace db:wipe

Output:

"pg" (11 ms) SELECT "tablename" AS "table_name" FROM "pg_catalog"."pg_tables" WHERE "schemaname" IN (?) ORDER BY "tablename" ASC [ 'public' ]
[ success ]  Dropped tables successfully

You can see that the command running againt the public schema...

When you look in the sources of DbWipe.ts there is no schema specified on dropAllTables:

 /**
   * Drop all tables
   */
  private async performDropTables(client: QueryClientContract) {
    await client.dropAllTables() // <--- here mising the schema when using postgres
    this.logger.success('Dropped tables successfully')
  }
stale[bot] commented 1 year ago

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[bot] commented 10 months ago

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.

thetutlage commented 6 months ago

Fixed. Will be part of the next major release