Open jechols opened 1 week ago
Actually dbshell may work - it is simply invoking the mysql
command and accepts parameters that command accepts. So we could ask for all awardees in a tab-separated format, for instance, without actually interacting with (or having to parse) the DB shell:
./manage.py dbshell '-Be select * from core_awardee;'
Better command:
./manage.py dbshell "-BNe select org_code, name from core_awardee where org_code = 'scu';"
Checks for a specific org code, skips the column names, gives us the two important columns in a precise order so we have no ambiguity, and of course returns tab-separated output.
Nope, we need to do a direct DB connection here. The more I try to ensure the SQL will work (e.g., escaping apostrophes, making sure it's valid UTF8 so it doesn't fail just due to weird input, figuring out how to parse errors, etc.) the less appealing it is to call a command-line app for this. We'll just add a requirement for DB credentials to the agent. Bah.
This command will check for an awardee by name. If it exists, return success. If it doesn't, create the awardee and return success.
This will require us to add vars for the DB connection (easy, but adds a dependency on the Go mysql package), parse the Python settings (likely very hard to get right considering the ways a user might set things up), or else use the "dbshell" management command and send interactive commands (maybe doable? Probably a pain to parse correctly, though).