This script contains the code to identify those tables in database that are having auto-increment ids and are running short off those ids. Once it identifies those tables it will send an alert to slack using the webhook through the script. Lets visualize this scenario through the screenshots.
This pic below shows that currently I have two tables in my database, table T1 and table T2(Ignore the entries in the table, sorry if you think its offensive :) ). Each table has auto-increment id. In table T1 the auto-increment id starts by default from index 1. while in table T2 the auto-increment id starts from index 100000000. Both the tables have sufficient ids because the max value of the int(11) is 2147483647. Here int(11) is the data type of the primary keys in both tables.
When you run the python script, following messages will appear on the slack #general channel screeen. We can send the alert to any channel, accordingly the url will change. Here you can see that message reads --> "hello, everything is fine", that means everything is fine and ids are not running short of indexes. You see so many messages of same type because I used a timer due to which it sends the update to slack every 5 mins.
Now in next step here's what I do, I will change the auto-increment value of table T2 to some very big number such that the number is >2147483647(max limit of auto-increment id). I did this opertion using alter table command.
Now when you run python script, see what happens. Look at the last message in the pic below. It reads --> "table T2 are about to run short of auto-increment id".
Below is the query I used, to identify whether there is any table in database that is running short of auto-incement ids.
Above query gives a beautiful table that contains the auto-increment ratio of each table in database. If this ratio is around 0.954, that means about 95% of the ids are used up and are about to run short of ids.