postgres migration

Hi,

I’m trying to create migration in such way


php yii migrate/create create_visitor_ip_table --fields='ip:inet:notNull:unique,country:string(128),city:string(128),user_id:integer(10)'

after php yii migrate

I’ve got an error


Exception 'yii\base\UnknownMethodException' with message 'Calling unknown method: m160713_084726_create_visitor_ip_table::inet()'

What is the proper way to migrate postgres fields.

P.S. Is any way to add index

Like


php yii migrate/create create_visitor_ip_table --fields='country:string(128):index'

Will generate in migration




$this->createIndex(

            'idx-visitor_ip-country',

            'visitor_ip',

            'country'

        );



inet? It should be “integer”. I don’t know if “int” will work or not.

And note that you can edit your migration file after you have generated it with “migrate/create” command. You don’t have create a complete migration code only with the “–fields” option.

For adding index, you can use yii\db\Migration::createIndex().

http://www.yiiframework.com/doc-2.0/yii-db-migration.html#createIndex()-detail

How do you store ip address in integer field?

Ah, sorry. I didn’t know ‘INET’ type of Postgres.

But I don’t think it’s supported by PDO and hence by Yii. Probably I would use plain “string” for it.

It should be possible to define “INET” type column by manually specifying it in your migration code. But I’m not sure if it is a good idea or not.