import random
import mysql.connector
import time

# establish connection to the database
print("Connecting to travel DB.")

mydb = mysql.connector.connect(
  host="dbswf33330813.syss0001.stage1.skysql.net",
  user="dbswf33330813",
  password="Adm1n777#",
  port=5001,
  database="travel"
)

print("Connected to travel DB.")

# get a cursor to execute SQL statements
cursor = mydb.cursor()

print("Got a cursor.")

# set up the while loop to run 100 times
count = 0
while count < 100:
    count += 1

    # generate a random column name
    col_name = "col_" + str(random.randint(1, 100000))

    # construct the ALTER statement
    print("Performing ALTER.")
    alter_query = f"ALTER TABLE flights ADD COLUMN {col_name} VARCHAR(255);"
    time.sleep(3)
    print("Done performing ALTER.")

    # execute the ALTER statement
    cursor.execute(alter_query)

print("Done performing all ALTERs.")
# close the database connection
mydb.close()
