This guide describes how to setup and update your modules database scheme. All database installation and update scripts will reside in
- prefix your tables with the module id. e.g.
- singular table names
- use underscorce in fieldnames andattributes e.g.
Once you've a concept of your database scheme ready and want to start prototyping, you'll need to create an initial migration.
The following command executed in the
protected directory will create a new migration into the
which resembles the following grunt command executed within the
root of your installation:
Just copy the resulting migration from the
protected/humhub/migrations into your modules
migration folder and add your scheme setup.
Please refer to the Yii Migration Guide for more information about
how to use the
Your table names should be prefixed with your unique module id like
humhub\components\Migrationclass provides some additional helper functions.
Tip: Since a
Migration::safeUp()uses transactions you should consider splitting your migration files into multiple migrations.
Note: Only data manipulation queries can be rolled back in case a migration script fails.
In order to provide scheme updates for new versions, just follow the same steps as in the Initial Migration section.
You can manually execute new migrations by the following commands:
or by grunt
Missing migrations are also executed when accessing
Administration -> Information -> Database.
Your module should also privde an
The uninstall migration is by default executed within your
Module::disable() logic method and should look like:
The integrity check is a command which validates and if necessary repairs the application database.
If you want to add own checking methods for your module to it, you can intercept the
Example callback implementation:
HumHub uses Yii's ActiveRecords as database access layer.