22h/questdb-migration

A lightweight migration manager for QuestDB in PHP.

Installs: 0

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Forks: 0

pkg:composer/22h/questdb-migration

v0.1.0 2026-02-07 16:27 UTC

This package is auto-updated.

Last update: 2026-02-07 15:32:48 UTC


README

A lightweight package for managing database migrations for QuestDB in PHP.

This package allows you to manage versioned SQL migrations and execute them on a QuestDB instance. It supports forward migration (Up) and rolling back (Rollback) of migrations.

Features

  • Easy definition of migrations via PHP classes.
  • Automatic tracking of installed migrations in a QuestDB table.
  • Support for Symfony Finder for automatic discovery of migration files.
  • Rollback functionality.

Installation

Install the package via Composer:

composer require 22h/questdb-migration

Optional Dependencies

If you want to use the SymfonyFileMigrationLoader, also install:

composer require symfony/finder

Usage

1. Create a Migration

Create a PHP class that implements the MigrationInterface. The filename should match the class name (e.g., Version20250101000000.php).

<?php

declare(strict_types=1);

namespace App\Migrations;

use TwentyTwo\QuestDB\Client;
use TwentyTwo\QuestDBMigration\MigrationInterface;

class Version20250101000000 implements MigrationInterface
{
    public function getDescription(): string
    {
        return 'Creates the "sensor_data" table';
    }

    public function up(Client $client): void
    {
        $client->execute()->execute(
            "CREATE TABLE sensor_data (
                ts TIMESTAMP,
                sensor_id SYMBOL,
                reading DOUBLE
            ) timestamp(ts) PARTITION BY DAY"
        );
    }

    public function down(Client $client): void
    {
        $client->execute()->execute("DROP TABLE sensor_data");
    }
}

2. Execute Migrations

Use the MigrationManager to apply the migrations:

<?php

use TwentyTwo\QuestDB\Client;
use TwentyTwo\QuestDBMigration\MigrationManager;
use TwentyTwo\QuestDBMigration\QuestDbMigrationRepository;
use TwentyTwo\QuestDBMigration\SymfonyFileMigrationLoader;

require_once 'vendor/autoload.php';

// Configure QuestDB Client
$client = new Client();
$client->setUrl('http://localhost:9000');

// Repository for tracking versions
$repository = new QuestDbMigrationRepository($client);

// Loader for finding migration classes
$loader = new SymfonyFileMigrationLoader([
    'App\\Migrations' => __DIR__ . '/migrations'
]);

$manager = new MigrationManager($loader, $repository, $client);

// Execute all pending migrations
$manager->migrate();

3. Rollback (Undo the last migration)

$manager->rollback();

License

This project is licensed under the MIT License.