2 Replies Latest reply on Sep 9, 2008 4:33 PM by JasonMH

    Updating an application with different database schema

    seme1 Level 1
      A new version of an application might contain new fields/tables in its database. How can I have a series of commands be executed only once after the application completes the update process to update the database ? Or is there a better approach ?
        • 1. Re: Updating an application with different database schema
          Joe ... Ward Level 4
          You should probably put a version table in your database to store your schema version. Then you can check the version on startup, upgrading if necessary.

          There is no automatic way to have some code execute once after an update.
          • 2. Updating an application with different database schema
            JasonMH
            I do this by having a table with system information and one column contains the schema version. This is actually the one place in my app where I use synchronous DB calls because I don't want the app to initialize or anything to happen until the schema is at the correct version. The code looks something like this:

            while (currentSchemaNum < requiredSchemaNum)
            {
            var newSchemaNum:int = currentSchemaNum + 1;
            var updateScript:String = "updatefile_" + newSchemaNum + ".sql";

            // < run updateScript synchronously >
            // this part sucks because you have to parse the script into individual statements
            // and run them one at a time

            dbSchemaId = newSchemaNum;
            }