How to automate migration (schema and data) for PHP/MySQL application -
I have an application in PHP / MySQL I am searching to update the database behind an application in an automated way .
I have read and articles on this.
I still can not believe how to implement PHP / MySQL application.
Is there any simple and good procedure for this?
I have a "schema" object that I use - but you can do this without classes
Create a ' db_schema_versions ' table what you want to do:
create table db_schema_versions (`table 'varchar ( 255) Tap primary key, `version 'INT no.) What version can you track after your database # It is running - it can automatically upgrade the SQL
You should lock your schema table while renewing the schema. In this way, you will not request two requests at the same time in an attempt to upgrade your schema.
So - keep an eye out for the version you are upgrading - make a big switch - something like this:
increases class SNTrack_Db_Schema MW_Db_Schema_Abstract {protected $ table = " Sntrack_db_schema "; Protected Version $ 5; Protected work upgrade ($ fromVersion) {// Switch (version to $) {Case 0: $ it- & gt; Db- & gt; Query ('Create Tables sntrack_inbound_shipment (`id` INT is not primary primary key AUTO_INCREMENT,` `VARARA (255), not dated,` date` is not date,' invoice 'VARCHAR (255) tap,' notes text ');) ; $ This- & gt; SetVersion (1); Case 1: $ this- & gt; Db- & gt; Query ('ALTER TABLE sntrack_details ADD' SHIPMENT_ID 'IN'); $ This- & gt; Db- & gt; Query ('ALTER TABLE sntrack_product ADD' inventory 'INT not less than 0'); $ This- & gt; Db- & gt; Query ('Create Tables sntrack_inventory_shipment (`shipment_id' INT is not zero,` product_id` INT is zero, `qty` INT is zero, primary key (` shipment_id`, `product_id`)) ';); $ This- & gt; SetVersion (2); ... etc
Comments
Post a Comment