[[PageOutline(2)]] = Trac Database Schema: Common Trac stores common authentication, caching, permission, session and system information in the database that is not specific to a certain module. == Table `system` ||'''Table'''||'''Key'''|| ||''system''||''name''|| ||'''Columns'''|| ||''name''|| ||''value''|| Stores some system properties. Trac itself only uses this table for managing database upgrades. It initializes this table with the following data during installation or upgrades: ||'''name'''||'''value'''|| ||''database_version''||The (upgraded) DB version|| ||''initial_database_version''||The DB version|| These values can be accessed using `env.get_version()` and `env.get_version(initial=True)` where `env` is an instance of `trac.env.Environment` (e.g. `self.env` in a `Component`.) (In earlier Trac versions, there were additional properties named ''repository_dir'' and ''youngest_rev''. These are now part of the VcCache.) See [browser:trunk/trac/env.py trac.env.Environment] == Table `permission` ||'''Table'''||'''Key'''|| ||''permission''||''username'', ''action''|| ||'''Columns'''|| ||''username''|| ||''action''|| Stores TracPermissions (and TracFineGrainedPermissions). If `action` is ''not all uppercase'', it actually stores a permission group name. (`username` might store a permission group name in both cases.) This table should be used via the permission cache that can be used to check the permissions of the relevant user (both for performance and correctness reasons, e.g. other permission group providers etc. would be sidestepped otherwise.) That permission cache is for example available as `req.perm` for request handlers, or as `formatter.perm` for wiki macros. During installation Trac initializes this table with some default permissions for the ''anonymous'' user and the ''authenticated'' group. See [browser:trunk/trac/perm.py trac.perm.DefaultPermissionStore] == Table `auth_cookie` ||'''Table'''||'''Key'''|| ||''auth_cookie''||''cookie'', ''ipnr'', ''name''|| ||'''Columns'''||'''Type'''||'''Notes'''|| ||''cookie''|| ||Value of the cookie (32 random hex digits)|| ||''name''|| ||User name authenticated by this cookie|| ||''ipnr''|| ||IP address of the user|| ||''time''||`int`||Last time of authentication|| Stores authentication credentials of users. The `trac_auth` cookie identifies the entry of a authenticated user in this table. See [browser:trunk/trac/web/auth.py trac.web.auth.LoginModule], TracDev/TracSession == Table `session` ||'''Table'''||'''Key'''|| ||''session''||''sid'', ''authenticated''|| ||'''Columns'''||'''Type'''||'''Notes'''|| ||''sid''|| ||Session ID|| ||''authenticated''||`int`||`1` for authenticated sessions, `0` for anonymous sessions|| ||''last_visit''||`int`||Time of last visit of this session's user|| ||'''Indexes'''|| ||''last_visit''|| ||''authenticated''|| See [browser:trunk/trac/web/session.py trac.web.session], TracDev/TracSession == Table `session_attribute` ||'''Table'''||'''Key'''|| ||''session_attribute''||''sid'', ''authenticated'', ''name''|| ||'''Columns'''||'''Type'''||'''Notes'''|| ||''sid''|| ||Session ID|| ||''authenticated''||`int`||`1` for authenticated sessions, `0` for anonymous sessions|| ||''name''|| ||Name of some attribute stored for that session|| ||''value''|| ||Value of that attribute|| This table can be managed using the `Session` object, which is usually available as `req.session`. Trac itself uses session attributes to store various configuration settings, e.g.: * [/prefs Preferences] * `name`, `email` * `tz`, `dateinfo`, `lc_time` * `accesskeys` * `language` * `pygments_style` * Wiki editing settings * `wiki_sidebyside` * `wiki_editrows` * Timeline settings * `timeline.lastvisit`, `timeline.nextlastvisit` * `timeline.daysback` * `timeline.authors` *`timeline.filter.*` * Ticket settings * `ticket_comments_order`, `ticket_comments_only` * Ticket Query settings * `query_href` * `query_tickets` * `query_time` * `query_constraints` * Diff settings * `diff_style` * `diff_contextlines` See [browser:trunk/trac/web/session.py trac.web.session], TracDev/TracSession == Table `cache` ||'''Table'''||'''Key'''|| ||''cache''||''id''|| ||'''Columns'''||'''Type'''||'''Notes'''|| ||''id''||`int`||Identifies a certain property to be cached|| ||''generation''||`int`||Current generation of this cached property|| ||''key''|| ||Usually the class-qualified name of the cached property|| Use the `CacheManager` component e.g. via the `cached_value` decorator to cache values (in process or thread-local memory). This table is used to manage (e.g., correctly invalidate) these caches. See [browser:trunk/trac/cache.py trac.cache], TracDev/CacheManager