Changes between Version 46 and Version 47 of GenericTrac
- Timestamp:
- May 31, 2016, 6:07:35 PM (8 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
GenericTrac
v46 v47 1 = GenericTrac Data Model = 2 3 This page defines a new data model for Trac that should be suitable 4 for manipulating and storing most of the data from resources, 5 along with their change history.1 [[PageOutline(2-5,Contents,pullout)]] 2 3 = GenericTrac Data Model 4 5 This page defines a new data model for Trac that should be suitable for manipulating and storing most of the data from resources, along with their change history. 6 6 7 7 There are effectively two parts to this proposal: … … 9 9 - the storage level, how the resource data are stored on persistent memory 10 10 11 The high level API is intended to unify and take the best aspects of the different model used so far (!WikiPage, Ticket, Milestone, etc.). Actually, only the Ticket is really flexible and nice, the others are just simpler and much more limited models, so it's rather an "embrace and extend" move from the Ticket model to the others. ..12 13 While the high level API tends to unify things, the low level API will be there to introduce some diversity in the storage, at best transparent to the "user" of the higher level API. Those different storage models could be different table layouts in the database, but also in the longer term, different or complementary storage backend. It would be more appropriate to keep the change history in a dedicated system, like a version control backend, even a [DistributedTrac distributed] one ).11 The high level API is intended to unify and take the best aspects of the different model used so far (!WikiPage, Ticket, Milestone, etc.). Actually, only the Ticket is really flexible and nice, the others are just simpler and much more limited models, so it's rather an "embrace and extend" move from the Ticket model to the others. 12 13 While the high level API tends to unify things, the low level API will be there to introduce some diversity in the storage, at best transparent to the "user" of the higher level API. Those different storage models could be different table layouts in the database, but also in the longer term, different or complementary storage backend. It would be more appropriate to keep the change history in a dedicated system, like a version control backend, even a [DistributedTrac distributed] one. 14 14 15 15 The main benefits expected from the new API are: 16 - simplification of the internals of Trac, especially for the ticket model, 17 in which the storage of changes is quite cumbersome (see #454, #6466) 16 - simplification of the internals of Trac, especially for the ticket model, in which the storage of changes is quite cumbersome (see #454, #6466) 18 17 - solve a few design problems with the current data model (like #1890, #4582) 19 - allow better code reuse and sharing of the base features 20 among different kinds of resources (like #695, #1113, and a lot more, 21 see [#RelatedTickets] below) 22 23 == Related Proposals == 24 25 The idea is not new, it has its root in the TracObjectModelProposal, and was refined several times (TracDev/Proposals/DataModel, TracDev/Proposals/Journaling, and [googlegroups:trac-dev:8cf3f5fe0e476ce5 this mail]). 26 27 As this will be a major redesign of the data model, 28 it could also be a good opportunity to take the 29 **MultipleProjectSupport** considerations into account (#11025). 30 31 Somehow related to the generic data model, but not strictly depending on it, 32 Trac should also make it possible to implement new kinds of plugins that would 33 perform ''generic'' operations on Trac resources. 34 This could allow the (re-)implementation of the TracCrossReferences idea 35 as a plugin, for example. 18 - allow better code reuse and sharing of the base features among different kinds of resources (like #695, #1113, and a lot more, see [#RelatedTickets] below) 19 20 == Related Proposals 21 22 The idea is not new, it has its root in the TracObjectModelProposal, and was refined several times in TracDev/Proposals/DataModel, TracDev/Proposals/Journaling and [googlegroups:trac-dev:8cf3f5fe0e476ce5 this mail]. 23 24 As this will be a major redesign of the data model, it could also be a good opportunity to take the **MultipleProjectSupport** considerations into account (#11025). 25 26 Somehow related to the generic data model, but not strictly depending on it, Trac should also make it possible to implement new kinds of plugins that would perform ''generic'' operations on Trac resources. 27 This could allow the (re-)implementation of the TracCrossReferences idea as a plugin, for example. 36 28 See #31, #886, #6543 and TracDev/Proposals/TracRelations. 37 29 38 39 == Design Discussion == 30 == Design Discussion 40 31 41 32 Requirements for the new model: 42 33 1. it has to be ''simple'' (//easy to understand, easy to code with, when looking at the raw data in the database one should be able to intuitively understand what it means//) 43 2. it must be ''flexible'' ((//accommodate different kinds of resources, allow for dynamic evolution like addition or removal of fields by plugin or via the web admin//) 44 3. it should remain ''fast'', if not become faster than what we currently have; 45 4. it should lead to a more ''compact'' representation of data 46 5. all the existing constraints about maintaining resource history and associated metadata should be taken into account 47 48 Note that the persistence constraints imposed by the Trac data model are not necessarily only (or even best) approached using the RelationalModel, one could imagine that a future version could use more document-oriented persistence layers (e.g. [http://www.mongodb.org/ MongoDB]), or object-oriented databases (e.g. [http://www.zodb.org/ ZODB]). Also, as said above, the versioning of resources should be delegated to a version control backend, with a default, simple, in-database VCS backend. 49 50 === The ticket data model === 51 52 The ticket model is by far richer data model we would have to support, 53 so we could use it as a basis to lay out the foundations of the new model. 34 1. it must be ''flexible'' (//accommodate different kinds of resources, allow for dynamic evolution like addition or removal of fields by plugin or via the web admin//) 35 1. it should remain ''fast'', if not become faster than what we currently have; 36 1. it should lead to a more ''compact'' representation of data 37 1. all the existing constraints about maintaining resource history and associated metadata should be taken into account 38 39 Note that the persistence constraints imposed by the Trac data model are not necessarily only (or even best) approached using the RelationalModel, one could imagine that a future version could use more document-oriented persistence layers (such as [http://www.mongodb.org/ MongoDB]), or object-oriented databases (such as [http://www.zodb.org/ ZODB]). Also, as said above, the versioning of resources should be delegated to a version control backend, with a default, simple, in-database VCS backend. 40 41 === The ticket data model 42 43 The ticket model is by far richer data model we would have to support, so we could use it as a basis to lay out the foundations of the new model. 54 44 55 45 ==== Trac =< 1.1.3 model #legacy 56 For ticket, we currently have a fixed set of properties 57 (as columns in the `ticket` table) 58 and a flexible set of properties 59 (as prop/value columns in a `ticket_custom` table). 46 47 For ticket, we currently have a fixed set of properties (as columns in the `ticket` table) and a flexible set of properties (as prop/value columns in a `ticket_custom` table). 60 48 61 49 Note that we'd like to get ''relations'' (or ''links'') as well, see #31. … … 66 54 - (-) no multiple values per field possible 67 55 - (+) faster especially for multicriteria queries (?) 68 - (+) straightforward code (`for field1, field2, ... in cursor: ...`) (?)56 - (+) straightforward code (`for field1, field2, ... in cursor: ...`) (?) 69 57 2. properties stored in prop/value columns of a generic table 70 58 - (+) highest flexibility, add or remove fields at will 71 - (+) allow for multiple values per property, provided we don't use a primary key 72 as we currently do for the `ticket_custom` table (#918) 59 - (+) allow for multiple values per property, provided we don't use a primary key as we currently do for the `ticket_custom` table (#918) 73 60 - (+) a slight extension would allow ordered multiple values (sequences), otherwise we have no control over the order in which those multiple values are retrieved, which might introduce confusion as this order will vary when new values are added; 74 61 while primarily useful for `int` fields, this could also be useful to implement `text` fields for Oracle (working around the limits on varchars and not having to use CLOBs) 75 - (-) slower, less memory efficient, especially for multi criteria queries(?)62 - (-) slower, less memory efficient, especially for multi-criteria queries (?) 76 63 - (-) more complex code (?) 77 - (-) cannot use DBfeatures to assure data integrity (not NULL constraints, foreign key constraints, etc.)64 - (-) cannot use database features to assure data integrity (not NULL constraints, foreign key constraints, etc.) 78 65 - (-) very difficult to integrate against the database (e.g. import/export, analysis) 79 66 … … 105 92 106 93 CREATE TABLE ticket_custom ( 107 ticket 94 ticket integer, 108 95 name text, 109 96 value text, … … 129 116 }}} 130 117 131 Squeezed in the above are the ticket comments, complete with "reply-to" information and their own versioning scheme ;-) 132 118 Squeezed in the above are the ticket comments, complete with "reply-to" information and their own versioning scheme. 133 119 134 120 ==== Refactored model 135 121 136 The new model is heavily relational, as opposed to the earlier EAV-like approach (see [./Brainstorm#EAV]).122 The new model is heavily relational, as opposed to the earlier [wikipedia:Entity%E2%80%93attribute%E2%80%93value_model EAV-like approach], see [./Brainstorm#EAV]. 137 123 138 124 We keep a ''primary'' table for the resource, for all 1-to-1 properties and relations (table named `Ticket` here). … … 230 216 }}} 231 217 232 Adding the Project to mix becomes a simplematter of yet another relation table:218 Adding the Project to the mix becomes a matter of yet another relation table: 233 219 {{{#!sql 234 220 CREATE TABLE Ticket_Project ( … … 241 227 CREATE INDEX Ticket_Project_Project_idx ON Ticket_Project (Project); 242 228 }}} 229 243 230 A word about naming conventions: 244 231 * for table names: … … 275 262 CREATE INDEX TicketChange_TEvent_idx ON TicketChange (TEvent); 276 263 }}} 264 277 265 The `<Resource>Change` table is clearly inspired of the existing `ticket_change`: we don't want to replicate all the complexity of the ticket relational model in dedicated versioning tables, because it would be clearly overkill. We're not interested in //querying// these values anyway, only in storing them for displaying them whenever we're going to show the history of the resource. 278 266 … … 321 309 In addition, even though the relational information given by the foreign keys can be enlightening for understanding the data model, we'll need an additional descriptive layer, metadata describing the precise relationships between the tables (e.g. list of fields for a given resource/type?). 322 310 323 This metadata is a natural continuation of the configuration of fields one can find in `[ticket-custom]` section of TracIni. Of course this time it is generalized to the "standard" resources and fields, and it is stored in the DB. Speaking of custom fields, one can see how custom fields fit in the above approach: they will simply correspond to additional secondary tables. The presence of a field in the primary table or in one secondary table becomes an implementation detail abstracted away by the metadata description of the resource. This will be also used to ease the transition to the new model by first describing the "current" state (all 1-to-1 fields in the primary table) and allowing for progressive upgrade steps.311 This metadata is a natural continuation of the configuration of fields one can find in `[ticket-custom]` section of TracIni. Of course this time it is generalized to the "standard" resources and fields, and it is stored in the database. Speaking of custom fields, one can see how custom fields fit in the above approach: they will simply correspond to additional secondary tables. The presence of a field in the primary table or in one secondary table becomes an implementation detail abstracted away by the metadata description of the resource. This will be also used to ease the transition to the new model by first describing the "current" state (all 1-to-1 fields in the primary table) and allowing for progressive upgrade steps. 324 312 325 313 Finally, for the code that would handle the resources in a generic way, instead of dealing with the same tables for every resources (the EAV approach), they would deal with the same API and use the metadata to know how to handle each particular kind of resources. … … 327 315 By the way, we could also easily graft the idea of ''sub-types'' (cf. TicketTypes) that would use the same primary table as their main type but perhaps a subset (or a slightly different set) of secondary tables (e.g. no 'Version' for tasks). 328 316 329 330 == Implementation Plan == 317 == Implementation Plan 331 318 332 319 The idea is to introduce the "right" model at the occasion of the implementation of the MultipleProjectSupport. So the new `project` resource will use this generic model, but as we're primarily concerned with `ticket`s in association with the `project`s, we'll have to address the ticket module early as well. 333 320 334 === Applied on Ticket module === 335 336 As the ticket module is by far the most complex, it might be worth to 337 try out the new model there first: 321 === Applied on Ticket module 322 323 As the ticket module is by far the most complex, it might be worth to try out the new model there first: 338 324 - we could verify that we meet the expectations in terms of code simplification, 339 325 solving open issues, etc. … … 343 329 custom fields, queries, etc.) to other resources (milestone, wiki, component, ...) 344 330 345 === Applied on new Component and Version resources ===346 347 The not yet existing resource types like 'component' and 'version' will be implemented using this generic approach (#1233). Initially the corresponding fields would remain in the primary 348 349 === Applied on Milestone module ===331 === Applied on new Component and Version resources 332 333 The not yet existing resource types like 'component' and 'version' will be implemented using this generic approach (#1233). Initially the corresponding fields would remain in the primary Ticket table, they will be replaced from being properties (`component`, `version`) to relations (`Component`, `Version`). In a second step we could move these fields from the primary Ticket table to new secondary relation tables (`Ticket_Version`) and (`Ticket_Component`), still keeping the 1-to-1 relationship. The last step would be to allow them to be used as multi-valued relations (1 ticket to m versions and components). 334 335 === Applied on Milestone module 350 336 351 337 - modify the Milestone module so that it uses the new proposed datamodel. 352 338 - adapt the Roadmap module to the new model 353 339 - adapt the Milestone admin component to the new model 354 - for a first approach, the generic scheme would be enough, 355 no need for versioning as we currently don't support that 340 - for a first approach, the generic scheme would be enough, no need for versioning as we currently don't support that 356 341 357 342 Later: … … 359 344 - migrate to generic versioned scheme 360 345 361 === Applied on Wiki module ===346 === Applied on Wiki module 362 347 363 348 Milestone and components are closer in spirit to a wiki page than to a ticket (we have the long standing #3776 ticket). … … 367 352 If we do this, we can also at the same time think about the storage model, in particular how past versions could be stored in a VCS (#1132). We could then think about a serialization model that would play nicely with the genericity of the Trac resources on one hand side, and with the external editors on the other hand. 368 353 369 See how a VCS backend could be written for the versioned generic scheme... 370 371 372 == Related Tickets == 354 See how a VCS backend could be written for the versioned generic scheme. 355 356 == Related Tickets 373 357 374 358 - Data model issues: [[TicketQuery(status=!closed&keywords=~model)]] 375 359 - Resource related: [[TicketQuery(status=!closed&keywords=~tracobject)]] 376 360 377 See also: [./Brainstorm] for older iterations of the idea and discussion.361 See also: [./Brainstorm] and TracDev/ScratchPad/DataModels for older iterations of the idea and discussion.