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

MS SQL Server Databases in Schema other than "dbo" not supported #440

Open
ravage84 opened this issue Apr 6, 2020 · 1 comment
Open

Comments

@ravage84
Copy link
Member

ravage84 commented Apr 6, 2020

  • Migrations plugin version: 2.4.2
  • Phinx version: 0.11.4
  • CakePHP Version: 3.7.9 (but version should not be relevant)
  • Bake plugin version (if relevant): 1.10.1 (but version should not be relevant)
  • Database server : MS SQL Server 2017 (but version should not be relevant)
  • PHP Version: 7.1.7 (but version should not be relevant)
  • Platform / OS: Windows 7 (but version should not be relevant)

What you did

I have created a table in a database on a MS SQL Server in a schema other than the default one dbo, e.g. [my_database].[custom_schema].[my_table].
The custom schema custom_schema is the default schema of the user used to connect to this DB.
The custom schema is also set in the CakePHP datasource configuration setting schema of this DB to custom_schema.

Baking the migration_diff works fine. It finds the table and generates a migration script.
In that migration script there is no mention of the custom schema, which is OK.

Actual Behavior

When I use that migration script though, it creates the table as [my_database].[dbo].[my_table].

Expected Behavior

Creating the table as [my_database].[custom_schema].[my_table].

Reason

In Phinx, schema is set to dbo but never gets overwritten.

https://github.com/cakephp/phinx/blob/0.11.4/src/Phinx/Db/Adapter/SqlServerAdapter.php#L32

Related

Somewhat releated issue (about PostgreSQL):
#254

@ravage84 ravage84 added this to the 2.x (CakePHP 3) milestone Apr 6, 2020
@RahulKumarSaini
Copy link

RahulKumarSaini commented Apr 3, 2021

I am also facing a similar issue while using phinx with SQL server. Is there any update on this?
The table should be created within the user's default schema instead of dbo.

It can be fixed by query DB to get the default schema name and set it to $schema property, after the connection is established.

$result = $this->fetchRow("SELECT SCHEMA_NAME() as schema_name");
$this->schema= $result['schema_name'];

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants