Inherits QObject.
Inherited by M20190121T174100_Example.
|
| Table * | create (const QString &tableName) |
| | Creates a new table with the given tableName. More...
|
| |
| Table * | createTableIfNotExists (const QString &tableName) |
| | Creates a new table with the given tableName if it not exists already. More...
|
| |
| Migrator::DatabaseFeatures | dbFeatures () const |
| | Returns features supported by the used datbase system. More...
|
| |
| Migrator::DatabaseType | dbType () const |
| | Returns the type of the used database system. More...
|
| |
| QString | dbTypeToStr () const |
| | Returns the name of the used database system. More...
|
| |
| QVersionNumber | dbVersion () const |
| | Returns the version of the used database system. More...
|
| |
| virtual void | down ()=0 |
| | Reimplement this function to perform database operations when performing migration rollback. More...
|
| |
| void | drop (const QString &tableName) |
| | Drops the table identified by tableName. More...
|
| |
| void | dropIfExists (const QString &tableName) |
| | Drops the table identified by tableName if it exists. More...
|
| |
| bool | isDbFeatureAvailable (Migrator::DatabaseFeatures dbFeatures) const |
| | Returns true if the dbFeatures are available on the used database system. More...
|
| |
| Error | lastError () const |
| | Returns error information about the last error (if any) that occurred with this migrator. More...
|
| |
| void | raw (const QString &statement) |
| | Executes a raw SQL statement. More...
|
| |
| void | rename (const QString &tableName, const QString &newName) |
| | Renames the table named tableName to newName. More...
|
| |
| Table * | table (const QString &tableName) |
| | Returns an existing Table object for a table with the given tableName. More...
|
| |
| virtual void | up ()=0 |
| | Reimplement this function to perform database operations when performing migrations. More...
|
| |
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>
{
Q_OBJECT
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
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[])
{
QCoreApplication app(argc, argv);
auto migrator =
new Firfuorida::Migrator(QLatin1String(QSqlDatabase::defaultConnection), QStringLiteral(
"migrations"), &app);
new M20190121T174100_Example(migrator);
if (!migrator->migrate()) {
return 1;
}
if (!migrator->rollback(0)) {
return 1;
}
return 0;
}