Skip to content

purocean/php-db-migration

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

数据库迁移工具,仿照Yii2

仅支持 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

About

数据库版本管理迁移工具

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages