Changes between Version 7 and Version 8 of TracDev/ScratchPad/DataModels
- Timestamp:
- Aug 11, 2018, 1:49:06 PM (5 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
TracDev/ScratchPad/DataModels
v7 v8 1 = Improvements to ourdata models1 = Improvements to Trac's data models 2 2 3 Usually implemented in the `<subsystem>/model.py` files.3 Trac's datamodels are usually implemented in the `<subsystem>/model.py` files. 4 4 5 In the current situation (1.0.x/1.1.1), we have different APIs and different conventions for the d ifferent models. We should try to be more consistent.5 In the current situation (1.0.x/1.1.1), we have different APIs and different conventions for the datamodels. This page describes a few issues where the API and conventions can be improved and made more consistent. 6 6 7 7 == Representation of data … … 10 10 11 11 For tickets, when a field is unset the database value is set to `None` / `NULL` (#11018). When retrieving `NULL` values from the database, we get `None` in Python, and the value returned from the model depends on the field type: 12 * For text fields, the empty string is returned from the model using the special value [apidoc:api/trac_util_text#trac.util.text.empty empty]. See e.g.what we do for [source:trunk/trac/ticket/model.py@11111:127,137#L110 ticket fields].12 * For text fields, the empty string is returned from the model using the special value [apidoc:api/trac_util_text#trac.util.text.empty empty]. See for example what we do for [source:trunk/trac/ticket/model.py@11111:127,137#L110 ticket fields]. 13 13 * For time fields, `None` is returned. 14 14 … … 17 17 === `NOT NULL` columns 18 18 19 Validation of the ticket summary is done in the [browser:tags/trac-1.0.12/trac/ticket/web_ui.py@:1247-1250#L1246 IRequestHandler], to prevent creating a ticket with an empty summary. The schema could be changed to use `NOT NULL` in the column specification since the empty string is [browser:tags/trac-1.0.12/trac/ticket/model.py#L372 replaced with NULL]. Alternatively, a `TracError` could be raised in the `Ticket` model when `insert`ing or `update`ing a ticket with an empty summary (#12458).19 Validation of the ticket summary is done in the [browser:tags/trac-1.0.12/trac/ticket/web_ui.py@:1247-1250#L1246 IRequestHandler], to prevent creating a ticket with an empty summary. The schema could be changed to use `NOT NULL` in the column specification, since the empty string is [browser:tags/trac-1.0.12/trac/ticket/model.py#L372 replaced with NULL]. Alternatively, a `TracError` could be raised in the `Ticket` model when `insert`ing or `update`ing a ticket with an empty summary (#12458). 20 20 21 21 === Class methods 22 22 23 Class methods , one example being `select`, are used for table-wide queries.23 Class methods are used for table-wide queries. One such example is `select`. 24 24 25 25 The signature of the `select` method is not consistent across all classes.