enable AutoMigrate when using non default sqlserver schemas #50
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Sqlserver supports multiple schemas per database. This feature works in gorm.io (using custom TableName/NamingStrategy) but fails at AutoMigrate.
This commit fixes the migrator to also support non-default schemas.
What did this pull request do?
This pull request fixes the migrator to support "non user-default schemas" and to support the same table names in multiple schemas (e.g. dbo.testtables/testschema1.testtables/testschema2.testtables).
This pull request could be solved more elegant but this would require changes in gorm.io/migrator because the function "ColumnTypes" almost equal to the default migrator.
User Case Description
usecase1: We need to use multiple schemas for security purposes because this way access rights to the tables/schemas can be configured via the schema.
usecase2: Integrationtests are executed in the same database. The user default schema equals to the username which leads to ambigous table names if the schema isn't observed (e.g. user1.testtable1 vs. user2.testtable1)