Customise schema/object name of the MigrationLog table
Is it possible to configure a ReadyRoll project to use a __MigrationLog table in a schema other than dbo, so that more than one application could manage and version control its database schema within a shared database?
Alternatively, is it possible to use a table named something other than __MigrationLog, to the same end?
Apologies if this is documented somewhere; I have tried to find an answer, and failed.
-Mark Davies
Alternatively, is it possible to use a table named something other than __MigrationLog, to the same end?
Apologies if this is documented somewhere; I have tried to find an answer, and failed.
-Mark Davies
Daniel Nolan
Product Manager
Redgate Software
Product Manager
Redgate Software
Tagged:
Comments
In order to set a custom schema name, edit your project file (.sqlproj) and add the following under the root node:
The next time you deploy your project, the migration log table will be created within the specified schema (as will the related view object, [MigrationLogCurrent]).
(Incidentally, if you're looking to split your shared database into multiple projects by schema (i.e. in order have individual namespaces, where each project contains a subset of objects from a given database), have a look at the following article in the documentation to find out how to setup project filters:
Partitioning a database by schema)
It is also possible to customise the table name (default: __MigrationLog) and view name (default: __MigrationLogCurrent):
Updated 2017-09-19: Please note that customising of the table and view name is now deprecated, and support for the the following project settings will soon be removed:
See further below for steps on how to adapt your existing projects to the MigrationLogSchemaName setting which replaces these settings.
Product Manager
Redgate Software
EXECUTE sp_rename 'PK___MigrationLog', 'PK___MigrationLog_todrop';
I guess this works fine when ___MigrationLog is within default (dbo) schema, but for custom schema it doesn't work. It should be
EXECUTE sp_rename '<custom schema>.PK___MigrationLog', 'PK___MigrationLog_todrop';
The reason why I ask is that I can only reproduce the issue either when that property is either not present or set to something other than this value.
Product Manager
Redgate Software
You're totally right, this node somehow was missing from the file (I played a lot with it to set up the project). Now when it's back it works fine, thanks
We're in the process of resolving the T-SQL defect you spotted. I'll update this thread once its available
Product Manager
Redgate Software
If you have any projects that are currently using the above settings, you will need to adapt your project to use the MigrationLogSchemaName setting. This means that your migration log table and view objects will always be named __MigrationLog and __MigrationLogCurrent respectively, however the schema in which they are contained will still be customisable.
Once you have removed the MigrationLogTableName and MigrationLogViewName settings from your sqlproj file, and added the MigrationLogSchemaName setting, you will need to move your existing migration log table to the newly-defined schema.
Adapting existing projects can be accomplished by performing the following steps:
In the Output window, look for the following message:
If this message does not appear, check that the variables are set correctly and try again. Note that you may receive the following error after this message:
However, the migration object move should have succeeded in spite of this message, and the error should not appear during subsequent deployment attempts. If the error reappears, check that the NewMigrationLogSchemaName is set to the correct value.
Content of Pre-Deployment\02_Move_MigrLog_to_Schema.sql:
Product Manager
Redgate Software