Files
Bubberstation/tools/ezdb/steps/install_initial_schema.py
Mosley 45a373cdfa Bubber CI checks (#1830)
<!-- Write **BELOW** The Headers and **ABOVE** The comments else it may
not be viewable. -->
<!-- You can view Contributing.MD for a detailed description of the pull
request process. -->

## About The Pull Request
Adds support for bubber-related code for the CI checks
<!-- Describe The Pull Request. Please be sure every change is
documented or this can delay review and even discourage maintainers from
merging your PR! -->

<!-- Please make sure to actually test your PRs. If you have not tested
your PR mention it. -->

## Why It's Good For The Game
Helps ensure code sanity.
<!-- Argue for the merits of your changes and how they benefit the game,
especially if they are controversial and/or far reaching. If you can't
actually explain WHY what you are doing will improve the game, then it
probably isn't good for the game in the first place. -->

## Proof Of Testing
CI checks
<!-- Compile and run your code locally. Make sure it works. This is the
place to show off your changes! We are not responsible for testing your
features. -->

---------

Co-authored-by: BongaTheProto <93835010+BongaTheProto@users.noreply.github.com>
Co-authored-by: Swift <jackwars4@gmail.com>
Co-authored-by: The Sharkening <95130227+StrangeWeirdKitten@users.noreply.github.com>
Co-authored-by: SkyratBot <59378654+SkyratBot@users.noreply.github.com>
Co-authored-by: Kyle Spier-Swenson <kyleshome@gmail.com>
Co-authored-by: thegrb93 <grbrown93@sbcglobal.net>
Co-authored-by: SpaceLoveSs13 <68121607+SpaceLoveSs13@users.noreply.github.com>
Co-authored-by: projectkepler-RU <99981766+projectkepler-ru@users.noreply.github.com>
Co-authored-by: Bubberbot <151680451+Bubberbot@users.noreply.github.com>
Co-authored-by: lessthanthree <83487515+lessthnthree@users.noreply.github.com>
Co-authored-by: Shadow-Quill <44811257+Shadow-Quill@users.noreply.github.com>
Co-authored-by: KathrinBailey <53862927+KathrinBailey@users.noreply.github.com>
Co-authored-by: Waterpig <49160555+Majkl-J@users.noreply.github.com>
Co-authored-by: snailomi <148835423+snailomi@users.noreply.github.com>
Co-authored-by: Cursor <102828457+theselfish@users.noreply.github.com>
Co-authored-by: Lutowski <136726218+Lutowski@users.noreply.github.com>
Co-authored-by: nevimer <77420409+nevimer@users.noreply.github.com>
2024-08-20 23:09:56 -04:00

62 lines
2.2 KiB
Python

from contextlib import closing
from ..ezdb.changes import get_current_version
from ..ezdb.config import read_config
from ..ezdb.mysql import execute_sql, insert_new_schema_query, open_connection, start_daemon
from ..ezdb.paths import get_initial_schema_path, get_modular_schema_path, get_bubber_schema_path
from .step import Step
class InstallInitialSchema(Step):
@staticmethod
def should_run() -> bool:
start_daemon()
config = read_config()
assert config is not None, "No config file found"
database = config["FEEDBACK_DATABASE"]
assert database is not None, "No database found in config file"
with open_connection() as connection:
with closing(connection.cursor()) as cursor:
cursor.execute(f"SHOW DATABASES LIKE '{database}'")
if cursor.fetchone() is None:
return True
cursor.execute(f"USE {database}")
cursor.execute("SHOW TABLES LIKE 'schema_revision'")
if cursor.fetchone() is None:
return True
cursor.execute("SELECT * FROM `schema_revision` LIMIT 1")
if cursor.fetchone() is None:
return True
return False
@staticmethod
def run(args):
print("Installing initial schema...")
config = read_config()
assert config is not None, "No config file found"
with open_connection() as connection:
with closing(connection.cursor()) as cursor:
database = config["FEEDBACK_DATABASE"]
cursor.execute(f"CREATE DATABASE {database}")
cursor.execute(f"USE {database}")
(major_version, minor_version) = get_current_version()
with open(get_initial_schema_path(), 'r') as file:
schema = file.read()
execute_sql(schema + ";" + insert_new_schema_query(major_version, minor_version))
with open(get_modular_schema_path(), 'r') as file:
schema = file.read()
execute_sql(schema)
with open(get_bubber_schema_path(), 'r') as file:
schema = file.read()
execute_sql(schema)