= GenericTrac Data Model = 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. There are effectively two parts to this proposal: - the API level, how resource data is presented to the program - the storage level, how the resource data are stored on persistent memory 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... 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). The main benefits expected from the new API are: - simplification of the internals of Trac, especially for the ticket model, in which the storage of changes is quite cumbersome (see #454, #6466) - solve a few design problems with the current data model (like #1890, #4582) - allow better code reuse and share of the base features among different kinds of resources (like #695, #1113, and a lot more, see [#RelatedTickets] below) == Related Proposals == 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]). 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 (#130). 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. This could allow the (re-)implementation of the TracCrossReferences idea as a plugin, for example. See #31, #886, #6543 and TracDev/Proposals/TracRelations. == Design Discussion == Requirements for the new model: 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//) 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//) 3. it should remain ''fast'', if not become faster than what we currently have; 4. it should lead to a more ''compact'' representation of data 5. all the existing constraints about maintaining resource history and associated metadata should be taken into account 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. === Resource Content === 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. 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). Note that we'd like to get ''relations'' (or ''links'') as well, see #31. ==== Properties Let's examine the advantages and disadvantages of each different styles of properties storage: 1. properties stored in columns of a main table: - (-) only flexibility is to not use some fields (e.g. 'severity', 'url') - (-) no multiple values per field possible - (+) faster especially for multicriteria queries (?) - (+) straightforward code (`for field1,field2, ... in cursor: ...`) (?) 2. properties stored in prop/value columns of a generic table - (+) highest flexibility, add or remove fields at will - (+) allow for multiple values per property, provided we don't use a primary key as we currently do for the `ticket_custom` table (#918) - (+) 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; 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) - (-) slower, less memory efficient, especially for multicriteria queries(?) - (-) more complex code (?) - (-) cannot use DB features to assure data integrity (not NULL constraints, foreign key constraints, etc.) - (-) very difficult to integrate against the database (e.g. import/export, analysis) (?) means ''yet to be verified'' == Implementation Plan == 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. === Applied on Ticket module === As the ticket module is by far the most complex, it might be worth to try out the new model there first: - we could verify that we meet the expectations in terms of code simplification, solving open issues, etc. - we could detect early if there are no regressions or risk of losing current features - by redeploying the ticket infrastructure to the other components, we could spread the most benefits of tickets (comments, custom fields, queries, etc.) to other resources (milestone, wiki, component, ...) === Applied on Milestone module === - modify the Milestone module so that it uses the new proposed datamodel. - adapt the Roadmap module to the new model - adapt the Milestone admin component to the new model - for a first approach, the generic scheme would be enough, no need for versioning as we currently don't support that Later: - experiment new tabbed view for the milestone (''View'', ''Discussion'', ''History''). See TracProject/UiGuidelines. - migrate to generic versioned scheme === Applied on Wiki module === Milestone and components are closer in spirit to a wiki page than to a ticket (we have the long standing #3776 ticket). We could as well start simply on the wiki model and wiki module, to rework the basics there, and once this is done port the changes to the milestone module, then work on the components. 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. See how a VCS backend could be written for the versioned generic scheme... === Applied on Component module === An other possibility would be to start on fresh ground, implementing not yet existing resource typse in a generic way (#1233). That would be the less disrupting approach, as everything else should just continue to work unchanged (or mostly unchanged, except for things like #5211 and places where we deal with the old `component` table). == Related Tickets == - Data model issues: [[TicketQuery(status=!closed&keywords=~model)]] - Resource related: [[TicketQuery(status=!closed&keywords=~tracobject)]] See also: [./Brainstorm] for older iterations of the idea and discussion.