Schema management and migrations in CakePHP 3 - cakephp-3.0

I used to utilize
Console/cake schema
in CakePHP 2.
Now I am on my way to CakePHP 3 and find out that Console/cake schema is gone.
So what is the recommended way to manage schema and migrations now?

Lorenzo from the CakePHP core has created the below plugin. It is currently under development and should be considered experimental.
CakePHP 3.0 database migrations plugin
https://github.com/cakephp/migrations
The Migrations Plugin is now part of the CakePHP Core

There are now 2 routes to generate migrations:
Cake (using bake)
bin/cake bake migration [migration_name]
Phinx
bin/cake migrations
Using the Phinx code above it will give you multiple options ie create, migrate, rollback - Create needs a migration name make sure to use CamelCase

Related

Recreate database tables from Yii2 models

I wrote an application in Yii2, and unfortunately, we've lost all the database back ups. What we now have is the application files only. Is there a shorter way of recreating the 98 database tables based on the existing models?
I notice that some 22 Tables' Schema were cached under "/app/runtime/cache". Has anyone done something like this?
I have to warn that I have used this ones and it's very helpful, when you need some a$$ saving.
This is a very interesting extension for Gii, that will at least help you restart the database, and then you will be working on it to fix some things.
What it will allow you to do, it's to build migrations from the PHPDoc in your models. The use those migrations to rebuild the database.
You need to install https://github.com/Insolita/yii2-migrik by using composer, if it gives you some trouble use version 2.3 and not 3.
Add
"insolita/yii2-migration-generator": "2.3"
Then open Gii and use "Model and PhpDoc migrations".
Now use Yii2 migration system to build the tables, check the migrations, compare them to the models and add relations, them UP them and will need to fix some stuff. It's not perfect. But it saves time.
https://www.yiiframework.com/doc/guide/2.0/en/db-migrations
Good luck.
You need to create migration scripts for each model to do database backup.
You need to create database schema in Migration script up() function and need to use following command to manage database.
- migrate Manages application migrations.
migrate/create Creates a new migration.
migrate/down Downgrades the application by reverting old migrations.
migrate/fresh Truncates the whole database and starts the migration from the beginning.
migrate/history Displays the migration history.
migrate/mark Modifies the migration history to the specified version.
migrate/new Displays the un-applied new migrations.
migrate/redo Redoes the last few migrations.
migrate/to Upgrades or downgrades till the specified version.
migrate/up (default) Upgrades the application by applying new migrations.
For more please refer Official Documentation for Yii2 DB Migrations.
Migration script keeps track of database and if it lost again, you can easily create it.
Thanks.

Symfony 1.4 with sfPropelORMPlugin and MySQL Replication

I upgraded my symfony 1.4 project with the latest version of sfPropelORMPlugin and I created my runtime-conf.xml according to: http://www.propelorm.org/cookbook/replication.html with the intend to write my sql to a master and read from the slaves.
I'm rebuilding my model with symfony propel:build-model and everything goes fine but both write/read SQL statements are sent to the master. I'm not sure I understand how propel is using runtime-conf.xml within the symfony framework.
Am I missing an extra step?

Can we use EF migrations with MySql

Is there a way to use EntityFramework 4.3 beta with migrations with MySql database? Can we use migrations with MySql Database? Is it possible to use incremental database development with EF code first without me touching the database
Theoretically yes. Practically you first need to get (or create yourselves) class derived from System.Data.Entity.Migrations.Sql.MigrationSqlGenerator which will be responsible for generating SQL for MySQL. Here is more about customizing (or rewriting) SQL generation.
You can also wait until developers of EF supporting ADO.NET providers include this feature to their packages. For example Devart already started work on their migrations support for thier Oracle, MySQL, PostgreSQL and SQLite.

Easiest way to port a data model to Rails migration

I have designed a data model which has almost 24 tables. I have finished specifying the relations and all the data types are finalized. Now, I want to convert it to migrations in Rails.
I have all the scripts ready for it to be created in MySQL. Is there any tool that converts all the table creation queries into a single Rails migration file?
Thanks
I haven't done it myself but according to this post on the ruby forums
rake db:schema:dump
should be sufficient (delete the schema.rb beforehand).
The almost same question here on SO: Ruby / Rails - Reverse Migration - DDL to Ruby Code

Export MySQL Workbench data model directly to Schema YML in Propel/ Symfony

Is there any plugin that directly exports MYSQL Workbench data model directly to YML for Propel consumption?
Yes, MySQL Workbench Plugins are available for generating schemas for Propel, Doctrine, Symfony, etc
http://forums.mysql.com/read.php?153,208229
Just an update on this issue. If you are looking for a quick and convenient way to export your database tables to entities and mapping .yml files, there used to be a plugin for Workbench that would do this, but this LUA is not supported any more, unfortunately. It worked great -- too bad because if you use MySQL Workbench, a plugin would ideally be the most convenient and fastest way to export your database as entities into your Symfony project.
So, the next best solution I found is installing a utility that can be executed from Symfony's app/console called "mysqlworkbenchschemaexporter". With this utility, you will have to save your Workbench files (*.wmb) then upload them to a folder, then the following app/console commands are available:
app/console mysqlworkbenchschemaexporter:dump
app/console mysqlworkbenchschemaexporter:withRepository
Without buying an ORM tool like Skipper, which costs over $300, I did find this recently updated solution that is supported at:
https://github.com/turnaev/mysql-workbench-schema-exporter-symfony2-bundle
I hope this helps other Symfony developers save some time with entity creation and ORM mappings!
When using symfony 1.x, personally I prefer the following process:
design the model with workbench
use the "synchronize model" option to apply changes to the DB
run the propel:build-schema task to update the schema.yml
run the propel:build --all-classes task (it implies model, forms and filters)
Please note: step 3 will overwrite your entire schema.yml file. If you need to add special tweaks to it, just add a schema.custom.yml to your project and you're good to go.
If export from MySQL workbench isn't sufficient, you can try our tool Skipper - formerly ORM Designer (I'm chief developer). With Skipper you can define and export also behaviours, Propel specific column/table/... attributes and much more.
http://www.skipper18.com