Maintaining Hosting and Local Copies of Web Applications
Here are tips and tricks to help you maintain code consistency between your application on your local machine and your host.
Code Version Management – GIT
Code management is most common with a code management tool and the most popular of these is git. Git allows you to maintain and track versions of code and also synchronize between different repositories of code. Git can be downloaded at this site;
https://git-scm.com/
You will also want to maintain cloud based repositories of your code and github is the most common of these. There is a lot to learn with these tools, but there are also many resources to help you including video on this site.
https://github.com/
Another tool which is important to have and use is ftp, and for most FileZilla is the best ftp tool to have and use.
http://filezilla-project.org/ – Use the client download for FileZilla.
Updating the Database
Keeping the database up to date is a bit trickier. One option for the database is to completely delete all database objects and then recreate them. A good script to delete all objects from a database for SQL Server is available from Stack Overflow. This is a good procedure to have in your library of Stored Procedures.
https://stackoverflow.com/questions/536350/drop-all-the-tables-stored-procedures-triggers-constraints-and-all-the-depend
Of course you should not delete everything unless you have a back-up. With SQL Server this is built into the SQL Server Management Studio and is under the menus to generate scripts. These are available for individual objects or for the entire database.
In addition to this you will also want to have a script (in this case a stored procedure) generate inserts for data that you want to transfer from your local machine to your host. I use a script avalaible here = http://www.malgreve.net/2008/11/how-to-script-data-generate-insert-t.html . This script will place the script in the master database, making it available to all databases for generating insert scripts.
When using – remember to use the USE command prior to executing the script to specify the database that you want to script data for. Then simple execute it as
USE YourDatabase
GO
EXEC sp_generate_inserts Your_Table_Name
As a note – be sure to right click on the Query Analyzer Screen and select Results, To Text …
that will make the results easy to copy and paste. If you have identity fields in the database you are scripting you may have to manually change the insert script OR possibly change your IDENTITY INSERT to OFF to be able to use the insert script.
For example running this script would look like
USE MyDailyMath
GO
EXEC sp_generate_inserts Roles
GO
GO
PRINT 'Inserting values into [Roles]'
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
INSERT INTO [Roles] ([id],[RoleNameText],[RoleDescriptionText])
VALUES(1,'Administrator','Full rights to all parts of system')
INSERT INTO [Roles] ([id],[RoleNameText],[RoleDescriptionText])
VALUES(2,'Contributor','Allow users to contribute content to the site.')
PRINT 'Done'
SET IDENTITY_INSERT [dbo].[Roles] OFF
GO
SET NOCOUNT OFF
I normally remove the identity insert – so the Insert looks like
INSERT INTO [Roles] ([RoleNameText],[RoleDescriptionText])
VALUES('Administrator','Full rights to all parts of system')
INSERT INTO [Roles] ([RoleNameText],[RoleDescriptionText])
VALUES('Contributor','Allow users to contribute content to the site.')