定制 krajcjakub/simple-migrations 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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

  1. The Migrator class takes a PDO instance, the name of the migrations table, and the path to the migrations directory.
  2. It checks if the migrations table exists and creates it if necessary.
  3. It scans the migrations directory for new SQL migration files.
  4. Each migration file is executed in a transaction.
  5. 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

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2025-09-18