Re: Why does sqlmigrate need a connection to an existing database?

2021-12-24 Thread Shmuel Treiger
To any future readers, the real answer is that connections are deeply baked into how Django migrations operate. Things as seemingly simple as `can_migrate_model` require a connection. The other problems pointed out by Jason are easily patched, but the schema_editor (and all of the migration

Re: Why does sqlmigrate need a connection to an existing database?

2021-12-11 Thread Jason
https://github.com/django/django/blob/main/django/db/migrations/loader.py#L20-L40 the comment in the migration loader class probably explains your question. also, look at `collect_sql` at the bottom, and how its used at the end of sqlmigrate. specifically, it uses schema editor (

Re: Why does sqlmigrate need a connection to an existing database?

2021-12-10 Thread Shmuel Treiger
Build graph has a specific separate path for `if self.connection is None:`, so that shouldn't be an issue? As far as atomicity, what if, in a case where no connection is found, it could just prompt: "No database connection found. Do you want your migration to be atomic? (y/N)" On Thursday, 9

Re: Why does sqlmigrate need a connection to an existing database?

2021-12-09 Thread Jason
It uses db connection in two places: building the migration graph in order to load previous applied migrations and transaction begin/end wrapping

Why does sqlmigrate need a connection to an existing database?

2021-12-07 Thread Shmuel Treiger
Wondering why sqlmigrate needs a connection to an existing database. I understand that for certain commands, it needs the database to generate the migration. But for most (basic) commands, no connection is really needed. For example, I created a test project