mirror of
https://github.com/Bubberstation/Bubberstation.git
synced 2026-07-19 12:05:59 +01:00
d91555b79e
* ezdb - A one click script to quickly setting up a development database (#75053) https://user-images.githubusercontent.com/35135081/235344815-8e825ba9-52cf-44e8-b8e2-a2aeb5d47276.mp4 - Downloads a portable MariaDB (doesn't pollute your main system) - Sets up a database with a random password on port 1338 (configurable) - Installs the initial schema - Every time after, will run updates Major versions right now explicitly escape hatch, because those historically come with something like a Python script, and I do not want it to pretend to work. --------- Co-authored-by: san7890 <the@san7890.com> * touchups * oh well --------- Co-authored-by: Mothblocks <35135081+Mothblocks@users.noreply.github.com> Co-authored-by: san7890 <the@san7890.com> Co-authored-by: Useroth <37159550+Useroth@users.noreply.github.com>
39 lines
1.5 KiB
Python
39 lines
1.5 KiB
Python
from contextlib import closing
|
|
from ..ezdb.changes import get_changes
|
|
from ..ezdb.config import read_config
|
|
from ..ezdb.mysql import execute_sql, insert_new_schema_query, open_connection
|
|
from .step import Step
|
|
|
|
class UpdateSchema(Step):
|
|
@staticmethod
|
|
def should_run() -> bool:
|
|
# Last step is always run
|
|
return True
|
|
|
|
@staticmethod
|
|
def run(args):
|
|
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"USE {database}")
|
|
cursor.execute("SELECT major, minor FROM `schema_revision` ORDER BY `major` DESC, `minor` DESC LIMIT 1")
|
|
(major_version, minor_version) = cursor.fetchone()
|
|
|
|
changes = get_changes()
|
|
for change in changes:
|
|
if change.major_version != major_version:
|
|
print("NOT IMPLEMENTED: Major version change, these historically require extra tooling")
|
|
continue
|
|
|
|
if change.minor_version > minor_version:
|
|
print(f"Running change {change.major_version}.{change.minor_version}")
|
|
execute_sql(change.sql + ";" + insert_new_schema_query(change.major_version, change.minor_version))
|
|
else:
|
|
print("No updates necessary")
|
|
return
|