Edgewall Software

Changes between Version 1 and Version 2 of TracDev/PluginDevelopment/ExtensionPoints/trac.env.IEnvironmentSetupParticipant


Ignore:
Timestamp:
May 12, 2010, 8:23:28 PM (14 years ago)
Author:
Carsten Klein <carsten.klein@…>
Comment:

Finalized the initial version of the documentation for the IEnvironmentSetupParticipant extension point interface.

Legend:

Unmodified
Added
Removed
Modified
  • TracDev/PluginDevelopment/ExtensionPoints/trac.env.IEnvironmentSetupParticipant

    v1 v2  
    44||'''Module'''||''trac.env''||'''Source'''||[source:trunk/trac/env.py#L51 env.py]||
    55
    6 The ''IEnvironmentSetupParticipant'' is responsible for either creating a new environment or to upgrade (aka migrate) an existing environment to a newer version of the database. In addition to that, the implementation of the extension point interface might also migrate existing data in the database so that it will correspond to the newly installed changes to the existing database schema, or similar such use cases.
     6The ''IEnvironmentSetupParticipant'' is responsible for either creating a new environment or to upgrade (aka migrate) an existing environment to a newer version of that environment.
    77
    8 The implementation will be called on either ''trac-admin <env-dir> initenv'' or, if an existing environment must be upgraded, on ''trac-admin <env-dir> upgrade''.
     8Implementations of the extension point interface will be called during both ''trac-admin <env-dir> initenv'' and on ''trac-admin <env-dir> upgrade''.
    99
    1010== Purpose ==
    1111
    12 TBD
     12Responsibilities of the interface are to participate in the creation of a new environment. This includes adding information to the database schema, such as table declarations and so on. Some implementations, see below, might also opt in for adding default data to the newly created database, or to set up the folder where the environment will be created in.
    1313
    14 Provide detailed information on the purpose of the interface here. E.g. ''IAuthenticator'' is used by the main request dispatcher to associate the current request's session with a user, or, in case that no such user exists, with the anonymous user. The most basic implementation would search for a cookie in the request. Other, more elaborated implementations for example would provide single sign on for example by evaluating an existing request header, and so on.
     14On environment upgrade, the responsibilities of the participant are to non-destructively migrate existing user data to a newer database schema, provided that the data model has changed at the SQL level, and of course to migrate the environment's folder structure and content to meet the requirements of the participant.
    1515
    1616== Usage ==
    1717
    18 Provide detailed usage information of the extension point and implementations thereof. E.g. when is a method of the implementation being called and so on.
    19 
     18Implementing the interface follows the standard guidelines found in [wiki:TracDev/ComponentArchitecture] and of course [wiki:TracDev/PluginDevelopment].
    2019
    2120== Examples ==
    2221
    23 Provide one or more example implementations of the interface.
     22The following example basically does nothing more than logging to the standard log file during either ''trac-admin <env-dir> initenv'' or ''trac-admin <env-dir> upgrade''.
     23
     24{{{#!python
     25from trac.core import implements, Component
     26
     27class SampleEnvironmentSetupParticipant(Component):
     28
     29    implements(IEnvironmentSetupParticipant)
     30
     31    # IEnvironmentSetupParticipant methods
     32
     33    def environment_created():
     34        self.log.debug("creating environment for sample plugin.")
     35        pass
     36
     37    def environment_needs_upgrade(db):
     38        self.log.debug("the existing environment requires an upgrade for sample plugin.")
     39        return True
     40
     41    def upgrade_environment(db):
     42        self.log.debug("upgrading existing environment for sample plugin.")
     43        pass
     44}}}
    2445
    2546== Available Implementations ==
    2647
    27 Provide references to available implementations of the interface, for example by linking to sources in trac trunk or on trac-hacks. You might also include short discussions on how they have been implemented.
     48 * [source:trunk/trac/env.py#L558 trac.env.EnvironmentSetup][[br]]
     49   This is the setup participant that will initialize the trac database and also the sample configuration provided with each trac instance, providing sane initial defaults for use with both an existing environment and a newly created one. For the creation of a new environment it uses [source:trunk/trac/db_default.py the default db structure]. and on upgrade it will use [source:trunk/trac/upgrades a db upgrade path] defined in the individual db*.py modules therein. The version number of the trac database schema is available from the ''system'' table, the key to look for is ''database_version.'' The value of this system property will be updated on environment upgrade. In addition to that, trac will also keep track of the initial database version that was installed when first creating the environment. The key to look for in the ''system'' table is ''initial_database_version''.
     50