O Connor
O Connor

Reputation: 4402

Yii Framework 2.0 Migration with existing database

I know the concept of Yii framework 2.0 migrations. Let's say we generate migrations source code and run the command, the database tables will be created based on the source code. Is it possible to create migrations source code based on the existing database? With source code I do not mean the model, the controller or the CRUD classes but I mean the migrations source code. It is some kind of reverse engineer.

Upvotes: 6

Views: 7212

Answers (4)

PouriaDiesel
PouriaDiesel

Reputation: 735

I found a way that create migration from existing database tables.first install this extension from here via composer require bizley/migration.Then copy below code to your config/console.php:

'controllerMap' => [
    'migration' => [
        'class' => 'bizley\migration\controllers\MigrationController',
    ],
],

then in your command line type php yii migration/update table_name for single table or php yii migration/create table_name1,table_name2,table_name3 for multi tables or php yii migration/create * for all tables.

Upvotes: 5

Zhang Buzz
Zhang Buzz

Reputation: 11078

My practice is to mysqldump out a sql file, remove all unnecessary data, and put it in your source code, plus some migrating files, that way we can get the full schema of the system.

Upvotes: 0

Fory
Fory

Reputation: 403

The following yii2 extension generates migration scripts from an existing MySQL, MSSQL, PgSQL or SQLite database:

www.yiiframework.com/extension/yii2-migration-utility/

Source: www.github.com/c006/yii2-migration-utility

Upvotes: 10

arogachev
arogachev

Reputation: 33548

As far as I know there is no such functionality out of the box in Yii 2. Otherwise it must be menthioned in documentation and framework features.

And it's not trivial functionality to implement because of variety of RDMS. You can create issue on Github about that (but check if something similar already exists before that), but its unlikely will get high priority.

Upvotes: 0

Related Questions