doctrine how to generate db table from yaml
Is there any command in doctrine which can create db table from YAML. I can see we can create YAML from DB using ./doctrine generate-yaml-db
But How can we achieve the reverse feature of this. from yaml to db.
is there any command something like this 开发者_StackOverflow./doctrine generate-db-yaml
Generating a database from a yaml file must be done in two steps.
Generate the models from the yaml file using Doctrine_Core::generateModelsFromYaml().
Generate the database from the models using Doctrine_Core::createTablesFromModels().
I suggest writing a command-line script to call both these functions in sequence, and to automate a few other necessary steps. Here is the core of the script I use to re-generate my database.
echo 'Deleting old models...';
deleteAllFilesInDirectory(APPPATH . '/models/generated');
echo "done.\n";
echo 'Generating models...';
Doctrine_Core::generateModelsFromYaml('schema.yml', APPPATH . '/models');
echo "done.\n";
echo 'Recreating database tables...';
Doctrine_Core::dropDatabases();
Doctrine_Core::createDatabases();
Doctrine_Core::createTablesFromModels(APPPATH . '/models');
echo "done.\n";
echo 'Loading data...';
Doctrine_Core::loadData('autoload.yml', 'true');
echo "done.\n";
精彩评论