fix: all django management command related subcommands

We just called `manage` inside docker instead of
`exec appserver python manage.py`. Now we make assumption that django
app is running in docker-compose in service named `appserver`.

While fixing this bug we also refactored for `shell`, `makemigrations`
and `migrate` to all call `manage` under the hood to avoid repeating code.
This commit is contained in:
Matej Janezic 2023-05-24 00:18:24 +02:00
parent 22d263dfaa
commit 423badfe07
Signed by: janezicmatej
GPG Key ID: 4298E230ED37B2C0
1 changed files with 13 additions and 15 deletions

View File

@ -46,28 +46,26 @@ pub fn make_command(app: &PathBuf, name: &str) -> Result<()> {
Ok(())
}
pub fn makemigrations() -> Result<()> {
let dsm = get_django_settings_module()?;
let command = format!("manage makemigrations --settings={dsm}");
DockerCommand::docker_compose().args(&command).spawn_wait()
}
pub fn manage(rest: &[String]) -> Result<()> {
let dsm = get_django_settings_module()?;
let joined = rest.join(" ");
let command = format!("manage {joined} --settings={dsm}");
let command = format!("exec appserver python manage.py {joined} --settings={dsm}");
DockerCommand::docker_compose().args(&command).spawn_wait()
}
pub fn migrate(rest: &[String]) -> Result<()> {
let dsm = get_django_settings_module()?;
let joined = rest.join(" ");
let command = format!("manage migrate {joined} --settings={dsm}");
DockerCommand::docker_compose().args(&command).spawn_wait()
// shortcuts
pub fn makemigrations() -> Result<()> {
manage(&["makemigrations".to_string()])
}
pub fn shell() -> Result<()> {
let dsm = get_django_settings_module()?;
let command = format!("manage shell --settings={dsm}");
DockerCommand::docker_compose().args(&command).spawn_wait()
manage(&["shell".to_string()])
}
pub fn migrate(rest: &[String]) -> Result<()> {
let mut full_rest = vec!["migrate".to_string()];
full_rest.extend_from_slice(rest);
manage(&full_rest)
}