Table of Contents
Kanboard executes database migrations automatically for you. Migrations must be stored in a folder Schema and the filename must be the same as the database driver:
Schema
├── Mysql.php
├── Postgres.php
└── Sqlite.php
Each file contains all migrations, here an example for Sqlite:
<?php
namespace Kanboard\Plugin\Something\Schema;
const VERSION = 1;
function version_1($pdo)
{
$pdo->exec('CREATE TABLE IF NOT EXISTS something (
"id" INTEGER PRIMARY KEY,
"project_id" INTEGER NOT NULL,
"something" TEXT,
FOREIGN KEY(project_id) REFERENCES projects(id) ON DELETE CASCADE
)');
}
VERSION
is the last version of your schemaversion_1()
, version_2()
, etc.PDO
instance is passed as first argumentKanboard will compare the version defined in your schema and the version stored in the database. If the versions are different, Kanboard will execute one by one each migration until to reach the last version.