Skip to content

Commit

Permalink
renaming of database tables removed
Browse files Browse the repository at this point in the history
  • Loading branch information
miguel-bermudo committed Feb 14, 2024
1 parent 77264c0 commit 585ff1c
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions silence/db/populate.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,30 +52,31 @@ def create_database():

# after all database schema is created, we rename all columns and tables to be fully lowercase, this way we avoid any linux/windows weirdness.
# there's a custom option when installing mysql server, it forces tablenames to be lowercase, maybe include that in the curriculum?
# SQL views maintain the nomenclature given in the query so renaming is out of the question.

get_table_names_q = f"SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE' AND TABLE_SCHEMA= '{db_name}';"
# get_table_names_q = f"SELECT TABLE_NAME FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_TYPE = 'BASE TABLE' AND TABLE_SCHEMA= '{db_name}';"

cursor.execute(get_table_names_q)
all_created_tables = cursor.fetchall()
# cursor.execute(get_table_names_q)
# all_created_tables = cursor.fetchall()

for table_name_tuple in all_created_tables:
table_name = table_name_tuple[0]
# for table_name_tuple in all_created_tables:
# table_name = table_name_tuple[0]

get_column_names_q = f"SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = '{db_name}' AND TABLE_NAME = '{table_name}'"
cursor.execute(get_column_names_q)
# get_column_names_q = f"SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = '{db_name}' AND TABLE_NAME = '{table_name}'"
# cursor.execute(get_column_names_q)

# table_column_names = cursor.fetchall()
# # table_column_names = cursor.fetchall()

# for column_name_tuple in table_column_names:
# column_name = column_name_tuple[0]
# # for column_name_tuple in table_column_names:
# # column_name = column_name_tuple[0]

# THIS STATEMENT REQUIRES THE NEW TYPE TO BE SPECIFIED, WHICH MIGHT BE A PROBLEM SINCE IT IS HARD TO GET I GUESS.
# rename_table_q = f"ALTER TABLE '{table_name}' CHANGE '{column_name}' '{column_name.lower()}' INT(11) NOT NULL;"
# cursor.execute(rename_table_q)
# # THIS STATEMENT REQUIRES THE NEW TYPE TO BE SPECIFIED, WHICH MIGHT BE A PROBLEM SINCE IT IS HARD TO GET I GUESS.
# # rename_table_q = f"ALTER TABLE '{table_name}' CHANGE '{column_name}' '{column_name.lower()}' INT(11) NOT NULL;"
# # cursor.execute(rename_table_q)

rename_table_q = f"ALTER TABLE {table_name} RENAME {table_name.lower()};"
cursor.execute(rename_table_q)
# rename_table_q = f"ALTER TABLE {table_name} RENAME {table_name.lower()};"
# cursor.execute(rename_table_q)

conn.commit()
# conn.commit()
# Clean up when we're done
cursor.close()

0 comments on commit 585ff1c

Please sign in to comment.