purocean/php-db-migration

A database migration tool

v0.0.1 2017-01-20 13:17 UTC

This package is not auto-updated.

Last update: 2024-05-11 17:23:48 UTC


README

仅支持 MySQL

使用

// migration.php
date_default_timezone_set('PRC');
$migrationConfig = [
    'tablePrefix' => 'test_prefix_', // 表前缀
    'migrationsPath' => __DIR__.'/migrations', // 迁移储存位置
    'dbConfig' => [ // 数据库配置
        'username' => 'root',
        'password' => '',
        'dsn' => 'mysql:host=localhost;port=3306;dbname=db_migration_test;charset=utf8',
    ]
];

(new \DbMigration\Cli($migrationConfig))->run();
php migration.php help

迁移示例:/test/migrations/m170119_101310_test_migration.php

功能

  • create 创建迁移
  • up 升级一个迁移
  • down 降级一个迁移
  • mark 讲某个迁移标记为已升级/未升级
  • new 显示未升级迁移
  • history 查看迁移历史

测试

cd test
vim config.php # 修改数据库配置
php test.php

MySQL

  • execute
  • createTable
  • renameTable
  • dropTable
  • truncateTable
  • addColumn
  • dropColumn
  • renameColumn
  • alterColumn
  • addPrimaryKey
  • dropPrimaryKey
  • addForeignKey
  • dropForeignKey
  • createIndex
  • dropIndex
  • addCommentOnColumn()
  • addCommentOnTable
  • dropCommentFromColumn
  • dropCommentFromTable
  • primaryKey
  • char
  • varchar
  • string
  • text
  • smallInteger
  • integer
  • bigInteger
  • float
  • double
  • decimal
  • dateTime
  • timestamp
  • time
  • date
  • binary
  • boolean
  • notNull
  • null
  • unique
  • defaultValue
  • comment
  • unsigned
  • after
  • first
  • append