Loading...
 
HowTo: Implement a Schema Module

Qorus provides support for automated database schema management through schema modules.

Automated schema management means that the creation, upgrade, downgrade, and drop actions for all schema objects are completely automated.

The base functionality for schema management in Qorus is provided by the Schema module. The Schema module's approach is based on schema alignment and works as follows:
  • Write a schema module file with a class that inherits AbstractSchema providing a description of the schema (and optionally reference data) as Qore data.
  • implement the following two public functions in the module:
    • get_datasource_name(): returns the name of the Qorus datasource where the schema should reside
    • get_user_schema(): creates and returns the schema object itself

For example:
public namespace ExampleSchema {
    public string sub get_datasource_name() {
        return "omquser";
    }

    public ExampleSchema sub get_user_schema(AbstractDatasource ds, *string dts, *string its) {
        return new ExampleSchema(ds, dts, its);
    }

    class ExampleSchema inherits AbstractSchema {
        # the actual schema implementation goes here
    }
}


Schema modules end in .qsm and are processed by oload, which will automatically run schema alignment in the database identified by the Qorus datasource provided by get_datasource_name() in the schema module.

If the schema implements the AbstractVersionedSchema interface, then oload will only execute schema alignment if the schema does not exist in the database or if the declared schema version is greater than the version in the database (or if the --force option is given to oload).

For more information on automatic schema management, see: