Note: You are currently viewing documentation for Moodle 1.9. Up-to-date documentation for the latest stable version is available here: XMLDB editor.

XMLDB editor: Difference between revisions

From MoodleDocs
(formatting, small re-writing)
Line 1: Line 1:
{{Moodle 1.7}}
{{Moodle 1.7}}


Although the XML is pretty simple to read (and to write), one of the major drawbacks was its easy and error prune adoption by the developers. Also some problems with versioning systems getting crazy with XML files (thanks ML!) pointed us to the requirement to use one high-density format (it means, physically '''long lines''') in our XML files.
*Location: Administration > Miscellaneous > XMLDB editor


After some intense thoughts we decided to build one specialised editor for our XML format. This editor should be easy to use and provide support for all the objects present one Moodle DB. And it's done (and will support future enhancements easily, we hope).
*The XMLDB editor makes the edition of tables/fields/keys/indexes almost a trivial task, allowing developers to spend  the time coding and improving things instead of fighting with XML files and the errors caused by manual editing (of course, developers are free to use such extra time as desired - beers, dance, books, music...) ;-)


The XMLDB Editor makes the edition of tables/fields/keys/indexes practically a trivial task, allowing the developer to spend  the time coding and improving things instead of fighting against XML files and the errors caused by manual editing (of course, the developer is free to use such extra-time as desired, beers, dance, books, music...) ;-)
*All new ''install.xml'' files present under each ''db'' directory in Moodle can be edited (and we recommend it) with just some clicks and keystrokes. Those ''install.xml'' will contain all the info needed to generate the specific objects needed for each RDBMS supported. Obviously, such files are the neutral replacement for all the *.sql files used upto now.


All the new '''install.xml''' files, present under each '''db''' directory in Moodle can be edited (and we recommend it) with just some clicks and keystrokes. Those '''install.xml''' will contain all the info needed to generate the specific objects needed for each RDBMS supported. Obviously, such files, are the neutral replacement for all the *.sql files used until now.
*Note: To be able to handle files properly, the web server needs write access to all ''db'' directories where the ''install.xml'' files reside (and to the files themselves, of course).
 
== Launching ==
 
Just login to your server and, under the Admin Interface, you'll see a new link pointing to the "XMLDB Editor".
 
One '''important note''' is that, to be able to handle files properly, the web server needs write access to all those "db" directories where the "install.xml" files reside (and to the files themselves, of course). ;-)
 
That's all!


== Use==
== Use==


We really think the XMLDB Editor is pretty easy to use, so here you won't see a complete guide to use it. We highly recommend you to play with it for a while, viewing how it works and how it modifies the '''install.xml''' files.
*The XMLDB editor is pretty easy to use so there's no need for a complete guide here. Playing with it for a while is highly recommended, viewing how it works and how it modifies the ''install.xml'' files.
 
It's organised in a top-bottom structure, where you start '''loading''' (or '''creating''') a new XMLDB file. Then, you can '''edit''' such file and its '''general structure''' will be shown. This structure have two type of elements, '''tables''' and '''statements''' and the XMLDB Editor allows you to '''add''', '''edit''', '''delete''', and '''move''' them easily. Also, for initial creation of tables, one small but effective '''reverse-enginery''' tool has been developed (only under MySQL) allowing you to retrofit any table from the DB to the XMLDB Editor.


While editing tables you will see their '''fields''', '''keys''' and '''indexes''' and you'll be able to handle all them easily. Note that some fields can be no-editable. It uses to be because they are being used in some way (part of one key or index) and the idea is to warn you about that.
*It's organised in a top-bottom structure, where you start ''loading''' (or ''creating'') a new XMLDB file. Then, you can ''edit'' the file and its ''general structure'' will be shown. This structure has two type of elements, ''tables'' and ''statements'' and the XMLDB editor allows you to ''add'', ''edit'', ''delete'', and ''move'' them easily. Also, for initial creation of tables, one small but effective '''reverse-enginery''' tool has been developed (only under MySQL) allowing you to retrofit any table from the DB to the XMLDB Editor.


Fields can be edited and you can specify their '''name''', '''type''', '''length''', '''decimals''', '''null-ability''', '''defaults''' and so one. Exactly the same for both '''keys''' and '''indexes'''.
*Whilst editing tables you will see their ''fields'', ''keys'' and ''indexes'' and you'll be able to handle all them easily. Note that some fields can be non-editable. This is because they are being used in some way (part of one key or index) and the idea is to warn you about that.


While editing statements, you must think about them like "collections of sentences". Once you select the '''type''' (only inserts are allowed for now) and '''table''' you are interested you'll be able to introduce the exact values easily, being able to '''duplicate''' them easily to gain some speed if you have a lot of sentences in your development. Sentences can be '''edited''' and '''deleted''' easily too.
*Fields can be edited and you can specify their ''name'', ''type'', ''length'', ''decimals'', ''null-ability'', ''defaults'' and so on. Exactly the same for both ''keys'' and ''indexes''.


One interesting feature is that all the XMLDB Editor pages allow you to enter one '''comment''' about the item being modified (table, index, key, field, statement...). Use it at your entire needs, sure it helps other developers to understand a bit more the DB model.
*Whilst editing statements, you must think about them like "collections of sentences". Once you select the ''type'' (only inserts are allowed for now) and ''table'' you are interested in, you'll be able to introduce the exact values easily, being able to ''duplicate'' them easily to gain some speed if you have a lot of sentences in your development. Sentences can be ''edited'' and ''deleted'' easily too.


Please, don't forget to read and understand the next section, where we talk about '''some important guidelines''' to create and handle XMLDB files.
*One interesting feature is that all the XMLDB editor pages allow you to enter a ''comment'' about the item being modified (table, index, key, field, statement). Use it as you wish, sure that it helps other developers to understand a bit more about the DB model.


== Conventions ==
== Conventions ==


Apart of the [[Coding#Database_structures| Database Structures guidelines]], some more conventions should be followed:
Apart from the [[Coding#Database_structures| Database Structures guidelines]], some more conventions should be followed:


# About names:
# About names:

Revision as of 12:41, 26 January 2007

Moodle1.7


  • Location: Administration > Miscellaneous > XMLDB editor
  • The XMLDB editor makes the edition of tables/fields/keys/indexes almost a trivial task, allowing developers to spend the time coding and improving things instead of fighting with XML files and the errors caused by manual editing (of course, developers are free to use such extra time as desired - beers, dance, books, music...) ;-)
  • All new install.xml files present under each db directory in Moodle can be edited (and we recommend it) with just some clicks and keystrokes. Those install.xml will contain all the info needed to generate the specific objects needed for each RDBMS supported. Obviously, such files are the neutral replacement for all the *.sql files used upto now.
  • Note: To be able to handle files properly, the web server needs write access to all db directories where the install.xml files reside (and to the files themselves, of course).

Use

  • The XMLDB editor is pretty easy to use so there's no need for a complete guide here. Playing with it for a while is highly recommended, viewing how it works and how it modifies the install.xml files.
  • It's organised in a top-bottom structure, where you start loading' (or creating) a new XMLDB file. Then, you can edit the file and its general structure will be shown. This structure has two type of elements, tables and statements and the XMLDB editor allows you to add, edit, delete, and move them easily. Also, for initial creation of tables, one small but effective reverse-enginery tool has been developed (only under MySQL) allowing you to retrofit any table from the DB to the XMLDB Editor.
  • Whilst editing tables you will see their fields, keys and indexes and you'll be able to handle all them easily. Note that some fields can be non-editable. This is because they are being used in some way (part of one key or index) and the idea is to warn you about that.
  • Fields can be edited and you can specify their name, type, length, decimals, null-ability, defaults and so on. Exactly the same for both keys and indexes.
  • Whilst editing statements, you must think about them like "collections of sentences". Once you select the type (only inserts are allowed for now) and table you are interested in, you'll be able to introduce the exact values easily, being able to duplicate them easily to gain some speed if you have a lot of sentences in your development. Sentences can be edited and deleted easily too.
  • One interesting feature is that all the XMLDB editor pages allow you to enter a comment about the item being modified (table, index, key, field, statement). Use it as you wish, sure that it helps other developers to understand a bit more about the DB model.

Conventions

Apart from the Database Structures guidelines, some more conventions should be followed:

  1. About names:
    1. All lowercase names (tables, indexes, keys and fields).
    2. Table names and field names must use only a-z, 0-9 and _ chars.
    3. Key and index names under the XMLDB Files must be formed by concatenating the name of the fields present in the key/index with the '"-" (minus) character.
    4. Primary key always must be named "primary" (this is one exception to the previous convention).
    5. It's highly recommended to avoid reserved words completely. We know we have some of them now but they should be completely out for next releases.
  2. About NULLS
    1. Avoid to create all the fields as NOT NULL with the silly default value '' (empty string). The underlying code used to create tables will handle it properly but the XMLDB structure must be REAL. Read more in the [[XMLDB Problems#NOT NULL fields using a DEFAULT '' clause|Problems Page]].
  3. About FOREIGN KEYS
    1. Under the tables of every XMLDB file, you must define the existing Foreign Keys (FK) properly. This will allow everybody to know a bit better the structure, allow to evolve to a better constrained system in the future and will provide the underlying code with the needed info to create the proper indexes.
    2. Note that, if you define any field combination as FK you won't have to create any index on that fields, the code will do it automatically!
    3. This convention is only applicable for relations INSIDE one file. Don't generate FK constraints against other files (courseid, userid), use indexes there.
    4. Respect Convention 1.3
  4. About UNIQUE KEYS
    1. Declare any fields as UNIQUE KEY (UK) only if they are going to be used as target for one FK. Create unique indexes instead.
    2. Respect Convention 1.3