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:45
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:39
QObject * parent() const const
example.cpp
#include "example.h"
{
}
M20190121T174100_Example::~M20190121T174100_Example()
{
}
void M20190121T174100_Example::up()
{
auto t = createTableIfNotExists(QStringLiteral("ExampleTable"));
t->tinyIncrements();
t->tinyInteger(QStringLiteral("tinyIntCol"))->unique();
t->tinyBlob(QStringLiteral("tinyBlobCol"))->nullable();
t->tinyText(QStringLiteral("tinyTextCol"))->defaultValue(QStringLiteral("foobar"));
}
void M20190121T174100_Example::down()
{
dropIfExists(QStringLiteral("ExampleTable"));
}
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;
}