Phinx: LONGTEXT and TINYINT support

Created on 13 May 2014  路  13Comments  路  Source: cakephp/phinx

Phinx is amazing, and we're just now setting up PHPCI to use it for managing the database, however we'd really like to see support for LONGTEXT and TINYINT columns - as we use both extensively.

If these are not available in all database engines, perhaps in those adapters they could be aliased to TEXT and INT respectively?

feature

Most helpful comment

We might need better docs

use Phinx\Db\Adapter\MysqlAdapter;
...
->addColumn('request', 'text', [
    'default' => null,
    'limit' => MysqlAdapter::TEXT_MEDIUM,
    'null' => false,
])

also TEXT_LONG etc are available.

All 13 comments

Yes please, could really do with LONGTEXT/MEDIUMTEXT support.
Followed instructions here to add them in.

I also need support for TINYINT

@robmorgan - Would you accept a pull request that added these column types? Happy to implement, but don't want to waste time. :)

the only thing I'm on the fence about is whether or not we implement it similar to the Rails way. e.g: http://stackoverflow.com/questions/9670834/rails-change-column-to-mediumtext. A limit of say 20 for the text type would automatically use TINYTEXT

@robmorgan It depends on what the goal of this project is. If the goal is to provide portable migrations (stuff should work across all supported adapters when using the same code) then going the rails way is the only way. If you want to exposes the adapters as much as possible, then using the actual type names is better

I think the limit solution is perfect.

ok maybe we take limit then. does anybody want to contribute a PR?

I created a PR for this issue here #330.

The #330 PR only handles [tiny/medium/*]TEXT, not INT. But I guess it could be implemented following the same pattern.

If you set length/limit to something tiny and it translates into a tiny int on MySQL, I'd say it makes sense.

@cbrunnkvist that ends up being a _little_ bit weird, because INT(2) and INT(10) actually mean something. But since the maximum possible BIGINT width is 20 (for 18446744073709551615), and the TINYINT size is 255 it would be safe to declare that:

TINYINT = 255
SMALLINT = 65535
MEDIUMINT = 16777215
INT = 4294967295
BIGINT = 18446744073709551615

I will proceed implementing with these values in mind.

This is now complete. XINT and XTEXT are now fully supported.

We might need better docs

use Phinx\Db\Adapter\MysqlAdapter;
...
->addColumn('request', 'text', [
    'default' => null,
    'limit' => MysqlAdapter::TEXT_MEDIUM,
    'null' => false,
])

also TEXT_LONG etc are available.

@dereuromark I would prefer a factory method for columns.

->addColumn($this->column('foo')
    ->default('bar')
    ->null(true)
    ->type(Type::MEDIUM_TEXT));

The method could cast it to whatever the DB uses for MEDIUM_TEXT. This could be done in a backward compatible way by accepting a row object or the three args it takes. This gives us autocomplete in IDEs and an advantage over the messy arrays.

Was this page helpful?
0 / 5 - 0 ratings