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

Allow us to change protected string $schema in SqlServerAdapter #2304

Open
MichaelDesignamite opened this issue Sep 4, 2024 · 2 comments
Open

Comments

@MichaelDesignamite
Copy link
Contributor

MichaelDesignamite commented Sep 4, 2024

Currently the SqlServerAdapter has this property that cannot be changed:

protected string $schema = 'dbo'

Please allow us to change this.

@MasterOdin
Copy link
Member

Postgres has the following to override using the public schema:

protected function getGlobalSchemaName(): string
{
$options = $this->getOptions();
return empty($options['schema']) ? 'public' : $options['schema'];
}

Can add a similar function to SqlServerAdapter and anywhere it uses $this->schema, then use $this->getGlobalSchemaName() instead. Though, I think really better to still have the $schema class property and instead override it as part of setOptions, vs having this function that's called every time.

@MasterOdin
Copy link
Member

MasterOdin commented Sep 7, 2024

Hm, actually, won't be quite as simple, as I don't think sqlserver has the same concept as postgres in terms of being able to set a search_path that affects all schema-less references following it. We'll need to instead make sure that we're always quantifying any table name references with the schema, which is definitely a going to be a painful process to implement.

I suppose we could minimally allow changing the $schema variable and it'd affect the 2 places it's referenced (in dealing with column comments), and then otherwise just advise end users to create a new user and set the default schema on the user. There's probably potential for things still breaking, but 🤷

I think there's also potential bugs where if you have the DB objects with the same name in multiple schemas, then phinx may return data in unexpected ways from some functions (e.g. getColumns).

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

2 participants