Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename all non-snake_case types. #27268

Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
0a3c5a1
refactor: Rename all non-snake_case types (not procs or vars (yet)).
warriorstar-orion Nov 2, 2024
366e749
completely dynamic update script
warriorstar-orion Nov 2, 2024
c50cb4f
might help to include the data
warriorstar-orion Nov 2, 2024
c556f23
Merge remote-tracking branch 'upstream/master' into hell-is-empty-and…
warriorstar-orion Nov 2, 2024
9c856ed
update aa's scuffed python
warriorstar-orion Nov 3, 2024
ae68eac
oh
warriorstar-orion Nov 3, 2024
088af21
Merge remote-tracking branch 'upstream/master' into hell-is-empty-and…
warriorstar-orion Nov 14, 2024
1080197
set script PR number
warriorstar-orion Nov 14, 2024
21bc077
run updatepaths again
warriorstar-orion Nov 14, 2024
502760c
Merge remote-tracking branch 'upstream/master' into hell-is-empty-and…
warriorstar-orion Nov 22, 2024
a1ed71d
Add other table updates with JSON columns
warriorstar-orion Nov 22, 2024
989236d
bump SQL version
warriorstar-orion Nov 22, 2024
3dafa00
Merge remote-tracking branch 'upstream/master' into hell-is-empty-and…
warriorstar-orion Nov 24, 2024
33712a8
just fucking end my life
warriorstar-orion Nov 24, 2024
0155e4c
Merge remote-tracking branch 'upstream/master' into hell-is-empty-and…
warriorstar-orion Nov 24, 2024
6a963b7
Merge remote-tracking branch 'upstream/master' into hell-is-empty-and…
warriorstar-orion Nov 25, 2024
d58dced
Merge remote-tracking branch 'upstream/master' into hell-is-empty-and…
warriorstar-orion Nov 26, 2024
dbfb737
Merge remote-tracking branch 'upstream/master' into hell-is-empty-and…
warriorstar-orion Nov 30, 2024
24ab1b4
move JSON data
warriorstar-orion Nov 30, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
99 changes: 99 additions & 0 deletions SQL/updates/60-61.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# :wave: hello fellow contributors, this script is brought to you ad-free by AffectedArc07 and Warriorstar
# In order to run this script on Windows, you need to make sure you have Python **3** installed. Tested on 3.10.4
# In addition you must have the mysql-connector-python module installed (can be done through pip :D)
# if you do not have that module installed, you cannot run this script

# To run this, supply the following args in a command shell
# python 60-61.py address username password database
# Example:
# python 60-61.py 127.0.0.1 sirryan2002 myubersecretdbpassword paradise_gamedb

from pathlib import Path
from datetime import datetime
import argparse
import json

import mysql.connector


def log(msg):
print(f"[{datetime.utcnow()}] {msg}")


def main():
parser = argparse.ArgumentParser()
parser.add_argument(
"address", help="MySQL server address (use localhost for the current computer)"
)
parser.add_argument("username", help="MySQL login username")
parser.add_argument("password", help="MySQL login password")
parser.add_argument("database", help="Database name")

args = parser.parse_args()
db = mysql.connector.connect(
host=args.address, user=args.username, passwd=args.password, db=args.database
)
cursor = db.cursor()
log(f"Connected to {args.database}")

# want these ordered by length from longest to shortest so shorter replacements
# don't replace pieces of larger replacements
renames = sorted(
json.load(
open(Path(__file__).parent / "migration_data/snake_case_type_remap.json")
warriorstar-orion marked this conversation as resolved.
Show resolved Hide resolved
),
key=lambda x: len(x["original"]),
reverse=True,
)

sql_statements = list()

log("Running query")
cursor = db.cursor()
cursor.execute(
"""
SELECT round_id, key_name, json, id
FROM feedback
ORDER BY id DESC
"""
)

log("Fetching all data")
rows = cursor.fetchall()
log(f"Processing {len(rows)} rows...")

for row in rows:
row_replacements = []
for rename in renames:
if rename["original"] in row[2]:
row_replacements.append(rename)
if row_replacements:
for replacement in sorted(
row_replacements, key=lambda x: len(x["original"]), reverse=True
):
update_sql = (
"""UPDATE feedback SET json = REPLACE(json, %s, %s) WHERE id = %s""",
(
replacement["original"],
replacement.get("override", replacement["replace"]),
row[3],
),
)

sql_statements.append(update_sql)

log(f"Running {len(sql_statements)} SQL updates")

if len(sql_statements) > 0:
cursor = db.cursor()
for update_sql in sql_statements:
cursor.execute(*update_sql)

log("Committing data")
db.commit()

log("Script done")


if __name__ == "__main__":
main()
335 changes: 335 additions & 0 deletions SQL/updates/migration_data/snake_case_type_remap.json

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -773,7 +773,7 @@
/turf/simulated/floor/lubed/lavaland_air,
/area/ruin/powered/clownplanet)
"bq" = (
/obj/machinery/disposal/deliveryChute{
/obj/machinery/disposal/delivery_chute{
dir = 1
},
/obj/structure/disposalpipe/trunk,
Expand Down Expand Up @@ -890,7 +890,7 @@
/turf/simulated/floor/carpet/lavaland_air,
/area/ruin/powered/clownplanet)
"bN" = (
/obj/machinery/disposal/deliveryChute,
/obj/machinery/disposal/delivery_chute,
/obj/structure/disposalpipe/trunk{
dir = 1
},
Expand Down Expand Up @@ -1103,7 +1103,7 @@
/turf/simulated/floor/light/lavaland_air,
/area/ruin/powered/clownplanet)
"LH" = (
/obj/machinery/disposal/deliveryChute{
/obj/machinery/disposal/delivery_chute{
desc = "The following is engraved upon the chute: A FATE WORSE THAN DEATH LIES WITHIN";
dir = 1;
name = "THE TRIAL OF HONKITUDE"
Expand Down
2 changes: 1 addition & 1 deletion _maps/map_files/RandomRuins/SpaceRuins/clownmime.dmm
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@
/turf/simulated/floor/mineral/titanium,
/area/ruin/space/clown_mime_ruin)
"Dj" = (
/obj/item/toy/AI,
/obj/item/toy/ai,
/obj/item/toy/plushie/lizardplushie,
/obj/item/toy/plushie/voxplushie,
/obj/item/toy/plushie/greyplushie,
Expand Down
6 changes: 3 additions & 3 deletions _maps/map_files/RandomRuins/SpaceRuins/deepstorage.dmm
Original file line number Diff line number Diff line change
Expand Up @@ -4831,9 +4831,9 @@
dir = 1
},
/obj/structure/closet/crate/freezer,
/obj/item/reagent_containers/iv_bag/blood/OMinus,
/obj/item/reagent_containers/iv_bag/blood/OMinus,
/obj/item/reagent_containers/iv_bag/blood/OMinus,
/obj/item/reagent_containers/iv_bag/blood/o_minus,
/obj/item/reagent_containers/iv_bag/blood/o_minus,
/obj/item/reagent_containers/iv_bag/blood/o_minus,
/obj/item/reagent_containers/iv_bag/blood/random,
/obj/item/reagent_containers/iv_bag/blood/random,
/obj/item/reagent_containers/iv_bag/blood/random,
Expand Down
Loading
Loading