|
firfuorida 0.0.1
Qt based database migration library
|
Manages multiple migrations. More...
#include <Firfuorida/Migrator>

Public Types | |
| enum | DatabaseFeature : int { NoFeatures = 1 << 0 , DefValOnText = 1 << 1 , DefValOnBlob = 1 << 2 , DefValOnGeometry = 1 << 3 , JSONTypes = 1 << 4 , GeometryTypes = 1 << 5 , XMLType = 1 << 6 , NetworkAddressTypes = 1 << 7 , MonetaryTypes = 1 << 8 , ForeignKeys = 1 << 9 , CommentsOnColumns = 1 << 10 , CommentsOnTables = 1 << 11 , SetType = 1 << 12 , EnumType = 1 << 13 , UnsignedInteger = 1 << 14 , CharsetOnColumn = 1 << 15 , YearType = 1 << 16 } |
| Features supported by the currently used database system. More... | |
| enum | DatabaseType : uint8_t { Invalid = 0 , DB2 = 1 , InterBase = 2 , MySQL = 3 , MariaDB = 5 , ODBC = 6 , OCI = 7 , PSQL = 8 , SQLite = 9 } |
| These are the database systems supported by default by Qt. More... | |
Public Member Functions | |
| Migrator (const QString &connectionName, const QString &migrationsTable, QObject *parent=nullptr) | |
| Constructs a new Migrator object with the given parameters. | |
| Migrator (QObject *parent=nullptr) | |
| Constructs a new Migrator object with default values and given parent. | |
| ~Migrator () | |
| Deconstructs the Migrator object. | |
| QString | connectionName () const |
| Returns the name of the used SQL connection. | |
| DatabaseFeatures | dbFeatures () const |
| Returns features supported by the used datbase system. | |
| 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. | |
| bool | initDatabase () |
| Opens and initializes the database. | |
| bool | isDbFeatureAvailable (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. | |
| bool | migrate () |
Runs all migrations not already applied and return true on success. | |
| QString | migrationsTable () const |
| Returns the name of the table to store migrations to. | |
| bool | refresh (uint steps=0) |
| Rolls back and reapplies the number of migrations defined by steps. | |
| bool | reset () |
Rolls back all migrations and returns true on success. | |
| bool | rollback (uint steps=1) |
Rolls back the number of migrations set by steps and returns true on success. | |
Manages multiple migrations.
The Migrator class manages multiple Migration objects that are children of the Migrator class.
example.h
example.cpp
main.cpp
| enum Firfuorida::Migrator::DatabaseFeature : int |
Features supported by the currently used database system.
| enum Firfuorida::Migrator::DatabaseType : uint8_t |
These are the database systems supported by default by Qt.
|
explicit |
Constructs a new Migrator object with default values and given parent.
Uses QSqlDatabase::defaultConnection as connectionName and "migrations" as migrationsTable.
|
explicit |
Constructs a new Migrator object with the given parameters.
| connectionName | The name of the SQL connection to use. |
| migrationsTable | The name of the table to store the migrations in. |
| parent | Pointer to a parent object. |
|
default |
Deconstructs the Migrator object.
| QString Migrator::connectionName | ( | ) | const |
Returns the name of the used SQL connection.
| Migrator::DatabaseFeatures Migrator::dbFeatures | ( | ) | const |
Returns features supported by the used datbase system.
| Migrator::DatabaseType Migrator::dbType | ( | ) | const |
Returns the type of the used database system.
| QString Migrator::dbTypeToStr | ( | ) | const |
Returns the name of the used database system.
| QVersionNumber Migrator::dbVersion | ( | ) | const |
Returns the version of the used database system.
| bool Migrator::initDatabase | ( | ) |
Opens and initializes the database.
If the databae is not already open, this will try to open it. After that it will set the dbType(), the dbVersion() and the dbFeatures(). This has not to be called explicitely but is called by migrate() and rollback() automatically.
| bool Migrator::isDbFeatureAvailable | ( | DatabaseFeatures | dbFeatures | ) | const |
Returns true if the dbFeatures are available on the used database system.
| Error Migrator::lastError | ( | ) | const |
Returns error information about the last error (if any) that occurred with this migrator.
| bool Migrator::migrate | ( | ) |
Runs all migrations not already applied and return true on success.
If an error occures, false will be returned. Use lastError() to see what happened.
| QString Migrator::migrationsTable | ( | ) | const |
Returns the name of the table to store migrations to.
| bool Migrator::refresh | ( | uint | steps = 0 | ) |
Rolls back and reapplies the number of migrations defined by steps.
If steps is 0, all migrations are rolled back and reapplied. If an error occures, false will be returned. Use lastError() to see what happened.
| bool Migrator::reset | ( | ) |
Rolls back all migrations and returns true on success.
If an error occures, false will be returned. Use lastError() to see what happened.
| bool Migrator::rollback | ( | uint | steps = 1 | ) |
Rolls back the number of migrations set by steps and returns true on success.
If steps is 0, only one migration will be rolled back. If an error occures, false will be returned. Use lastError() to see what happened.