top-think / think-migration Goto Github PK
View Code? Open in Web Editor NEWthinkphp 数据库迁移工具
License: Other
thinkphp 数据库迁移工具
License: Other
如题
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 中无法使用
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']); }
在使用 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
mysql8 int不会自动写长度,指定limit和length 也没用
->addColumn('content', 'string', ['encoding' => 'utf8mb4', 'collation' => 'utf8mb4_unicode_ci'])
在php think migrate:run
时
报错:
[RuntimeException]
"encoding" is not a valid column option.
think-migration version: 1.*
thinkphp version: 5.0.14
phinx官方文档上说string有encoding选项
http://docs.phinx.org/en/latest/migrations.html#valid-column-options
php think migrate:create articles
报错InvalidArgumentException
。何解
think-migration版本是2.*
tp5.1
类库源码里面是支持这个类型的,但是设置后run依然会报错。
用phinx的文档 ,发现 3.03用的是 0.6.5 (Thursday, 27 October 2016) , 感觉 有点老了。现在phinx都更新到0.13.x了。mysql也更新到8.0了。好多新功能都没办法使用了。
[think\exception\ThrowableError]
Fatal error: Call to undefined method think\migration\command\migrate\Create::getHelper()
模板里没有这两个函数, 想写rollback版本,还得手动写方法
如题
这个项目是否还有人维护?
没有是否考虑招聘新的维护者?
在 think\migration\Factory 类中 修改
希望能修复这个问题,现在我是在本地直接修改扩展包代码,另外我也想贡献我的代码,是直接fock 然后修改提交嘛?
今天一台新设备使用migrate一直报错,看php think 发现没这个命令,估计是命令注册没进来,手动写入 vendor/services.php内容后可以了,感觉是composer install的时候没有自动写入内容,希望官方能够解决
->addColumn('email', 'string')
php think migrate:status
[InvalidArgumentException]
There was a problem connecting to the database: SQLSTATE[HY000] [1105] unknown error: Code: UNAVAILABLE
server does not allow insecure connections, client must use SSL/TLS
没有为sqlite adapter 写对应的参数
目前不兼容 PgSQL 数据库,执行创建报错,语法问题。
我使用的tp
版本为5.1
,think-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",
]);
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;
}
in vendor/topthink/think-migration/phinx/src/Phinx/Db/Adapter/MysqlAdapter.php:207
$defaultOptions = [
'engine' => 'InnoDB',
'collation' => 'utf8_general_ci'
];
migrations
table, options are hard code in the following filein 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);
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
rt
$fileName = static::getCurrentTimestamp() . '' . strtolower(implode($arr, '')) . '.php';
??
implode(): Passing glue string after array is deprecated. Swap the parameters
--> implode( '_', $arr )
在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
迁移的时候报错"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');
}
}
希望同步phinx的版本更新。
利用php-scoper
对phinx
的核心包进行命名空间隔离打包,我觉得操作起来会更省事,并且可以消除捆绑cakephp
导致的全局函数污染问题,这个框架底层声明的全局函数和tp
有冲突。
初步实验成功,代码在这个仓库:https://github.com/NHZEX/think-phinx
目录 third-party-src 是原生phinx包,经过scoper
处理后输出到 third-party,完成捆绑发布。
cc @yunwuxin
public function change()
{
$this->table('user', ['comment' => '用户', 'auto_increment' => 1000])
...
}
comment 生效了,auto_increment默认还是1 我该怎么设置
我看了phinx 最新版本才支持,不知我们这边是否已经升级了
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中是不推荐的
[think\exception\ErrorException]
implode(): Passing glue string after array is deprecated. Swap the parameters,
似乎新版php对顺序要求严格了
现在composer下载下来的还有问题,希望可以更新一下
怎么指定库
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
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.