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

Method getColumnListing doesn't work on postgresql using multiple schemas #34185

Closed
mpont91 opened this issue Sep 7, 2020 · 3 comments
Closed

Comments

@mpont91
Copy link

mpont91 commented Sep 7, 2020

  • Laravel Version: 7.27.0
  • PHP Version: 7.3.8
  • Database Driver & Version: Postgresql 12.3

Description:

The way of getting all columns of a table:

$this->getConnection()->getSchemaBuilder()->getColumnListing($this->getTable())

Doesn't work when the project works with multiple schemas.
Only works when you want to retrieve a table of primary schema defined.

Steps To Reproduce:

  1. By default postgresql should have the primary schema public.

  2. Create another schema warehouse.

  3. The .env must define to use public schema as default:

     DB_DATABASE=postgres
     DB_SCHEMA=public
    
  4. Create a new migration that creates a new table on warehouse schema:

     public function up()
     {
     	Schema::create('warehouse.products', function (Blueprint $table) {
     		$table->id();
     		$table->string('name');
     		$table->timestamps();
     	});
     }
    
  5. Run the migration.

  6. Create this example test:

     public function testBasicTest()
     {
     	$columns = [
     		'id',
     		'name',
     		'created_at',
     		'updated_at',
     	];
     	$this->assertEquals($columns, $this->getConnection()->getSchemaBuilder()->getColumnListing('warehouse.products'));
     }
    

Expected result

The test should pass.

Actual result

The test fails.
This line:

$this->getConnection()->getSchemaBuilder()->getColumnListing('warehouse.products');

returns []

@FreekVR
Copy link

FreekVR commented Sep 7, 2020

I believe this is the same issue I'm running into, with MySQL:

The new updates where Laravel is (I believe) using this function to determine what columns can be filled (Post 7.24) breaks when using Hyn Multi-tenancy, in this case, my model has a custom getTable() which returns system.roles instead of roles as the table name, and as long as this is the case, it won't fill any columns like "name" even though we have set $guarded = ['id']; set on the model

@mpont91
Copy link
Author

mpont91 commented Sep 8, 2020

@FreekVR I am not using any model. The problem is precisely that I'm passing this value you said as a parameter directly and it's not working.

$this->getConnection()->getSchemaBuilder()->getColumnListing('warehouse.products'); // not working
$this->getConnection()->getSchemaBuilder()->getColumnListing('products'); // not working
$this->getConnection()->getSchemaBuilder()->getColumnListing('public.users'); // not working
$this->getConnection()->getSchemaBuilder()->getColumnListing('users'); // working

@driesvints
Copy link
Member

We don't support setting the connection name on the table. Use the connection property for that.

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

3 participants