ezdb - A one click script to quickly setting up a development database (#75053) (#21458)

* 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>
This commit is contained in:
Tom
2023-06-03 23:15:41 +02:00
committed by GitHub
co-authored by san7890 Mothblocks Useroth
parent 8f9fd2893a
commit d91555b79e
22 changed files with 517 additions and 36 deletions
+46 -2
View File
@@ -37,6 +37,8 @@ SUBSYSTEM_DEF(dbcore)
var/connection // Arbitrary handle returned from rust_g.
var/db_daemon_started = FALSE
/datum/controller/subsystem/dbcore/Initialize()
//We send warnings to the admins during subsystem init, as the clients will be New'd and messages
//will queue properly with goonchat
@@ -74,8 +76,6 @@ SUBSYSTEM_DEF(dbcore)
CONFIG_SET(number/pooling_max_sql_connections, max(min_sql_connections, max_sql_connections))
log_config("ERROR: POOLING_MAX_SQL_CONNECTIONS ([max_sql_connections]) is set lower than POOLING_MIN_SQL_CONNECTIONS ([min_sql_connections]). Please check your config or the code defaults for sanity")
/datum/controller/subsystem/dbcore/stat_entry(msg)
msg = "P:[length(all_queries)]|Active:[length(queries_active)]|Standby:[length(queries_standby)]"
return ..()
@@ -188,6 +188,7 @@ SUBSYSTEM_DEF(dbcore)
qdel(query_round_shutdown)
if(IsConnected())
Disconnect()
stop_db_daemon()
//nu
/datum/controller/subsystem/dbcore/can_vv_get(var_name)
@@ -231,6 +232,8 @@ SUBSYSTEM_DEF(dbcore)
if(!CONFIG_GET(flag/sql_enabled))
return FALSE
start_db_daemon()
var/user = CONFIG_GET(string/feedback_login)
var/pass = CONFIG_GET(string/feedback_password)
var/db = CONFIG_GET(string/feedback_database)
@@ -447,6 +450,47 @@ Delayed insert mode was removed in mysql 7 and only works with MyISAM type table
. = Query.Execute(async)
qdel(Query)
/datum/controller/subsystem/dbcore/proc/start_db_daemon()
set waitfor = FALSE
if (db_daemon_started)
return
db_daemon_started = TRUE
var/daemon = CONFIG_GET(string/db_daemon)
if (!daemon)
return
ASSERT(fexists(daemon), "Configured db_daemon doesn't exist")
var/list/result = world.shelleo("echo \"Starting ezdb daemon, do not close this window\" && [daemon]")
var/error_code = result[1]
if (!error_code)
return
stack_trace("Failed to start DB daemon: [error_code]\n[result[3]]")
/datum/controller/subsystem/dbcore/proc/stop_db_daemon()
set waitfor = FALSE
if (!db_daemon_started)
return
db_daemon_started = FALSE
var/daemon = CONFIG_GET(string/db_daemon)
if (!daemon)
return
switch (world.system_type)
if (MS_WINDOWS)
var/list/result = world.shelleo("Get-Process | ? { $_.Path -eq '[daemon]' } | Stop-Process")
ASSERT(result[1], "Failed to stop DB daemon: [result[3]]")
if (UNIX)
var/list/result = world.shelleo("kill $(pgrep -f '[daemon]')")
ASSERT(result[1], "Failed to stop DB daemon: [result[3]]")
/datum/db_query
// Inputs
var/connection