Opened 8 years ago

Closed 8 years ago

#23966 closed Cleanup/optimization (duplicate)

Doing pre-migrate database requirements

Reported by: Kenial Sookyum Lee Owned by: nobody
Component: Database layer (models, ORM) Version: 1.7
Severity: Normal Keywords: migrate BaseDatabaseWrapper spatialite
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Kenial Sookyum Lee)

Some database backends has special requirements when the database gets migrated.

For example, when using django.contrib.gis.db.backends.spatialite as a backend, the database file should be initialized at first time with this command: "SELECT InitSpatialMetaData();" Unless, it causes some error like https://code.djangoproject.com/ticket/20968.

I guess this would be appropriate: adding a before_migration() method to DatabaseWrapper, and letting database backends inherit it to do some jobs.

New workaround codes are added to django/contrib/gis/apps.py. (Thanks @aaugustin!)

Pull request link: https://github.com/django/django/pull/3695

Change History (7)

comment:1 Changed 8 years ago by Kenial Sookyum Lee

Cc: keniallee@… added
Summary: Pre-migrate database requirements enhancementDoing pre-migrate database requirements

comment:2 Changed 8 years ago by Aymeric Augustin

Look at django/contrib/postgres/apps.py for how to implement this.

comment:3 Changed 8 years ago by Kenial Sookyum Lee

Description: modified (diff)

comment:4 Changed 8 years ago by Claude Paroz

Seems we have parallely worked on the same issue with two different approaches (#20968 reopened with https://github.com/django/django/pull/3697). Should we close this ticket now?

comment:5 Changed 8 years ago by Kenial Sookyum Lee

Perhaps ... if InitSpatialMetaData query is executed in init_connection_state() method, then it will check it every time when opening a connection. As you know, there is no connection pooling on sqlite3 (and SpatiaLite) by default. It means that every query will execute PRAGMA table_info(geometry_columns);, I don't think it's a right way.

How about merging document stuff from pull request ​https://github.com/django/django/pull/3697 into mine? I forgot to update document about this.

Last edited 8 years ago by Kenial Sookyum Lee (previous) (diff)

comment:6 in reply to:  4 Changed 8 years ago by Kenial Sookyum Lee

Replying to claudep:
Okay claudep, I will close this ticket. But as I commented, there is a possible issue on your code, so I'm gonna move my opinion on your ticket.

comment:7 Changed 8 years ago by Kenial Sookyum Lee

Cc: keniallee@… removed
Resolution: duplicate
Status: newclosed
Note: See TracTickets for help on using tickets.
Back to Top