What is the best practice to deploy update in a cloud database table

Hello all, currently I have 3 org, dev, QA, and prod.  I have made new inserts in a cloud data base table in the dev environment.  Given that the same table in the QA org have the same 14 entries as the table in dev org, what would be the best practice to deploy the update from said table from the dev to QA org.  Any help would be appreciated.

  Discussion posts and replies are publicly visible

  • 0
    Certified Senior Developer

    Hello  

    I recommend that while inserting data into the development environment, you create an SQL script. Please take note of it and run the same insert SQL script in the targeted environment's database with the proper timestamp. Manage those scripts for future reference.

  • 0
    Certified Associate Developer

    Hi,

    1. Create SQL scripts for your changes in the dev environment.
    2. Back up the QA database before applying any changes.
    3. Run the SQL scripts in the QA environment to replicate the dev changes.
    4. Verify the updates in QA before considering deployment to production.

    Creating SQL scripts of your database changes, backing up your QA database, running the scripts in QA, and verifying the updates before moving to production while using version control for script management is a best practice for deploying updates across environments.

  • 0
    Certified Senior Developer

    If you are confident about the scripts that you have run in the dev, You can upload the same scripts in the package that you will be deploying to higher environment. Else, try taking a back up or complete export of what is there in the higher environment and then do the deployment for scripts. Also if its an insert statement with no primary keys, I would recommend updating the Scripts with the Primary keys and then proceeding with the deployment.

  • 0
    Certified Senior Developer

    Hi   I would always recommend having a backup of your data when you are running scripts in the database. When you prepare scripts for your target Env, try running them a couple of times in dev and make sure your that your script gives you the expected output.  Before deploying the scripts check the data in the target env take back up the data compare the data make necessary changes. Also, make sure if you are using any conditions they should not affect other data in your table 

  • 0
    Certified Lead Developer

    Hi edmondx0001,

    When you deal with database scripts either in manual or automation scripts, I recommend using idempotent SQL Scripts as per Database best practices for deployment, which can be call as rerunnable script. These scripts can be used for creating table, alter, create view and other scripts use of which of information_schema. This will use be useful when you use third party automation pipelines. As per your problem statement i recommend you use replace keyword instead of insert.
    below is example of idempotent sql script.

    IF (
         (
         SELECT CASE --return 0 if not nullable 1 if nullable
                  (--return null if it doesn't exist
                  SELECT IS_NULLABLE
                    FROM INFORMATION_SCHEMA.COLUMNS
                    WHERE TABLE_SCHEMA = 'dbo'
                      AND TABLE_NAME = 'prices'
                      AND COLUMN_NAME = 'Edition_id'
                  ) WHEN 'NO' THEN 0
                  WHEN 'YES' THEN 1 ELSE -1 END
         ) = 1
       )
      BEGIN
        IF NOT EXISTS (SELECT 1 FROM prices WHERE Edition_id IS NULL)
          ALTER TABLE dbo.prices ALTER COLUMN Edition_id INT NOT NULL;
      END;