Reputation: 129
I am new to OR-mapping techniques. I wonder if I'm using SORM to persist data to DB, how do I handle future database schema changes?
For example, here is the User class : case class User(name:String, age:Int)
what if in the future I want to add one more field like gender do I need to manually change existing tables, or does the SORM helps me do this what's the default value for the new field what if I want to add a non-null field?
Or it is not easy to change data schema using SORM? That seems very restricted. What's the best method to handle database schema change?
Upvotes: 1
Views: 82
Reputation: 43350
Implement a migration. Have your original model and the updated one connect to associated DBs and use them to migrate all the data from the original model to the new one. You can drop the original database afterwards.
You can implement it either as a script or some form of a migration strategy-resolving function. E.g., you could have a table bearing the current schema version information, which you could use to determine how to migrate the database to the current version.
It, of course, won't be quite as fast as manual SQL alteration, but then it's the compromise of all ORMs.
Upvotes: 1