datanommer.models 1.3.0__py3-none-any.whl → 1.4.0__py3-none-any.whl

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.
@@ -32,6 +32,7 @@ from sqlalchemy import (
32
32
  event,
33
33
  ForeignKey,
34
34
  func,
35
+ Index,
35
36
  Integer,
36
37
  not_,
37
38
  or_,
@@ -158,6 +159,7 @@ def add(message):
158
159
  timestamp=sent_at,
159
160
  msg=message.body,
160
161
  headers=headers,
162
+ agent_name=getattr(message, "agent_name", None),
161
163
  users=usernames,
162
164
  packages=packages,
163
165
  )
@@ -213,7 +215,15 @@ packages_assoc_table = Table(
213
215
 
214
216
  class Message(DeclarativeBase):
215
217
  __tablename__ = "messages"
216
- __table_args__ = (UniqueConstraint("msg_id", "timestamp"),)
218
+ __table_args__ = (
219
+ UniqueConstraint("msg_id", "timestamp"),
220
+ Index(
221
+ "ix_messages_headers",
222
+ "headers",
223
+ postgresql_using="gin",
224
+ postgresql_ops={"headers": "jsonb_path_ops"},
225
+ ),
226
+ )
217
227
 
218
228
  id = Column(Integer, primary_key=True, autoincrement=True)
219
229
  msg_id = Column(Unicode, nullable=True, default=None, index=True)
@@ -223,7 +233,7 @@ class Message(DeclarativeBase):
223
233
  certificate = Column(UnicodeText)
224
234
  signature = Column(UnicodeText)
225
235
  category = Column(Unicode, nullable=False, index=True)
226
- username = Column(Unicode)
236
+ agent_name = Column(Unicode, index=True)
227
237
  crypto = Column(UnicodeText)
228
238
  source_name = Column(Unicode, default="datanommer")
229
239
  source_version = Column(Unicode, default=lambda context: __version__)
@@ -326,7 +336,8 @@ class Message(DeclarativeBase):
326
336
  timestamp=self.timestamp,
327
337
  certificate=self.certificate,
328
338
  signature=self.signature,
329
- username=self.username,
339
+ agent_name=self.agent_name,
340
+ username=self.agent_name, # DEPRECATED
330
341
  crypto=self.crypto,
331
342
  msg=self.msg,
332
343
  headers=self.headers,
@@ -358,6 +369,16 @@ class Message(DeclarativeBase):
358
369
  )
359
370
  return self.as_dict(request)
360
371
 
372
+ @property
373
+ def username(self):
374
+ warn(
375
+ "The username attribute has been renamed to agent_name, and will be removed "
376
+ "in the next major version",
377
+ DeprecationWarning,
378
+ stacklevel=2,
379
+ )
380
+ return self.agent_name
381
+
361
382
  @classmethod
362
383
  def make_query(
363
384
  cls,
@@ -372,6 +393,8 @@ class Message(DeclarativeBase):
372
393
  not_categories=None,
373
394
  topics=None,
374
395
  not_topics=None,
396
+ agents=None,
397
+ not_agents=None,
375
398
  contains=None,
376
399
  ):
377
400
  """Flexible query interface for messages.
@@ -400,6 +423,7 @@ class Message(DeclarativeBase):
400
423
 
401
424
  (user == 'ralph') AND
402
425
  NOT (category == 'bodhi' OR category == 'wiki')
426
+
403
427
  """
404
428
 
405
429
  users = users or []
@@ -410,6 +434,8 @@ class Message(DeclarativeBase):
410
434
  not_cats = not_categories or []
411
435
  topics = topics or []
412
436
  not_topics = not_topics or []
437
+ agents = agents or []
438
+ not_agents = not_agents or []
413
439
  contains = contains or []
414
440
 
415
441
  Message = cls
@@ -441,6 +467,9 @@ class Message(DeclarativeBase):
441
467
  if topics:
442
468
  query = query.where(or_(*(Message.topic == topic for topic in topics)))
443
469
 
470
+ if agents:
471
+ query = query.where(or_(*(Message.agent_name == agent for agent in agents)))
472
+
444
473
  if contains:
445
474
  query = query.where(or_(*(Message.msg.like(f"%{contain}%") for contain in contains)))
446
475
 
@@ -459,6 +488,9 @@ class Message(DeclarativeBase):
459
488
  if not_topics:
460
489
  query = query.where(not_(or_(*(Message.topic == topic for topic in not_topics))))
461
490
 
491
+ if not_agents:
492
+ query = query.where(not_(or_(*(Message.agent_name == agent for agent in not_agents))))
493
+
462
494
  return query
463
495
 
464
496
  @classmethod
@@ -500,13 +532,8 @@ class Message(DeclarativeBase):
500
532
 
501
533
  ----
502
534
 
503
- The ``jsons`` argument is a list of jsonpath filters, please refer to
504
- `PostgreSQL's documentation
505
- <https://www.postgresql.org/docs/current/functions-json.html#FUNCTIONS-SQLJSON-PATH>`_
506
- on the matter to learn how to build the jsonpath expression.
507
-
508
- The ``jsons_and`` argument is similar to the ``jsons`` argument, but all
509
- the values must match for a message to be returned.
535
+ If the `defer` argument evaluates to True, the query won't actually
536
+ be executed, but a SQLAlchemy query object returned instead.
510
537
  """
511
538
  query = cls.make_query(**kwargs)
512
539
  # Finally, tag on our pagination arguments
@@ -538,7 +565,7 @@ class Message(DeclarativeBase):
538
565
  def get_first(cls, *, order="asc", **kwargs):
539
566
  """Get the first message matching the regular grep filters."""
540
567
  query = cls.make_query(**kwargs)
541
- query = query.order_by(getattr(Message.timestamp, order)())
568
+ query = query.order_by(getattr(Message.timestamp, order)()).limit(1)
542
569
  return session.scalars(query).first()
543
570
 
544
571
 
@@ -0,0 +1,24 @@
1
+ """Message.username → Message.agent_name
2
+
3
+ Revision ID: 429e6f2cba6f
4
+ Revises: 951c40020acc
5
+ Create Date: 2024-06-07 09:12:33.393757
6
+
7
+ """
8
+
9
+ from alembic import op
10
+
11
+
12
+ # revision identifiers, used by Alembic.
13
+ revision = "429e6f2cba6f"
14
+ down_revision = "f6918385051f"
15
+
16
+
17
+ def upgrade():
18
+ op.alter_column("messages", "username", new_column_name="agent_name")
19
+ op.create_index(op.f("ix_messages_agent_name"), "messages", ["agent_name"], unique=False)
20
+
21
+
22
+ def downgrade():
23
+ op.drop_index(op.f("ix_messages_agent_name"), table_name="messages")
24
+ op.alter_column("messages", "agent_name", new_column_name="username")
@@ -0,0 +1,29 @@
1
+ """Messages.headers index
2
+
3
+ Revision ID: f6918385051f
4
+ Revises: 951c40020acc
5
+ Create Date: 2024-05-07 16:05:05.344863
6
+
7
+ """
8
+
9
+ from alembic import op
10
+
11
+
12
+ # revision identifiers, used by Alembic.
13
+ revision = "f6918385051f"
14
+ down_revision = "951c40020acc"
15
+
16
+
17
+ def upgrade():
18
+ op.create_index(
19
+ "ix_messages_headers",
20
+ "messages",
21
+ ["headers"],
22
+ unique=False,
23
+ postgresql_using="gin",
24
+ postgresql_ops={"headers": "jsonb_path_ops"},
25
+ )
26
+
27
+
28
+ def downgrade():
29
+ op.drop_index("ix_messages_headers", table_name="messages", postgresql_using="gin")
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: datanommer.models
3
- Version: 1.3.0
3
+ Version: 1.4.0
4
4
  Summary: SQLAlchemy models for datanommer
5
5
  Home-page: https://github.com/fedora-infra/datanommer
6
6
  License: GPL-3.0-or-later
@@ -0,0 +1,12 @@
1
+ datanommer/models/__init__.py,sha256=5By2KNqRy1d7abDFMT3DvhcQZ4UVrx92XokAYevjKnk,19322
2
+ datanommer/models/alembic/env.py,sha256=WNTimgnH70CakhvuV5QCilCnOcjTy7kcx0nD7hryYx0,2793
3
+ datanommer/models/alembic/script.py.mako,sha256=D8kFI44_9vBJZrAYSkZxDTX2-S5Y-oEetEd9BKlo9S8,412
4
+ datanommer/models/alembic/versions/429e6f2cba6f_message_agent_name.py,sha256=JT_q5oweCN8soqMTul1vEspWvqx5TXOfG3ifB9DYmgs,612
5
+ datanommer/models/alembic/versions/5db25abc63be_init.py,sha256=xMD7WGCOqeVNFroCZds_aS_jta2yTrAHc_XhtmZLZRs,249
6
+ datanommer/models/alembic/versions/951c40020acc_unique.py,sha256=GwKDhppKW7y5BUV8BqILZCAiR7GsNyIvoTXUu2A1ZMI,843
7
+ datanommer/models/alembic/versions/f6918385051f_messages_headers_index.py,sha256=vj-yzMOH3MNdQDufPLAxhix74fV_2tzBbEc6JNWt9Og,575
8
+ datanommer/models/testing/__init__.py,sha256=wwAZ-s1U4M7nYNxHgJsn5ZIqLuHMzHrJwGJOwgHAFgc,1693
9
+ datanommer_models-1.4.0.dist-info/LICENSE,sha256=jOtLnuWt7d5Hsx6XXB2QxzrSe2sWWh3NgMfFRetluQM,35147
10
+ datanommer_models-1.4.0.dist-info/METADATA,sha256=F6nCFWELLinPdPJVmvxwGN4a9wgB7RodZAOlPlA0KLM,2561
11
+ datanommer_models-1.4.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
12
+ datanommer_models-1.4.0.dist-info/RECORD,,
@@ -1,10 +0,0 @@
1
- datanommer/models/__init__.py,sha256=j3ZIgc2XnXoHaTuC2edq9RoVEqx0g8dc9-3dKi3ctBU,18628
2
- datanommer/models/alembic/env.py,sha256=WNTimgnH70CakhvuV5QCilCnOcjTy7kcx0nD7hryYx0,2793
3
- datanommer/models/alembic/script.py.mako,sha256=D8kFI44_9vBJZrAYSkZxDTX2-S5Y-oEetEd9BKlo9S8,412
4
- datanommer/models/alembic/versions/5db25abc63be_init.py,sha256=xMD7WGCOqeVNFroCZds_aS_jta2yTrAHc_XhtmZLZRs,249
5
- datanommer/models/alembic/versions/951c40020acc_unique.py,sha256=GwKDhppKW7y5BUV8BqILZCAiR7GsNyIvoTXUu2A1ZMI,843
6
- datanommer/models/testing/__init__.py,sha256=wwAZ-s1U4M7nYNxHgJsn5ZIqLuHMzHrJwGJOwgHAFgc,1693
7
- datanommer_models-1.3.0.dist-info/LICENSE,sha256=jOtLnuWt7d5Hsx6XXB2QxzrSe2sWWh3NgMfFRetluQM,35147
8
- datanommer_models-1.3.0.dist-info/METADATA,sha256=wKhrCYMD6cECmPOoosFOEIZdtAezEhw1SxwDxlotE54,2561
9
- datanommer_models-1.3.0.dist-info/WHEEL,sha256=sP946D7jFCHeNz5Iq4fL4Lu-PrWrFsgfLXbbkciIZwg,88
10
- datanommer_models-1.3.0.dist-info/RECORD,,