Skip to content

[9.x] Fix Postgres driver not dropping all tables & views #41701

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

Merged
merged 2 commits into from
Mar 28, 2022

Conversation

derekmd
Copy link
Contributor

@derekmd derekmd commented Mar 27, 2022

Fixes #41483
Replaces #41541

This fixes php artisan db:wipe not dropping all tables & views across multiple Postgres schemas. DROP queries didn't schema-qualify names so only the first object found is dropped. e.g., if a "migrations" table exists in two schemas, Schema::dropAllTables() leaves one of those tables.

Start schema-qualifying these names to ensure each object is explicitly removed.

-- assuming config('database.connections.pgsql.search_path') === 'public,laravel'

-- before
drop table "migrations","users" cascade

-- after
drop table "public"."migrations","public"."users","laravel"."migrations","laravel"."users" cascade

This implementation is almost functionality the same as the other draft PR except it:

  • simplifies quote-wrapping table/view/type names
  • Schema::getAllTables() returns an already-quoted $row['qualifiedname'] column. e.g,
    [
      [
        'tablename' => 'migrations',
        'qualifiedname' => '"laravel"."migrations"',
      ],
      [
        'tablename' => 'users',
        'qualifiedname' => '"laravel"."users"',
      ],
    ]
  • adds integration tests to wipe tables & views defined in two separate schemas
  • replaces array_walk() expressions from previous PRs with simpler array_map().
  • clarifies up some mock andReturn() values from previous PRs

derekmd and others added 2 commits March 27, 2022 11:43
array_map() without an array reference reads better than array_walk().
Drop queries don't qualify names with their search path so only the
first object found is dropped. e.g., if a "migrations" table exists
in two schemas, Schema::dropAllTables() leaves one of those tables.

Start schema-qualifying these names to ensure each object is removed by
command 'php artisan db:wipe'.
@taylorotwell taylorotwell merged commit ba1e833 into laravel:9.x Mar 28, 2022
@derekmd derekmd deleted the postgres-drop-all-tables-views branch March 28, 2022 14:16
@driesvints
Copy link
Member

Thanks @derekmd

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

Successfully merging this pull request may close these issues.

db:wipe doesn't remove migrations table from second schema
4 participants