|
| Table * | create (const QString &tableName) |
| | Creates a new table with the given tableName.
|
| Table * | createTableIfNotExists (const QString &tableName) |
| | Creates a new table with the given tableName if it not exists already.
|
| Migrator::DatabaseFeatures | dbFeatures () const |
| | Returns features supported by the used datbase system.
|
| Migrator::DatabaseType | dbType () const |
| | Returns the type of the used database system.
|
| QString | dbTypeToStr () const |
| | Returns the name of the used database system.
|
| QVersionNumber | dbVersion () const |
| | Returns the version of the used database system.
|
| virtual void | down ()=0 |
| | Reimplement this function to perform database operations when performing migration rollback.
|
| void | drop (const QString &tableName) |
| | Drops the table identified by tableName.
|
| void | dropIfExists (const QString &tableName) |
| | Drops the table identified by tableName if it exists.
|
| bool | isDbFeatureAvailable (Migrator::DatabaseFeatures dbFeatures) const |
| | Returns true if the dbFeatures are available on the used database system.
|
| Error | lastError () const |
| | Returns error information about the last error (if any) that occurred with this migrator.
|
| void | raw (const QString &statement) |
| | Executes a raw SQL statement.
|
| void | rename (const QString &tableName, const QString &newName) |
| | Renames the table named tableName to newName.
|
| Table * | table (const QString &tableName) |
| | Returns an existing Table object for a table with the given tableName.
|
| virtual void | up ()=0 |
| | Reimplement this function to perform database operations when performing migrations.
|
Contains a single migration instance.
The Migration object represents a single migration instance. A migration is defined by operations defined in the reimplemented up() and down() functions. The reimplemented up() function is called when the migration is done. The reimplemented down() function is called when the migrations will be rolled back. Inside up() and down() use the create(), createTableIfNotExists(), table(), drop(), dropIfExists(), rename() and raw() functions.
Additionally there is the possibility to use a custom function for migration by reimplenting executeUp() and executeDown().
Example
example.h
#include <Firfuorida/Migration>
{
public:
~M20190121T174100_Example() override;
protected:
}
Contains a single migration instance.
Definition migration.h:46
virtual void up()=0
Reimplement this function to perform database operations when performing migrations.
virtual void down()=0
Reimplement this function to perform database operations when performing migration rollback.
Manages multiple migrations.
Definition migrator.h:40
QObject * parent() const const
example.cpp
#include "example.h"
{
}
M20190121T174100_Example::~M20190121T174100_Example()
{
}
{
t->tinyIncrements();
t->tinyInteger(QStringLiteral("tinyIntCol"))->unique();
t->tinyBlob(QStringLiteral("tinyBlobCol"))->nullable();
t->tinyText(QStringLiteral("tinyTextCol"))->defaultValue(QStringLiteral("foobar"));
}
{
}
void dropIfExists(const QString &tableName)
Drops the table identified by tableName if it exists.
Definition migration.cpp:150
Table * createTableIfNotExists(const QString &tableName)
Creates a new table with the given tableName if it not exists already.
Definition migration.cpp:124
Migration(Migrator *parent)
Constructs a new Migration object with the given parent.
Definition migration.cpp:104
main.cpp
#include <QCoreApplication>
#include <QSqlDatabase>
#include <Firfuorida/Migrator>
#include "example.h"
int main(int argc, char *argv[])
{
new M20190121T174100_Example(migrator);
if (!migrator->migrate()) {
return 1;
}
if (!migrator->rollback(0)) {
return 1;
}
return 0;
}