The business team in my company has come up with a new field to add to one of our entities. For new instances of this entity, it'll be calculated dynamically, but for previously existing instances, we need to set up a default value of, at the moment, 15. I can easily set that as the default value in the db, but to me, it is part of the business logic. Not only can it change in the future, but it is also separated from the rest of the business logic, all of which is so far in the application level. It'll be even somehow hidden to developers.I can, not so elegantly, write some code at application level that will set that value when new instances are reloaded. But this is uglier.My question is then, is it ok to put this business logic in the database?EDIT: I'm not asking about pros/cons of different architectures with the business logic in the DB/app, but as stated in the title edit, about this concrete case of a default value.
Can a default value for a business process be set in the database column definition?
database;business logic;default values
You need to migrate some data. This logic belongs in that script. The script should change current entries to 15, but you absolutely shouldn't leave artifacts of that decision in your schema. After the migration, the number '15' isn't part of your domain, so shouldn't appear in a constraint or default.If you expect to be able to change this default value post migration, you're going to have to have some  way of indicating a pre-migration entity. Either use a null value for this, add an 'entity version' column (or something) or use some kind of inheritance based table structure. Then interpret this as 15 in the code.If there is a default value for new clients after the migration (which it sounds like there isn't) that could belong in the table schema as a default value, but I would prefer to see it in the the code. When I say 'In the code', I mean that's where the decisions are. It's okay to have the actual number 15 in some table or configuration depending on how it changes, why it changes and how distributed your system is. 