django-postpone-index 0.0.1__tar.gz → 0.0.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. {django_postpone_index-0.0.1/django_postpone_index.egg-info → django_postpone_index-0.0.3}/PKG-INFO +38 -1
  2. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3}/README.md +37 -0
  3. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3}/dev/config/settings.py +0 -6
  4. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3/django_postpone_index.egg-info}/PKG-INFO +38 -1
  5. django_postpone_index-0.0.3/django_postpone_index.egg-info/top_level.txt +6 -0
  6. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3}/postpone_index/_version.py +3 -3
  7. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3}/postpone_index/contrib/postgres/schema.py +1 -11
  8. django_postpone_index-0.0.3/postpone_index/models.py +129 -0
  9. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3}/setup.py +11 -1
  10. django_postpone_index-0.0.1/django_postpone_index.egg-info/top_level.txt +0 -1
  11. django_postpone_index-0.0.1/postpone_index/models.py +0 -61
  12. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3}/.github/workflows/ci.yml +0 -0
  13. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3}/.gitignore +0 -0
  14. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3}/dev/config/__init__.py +0 -0
  15. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3}/dev/config/base_tests.py +0 -0
  16. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3}/dev/config/urls.py +0 -0
  17. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3}/dev/config/utils.py +0 -0
  18. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3}/dev/config/wsgi.py +0 -0
  19. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3}/dev/manage.py +0 -0
  20. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3}/dev/test_explicit_constraint/__init__.py +0 -0
  21. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3}/dev/test_explicit_constraint/migrations/0001_initial.py +0 -0
  22. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3}/dev/test_explicit_constraint/migrations/0002_auto_20260130_1044.py +0 -0
  23. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3}/dev/test_explicit_constraint/migrations/0003_auto_20260130_1052.py +0 -0
  24. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3}/dev/test_explicit_constraint/migrations/__init__.py +0 -0
  25. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3}/dev/test_explicit_constraint/models.py +0 -0
  26. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3}/dev/test_explicit_constraint/tests.py +0 -0
  27. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3}/dev/test_explicit_index/__init__.py +0 -0
  28. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3}/dev/test_explicit_index/migrations/0001_initial.py +0 -0
  29. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3}/dev/test_explicit_index/migrations/0002_auto_20260130_1044.py +0 -0
  30. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3}/dev/test_explicit_index/migrations/0003_auto_20260130_1052.py +0 -0
  31. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3}/dev/test_explicit_index/migrations/__init__.py +0 -0
  32. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3}/dev/test_explicit_index/models.py +0 -0
  33. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3}/dev/test_explicit_index/tests.py +0 -0
  34. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3}/dev/test_fields/__init__.py +0 -0
  35. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3}/dev/test_fields/migrations/0001_initial.py +0 -0
  36. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3}/dev/test_fields/migrations/0002_auto_20260130_1258.py +0 -0
  37. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3}/dev/test_fields/migrations/0003_auto_20260130_1259.py +0 -0
  38. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3}/dev/test_fields/migrations/__init__.py +0 -0
  39. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3}/dev/test_fields/models.py +0 -0
  40. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3}/dev/test_fields/tests.py +0 -0
  41. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3}/dev/test_gis_index/__init__.py +0 -0
  42. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3}/dev/test_gis_index/migrations/0001_initial.py +0 -0
  43. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3}/dev/test_gis_index/migrations/0002_gisindex1_mline.py +0 -0
  44. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3}/dev/test_gis_index/migrations/0003_auto_20260202_1156.py +0 -0
  45. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3}/dev/test_gis_index/migrations/__init__.py +0 -0
  46. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3}/dev/test_gis_index/models.py +0 -0
  47. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3}/dev/test_gis_index/tests.py +0 -0
  48. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3}/dev/test_ignore_migration/__init__.py +0 -0
  49. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3}/dev/test_ignore_migration/migrations/0001_initial.py +0 -0
  50. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3}/dev/test_ignore_migration/migrations/0002_auto_20260130_1044.py +0 -0
  51. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3}/dev/test_ignore_migration/migrations/0003_auto_20260130_1052.py +0 -0
  52. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3}/dev/test_ignore_migration/migrations/__init__.py +0 -0
  53. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3}/dev/test_ignore_migration/models.py +0 -0
  54. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3}/dev/test_ignore_migration/tests.py +0 -0
  55. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3}/dev/test_index_together/__init__.py +0 -0
  56. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3}/dev/test_index_together/migrations/0001_initial.py +0 -0
  57. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3}/dev/test_index_together/migrations/0002_auto_20260130_1044.py +0 -0
  58. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3}/dev/test_index_together/migrations/0003_auto_20260130_1053.py +0 -0
  59. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3}/dev/test_index_together/migrations/__init__.py +0 -0
  60. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3}/dev/test_index_together/models.py +0 -0
  61. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3}/dev/test_index_together/tests.py +0 -0
  62. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3}/dev/test_unique_together/__init__.py +0 -0
  63. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3}/dev/test_unique_together/migrations/0001_initial.py +0 -0
  64. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3}/dev/test_unique_together/migrations/0002_auto_20260130_1044.py +0 -0
  65. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3}/dev/test_unique_together/migrations/0003_auto_20260130_1053.py +0 -0
  66. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3}/dev/test_unique_together/migrations/__init__.py +0 -0
  67. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3}/dev/test_unique_together/models.py +0 -0
  68. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3}/dev/test_unique_together/tests.py +0 -0
  69. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3}/django_postpone_index.egg-info/SOURCES.txt +0 -0
  70. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3}/django_postpone_index.egg-info/dependency_links.txt +0 -0
  71. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3}/django_postpone_index.egg-info/requires.txt +0 -0
  72. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3}/postpone_index/__init__.py +0 -0
  73. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3}/postpone_index/admin.py +0 -0
  74. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3}/postpone_index/apps.py +0 -0
  75. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3}/postpone_index/contrib/__init__.py +0 -0
  76. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3}/postpone_index/contrib/postgis/__init__.py +0 -0
  77. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3}/postpone_index/contrib/postgis/base.py +0 -0
  78. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3}/postpone_index/contrib/postgis/schema.py +0 -0
  79. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3}/postpone_index/contrib/postgres/__init__.py +0 -0
  80. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3}/postpone_index/contrib/postgres/base.py +0 -0
  81. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3}/postpone_index/management/__init__.py +0 -0
  82. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3}/postpone_index/management/commands/__init__.py +0 -0
  83. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3}/postpone_index/management/commands/apply_postponed.py +0 -0
  84. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3}/postpone_index/migration_utils.py +0 -0
  85. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3}/postpone_index/sql/start.sql +0 -0
  86. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3}/postpone_index/testing_utils.py +0 -0
  87. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3}/postpone_index/utils.py +0 -0
  88. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3}/pyproject.toml +0 -0
  89. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3}/setup.cfg +0 -0
  90. {django_postpone_index-0.0.1 → django_postpone_index-0.0.3}/tox.ini +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: django-postpone-index
3
- Version: 0.0.1
3
+ Version: 0.0.3
4
4
  Summary: Postpone index creation to provide Zero Downtime Migration feature
5
5
  Home-page: https://github.com/nnseva/django-postpone-index
6
6
  Author: Vsevolod Novikov
@@ -169,6 +169,43 @@ calling the `apply_postponed` migration command again. All not-applied indexes w
169
169
  **NOTICE** the `apply_postponed` management command doesn't have any explicit locking mechanics. Avoid starting this
170
170
  command concurrently with itself or another `migrate` command on the same database.
171
171
 
172
+ ## Intermediate migration state
173
+
174
+ Apart from standard Django migrations, using the `postpone_index` package leads to the *intermediate migration state*
175
+ after the `migrate` management command finished:
176
+
177
+ - new model structure is applied
178
+ - indexes to be deleted are deleted
179
+ - indexes to be created are *not created yet*
180
+
181
+ You should be aware that if you introduce a new unique index or constraint, the database does not control uniqueness
182
+ based on not yet created indexes at this time.
183
+
184
+ Your code works now as expected everywhere, except the code which is based on new unique constraints introduced in applied migrations.
185
+
186
+ Apply the `apply_postponed run` management command to make these new indexes work.
187
+
188
+ Any error while `apply_postponed run` execution is stored in the `PostponedSQL` model instance.
189
+
190
+ You can see erroneous lines using `apply_postponed list` command. See the `[E]` mark at the start of the line.
191
+
192
+ You also can see the error details using the format parameter of the `apply_postponed list -f '... %(error)s'` management command.
193
+
194
+ The `apply_postponed run -x` breaks execution on any error. You can see the error in the standard error or logging streams.
195
+
196
+ The `apply_postponed run` (without `-x` parameter) doesn't stop on error, but outputs warning to the log stream instead.
197
+
198
+ When the error happened, it most probably is caused by the non-unique records. Fix the data and try to execute
199
+ `apply_postponed run` again to create an index.
200
+
201
+ After the successfull `apply_postponed run` execution, the migration state is finalised to be equal as if you applied the migration
202
+ without `postpone_index` package at all.
203
+
204
+ The `apply_postponed run` management command marks all successfully executed `PostponedSQL` instances as `done`. You can see `[X]` mark
205
+ at the start of the line produced by `apply_ponsponed list` management command.
206
+
207
+ You can cleanup `done` instances using `apply_postponed cleanup` management command. This step is optional.
208
+
172
209
  ## Django testing
173
210
 
174
211
  Django migrates testing database before tests. Always use `POSTPONE_INDEX_IGNORE = True` settings to avoid postpone index
@@ -120,6 +120,43 @@ calling the `apply_postponed` migration command again. All not-applied indexes w
120
120
  **NOTICE** the `apply_postponed` management command doesn't have any explicit locking mechanics. Avoid starting this
121
121
  command concurrently with itself or another `migrate` command on the same database.
122
122
 
123
+ ## Intermediate migration state
124
+
125
+ Apart from standard Django migrations, using the `postpone_index` package leads to the *intermediate migration state*
126
+ after the `migrate` management command finished:
127
+
128
+ - new model structure is applied
129
+ - indexes to be deleted are deleted
130
+ - indexes to be created are *not created yet*
131
+
132
+ You should be aware that if you introduce a new unique index or constraint, the database does not control uniqueness
133
+ based on not yet created indexes at this time.
134
+
135
+ Your code works now as expected everywhere, except the code which is based on new unique constraints introduced in applied migrations.
136
+
137
+ Apply the `apply_postponed run` management command to make these new indexes work.
138
+
139
+ Any error while `apply_postponed run` execution is stored in the `PostponedSQL` model instance.
140
+
141
+ You can see erroneous lines using `apply_postponed list` command. See the `[E]` mark at the start of the line.
142
+
143
+ You also can see the error details using the format parameter of the `apply_postponed list -f '... %(error)s'` management command.
144
+
145
+ The `apply_postponed run -x` breaks execution on any error. You can see the error in the standard error or logging streams.
146
+
147
+ The `apply_postponed run` (without `-x` parameter) doesn't stop on error, but outputs warning to the log stream instead.
148
+
149
+ When the error happened, it most probably is caused by the non-unique records. Fix the data and try to execute
150
+ `apply_postponed run` again to create an index.
151
+
152
+ After the successfull `apply_postponed run` execution, the migration state is finalised to be equal as if you applied the migration
153
+ without `postpone_index` package at all.
154
+
155
+ The `apply_postponed run` management command marks all successfully executed `PostponedSQL` instances as `done`. You can see `[X]` mark
156
+ at the start of the line produced by `apply_ponsponed list` management command.
157
+
158
+ You can cleanup `done` instances using `apply_postponed cleanup` management command. This step is optional.
159
+
123
160
  ## Django testing
124
161
 
125
162
  Django migrates testing database before tests. Always use `POSTPONE_INDEX_IGNORE = True` settings to avoid postpone index
@@ -124,11 +124,6 @@ LOGGING = {
124
124
  }
125
125
  },
126
126
  'loggers': {
127
- 'postpone_index.contrib.postgres.schema': {
128
- 'handlers': ['console'],
129
- 'level': os.environ.get('POSTPONE_INDEX_LOGGING', 'INFO'),
130
- 'propagate': False,
131
- },
132
127
  'postpone_index': {
133
128
  'handlers': ['console'],
134
129
  'level': os.environ.get('POSTPONE_INDEX_LOGGING', 'INFO'),
@@ -139,7 +134,6 @@ LOGGING = {
139
134
  'level': os.environ.get('CONFIG_LOGGING', 'INFO'),
140
135
  'propagate': False,
141
136
  },
142
- # Again, default Django configuration to email unhandled exceptions
143
137
  'django.db': {
144
138
  'handlers': ['console'],
145
139
  'level': os.environ.get('DATABASE_LOGGING', 'INFO'),
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: django-postpone-index
3
- Version: 0.0.1
3
+ Version: 0.0.3
4
4
  Summary: Postpone index creation to provide Zero Downtime Migration feature
5
5
  Home-page: https://github.com/nnseva/django-postpone-index
6
6
  Author: Vsevolod Novikov
@@ -169,6 +169,43 @@ calling the `apply_postponed` migration command again. All not-applied indexes w
169
169
  **NOTICE** the `apply_postponed` management command doesn't have any explicit locking mechanics. Avoid starting this
170
170
  command concurrently with itself or another `migrate` command on the same database.
171
171
 
172
+ ## Intermediate migration state
173
+
174
+ Apart from standard Django migrations, using the `postpone_index` package leads to the *intermediate migration state*
175
+ after the `migrate` management command finished:
176
+
177
+ - new model structure is applied
178
+ - indexes to be deleted are deleted
179
+ - indexes to be created are *not created yet*
180
+
181
+ You should be aware that if you introduce a new unique index or constraint, the database does not control uniqueness
182
+ based on not yet created indexes at this time.
183
+
184
+ Your code works now as expected everywhere, except the code which is based on new unique constraints introduced in applied migrations.
185
+
186
+ Apply the `apply_postponed run` management command to make these new indexes work.
187
+
188
+ Any error while `apply_postponed run` execution is stored in the `PostponedSQL` model instance.
189
+
190
+ You can see erroneous lines using `apply_postponed list` command. See the `[E]` mark at the start of the line.
191
+
192
+ You also can see the error details using the format parameter of the `apply_postponed list -f '... %(error)s'` management command.
193
+
194
+ The `apply_postponed run -x` breaks execution on any error. You can see the error in the standard error or logging streams.
195
+
196
+ The `apply_postponed run` (without `-x` parameter) doesn't stop on error, but outputs warning to the log stream instead.
197
+
198
+ When the error happened, it most probably is caused by the non-unique records. Fix the data and try to execute
199
+ `apply_postponed run` again to create an index.
200
+
201
+ After the successfull `apply_postponed run` execution, the migration state is finalised to be equal as if you applied the migration
202
+ without `postpone_index` package at all.
203
+
204
+ The `apply_postponed run` management command marks all successfully executed `PostponedSQL` instances as `done`. You can see `[X]` mark
205
+ at the start of the line produced by `apply_ponsponed list` management command.
206
+
207
+ You can cleanup `done` instances using `apply_postponed cleanup` management command. This step is optional.
208
+
172
209
  ## Django testing
173
210
 
174
211
  Django migrates testing database before tests. Always use `POSTPONE_INDEX_IGNORE = True` settings to avoid postpone index
@@ -0,0 +1,6 @@
1
+ postpone_index
2
+ postpone_index/contrib
3
+ postpone_index/contrib/postgis
4
+ postpone_index/contrib/postgres
5
+ postpone_index/management
6
+ postpone_index/management/commands
@@ -28,7 +28,7 @@ version_tuple: VERSION_TUPLE
28
28
  commit_id: COMMIT_ID
29
29
  __commit_id__: COMMIT_ID
30
30
 
31
- __version__ = version = '0.0.1'
32
- __version_tuple__ = version_tuple = (0, 0, 1)
31
+ __version__ = version = '0.0.3'
32
+ __version_tuple__ = version_tuple = (0, 0, 3)
33
33
 
34
- __commit_id__ = commit_id = 'g35054a7d6'
34
+ __commit_id__ = commit_id = 'g98bba5fb9'
@@ -25,20 +25,10 @@ class DatabaseSchemaEditorMixin(Utils):
25
25
  """
26
26
  if self._base_tables_created:
27
27
  return
28
-
29
28
  # Avoid circular import
30
29
  from postpone_index.models import PostponedSQL
31
30
 
32
- cursor = self.connection.cursor()
33
- cursor.execute("SELECT 1 FROM information_schema.tables WHERE table_schema = 'public' AND table_name = '%s' limit 1" % PostponedSQL._meta.db_table)
34
- if cursor.fetchall():
35
- self._base_tables_created = True
36
- logger.debug('[%s] The PostponedSQL storage already exists', self.connection.alias)
37
- return
38
- logger.info('[%s] The PostponedSQL storage is absent, creating', self.connection.alias)
39
- with open(os.path.join(package_folder, 'sql/start.sql')) as f:
40
- sql = f.read()
41
- cursor.execute(sql)
31
+ PostponedSQL.objects.using(self.connection.alias)._create_base_tables()
42
32
  self._base_tables_created = True
43
33
 
44
34
  def _ignore(self):
@@ -0,0 +1,129 @@
1
+ import logging
2
+ import os
3
+ import time
4
+
5
+ from unlimited_char.fields import CharField
6
+
7
+ from django.db import models, connections
8
+ from django.utils.translation import gettext_lazy as _
9
+
10
+ logger = logging.getLogger(__name__)
11
+ package_folder = os.path.dirname(os.path.abspath(__file__))
12
+
13
+
14
+ class PostponedSQLQuerySet(models.QuerySet):
15
+ """
16
+ QuerySet for PostponedSQL model.
17
+
18
+ Redefined for admin view when table is absent.
19
+ """
20
+
21
+ def _create_base_tables(self):
22
+ """
23
+ Create base package table if absent
24
+ """
25
+ if self._is_present():
26
+ logger.debug('[%s] The PostponedSQL storage already exists', self.db)
27
+ return
28
+ logger.info('[%s] The PostponedSQL storage is absent, creating', self.db)
29
+ with open(os.path.join(package_folder, 'sql/start.sql')) as f:
30
+ sql = f.read()
31
+ cursor = connections[self.db].cursor()
32
+ cursor.execute(sql)
33
+
34
+ def count(self):
35
+ """
36
+ Count only if table is present
37
+ """
38
+ if not self._is_present():
39
+ return 0
40
+ return super().count()
41
+
42
+ def _is_present(self):
43
+ """
44
+ Check if table is present
45
+ """
46
+ cursor = connections[self.db].cursor()
47
+ cursor.execute(
48
+ """
49
+ SELECT 1 FROM information_schema.tables
50
+ WHERE table_schema = 'public' AND table_name = '%s' limit 1
51
+ """ % PostponedSQL._meta.db_table
52
+ )
53
+ return bool(cursor.fetchall())
54
+
55
+
56
+ class PostponedSQLManager(models.Manager):
57
+ """
58
+ Manager for PostponedSQL model.
59
+
60
+ Redefined for admin view when table is absent.
61
+ """
62
+
63
+ def get_queryset(self):
64
+ """
65
+ Get custom QuerySet
66
+ """
67
+ qs = PostponedSQLQuerySet(self.model, using=self._db)
68
+ if not qs._is_present():
69
+ return qs.none()
70
+ return qs
71
+
72
+
73
+ class PostponedSQL(models.Model):
74
+ """Model to store postponed SQL commands"""
75
+
76
+ ts = models.BigIntegerField(
77
+ primary_key=True, editable=False,
78
+ default=time.time_ns,
79
+ verbose_name=_('Timestamp ns'),
80
+ help_text=_('Timestamp in nanoseconds')
81
+ )
82
+ description = CharField(
83
+ verbose_name=_('Description'),
84
+ help_text=_('Free-form short description')
85
+ )
86
+ sql = models.TextField(
87
+ verbose_name=_('SQL'),
88
+ help_text=_('Original SQL generated on the migration stage'),
89
+ )
90
+ table = CharField(
91
+ blank=True, null=True, db_index=True,
92
+ verbose_name=_('Table'),
93
+ help_text=_('Table name if applied to the table')
94
+ )
95
+ db_index = CharField(
96
+ blank=True, null=True, db_index=True,
97
+ verbose_name=_('Index'),
98
+ help_text=_('Index name if applied to the index')
99
+ )
100
+ fields = CharField(
101
+ blank=True, null=True,
102
+ verbose_name=_('Fields'),
103
+ help_text=_('Field names separated by comma if applied to the fields')
104
+ )
105
+ done = models.BooleanField(
106
+ default=False,
107
+ verbose_name=_('Done'),
108
+ help_text=_('Has the command been applied')
109
+ )
110
+ error = models.TextField(
111
+ blank=True, null=True,
112
+ verbose_name=_('Error'),
113
+ help_text=_('Last error reported when tried to apply')
114
+ )
115
+
116
+ objects = PostponedSQLManager()
117
+
118
+ @property
119
+ def d(self):
120
+ """Status mark"""
121
+ return '[X]' if self.done else '[E]' if self.error else '[ ]'
122
+
123
+ class Meta:
124
+ managed = False
125
+ verbose_name = _('Postponed SQL')
126
+ verbose_name_plural = _('Postponed SQLs')
127
+
128
+ def __str__(self):
129
+ return self.description
@@ -49,5 +49,15 @@ setup(
49
49
  'postgresql',
50
50
  ],
51
51
  license='LGPLv3',
52
- packages=['postpone_index'],
52
+ packages=[
53
+ 'postpone_index',
54
+ 'postpone_index/contrib',
55
+ 'postpone_index/contrib/postgres',
56
+ 'postpone_index/contrib/postgis',
57
+ 'postpone_index/management',
58
+ 'postpone_index/management/commands',
59
+ ],
60
+ package_data={
61
+ 'postpone_index': ['sql/start.sql'],
62
+ },
53
63
  )
@@ -1,61 +0,0 @@
1
- import time
2
-
3
- from unlimited_char.fields import CharField
4
-
5
- from django.db import models
6
- from django.utils.translation import gettext_lazy as _
7
-
8
-
9
- class PostponedSQL(models.Model):
10
- ts = models.BigIntegerField(
11
- primary_key=True, editable=False,
12
- default=time.time_ns,
13
- verbose_name=_('Timestamp ns'),
14
- help_text=_('Timestamp in nanoseconds')
15
- )
16
- description = CharField(
17
- verbose_name=_('Description'),
18
- help_text=_('Free-form short description')
19
- )
20
- sql = models.TextField(
21
- verbose_name=_('SQL'),
22
- help_text=_('Original SQL generated on the migration stage'),
23
- )
24
- table = CharField(
25
- blank=True, null=True, db_index=True,
26
- verbose_name=_('Table'),
27
- help_text=_('Table name if applied to the table')
28
- )
29
- db_index = CharField(
30
- blank=True, null=True, db_index=True,
31
- verbose_name=_('Index'),
32
- help_text=_('Index name if applied to the index')
33
- )
34
- fields = CharField(
35
- blank=True, null=True,
36
- verbose_name=_('Fields'),
37
- help_text=_('Field names separated by comma if applied to the fields')
38
- )
39
- done = models.BooleanField(
40
- default=False,
41
- verbose_name=_('Done'),
42
- help_text=_('Has the command been applied')
43
- )
44
- error = models.TextField(
45
- blank=True, null=True,
46
- verbose_name=_('Error'),
47
- help_text=_('Last error reported when tried to apply')
48
- )
49
-
50
- @property
51
- def d(self):
52
- """Status mark"""
53
- return '[X]' if self.done else '[E]' if self.error else '[ ]'
54
-
55
- class Meta:
56
- managed = False
57
- verbose_name = _('Postponed SQL')
58
- verbose_name_plural = _('Postponed SQLs')
59
-
60
- def __str__(self):
61
- return self.description