|
cwist
Modern C web framework with libttak runtime
|
Schema migration system with version history and rollback. More...
#include <sqlite3.h>

Go to the source code of this file.
Classes | |
| struct | cwist_migration_t |
| A single migration step. More... | |
Macros | |
| #define | CWIST_MIGRATE_OK 0 |
| Return codes. | |
| #define | CWIST_MIGRATE_ERR_GENERIC (-1) |
| #define | CWIST_MIGRATE_ERR_SQL (-2) |
| #define | CWIST_MIGRATE_ERR_ARGS (-3) |
Typedefs | |
| typedef struct cwist_migration_t | cwist_migration_t |
| A single migration step. | |
Functions | |
| int | cwist_migrate_up (sqlite3 *db, const cwist_migration_t *migrations, int count) |
| Apply all migrations whose version > current schema version. | |
| int | cwist_migrate_down (sqlite3 *db, const cwist_migration_t *migrations, int count, int steps) |
Roll back the most recent steps migrations. | |
| int | cwist_migrate_version (sqlite3 *db) |
| Return the highest version number that has been applied. | |
Schema migration system with version history and rollback.
Each migration is a (version, name, up_sql, down_sql) tuple. The system stores applied migrations in a _cwist_migrations table and executes UP or DOWN SQL inside transactions, so a failed migration leaves the database unchanged.
Definition in file migrate.h.
A single migration step.
Roll back the most recent steps migrations.
Runs each migration's down_sql inside a transaction and removes the entry from the history table. Irreversible migrations (down_sql == NULL) are skipped entirely: they stay in the history table, so a later cwist_migrate_up will not re-apply them, and they do not count towards steps.
| db | Open SQLite3 handle. |
| migrations | Array of migrations (same array passed to cwist_migrate_up). |
| count | Number of elements in migrations. |
| steps | Number of versions to roll back (0 = all applied). |
Roll back the most recent steps migrations.
| db | SQLite connection to migrate. |
| migrations | Caller-supplied migration array. |
| count | Number of entries in migrations. |
| steps | Maximum number of applied versions to roll back, or all when <= 0. |
Definition at line 174 of file migrate.c.
References count, CWIST_MIGRATE_ERR_ARGS, CWIST_MIGRATE_ERR_GENERIC, CWIST_MIGRATE_ERR_SQL, CWIST_MIGRATE_OK, and cwist_migrate_version().
| int cwist_migrate_up | ( | sqlite3 * | db, |
| const cwist_migration_t * | migrations, | ||
| int | count | ||
| ) |
Apply all migrations whose version > current schema version.
Migrations are applied in ascending version order inside individual transactions. On failure the transaction is rolled back and the function returns the error code.
| db | Open SQLite3 handle. |
| migrations | Array of migrations (need not be sorted; function sorts). |
| count | Number of elements in migrations. |
Apply all migrations whose version > current schema version.
| db | SQLite connection to migrate. |
| migrations | Caller-supplied migration array. |
| count | Number of entries in migrations. |
Definition at line 123 of file migrate.c.
References count, CWIST_MIGRATE_ERR_ARGS, CWIST_MIGRATE_ERR_GENERIC, CWIST_MIGRATE_ERR_SQL, CWIST_MIGRATE_OK, and cwist_migrate_version().
Return the highest version number that has been applied.
Return the highest version number that has been applied.
| db | SQLite connection to inspect. |
Definition at line 99 of file migrate.c.
References CWIST_MIGRATE_OK.
Referenced by cwist_migrate_down(), and cwist_migrate_up().