﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
31658	Performing SQL queries in AppConfig.ready().	Ying Wang	nobody	"Hello,

I might have an unusual request for understanding Django lifecycle methods. I would like to run an SQL query during application startup in order to configure PostgreSQL triggers and functions. Right now, my understanding is Django can load custom AppConfigs and overwrite method 'ready()' with custom logic. However, this AppConfig is run all the time, including during all commands of 'manage.py', which means 'manage.py migrate' cannot be run without first hitting the custom AppConfig. This means my SQL file errors out, since the underlying PostgreSQL tables do not yet exist and I cannot even make a hardcoded reference to them. So I have to check whether or not the database is synchronized with the application, before running the SQL script. I don't want to execute the migration during the AppConfig ready() step, since there may be other commands I want to run in some specific order, and I see it as more of a CLI command. So my other option would then be to run 'manage.py' multiple times, and only run the SQL file once the database is synchronized. This may make ops overhead a bit more complicated.

I think having multiple handles, like 'DatabaseHasSynchronized()', and external stateful hooks critical to Django usage, as top-level AppConfig overriddable methods would be really useful in managing app lifecycles. That way, less stuff needs to be done using the shell. This might be like React.js's 'ComponentDidMount()' or 'ComponentWillMount()' lifecycle methods where you have high API-level visibility into lifecycles.

I'm not sure if it's a good idea, so I wanted to raise it as a topic of discussion. I'd be happy to take a shot at implementing this, should the feature be deemed by the community as worthwhile.

Thanks
Ying"	New feature	closed	Core (Other)	3.0	Normal	wontfix	database, migrations, lifecycle, hooks		Unreviewed	0	0	0	0	0	0
