|
17 | 17 |
|
18 | 18 | import datetime
|
19 | 19 |
|
20 |
| -from sqlalchemy import types, Column, text, Index |
| 20 | +from sqlalchemy import types, Column, text, Index, Table |
21 | 21 |
|
22 | 22 | import ckan.model.meta as meta
|
23 | 23 | import ckan.model.domain_object as domain_object
|
|
27 | 27 | __all__ = ['TrackingSummary', 'TrackingRaw']
|
28 | 28 |
|
29 | 29 |
|
30 |
| -class TrackingRaw(domain_object.DomainObject, BaseModel): # type: ignore |
| 30 | +class TrackingRaw(domain_object.DomainObject, BaseModel): |
31 | 31 |
|
32 |
| - __tablename__ = 'tracking_raw' |
33 |
| - |
34 |
| - user_key = Column("user_key", types.Unicode(100), nullable=False, |
35 |
| - primary_key=True) |
36 |
| - url = Column("url", types.UnicodeText, nullable=False, primary_key=True) |
37 |
| - tracking_type = Column("tracking_type", types.Unicode(10), |
38 |
| - nullable=False) |
39 |
| - access_timestamp = Column("access_timestamp", types.DateTime, |
40 |
| - primary_key=True, default=datetime.datetime.now) |
| 32 | + __table__ = Table( |
| 33 | + "tracking_raw", |
| 34 | + BaseModel.metadata, |
| 35 | + Column("user_key", types.Unicode(100), nullable=False, primary_key=True), |
| 36 | + Column("url", types.UnicodeText, nullable=False, primary_key=True), |
| 37 | + Column("tracking_type", types.Unicode(10), nullable=False), |
| 38 | + Column( |
| 39 | + "access_timestamp", |
| 40 | + types.DateTime, |
| 41 | + primary_key=True, |
| 42 | + default=datetime.datetime.now |
| 43 | + ), |
| 44 | + ) |
41 | 45 |
|
42 | 46 | def __init__(self, user_key: str,
|
43 | 47 | url: str,
|
@@ -66,19 +70,19 @@ def create(cls, **kw: _types.Any) -> TrackingRaw:
|
66 | 70 | Index('tracking_raw_access_timestamp', 'access_timestamp')
|
67 | 71 |
|
68 | 72 |
|
69 |
| -class TrackingSummary(domain_object.DomainObject, BaseModel): # type: ignore |
70 |
| - |
71 |
| - __tablename__ = 'tracking_summary' |
| 73 | +class TrackingSummary(domain_object.DomainObject, BaseModel): |
72 | 74 |
|
73 |
| - url = Column("url", types.UnicodeText, nullable=False, primary_key=True) |
74 |
| - package_id = Column("package_id", types.UnicodeText) |
75 |
| - tracking_type = Column("tracking_type", types.Unicode(10), nullable=False) |
76 |
| - count = Column("count", types.Integer, nullable=False) # type: ignore |
77 |
| - running_total = Column("running_total", types.Integer, nullable=False, |
78 |
| - server_default='0') |
79 |
| - recent_views = Column("recent_views", types.Integer, nullable=False, |
80 |
| - server_default='0') |
81 |
| - tracking_date = Column("tracking_date", types.Date) |
| 75 | + __table__ = Table( |
| 76 | + "tracking_summary", |
| 77 | + BaseModel.metadata, |
| 78 | + Column("url", types.UnicodeText, nullable=False, primary_key=True), |
| 79 | + Column("package_id", types.UnicodeText), |
| 80 | + Column("tracking_type", types.Unicode(10), nullable=False), |
| 81 | + Column("count", types.Integer, nullable=False), |
| 82 | + Column("running_total", types.Integer, nullable=False, server_default="0"), |
| 83 | + Column("recent_views", types.Integer, nullable=False, server_default="0"), |
| 84 | + Column("tracking_date", types.Date) |
| 85 | + ) |
82 | 86 |
|
83 | 87 | def __init__(self,
|
84 | 88 | url: str,
|
@@ -141,5 +145,5 @@ def get_for_resource(cls, url: str) -> dict[str, int]:
|
141 | 145 |
|
142 | 146 |
|
143 | 147 | Index('tracking_summary_url', TrackingSummary.url)
|
144 |
| -Index('tracking_summary_package_id', TrackingSummary.package_id) # type: ignore |
| 148 | +Index('tracking_summary_package_id', TrackingSummary.package_id) |
145 | 149 | Index('tracking_summary_date', 'tracking_date')
|
0 commit comments