krajcjakub / simple-migrations
Simple PHP tool for database migrations.
Installs: 6
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Forks: 0
pkg:composer/krajcjakub/simple-migrations
This package is not auto-updated.
Last update: 2026-01-09 19:53:33 UTC
README
SimpleMigrations is a simple PHP migration tool designed as a Composer package. It provides a lightweight way to manage database migrations using raw SQL files.
Usage
Once installed, you can use the Migrator class to manage your database migrations.
Basic Example
<?php
require_once __DIR__ . '/../../vendor/autoload.php';
use KrajcJakub\SimpleMigrations\Migrator;
use PDO;
$pdo = new PDO('mysql:host=localhost;dbname=test', 'user', 'password');
$migrator = new Migrator($pdo, 'migrations', __DIR__ . '/../migrations');
$migrator->migrate();
How It Works
- The
Migratorclass takes aPDOinstance, the name of the migrations table, and the path to the migrations directory. - It checks if the migrations table exists and creates it if necessary.
- It scans the migrations directory for new SQL migration files.
- Each migration file is executed in a transaction.
- After successful execution, the migration is recorded in the database to prevent duplicate execution.
Directory Structure
project-root/
│── migrations/
│ ├── 20240201_create_users_table.sql
│ ├── 20240202_add_email_to_users.sql
│── src/
│ ├── Migrator.php
│── public/
│ ├── migrate.php
│── vendor/
│── composer.json
Limitations
- No Abstraction: Migrations are raw SQL files, meaning they are database-specific.
- No Rollback (Down Migrations): Once a migration is applied, it cannot be undone automatically.
License
This project is licensed under the GPL-3.0 License.