krajcjakub/simple-migrations
最新稳定版本:0.9.1
Composer 安装命令:
composer require krajcjakub/simple-migrations
包简介
Simple PHP tool for database migrations.
README 文档
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.
统计信息
- 总下载量: 6
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2025-09-18