The place where to execute custom code while migration - aspnetboilerplate

Guys please advice. I'm release new version of software and there were some braking changes, to order properly update from previous version i need to execute custom code on applying certain migration.
Update steps are:
1. Get all records from one table
2. Foreach thought them and create appropriate record in other tables
I prefer to use my "Manager" from business logic layer(core)
I don't know yet how to implements this. Please give me advice or code sample would be better.
So far I see 3 places where I can put these logic.
1. Migration file itself. in EF layer.
2. Migrator project.
3. Seed file in EF layer.

According to #Avin Kavish recommendation I've created method in Migrator project with additional flag "-migrateToV2" and create method which use my manager from core to update data properly. Thanks.

Related

Coredata lightweight migration "Can't find mapping model for migration"

I am doing a coredata database migration using lightweight migration in xcode4.5, I kept on getting "Can't find mapping model for migration" when I set "NSInferMappingModelAutomaticallyOption" to "NO". If I set "NSInferMappingModelAutomaticallyOption" to "YES", lightweight migration passes without problem.
Here is the steps I followed:
add a new model version .xcdatamodelId
make changes on the entities (including adding a new entity)
select the newer versioned datamodel as the current version, generate the new NSManagedObject subclasses, and make correspondant changes to the code.
create a mapping model and make the source points to the old datamodel version and the destination points to the new datamodel version
create custom migration policy and hook it up with one of the mappings inside the
mapping model
set up lightweight migration with "NSInferMappingModelAutomaticallyOption" equals to "NO".
test migration on simulator with the database coming from an older build.
I followed all and steps talked on apple documents and didn't make any changes on the entity schema after creating the mapping.. I tried to clean the DerivedData folder in xcode, and also I check the "VersionInfo.plist" which contains the correct versions of my datamodel. For the unchanged entities their hashkey are matching.
However I still get this error when I tried to do an migration.... Quite frustrated now.. Anyone can help to give me some guid on this problem?

MagicalRecord delete core data store when rebooting the application

I don't know why but MagicalRecord delete my store every time I reboot the application, I saw in the documentation :
When using the default sqlite data store with the DEBUG flag set, if you change your model without creating a new model version, Magical Record will delete the old store and create a new one automatically. No more uninstall/reinstall every time you make a change! (see magicalRecord github page
Removed the DEBUG flag,Tried to create a new model version, MR is still deleting my store...
Help me please :-)
This may be a bug. Please add an issue to the github repo. Or, if you need to get going faster, you can peek into the code, and comment out the line that checks to see if your model is compatible with your persistent store.

Changes in Model class causes drop database first and recreate, How to avoid this?

In Models context file it was mentioned
If you want Entity Framework to drop and regenerate your database
automatically whenever you change your model schema, add the following
code to the Application_Start method in your Global.asax file. Note:
this will destroy and re-create your database with every model change.
System.Data.Entity.Database.SetInitializer(new System.Data.Entity.DropCreateDatabaseIfModelChanges<HMS.Models.HMSContext>());
so I added this code in the Global.asax file inside protected void Application_Start().
Adding this line drops whole database when I do any changes in model class. Is there any alternate way to avoid this and still I can do Model changes?
i.e After performing changes in model when I rebuild and run my application, it drops my database and regenerate all the empty model tables. So I loose all my entered data and I want to preserve table data.
If you're using EF Code First 4.1, then, no, it will only drop and recreate. EF version 5 apparently supports dynamically changing the underlying database. It's in beta at the moment, but is available for production use if you want to try it out. You can install it through NuGet.

ASP.Net MVC 3 with EF 4.1: Is it possible to switch from database first to code first

Net MVC 3 web application. I generated my models from an existing database using "database first". But now, I would prefer to use the "code first" paradigm. Is that possible at all? How do I tell my solution that I want it to create tables for new models I code?
Yes but be aware this happens if your database doesn't exist.
see http://weblogs.asp.net/scottgu/archive/2010/07/16/code-first-development-with-entity-framework-4.aspx
Add your context class that inherits from DbContext
Declare your DbSet Customers {get;set;}
Add your connect string to your sdf file.
Note the important part regarding your database creation:
"This happens by default if your connection-string points to either a SQL CE or SQL Express database file that does not already exist on disk. You do not need to take any manual steps for this to happen."
So to add to an existing database this way - isn't going to happen.

using doctrine with codeigniter

I am planning to use doctrine to write a module of my app which is built with codeigniter.
I have a very basic question :
lets say I have a table called "user", with doctrine generate-models from db, 3 classes are generated BaseUser.php, User.php and UserTable.php. Now as I saw in the examples they use User class straigtaway. Should I be doing this ? I need additional business functionality for the user objects. So should I create a codeigniter model user_model and then use User class inside it (aggregation) or somehow extend user class ( i dont know how this will be done as user_model extends model)
Am little confused on this one and cannot locate any appropriate literature for the same.
Any help would be appreciated.
thanks in advance,
For anyone who is interested - I’ve posted up a project starter on my blog - a dev ready incorporation of the following technologies:
ExtJS : client side JS library,
CodeIgniter : presentation + domain tier,
Doctrine : ORM data layer framework
Some features of this project starter are:
- CodeIgniter Models have been replaced with Doctrine Records
- Doctrine is loaded into CI as a plugin
- RoR type before and after filters….
- Doctrine transactions automatically wrapped around every action at execution time (ATOMIC db updates)
Basic Role based security (I think Redux may be in there as well?)
Simply extract, hook up the database.php config file and viola…. You can start coding your layouts, views and models. Probably a few things to iron out - but enjoy!
Hope it helps
GET IT AT: http://thecodeabode.blogspot.com
Check out this info on Doctrine_Table class.
To your 3 generated files:
BaseXXX.php:
Holds the definition of your models so that Doctrine is able to handle the operations on the database. This class tells the ORM what colums are available, their types, advaned functions (like Timestampable,...) and more. You should not put your own data into this file since it will be over-written when re-creating the models from the database.
XXX.php:
Your actual model. This won't be re-created with each new generation process and this is were you keep most of your code. You can overwrite functions of the BaseXXX.php if you have to.
XXXTable.php:
Check my link from the top, This gives you access to the table itself. Personally, I do not use it that often since I put most of the code into XXX.php.
Of course you can create new classes and use them inside your XXX.php file. In order to actually do something with the data (save, read,...) you need classes that are connected (exteneded) from Doctrine's classes.
edit: also check this on a more infos with extending from the Doctrine_Table class

Resources