Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 543665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T10:34:28+00:00 2026-05-13T10:34:28+00:00

Given: MySQL database. Sometimes db schema changes and updates are rolled out (in the

  • 0

Given: MySQL database. Sometimes db schema changes and updates are rolled out (in the form of sql script). In order to guarantee correct order of updates applied (no duplicate updates, no updates missing, etc) I plan to deploy the following solution:

  • CREATE TABLE meta (name TEXT PRIMARY KEY, val TEXT);
  • INSERT INTO meta VALUES (‘version’,’0′);

Each update script carries a version N which is assigned sequentially. Before executing updates the script checks that the meta.version matches the previous script version N-1. After executing updates meta.version is updated to N. I do not need to protect against multiple scripts running in parallel.

The question: How to check the version and abort the script if it doesn’t match? I figured out that executing

CALL `raise error`

will break the script, but how to execute it conditionally depending on meta.version? No stored procedures allowed. Meaningful error message is a plus. This doesn’t provide a suitable solution.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T10:34:28+00:00Added an answer on May 13, 2026 at 10:34 am

    I think this would best be solved in a shell script, or installer app. You cannot really have any control constructs in SQL script.

    A very simple solution would be to create a script that generates the command line for the actual script to execute based on a select on the meta table.

    So lets say you have this script, gen_upgrade_command.sql:

    select concat(
           'mysql -u<user> -p<password> -h<host> -e"SOURCE upgrade'
       ,    val + 1
       ,   '.sql"'
       )
    from meta;
    

    Which you run like this

    mysql -u<user> -p<password> -h<host> -Nrs < gen_upgrade_command.sql > do_upgrade.bat
    

    Now, do_upgrade.bat contains this generated command line:

    mysql -u<usere> -p<password> -h<host> -e"SOURCE upgrade1.sql"
    

    and running do_upgrade.bat will run upgrade1.sql

    Of course you can modify the original script to not select any row at all too, that’s just up to you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 301k
  • Answers 301k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The first function has a default value for its first… May 13, 2026 at 8:14 pm
  • Editorial Team
    Editorial Team added an answer Looks like a scope problem. The various arrays in the… May 13, 2026 at 8:14 pm
  • Editorial Team
    Editorial Team added an answer Try debugging with the jetty plugin, and leave you output… May 13, 2026 at 8:14 pm

Related Questions

I'm helping maintain a program that's essentially a friendly read-only front-end for a big
I'm trying to debug an error I got on a production server. Sometimes MySQL
We have a (currently InnoDB) table which contains roughly 500,000 rows. This represents a
I've constructed a database in MySQL and I am attempting to map it out
I have a table in database that is having unique id's. I have a

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.