database-command
Yii command to create database migrations from existing schema.
Migration classes are created in application runtime folder.
Get it from github and place it into your application.
Run the command...
./yiic database
... to show the help page
dump [<name>] [--prefix=<table_prefix,...>] [--dbConnection=<db>]
[--createSchema=<1|0>] [--insertData=<1|0>] [--foreignKeyChecks=<1|0>]
[--truncateTable=<0|1>]
| Param | Default | Info |
|---|---|---|
| name | dump | migration class name |
| --prefix | dump only tables with given prefix (specify multiple prefixes separated by commas) | |
| --createSchema | 1 | wheter to create tables |
| --insertData | 1 | wheter to create insert statements |
| --foreignKeyChecks | 1 | set to 0 to disable foreign key checks |
| --truncateTable | 0 | wheter to remove all records from the table first |
| --dbConnection | db | application component to use |
To create a migration from an existing application scheme, define an alternative database component in your
application, e.g. db-production.
The following command dumps all tables starting with p3_media and omits
the schema create statements:
./yiic database dump p3media-no-schema-production --prefix=p3_media --createSchema=0 --dbConnection=db-production
This example shows data dumping, removes all data (truncate tables) and omits foreign key checks:
./yiic database dump p3_replace_data --prefix=Auth,Rights,usr,p3 --createSchema=0 --foreignKeyChecks=0 --truncateTable=1
Separate schema and data:
./yiic database dump my_schema --insertData=0 ./yiic database dump my_data --createSchema=0
config/console.php
'commandMap' => array(
'database' => array(
'class' => 'vendor.schmunk42.database-command.EDatabaseCommand',
),
)
http://packages.phundament.com
Total 6 comments
I know :)
I've added the two open points to github as issue 5 and 6
I understand the message, and I know what its like - I have an opensource of my own: BT747 - unfortunately we are too often on our own. When I can, I provide code (see the ireport extension for instance), however I have no time for this one (and no time to dig into GIT for the moment).
Regarding the use of the model table names: there may be cases where migrations run into issues but I do not expect somebody to use this extension to create a migration, but more often to use it to do the initial setup. Personnally, I keep some initialisation code ready for the test setup and initialisation, and use migrations for live databases.
I'ld also like to see comments be recovered.
Thanks for your code and suggestions I've included most of them in the just released version 0.8.6
About these two points:
A small suggestion for the generator: I prefer to get the table name form the Model, like this: $this->createTable(ActionHistory::model()->tableName()
I think this will create additional dependencies from migrations to models and you may run into problems, when you need a migration which changes your table name.
When the primary key is composed of two columns, the command generation is also incorrect:
Feel free to create a pull request ;)
Hi
As foreign keys depend on multiple tables, they should be added only after all tables have been created.
When the primary key is composed of two columns, the command generation is also incorrect:
gives
I had to make small changes because the foreign keys generated were not compatible with the primary key generation (mainly due to 'unsigned')
and
refer here Run Yiic directly from your app without a shell
i just simple test it ,and it works :
Leave a comment
Please login to leave your comment.