I'm working on a software solution which was written using PHP Symfony with mysql database. When we do upgrades to the existing product what we use now is copping the existing database to a new database and do the upgrade standing on the new database. But the current method of asking the user to copy the existing database does not seem to be the professional way to do an upgrade.
Is there any standard way of doing that automatically and preserve the consistency of the old database? Please help me on this issue. Thanks in advance.
You could create a copy of the tables with a different table prefix (like updateAttempt_) and then if everything goes well delete the old ones and rename the new ones to the old ones.
Although, If you're doing this to make sure the data isn't corrupted in the event something goes wrong.. isn't that what TRANSACTIONS are for?
Related
I have built a web app using MySQL and php and I'm at the moment trying to figure out the best approach to make a script to automatically update the customers based on the new changes on my development environment without affect the customer data.
So far my first attempt was to check the app version if there is a new one, download the zip with the new and changed files, then I do a mysqldump skipping triggers, etc. of the customers, drop all tables on the customers database, load the scheme and reload the dumped file.
The problem I am facing is that this work if the change in the scheme is a minor one, if I decide to add a couple of columns with new values, or remove unused tables, or to remove unused rows the upload fails.
So my question is whats the best approach to safely update different databases, based on the my development database changes?
I guess the best way is to include queries upgraded script with all the needed queries on it?
But is this the right way?
There is some automatic way to handle this to avoid to manually have to write each change and avoid as well to miss some changes on the script and screw it all?
I really appreciate your opinions as looking around, I didn't find any clear approach of this procedure.
I am using mysql database for my site.
I have create one site using codeigniter php framework and mysql.
Now after few months I have updated that site and also the database.
I have added some new columns to my database table not deleted or alert any previous one.
Now I want to update my site but don't want to lose data that I already have right now.
Is there anyway I can update database without losing the data present in it.
If your database is created/updated automatically by some modeling tool, I think the best you way you should do is to understand those changes and write the "alter table" statements yourself and run it in your deployment.
As user1281385 pointed in answer https://stackoverflow.com/a/22012478/1033539 , there may be some tool that can help you generate those statements.
SQLyog has a great feature called "Schema Synchronization tool" which will do it
they also have a blog comparing other methods of doing it
http://blog.webyog.com/2012/10/16/so-how-do-you-sync-your-database-schema/
Im sure other similar tools can do it also
Edit:
Mysql Workbench also has this feature
http://www.mysql.com/products/workbench/features.html
Inside the Oscommerce folder there is an upgrade_guide called upgrade-230.pdf.
there it sais
If you wish to upgrade to a full v2.3 version, perform only (SQL) Database Changes and use the database with a new v2.3 installation.
But how do I make those Database Changes to use it with a new v2.3?
I think I have to manually compare database schemas and modify the old site's backup .sql file (adding/changing fields, adding tables, etc., to match the schema and fixing the corresponding INSERT statements to match). Then you can simply replace the new installation's database with the restored old one.
In the file there are only some SQL-commands to create the action recorder:
CREATE TABLE action_recorder ( ...
What else do I have to change in the old database backup?
The databases are pretty much the same, only some small differences that you can correct with these statements, I collected the needed changes here:
https://gist.github.com/rubo77/7330900
Or you could try the Community Add-On SQL upgrades from 2.2MS to 2.3.3.
Depending on your old version you may or may not need all of it. Also, be sure to make a backup of your database before running any of this
I'm developing a new version for my web application with some redesigned database structure. However, the old application is still working onine with customers. Is there any solutions for easing this deployment?
Thanks and best regards.
Edited: My question is about how to merge the old database with the new database with new redesigned structure. The old database had many new records when I developed new application with new database.
Just make a new database, and include the version in the name for example. You can have multiple databases on the same server, and even use multiple databases in the same application.
I believe there are two choices;
Either force all users to the new system with a bit of downtime, which as long as your site has some quite time on traffic you can schedule it then.
Alternatively upload both and run concurrently pointing everyone at the new site and give a time-frame to your users for taking down the old site.
These are some steps you can follow.
First you have to get a backup database dump from the your existing database. Eventhough you made some mistake you are in the safe side.
Then you can create a new database using the old dump.
Then you have to figure out what are the changes you did in the structure.
Then you have to map old data to the new tables which are changed using ALTER TABLE commands. For this you can first create necessary new tables using sql commands and then read the old data and insert in to new ones.
If you are using mysql you can use "Transactions" to make sure your changes are persistent. You can refer my blog post to learn more on "Transactions" http://coders-view.blogspot.com/2012/03/how-to-use-mysql-transactions-with-php.html
I have just taken over a project for a client and the database schema is in a total mess. I would like to rename a load of fields make it a relationship database.
But doing this will be a painstaking process as they have an API running of it also. So the idea would be to create a new database and start re-writing the code to use this instead. But I need a way to keep these tables in sync during this process.
Would you agree that I should use MYSQL EVENT's to keep updating the new table on Inserts / updates & deletes??
Or can you suggest a better way??
Hope you can advise !!
thanks for any input I get
I had the same problem in my project. I did the same thing like you - writing the whole database new. We developed the new database and the fitting code and after finishing that work we made a migration script (small application) which did the migration from old to new database.
Hope this gives you some ideas...
I had the same problem as well, and went by the way of duplicating data at the point of user input (basically saved to both databases at once, since the original schema lacked all the required information). After several months of development the customer realized that he is going to move to a completely new database and considered it too risky (and I agree with him).
Thus, I would advice to utter clearly to your customer that you are going to implement a new database instead of iterative refactoring of the current one.