0001_initial.py 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399
  1. # Generated by Django 5.0.2 on 2024-02-14 14:07
  2. import django.contrib.postgres.indexes
  3. import django.contrib.postgres.search
  4. import django.db.models.deletion
  5. import django.utils.timezone
  6. import psqlextra.backend.migrations.operations.create_partitioned_model
  7. import psqlextra.manager.manager
  8. import psqlextra.models.partitioned
  9. import psqlextra.types
  10. import uuid
  11. from django.conf import settings
  12. from django.db import migrations, models
  13. from glitchtip.model_utils import TestDefaultPartition
  14. from .functions.partition import create_partitions
  15. class Migration(migrations.Migration):
  16. initial = True
  17. dependencies = [
  18. ("projects", "0014_auto_20240318_1449"),
  19. (
  20. "releases",
  21. "0001_squashed_0004_alter_release_id_alter_releasefile_id_and_more",
  22. ),
  23. migrations.swappable_dependency(settings.AUTH_USER_MODEL),
  24. ]
  25. operations = [
  26. migrations.CreateModel(
  27. name="Comment",
  28. fields=[
  29. (
  30. "id",
  31. models.BigAutoField(
  32. auto_created=True,
  33. primary_key=True,
  34. serialize=False,
  35. verbose_name="ID",
  36. ),
  37. ),
  38. ("created", models.DateTimeField(auto_now_add=True)),
  39. ("text", models.TextField(blank=True, null=True)),
  40. (
  41. "user",
  42. models.ForeignKey(
  43. null=True,
  44. on_delete=django.db.models.deletion.SET_NULL,
  45. related_name="+",
  46. to=settings.AUTH_USER_MODEL,
  47. ),
  48. ),
  49. ],
  50. options={
  51. "ordering": ("-created",),
  52. },
  53. ),
  54. migrations.CreateModel(
  55. name="Issue",
  56. fields=[
  57. (
  58. "id",
  59. models.BigAutoField(
  60. auto_created=True,
  61. primary_key=True,
  62. serialize=False,
  63. verbose_name="ID",
  64. ),
  65. ),
  66. ("is_deleted", models.BooleanField(default=False)),
  67. ("culprit", models.CharField(blank=True, max_length=1024, null=True)),
  68. ("is_public", models.BooleanField(default=False)),
  69. (
  70. "level",
  71. models.PositiveSmallIntegerField(
  72. choices=[
  73. (0, "sample"),
  74. (1, "debug"),
  75. (2, "info"),
  76. (3, "warning"),
  77. (4, "error"),
  78. (5, "fatal"),
  79. ],
  80. default=4,
  81. ),
  82. ),
  83. ("metadata", models.JSONField()),
  84. ("title", models.CharField(max_length=255)),
  85. (
  86. "type",
  87. models.PositiveSmallIntegerField(
  88. choices=[(0, "default"), (1, "error"), (2, "csp")], default=0
  89. ),
  90. ),
  91. (
  92. "status",
  93. models.PositiveSmallIntegerField(
  94. choices=[(0, "unresolved"), (1, "resolved"), (2, "ignored")],
  95. default=0,
  96. ),
  97. ),
  98. ("short_id", models.PositiveIntegerField(null=True)),
  99. (
  100. "search_vector",
  101. django.contrib.postgres.search.SearchVectorField(
  102. default="", editable=False
  103. ),
  104. ),
  105. ("count", models.PositiveIntegerField(default=1, editable=False)),
  106. (
  107. "first_seen",
  108. models.DateTimeField(
  109. db_index=True, default=django.utils.timezone.now
  110. ),
  111. ),
  112. (
  113. "last_seen",
  114. models.DateTimeField(
  115. db_index=True, default=django.utils.timezone.now
  116. ),
  117. ),
  118. (
  119. "project",
  120. models.ForeignKey(
  121. on_delete=django.db.models.deletion.CASCADE,
  122. related_name="issues",
  123. to="projects.project",
  124. ),
  125. ),
  126. ],
  127. options={
  128. "base_manager_name": "objects",
  129. },
  130. ),
  131. psqlextra.backend.migrations.operations.create_partitioned_model.PostgresCreatePartitionedModel(
  132. name="IssueEvent",
  133. fields=[
  134. (
  135. "id",
  136. models.UUIDField(
  137. default=uuid.uuid4,
  138. editable=False,
  139. primary_key=True,
  140. serialize=False,
  141. ),
  142. ),
  143. (
  144. "type",
  145. models.PositiveSmallIntegerField(
  146. choices=[(0, "default"), (1, "error"), (2, "csp")], default=0
  147. ),
  148. ),
  149. (
  150. "timestamp",
  151. models.DateTimeField(help_text="Time at which event happened"),
  152. ),
  153. (
  154. "received",
  155. models.DateTimeField(
  156. help_text="Time at which GlitchTip accepted event"
  157. ),
  158. ),
  159. ("title", models.CharField(max_length=255)),
  160. ("transaction", models.CharField(max_length=200)),
  161. (
  162. "level",
  163. models.PositiveSmallIntegerField(
  164. choices=[
  165. (0, "sample"),
  166. (1, "debug"),
  167. (2, "info"),
  168. (3, "warning"),
  169. (4, "error"),
  170. (5, "fatal"),
  171. ],
  172. default=4,
  173. ),
  174. ),
  175. ("data", models.JSONField()),
  176. ("tags", models.JSONField()),
  177. (
  178. "issue",
  179. models.ForeignKey(
  180. on_delete=django.db.models.deletion.CASCADE,
  181. to="issue_events.issue",
  182. ),
  183. ),
  184. (
  185. "release",
  186. models.ForeignKey(
  187. blank=True,
  188. null=True,
  189. on_delete=django.db.models.deletion.SET_NULL,
  190. to="releases.release",
  191. ),
  192. ),
  193. ],
  194. options={},
  195. partitioning_options={
  196. "method": psqlextra.types.PostgresPartitioningMethod["RANGE"],
  197. "key": ["received"],
  198. },
  199. bases=(psqlextra.models.partitioned.PostgresPartitionedModel,),
  200. managers=[
  201. ("objects", psqlextra.manager.manager.PostgresManager()),
  202. ],
  203. ),
  204. migrations.AddIndex(
  205. model_name="issueevent",
  206. index=models.Index(
  207. fields=["issue", "-received"], name="issue_event_issue_i_3b4e7f_idx"
  208. ),
  209. ),
  210. TestDefaultPartition(
  211. model_name="IssueEvent",
  212. name="default",
  213. ),
  214. migrations.CreateModel(
  215. name="IssueHash",
  216. fields=[
  217. (
  218. "id",
  219. models.BigAutoField(
  220. auto_created=True,
  221. primary_key=True,
  222. serialize=False,
  223. verbose_name="ID",
  224. ),
  225. ),
  226. ("value", models.UUIDField(db_index=True)),
  227. (
  228. "issue",
  229. models.ForeignKey(
  230. on_delete=django.db.models.deletion.CASCADE,
  231. related_name="hashes",
  232. to="issue_events.issue",
  233. ),
  234. ),
  235. (
  236. "project",
  237. models.ForeignKey(
  238. on_delete=django.db.models.deletion.CASCADE,
  239. related_name="+",
  240. to="projects.project",
  241. ),
  242. ),
  243. ],
  244. ),
  245. psqlextra.backend.migrations.operations.create_partitioned_model.PostgresCreatePartitionedModel(
  246. name="IssueTag",
  247. fields=[
  248. (
  249. "id",
  250. models.BigAutoField(
  251. auto_created=True,
  252. primary_key=True,
  253. serialize=False,
  254. verbose_name="ID",
  255. ),
  256. ),
  257. ("date", models.DateTimeField()),
  258. ("count", models.PositiveIntegerField(default=1)),
  259. (
  260. "issue",
  261. models.ForeignKey(
  262. on_delete=django.db.models.deletion.CASCADE,
  263. to="issue_events.issue",
  264. ),
  265. ),
  266. ],
  267. partitioning_options={
  268. "method": psqlextra.types.PostgresPartitioningMethod["RANGE"],
  269. "key": ["date"],
  270. },
  271. bases=(psqlextra.models.partitioned.PostgresPartitionedModel,),
  272. managers=[
  273. ("objects", psqlextra.manager.manager.PostgresManager()),
  274. ],
  275. ),
  276. TestDefaultPartition(
  277. model_name="IssueTag",
  278. name="default",
  279. ),
  280. migrations.CreateModel(
  281. name="TagKey",
  282. fields=[
  283. ("id", models.AutoField(primary_key=True, serialize=False)),
  284. ("key", models.CharField(max_length=255, unique=True)),
  285. ],
  286. ),
  287. migrations.CreateModel(
  288. name="TagValue",
  289. fields=[
  290. (
  291. "id",
  292. models.BigAutoField(
  293. auto_created=True,
  294. primary_key=True,
  295. serialize=False,
  296. verbose_name="ID",
  297. ),
  298. ),
  299. ("value", models.CharField(max_length=255, unique=True)),
  300. ],
  301. ),
  302. migrations.AddField(
  303. model_name="comment",
  304. name="issue",
  305. field=models.ForeignKey(
  306. on_delete=django.db.models.deletion.CASCADE,
  307. related_name="comments",
  308. to="issue_events.issue",
  309. ),
  310. ),
  311. migrations.AddField(
  312. model_name="issuetag",
  313. name="tag_key",
  314. field=models.ForeignKey(
  315. on_delete=django.db.models.deletion.CASCADE, to="issue_events.tagkey"
  316. ),
  317. ),
  318. migrations.AddField(
  319. model_name="issuetag",
  320. name="tag_value",
  321. field=models.ForeignKey(
  322. on_delete=django.db.models.deletion.CASCADE, to="issue_events.tagvalue"
  323. ),
  324. ),
  325. migrations.CreateModel(
  326. name="UserReport",
  327. fields=[
  328. (
  329. "id",
  330. models.BigAutoField(
  331. auto_created=True,
  332. primary_key=True,
  333. serialize=False,
  334. verbose_name="ID",
  335. ),
  336. ),
  337. ("created", models.DateTimeField(auto_now_add=True, db_index=True)),
  338. ("event_id", models.UUIDField()),
  339. ("name", models.CharField(max_length=128)),
  340. ("email", models.EmailField(max_length=254)),
  341. ("comments", models.TextField()),
  342. (
  343. "issue",
  344. models.ForeignKey(
  345. null=True,
  346. on_delete=django.db.models.deletion.CASCADE,
  347. to="issue_events.issue",
  348. ),
  349. ),
  350. (
  351. "project",
  352. models.ForeignKey(
  353. on_delete=django.db.models.deletion.CASCADE,
  354. related_name="+",
  355. to="projects.project",
  356. ),
  357. ),
  358. ],
  359. ),
  360. migrations.AddIndex(
  361. model_name="issue",
  362. index=django.contrib.postgres.indexes.GinIndex(
  363. fields=["search_vector"], name="issue_event_search__346c17_gin"
  364. ),
  365. ),
  366. migrations.AddConstraint(
  367. model_name="issue",
  368. constraint=models.UniqueConstraint(
  369. fields=("project", "short_id"), name="project_short_id_unique"
  370. ),
  371. ),
  372. migrations.AddConstraint(
  373. model_name="issuehash",
  374. constraint=models.UniqueConstraint(
  375. fields=("project", "value"), name="issue hash project"
  376. ),
  377. ),
  378. migrations.AddConstraint(
  379. model_name="issuetag",
  380. constraint=models.UniqueConstraint(
  381. fields=("issue", "date", "tag_key", "tag_value"),
  382. name="issue_tag_key_value_unique",
  383. ),
  384. ),
  385. migrations.AddConstraint(
  386. model_name="userreport",
  387. constraint=models.UniqueConstraint(
  388. fields=("project", "event_id"), name="project_event_unique"
  389. ),
  390. ),
  391. migrations.RunPython(create_partitions, migrations.RunPython.noop),
  392. ]