how to deploy new web application to old application with old database - php

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

Related

Create A New Database From Another Database

I am using CodeIgniter 3 and MySQL 5.7 and I need to find a way to create a new database on-the-fly for every new client that signs up for an account.
So basically, I have a skeleton or source database called db_source which contains all the tables and some initial data. I need to be able to create a new database, eg. db_client_xxx, every time a new user signs up for an account. I would prefer to create the new database from the source database if possible.
If anyone needs more information, please let me know. Thanks.
Regards,
Allie
A question similar to what you need has been answered here:
how to import .sql file in mysql database using php
You can dump the db_source into a file.
The correct answers explains how to run import a dump into an existing database. What you have to add to that script is to create database before that.
Please keep in mind that the database creation may take some time and may not be a very good experience for the user.
If I may suggest you another option is to create in advance the databases, e.g.: database_1, database_2 etc. and when a new user creates an account assign one database that is not used to that account. This may be easier and faster for the user. You can create a cron job to keep creating database so you always have a number of X databases available.
This approach also may be easier because you can use shell instead of PHP to dump and create new databases.

Redirect document root internally to another folder based on condition

I currently have the following setup:
*.mysite.com --> /home/public_html/app/index.php
I want to write some code in index.php that changes the whole document root to /home/public_html/app_prev/index.php based on a condition. The reason for this is that I am doing a migration and if they haven't been migrated yet, I want to serve the old version of the code; once they are migrated. Each user has their own database and I will migrate 1 by 1. Normally it would take seconds to migrate all of them, but this release will take awhile to do.
Is this possible?
Is this recommend when making large database schema changes? Will it cause performance problems/errors?
You could just use a PHP redirect based on the condition that you're looking for. It's no different then serving a different page based on what's coming in.
It's a reasonable implementation if you have many large databases and you're worried about performance. I'd test it by
Keep the old code path and old database.
Migrate a test database over to the new codebase. I don't know how you're doing your logic, but you could have a single column, one entry table in each database that describes whether it's on the old or new code base.
Test that the new codebase works.
Start migrating your databases over, changing that single entry in each database (or however your logic is determined).

Upgrading the existing database in a PHP system

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?

How to provide updates for client's mysql database without loosing clients existing data?

I am working on the project like wordpress. Where clients will be notified when updates are available. I am done with providing UI updates but how to provide database updates. What steps should i follow?
Database updates may include
Creation of new tables or
Deletion / Updation of new tables.
Then how can I update client database without affecting his/her existing data?
Please help.
You are looking for database migration. The general idea is that you should provide a script to downgrade and upgrade your database between different versions.
http://davedevelopment.co.uk/2008/04/14/how-to-simple-database-migrations-with-phing-and-dbdeploy.html
http://drarok.com/ladder/

MYSQL Event to update another database table

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.

Categories