Giter VIP home page Giter VIP logo

think-migration's People

Contributors

hugtale avatar joewulf avatar leeqvip avatar leogorden avatar liu21st avatar yunwuxin avatar yupoxiong avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

think-migration's Issues

migrate:run error when not support InnoDB engine

To create a table may use InnoDB engine by default

in vendor/topthink/think-migration/phinx/src/Phinx/Db/Adapter/MysqlAdapter.php:207

        $defaultOptions = [
            'engine'    => 'InnoDB',
            'collation' => 'utf8_general_ci'
        ];

And when calling createSchemeTable to create migrations table, options are hard code in the following file

in vendor/topthink/think-migration/phinx/src/Phinx/Db/Adapter/PdoAdapter.php:508

            $options = array(
                'id'          => false,
                'primary_key' => 'version',
            );

            $table = new Table($this->getSchemaTableName(), $options, $this);

看到 migration 尝试兼容新版的 phinx,提一个相对比较优雅的解决方案

利用php-scoperphinx的核心包进行命名空间隔离打包,我觉得操作起来会更省事,并且可以消除捆绑cakephp导致的全局函数污染问题,这个框架底层声明的全局函数和tp有冲突。

初步实验成功,代码在这个仓库:https://github.com/NHZEX/think-phinx

目录 third-party-src 是原生phinx包,经过scoper处理后输出到 third-party,完成捆绑发布。

执行构建的方法:
https://github.com/NHZEX/think-phinx/blob/4b816a5bfb56433f76823455011cb615315b879c/composer.json#L73-L79

cc @yunwuxin

php7.4版本运行migrate:create命令报错

implode(): Passing glue string after array is deprecated. Swap the parameters

phinx/src/Phinx/Util/Util.php文件中$fileName = static::getCurrentTimestamp() . '_' . strtolower(implode($arr, '_')) . '.php';的implode方法的参数顺序在php7.4中是不推荐的

mysql

mysql8 int不会自动写长度,指定limit和length 也没用

Long text 字段类型加上进去

用phinx的文档 ,发现 3.03用的是 0.6.5 (Thursday, 27 October 2016) , 感觉 有点老了。现在phinx都更新到0.13.x了。mysql也更新到8.0了。好多新功能都没办法使用了。

implode函数 php7.4.5支持问题

[think\exception\ErrorException]
implode(): Passing glue string after array is deprecated. Swap the parameters,
似乎新版php对顺序要求严格了

seeder中获取output失败。

在tp8中,通过getOutput获取输出对象失败,在之前的版本可以正常获取到。

图片

  [TypeError]
  Phinx\Seed\AbstractSeed::getOutput(): Return value must be of type think\console\Output, null returned



Exception trace:
 () at C:\www\user_hub\vendor\topthink\think-migration\phinx\Seed\AbstractSeed.php:138
 Phinx\Seed\AbstractSeed->getOutput() at C:\www\user_hub\database\seeds\InitBaseAdminData.php:20
 InitBaseAdminData->run() at C:\www\user_hub\vendor\topthink\think-migration\src\command\seed\Run.php:96
 think\migration\command\seed\Run->executeSeed() at C:\www\user_hub\vendor\topthink\think-migration\src\command\seed\Run.php:67
 think\migration\command\seed\Run->seed() at C:\www\user_hub\vendor\topthink\think-migration\src\command\seed\Run.php:52
 think\migration\command\seed\Run->execute() at C:\www\user_hub\vendor\topthink\framework\src\think\console\Command.php:210
 think\console\Command->run() at C:\www\user_hub\vendor\topthink\framework\src\think\Console.php:649
 think\Console->doRunCommand() at C:\www\user_hub\vendor\topthink\framework\src\think\Console.php:308
 think\Console->doRun() at C:\www\user_hub\vendor\topthink\framework\src\think\Console.php:245
 think\Console->run() at C:\www\user_hub\think:12

Seeder.php是不是应该这么写

namespace think\migration;

use Phinx\Seed\AbstractSeed;
use think\migration\db\Table;
class Seeder extends AbstractSeed
{
    public function table($tableName, $options = [])
    {
        return new Table($tableName, $options, $this->getAdapter());
    }
}

返回的table对象应该是 think\migration\db\Table 这个对象。

不然的话 会直接调用 \Phinx\Db\Table ,很多方法在 seed 中无法使用

migrate:run不创建表也不会报错

迁移的时候报错"extra" is not a valid column option. 应该怎么办?

class Contact extends Migrator
{
    public function change()
    {
        $table = $this->table('contact');
        $table->addColumn('user_id', 'integer', ['comment' => '用户 ID'])
            ->addColumn('contact_id', 'integer', ['comment' => '联系人 ID'])
            ->addColumn('type', 'enum', ['values' => ['normal', 'blocked'], 'default' => 'normal', 'comment' => '关系类型'])
            ->addColumn('created_at', 'datetime', array('null' => true, 'default' => 'CURRENT_TIMESTAMP', 'comment' => '创建时间'))
            ->addColumn('updated_at', 'datetime', array('null' => true, 'default' => 'CURRENT_TIMESTAMP', 'extra' => 'ON UPDATE CURRENT_TIMESTAMP', 'comment' => '更新时间'))
            ->create();
    }

    public function down()
    {
        $this->dropTable('contact');
    }
}

数据库迁移脚本向不同的连接库迁移问题

在使用 https://github.com/php-casbin/think-authz/ 的时候发现定义了它的 connection 配置,也无法在指定的连接库中创建表,还是会创建到默认连接的库中

在 topthink/think-migration/src/command/Migrate.php 的 executeMigration() 方法中发现

$migration->setAdapter($this->getAdapter());

这一行的 getAdapter() 方法会直接使用 config 中指定的 default 的连接,即我在迁移脚本中指定了自己想要连接的数据库也无效,要在指定的连接库中创建表只能去改整体的 database.default

请问下怎么设置 auto_increment

public function change()
{

  • $this->table('user', ['comment' => '用户', 'auto_increment' => 1000])

  • ...

}
comment 生效了,auto_increment默认还是1 我该怎么设置

Type error: implode(): Argument #2 ($array) must be of type ?array, string given

D:\www\cdirs\master>php think migrate:create Users

[think\exception\ThrowableError]
Type error: implode(): Argument #2 ($array) must be of type ?array, string given

Exception trace:
() at D:\www\cdirs\master\vendor\topthink\think-migration\phinx\src\Phinx\Util\Util.php:110
implode() at D:\www\cdirs\master\vendor\topthink\think-migration\phinx\src\Phinx\Util\Util.php:110
Phinx\Util\Util::mapClassNameToFileName() at D:\www\cdirs\master\vendor\topthink\think-migration\src\command\migrate\Create.php:65
think\migration\command\migrate\Create->execute() at D:\www\cdirs\master\thinkphp\library\think\console\Command.php:175
think\console\Command->run() at D:\www\cdirs\master\thinkphp\library\think\Console.php:675
think\Console->doRunCommand() at D:\www\cdirs\master\thinkphp\library\think\Console.php:261
think\Console->doRun() at D:\www\cdirs\master\thinkphp\library\think\Console.php:198
think\Console->run() at D:\www\cdirs\master\thinkphp\library\think\Console.php:115
think\Console::init() at D:\www\cdirs\master\think:20

"topthink/think-migration": "2.0.3"
public static function mapClassNameToFileName($className)
{
$arr = preg_split('/(?=[A-Z])/', $className);
unset($arr[0]); // remove the first element ('')
$fileName = static::getCurrentTimestamp() . '' . strtolower(implode( $arr,'')) . '.php';
return $fileName;
}
Change
public static function mapClassNameToFileName($className)
{
$arr = preg_split('/(?=[A-Z])/', $className);
unset($arr[0]); // remove the first element ('')
$fileName = static::getCurrentTimestamp() . '' . strtolower(implode( '',$arr)) . '.php';
return $fileName;
}

Fatal error: Uncaught Error: Class 'think\Console' not found

我使用的tp版本为5.1think-migration版本为2.0.3,这个库本身使用没有问题,但是会导致其它库的脚本无法执行,我使用这个库(captainhook/captainhook)时,此库需要使用自动加载加载文件,执行cli的脚本,但是当require vendor/autoload.php
库的源码如下

 // check installation type [composer bin dir, git clone / phar, composer package dir]
    $composerAutoloadLocations = [
        __DIR__ . '/../autoload.php',
        __DIR__ . '/../vendor/autoload.php',
        __DIR__ . '/../../../autoload.php'
    ];

    foreach ($composerAutoloadLocations as $file) {
        if (file_exists($file)) {
            define('CAPTAINHOOK_COMPOSER_AUTOLOAD', $file);
            break;
        }
    }
    unset($file);

    if (!defined('CAPTAINHOOK_COMPOSER_AUTOLOAD')) {
        fwrite(STDERR,
            'You need to set up the project dependencies using the following commands:' . PHP_EOL .
            'wget http://getcomposer.org/composer.phar' . PHP_EOL .
            'php composer.phar install' . PHP_EOL
        );
        exit(1);
    }

    require CAPTAINHOOK_COMPOSER_AUTOLOAD;

就会报如下错误,不光是这个库,我试了凡是用的自动加载的都会报错,这个应该是think-migration库的问题,我单独试了这个库没有问题,在laravel试了也没有问题

Fatal error: Uncaught Error: Class 'think\Console' not found in E:\UPUPW_NP7.2_64\vhosts\contract_tp5.1\vendor\topthink\think-migration\src\config.php on line 10

config.php的文件源码如下,为什么使用自动加载会无法加载到think\Console这个类呢,希望能修复这个bug


\think\Console::addDefaultCommands([
    "think\\migration\\command\\migrate\\Create",
    "think\\migration\\command\\migrate\\Run",
    "think\\migration\\command\\migrate\\Rollback",
    "think\\migration\\command\\migrate\\Breakpoint",
    "think\\migration\\command\\migrate\\Status",
    "think\\migration\\command\\seed\\Create",
    "think\\migration\\command\\seed\\Run",
]);

php8.2 兼容问题

1. 在 PHP 8.2.x 中,要求方法的返回类型必须与接口或父类中定义的返回类型一致,因此在 think\migration\Factory 类中的 offsetExists 方法中显式指定返回类型。这样可以确保方法的返回类型与 ArrayAccess 接口的要求一致

image

在 think\migration\Factory 类中 修改
image

2. fzaninotto/faker 扩展包已经停止更新了并且不支持 php8.x ,建议可以使用 akerphp/faker

希望能修复这个问题,现在我是在本地直接修改扩展包代码,另外我也想贡献我的代码,是直接fock 然后修改提交嘛?

有文档?

php think migrate:create articles报错InvalidArgumentException。何解

Fatal error: Class 'think\facade\Env' not found

 php think migrate:create  gift
[think\exception\ThrowableError]                 
Fatal error: Class 'think\facade\Env' not found  
Exception trace:
 () at /Library/WebServer/Documents/xiaoshuo_full/vendor/topthink/think-migration/src/command/Migrate.php:34
 think\migration\command\Migrate->getPath() at /Library/WebServer/Documents/xiaoshuo_full/vendor/topthink/think-migration/src/command/migrate/Create.php:43
 think\migration\command\migrate\Create->execute() at /Library/WebServer/Documents/xiaoshuo_full/thinkphp/library/think/console/Command.php:175
 think\console\Command->run() at /Library/WebServer/Documents/xiaoshuo_full/thinkphp/library/think/Console.php:655
 think\Console->doRunCommand() at /Library/WebServer/Documents/xiaoshuo_full/thinkphp/library/think/Console.php:223
 think\Console->doRun() at /Library/WebServer/Documents/xiaoshuo_full/thinkphp/library/think/Console.php:166
 think\Console->run() at /Library/WebServer/Documents/xiaoshuo_full/thinkphp/library/think/Console.php:126
 think\Console::init() at /Library/WebServer/Documents/xiaoshuo_full/thinkphp/console.php:20
 require() at /Library/WebServer/Documents/xiaoshuo_full/think:17

3.1.x-dev php think migrate:run 运行报错

warning Migration contains both change() and up()/down() methods. Ignoring up() and down().
[TypeError]
Phinx\Db\Table\Index::setName(): Argument #1 ($name) must be of type string, null given, called in /vendor/topthink/think-migr
ation/phinx/Db/Table/Index.php on line 222

An invalid encoding was specified for SQLSRV_ATTR_ENCODING

think-migration version: 1.*
thinkphp version: 5.0.13

使用sqlsrv报错 SQL Server fails with SQLSTATE[IMSSP]: An invalid encoding was specified for SQLSRV_ATTR_ENCODING.

官方解决方法应该去除charset设置,应该在Command.php的getDbConfig方法返回数据之前增加
if($config['type'] == 'sqlsrv'){ unset($dbConfig['charset']); }

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.