-
Notifications
You must be signed in to change notification settings - Fork 295
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
documents different approach for initial population of data #6691
base: develop
Are you sure you want to change the base?
documents different approach for initial population of data #6691
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for taking a stab at this!
|
||
In many cases, an app may wish to make use of Nautobot's various extensibility features, such as [custom fields](../../../../user-guide/platform-functionality/customfield.md) or [relationships](../../../../user-guide/platform-functionality/relationship.md). It can be useful for an app to automatically create a custom field definition or relationship definition as a consequence of being installed and activated, so that everyday usage of the app can rely upon these definitions to be present. | ||
|
||
To make this possible, Nautobot provides a custom [signal](https://docs.djangoproject.com/en/stable/topics/signals/), `nautobot_database_ready`, that apps can register to listen for. This signal is triggered when `nautobot-server migrate` or `nautobot-server post_upgrade` is run after installing an app, and provides an opportunity for the app to make any desired additions to the database at this time. | ||
Furthermore, sometimes apps might want to create a baseline of available data. This could, for example, be a baseline of circuit providers for an SSoT app that synchronizes circuit data. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
May want to define SSoT
here as it's the first time it's referenced in the doc?
A couple other examples would probably be helpful to get developers thinking; the one I've seen the most is creating default Status
and/or Role
records (or just adding to the content_types
of existing records) to use with an app's new data models.
|
||
**Con**: | ||
|
||
- Prevent Nautobot from starting when there are errors |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Re-runs every time
nautobot-server migrate
ornautobot-server post_upgrade
is run- Must be idempotent (doesn't introduce duplicate records or error out if run repeatedly)
- May recreate or revert records that a user intentionally deleted or altered
- Nautobot startup/upgrade performance?
- The possibility of later user modifications to data must be accounted for and handled in code.
**Pro**: | ||
|
||
- Execution: Automatic | ||
- Provide a clean way to delete any associated objects when uninstalling the app |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Runs exactly once (on
nautobot-server migrate
ornautobot-server post_upgrade
), so idempotence is not a concern, and will not later revert or recreate records that a user intentionally deleted or altered. - Users can later modify the created data like any other record, if a need arises.
|
||
- Implementation: Medium | ||
- Prevent Nautobot from starting when there are errors | ||
- Immutable—if you add new objects, you need to add a new migration |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Immutable—if you add new objects, you need to add a new migration | |
- Immutable — if you later need to add new objects or alter existing one, you need to add a new migration |
**Pro**: | ||
|
||
- Execution: Automatic | ||
- Implementation: Easy |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Can be rerun as needed (opposite of "Con" on data migrations below)
- Can be updated "in place" in later App releases (opposite of "Con" on data migrations below)
- Users can later modify the created data like any other record, if a need arises.
**Con**: | ||
|
||
- Data is not available in the DB/API/GUI until the process that uses it runs | ||
- Some care has to be taken to not duplicate information if multiple things depend on this data |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Later modifications to the object definitions may be error-prone if a given record/set of attributes is created/referenced in many locations
- User modifications to the data may result in side effects (renaming a Status may result in a new Status with the original name being recreated next time the code runs, etc.)
|
||
- Execution: Manual | ||
- Implementation: Medium | ||
- Creating/updating them is not straight-forward, especially for big data sets |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- The possibility of later user modifications to data must be accounted for and handled in code.
**Pro**: | ||
|
||
- Have good support for usage in unit tests | ||
- Have good performance |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- Users can later modify the created data like any other record, if a need arises.
|
||
**Con**: | ||
|
||
- Execution: Manual |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- The possibility of later user modifications to data must be accounted for and handled in code.
- Signal Handlers on `nautobot_database_ready` (see above) | ||
- [Django Onboard Tooling](https://docs.djangoproject.com/en/4.2/howto/initial-data/) | ||
- [Django Data Migrations](https://docs.djangoproject.com/en/4.2/topics/migrations/#data-migrations) | ||
- [Django Fixtures](https://docs.djangoproject.com/en/4.2/topics/db/fixtures/#fixtures) | ||
- [Design Builder Jobs](https://docs.nautobot.com/projects/design-builder/en/latest/) | ||
- Creating data in-place where needed |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Given the repetition of pros/cons below, I wonder if it'd be possible and reasonable to create a table here of approaches versus their use cases/pros/cons?
Closes #6671
What's Changed
See attached issue.
TODO