Loading django/contrib/gis/db/backends/spatialite/base.py +9 −0 Original line number Diff line number Diff line Loading @@ -79,3 +79,12 @@ class DatabaseWrapper(SQLiteDatabaseWrapper): six.reraise(ImproperlyConfigured, ImproperlyConfigured(new_msg), sys.exc_info()[2]) cur.close() return conn def prepare_database(self): super(DatabaseWrapper, self).prepare_database() # Check if spatial metadata have been initialized in the database with self.cursor() as cursor: cursor.execute("PRAGMA table_info(geometry_columns);") if cursor.fetchall() == []: arg = "1" if self.features.supports_initspatialmetadata_in_one_transaction else "" cursor.execute("SELECT InitSpatialMetaData(%s)" % arg) django/contrib/gis/db/backends/spatialite/creation.py +0 −8 Original line number Diff line number Diff line Loading @@ -30,11 +30,3 @@ class SpatiaLiteCreation(DatabaseCreation): style.SQL_FIELD(gqn(f.column)) + ');') return output def _create_test_db_pre_migrate_sql(self): """ Creates the spatial metadata tables. """ cur = self.connection._cursor() arg = "1" if self.connection.features.supports_initspatialmetadata_in_one_transaction else "" cur.execute("SELECT InitSpatialMetaData(%s)" % arg) django/core/management/commands/migrate.py +2 −0 Original line number Diff line number Diff line Loading @@ -64,6 +64,8 @@ class Command(BaseCommand): if options.get("list", False): return self.show_migration_list(connection, [options['app_label']] if options['app_label'] else None) # Hook for backends needing any database preparation connection.prepare_database() # Work out which apps have migrations and which do not executor = MigrationExecutor(connection, self.migration_progress_callback) Loading django/db/backends/__init__.py +7 −0 Original line number Diff line number Diff line Loading @@ -432,6 +432,13 @@ class BaseDatabaseWrapper(object): ##### Miscellaneous ##### def prepare_database(self): """ Hook to do any database check or preparation, generally called before migrating a project or an app. """ pass @cached_property def wrap_database_errors(self): """ Loading django/db/backends/creation.py +0 −8 Original line number Diff line number Diff line Loading @@ -371,8 +371,6 @@ class BaseDatabaseCreation(object): settings.DATABASES[self.connection.alias]["NAME"] = test_database_name self.connection.settings_dict["NAME"] = test_database_name self._create_test_db_pre_migrate_sql() # We report migrate messages at one level lower than that requested. # This ensures we don't get flooded with messages during testing # (unless you really ask to be flooded). Loading @@ -398,12 +396,6 @@ class BaseDatabaseCreation(object): return test_database_name def _create_test_db_pre_migrate_sql(self): """ Hook for databases to load SQL before creating the test DB. """ pass def serialize_db_to_string(self): """ Serializes all data in the database into a JSON string. Loading Loading
django/contrib/gis/db/backends/spatialite/base.py +9 −0 Original line number Diff line number Diff line Loading @@ -79,3 +79,12 @@ class DatabaseWrapper(SQLiteDatabaseWrapper): six.reraise(ImproperlyConfigured, ImproperlyConfigured(new_msg), sys.exc_info()[2]) cur.close() return conn def prepare_database(self): super(DatabaseWrapper, self).prepare_database() # Check if spatial metadata have been initialized in the database with self.cursor() as cursor: cursor.execute("PRAGMA table_info(geometry_columns);") if cursor.fetchall() == []: arg = "1" if self.features.supports_initspatialmetadata_in_one_transaction else "" cursor.execute("SELECT InitSpatialMetaData(%s)" % arg)
django/contrib/gis/db/backends/spatialite/creation.py +0 −8 Original line number Diff line number Diff line Loading @@ -30,11 +30,3 @@ class SpatiaLiteCreation(DatabaseCreation): style.SQL_FIELD(gqn(f.column)) + ');') return output def _create_test_db_pre_migrate_sql(self): """ Creates the spatial metadata tables. """ cur = self.connection._cursor() arg = "1" if self.connection.features.supports_initspatialmetadata_in_one_transaction else "" cur.execute("SELECT InitSpatialMetaData(%s)" % arg)
django/core/management/commands/migrate.py +2 −0 Original line number Diff line number Diff line Loading @@ -64,6 +64,8 @@ class Command(BaseCommand): if options.get("list", False): return self.show_migration_list(connection, [options['app_label']] if options['app_label'] else None) # Hook for backends needing any database preparation connection.prepare_database() # Work out which apps have migrations and which do not executor = MigrationExecutor(connection, self.migration_progress_callback) Loading
django/db/backends/__init__.py +7 −0 Original line number Diff line number Diff line Loading @@ -432,6 +432,13 @@ class BaseDatabaseWrapper(object): ##### Miscellaneous ##### def prepare_database(self): """ Hook to do any database check or preparation, generally called before migrating a project or an app. """ pass @cached_property def wrap_database_errors(self): """ Loading
django/db/backends/creation.py +0 −8 Original line number Diff line number Diff line Loading @@ -371,8 +371,6 @@ class BaseDatabaseCreation(object): settings.DATABASES[self.connection.alias]["NAME"] = test_database_name self.connection.settings_dict["NAME"] = test_database_name self._create_test_db_pre_migrate_sql() # We report migrate messages at one level lower than that requested. # This ensures we don't get flooded with messages during testing # (unless you really ask to be flooded). Loading @@ -398,12 +396,6 @@ class BaseDatabaseCreation(object): return test_database_name def _create_test_db_pre_migrate_sql(self): """ Hook for databases to load SQL before creating the test DB. """ pass def serialize_db_to_string(self): """ Serializes all data in the database into a JSON string. Loading