Changes between Version 11 and Version 12 of PluginDevelopmentGuide


Ignore:
Timestamp:
09.04.2013 16:04:10 (12 years ago)
Author:
jri
Comment:

Declarative migrations

Legend:

Unmodified
Added
Removed
Modified
  • PluginDevelopmentGuide

    v11 v12  
    368368A //migration// is a sequence of database operations that is executed exactly once in the lifetime of a particular DeepaMehta installation. You as a developer are responsible for equipping your plugin with the required migrations. Migrations serve several purposes: 
    369369 
    370 1. Define the plugin's data model. That is, storing new topic type definitions and association type definitions in the database. E.g. a //Books// plugin might define the Book, Title, and Author types. 
     3701. Define the plugin's data model. That is, storing new topic type definitions and association type definitions in the database. E.g. a //Books// plugin might define the types //Book//, //Title//, and //Author//. 
    371371 
    3723722. A newer version of your plugin might extend or modify the data model defined by the previous version of your plugin. The migration of the updated plugin change the stored type definitions //and// transforms existing content if necessary. 
     
    419419=== Writing migrations === 
    420420 
     421==== Declarative migrations ==== 
     422 
     423In a declarative migration you can define 4 things: topic types, association types, topics, associations. The general format is: 
     424 
     425{{{ 
     426#!js 
     427{ 
     428    topic_types: [ 
     429        ... 
     430    ], 
     431    assoc_types: [ 
     432        ... 
     433    ], 
     434    topics: [ 
     435        ... 
     436    ], 
     437    associations: [ 
     438        ... 
     439    ] 
     440} 
     441}}} 
     442 
     443Each of the 4 sections is optional. 
     444 
     445As an example see the (simplified) migration that defines the //Note// topic type. This migration is part of the //DeepaMehta 4 Notes// plugin: 
     446 
     447{{{ 
     448#!js 
     449{ 
     450    topic_types: [ 
     451        { 
     452            value: "Title", 
     453            uri: "dm4.notes.title", 
     454            data_type_uri: "dm4.core.text", 
     455            index_mode_uris: ["dm4.core.fulltext"] 
     456        }, 
     457        { 
     458            value: "Text", 
     459            uri: "dm4.notes.text", 
     460            data_type_uri: "dm4.core.html", 
     461            index_mode_uris: ["dm4.core.fulltext"] 
     462        }, 
     463        { 
     464            value: "Note", 
     465            uri: "dm4.notes.note", 
     466            data_type_uri: "dm4.core.composite", 
     467            assoc_defs: [ 
     468                { 
     469                    child_type_uri:        "dm4.notes.title", 
     470                    child_cardinality_uri: "dm4.core.one", 
     471                    assoc_type_uri:        "dm4.core.composition_def" 
     472                }, 
     473                { 
     474                    child_type_uri:        "dm4.notes.text", 
     475                    child_cardinality_uri: "dm4.core.one", 
     476                    assoc_type_uri:        "dm4.core.composition_def" 
     477                } 
     478            ], 
     479            view_config_topics: [ 
     480                { 
     481                    type_uri: "dm4.webclient.view_config", 
     482                    composite: { 
     483                        dm4.webclient.icon: "/de.deepamehta.notes/images/yellow-ball.png", 
     484                        dm4.webclient.show_in_create_menu: true 
     485                    } 
     486                } 
     487            ] 
     488        } 
     489    ] 
     490} 
     491}}} 
     492 
     493This migration defines 3 topic types: the 2 simple types //Title// and //Text//, and the composite type //Note// that combines the former two. That is, a Note is composed of a Title and a Text.  
     494 
     495==== Imperative migrations ====