This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hi, According to Ivan's blog Upgrading database structures with LightSpeed migrations, we should be able to see which migrations would be executed if we use CreateMigrator method. So I got the following code:
My first question is how do I get detailed information about what tables will be inserted or what columns will be modified during the migration process? My second question is because I set previewOnly to true in Migrator.CreateMigrator method, I got an exception when I am trying to update a database which does not have DBVersion table in it (e.g Empty DB) after I call migrator.Execute(). Can you provide a workaround for this issue please? We are using LS4 and SQL Server 2005/2008. The Mindscape.LightSpeed.Migrations.dll version is 4.0.1264.20228. Thanks for help. Xiaosu |
|
|
I have set the MigrationLogger property on the migrator instance with my custom implementation of an IMigrationLogger looking similar to this:
That way I can see what it is trying to do during a migration. Werner |
|
|
Thanks for your post, Werner. I will try that. I am still waiting someone to answer my second question. Thanks again. Xiaosu |
|
|
As Werner mentioned you can attach a logger to get details about the SQL statement which are being executed during the migrations, or you can subscribe to the events on the Migrator instance to get access to the Migration instances which contain more detailed information about the changes themselves and as you have found you can then run this in preview mode to get a review of the changes. In regards to the error you are seeing about the lack of a DbVersion table, I presume you are running this in preview mode when the error occurs? Preview mode will not perform any writes so it cannot initialize the DbVersion table (which is checked for and initialized as the first step of any normal migration being executed). If you are starting with an empty database you will need to either create the table manually or execute a blank migration first.
|
|
|
Hi Jeremy, Thank you for your reply. In terms of "you can subscribe to the events on the Migrator instance to get access to the Migration instances which contain more detailed information about the changes themselves" you metioned, can you give some sample code please? My code looks like this:
The migration instance only has Version property, so how do I get detailed information about the changes? Thanks a lot. Xiaosu |
|
|
The Migration instance is going to be an instance of one of the classes which have been code generated for you. You can extend these as required to annotate them with any information you need to surface. Because the Migration is a rollup of a number of individual changes we dont provide anything more granular, but you can certainly extend the class to provide this information more manually. e.g. Assuming I have a Migration called Version2
where your migration itself might have looked like:
And then you can do the following in your event handler:
|
|
|
Thanks for the sample code. However, when I choose "Update from Source" or "Update Database" from designer, it tells me what changes will be made. So obviously you have already created these changes somewhere, can you expose that information to the users please? That will be very helpful because I don't need to create these information manually. Thanks again. Xiaosu |
|
|
We produce this by diffing the LightSpeed model against a LightSpeed model which represents the current state of the database which is derived from schema inspection. This is not something we expose for end use. In the context of creating the migrations we use that information to build up the specific of what the migration actions need to be to represent those differences. If we look at adding a list of text based descriptions of the actions being performed (similar to the text you see in the differencing dialogs) and added that to the Migration class so you could access it in a similar fashion to the code earlier, would that be the information you are looking to get access to?
|
|
|
Hi Jemery, Yes, that is exactly what I want. If we can have something like migration.ActionList property or similar, that will be very helpful. Thanks Xiaosu |
|