engine
engine copied to clipboard
Feature request: `formerlyKnownAs(oldName)`
When renaming fields and entities there are (at least) 2 problems:
- Need to manually modify migration file.
- Back compatibilty.
I got an idea to have formerlyKnownAs
decorators for both entites and fields.
@def.formerlyKnownAs('Folder')
export class Directory {
name = def.stringColumn().formerlyKnownAs('title')
}
- Contember would know that it should generate migration using
rename
strategy. - GraphQL schema could keep providing data under old name for back compatibility, until developer removes
formerlyKnownAs
.
Bonus: something similar could even handle mapping enum values. It could map values during migration, and keep accepting old values and storing them as mapped new values.
const OldType = def.createEnum('a', 'b', 'c')
const Type = def.createEnum('c', 'd', 'e')
export class Directory {
type = def.enumColumn(Type).deprecate(OldType, { a: null, b: 'c' })
}