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:
		@@ -46,28 +46,26 @@ pub fn make_command(app: &PathBuf, name: &str) -> Result<()> {
 | 
				
			|||||||
    Ok(())
 | 
					    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<()> {
 | 
					pub fn manage(rest: &[String]) -> Result<()> {
 | 
				
			||||||
    let dsm = get_django_settings_module()?;
 | 
					    let dsm = get_django_settings_module()?;
 | 
				
			||||||
    let joined = rest.join(" ");
 | 
					    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()
 | 
					    DockerCommand::docker_compose().args(&command).spawn_wait()
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub fn migrate(rest: &[String]) -> Result<()> {
 | 
					// shortcuts
 | 
				
			||||||
    let dsm = get_django_settings_module()?;
 | 
					pub fn makemigrations() -> Result<()> {
 | 
				
			||||||
    let joined = rest.join(" ");
 | 
					    manage(&["makemigrations".to_string()])
 | 
				
			||||||
    let command = format!("manage migrate {joined} --settings={dsm}");
 | 
					 | 
				
			||||||
    DockerCommand::docker_compose().args(&command).spawn_wait()
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub fn shell() -> Result<()> {
 | 
					pub fn shell() -> Result<()> {
 | 
				
			||||||
    let dsm = get_django_settings_module()?;
 | 
					    manage(&["shell".to_string()])
 | 
				
			||||||
    let command = format!("manage shell --settings={dsm}");
 | 
					 | 
				
			||||||
    DockerCommand::docker_compose().args(&command).spawn_wait()
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					pub fn migrate(rest: &[String]) -> Result<()> {
 | 
				
			||||||
 | 
					    let mut full_rest = vec!["migrate".to_string()];
 | 
				
			||||||
 | 
					    full_rest.extend_from_slice(rest);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    manage(&full_rest)
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user