Mercurial > libervia-backend
annotate sat/memory/sqla_mapping.py @ 3836:e183f1fbfa8d
doc (cli/pubsub): add doc for ``reference`` subcommand:
rel 369
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 10 Jul 2022 16:15:09 +0200 |
parents | 24c1c06c865b |
children | fe4725bf42fb |
rev | line source |
---|---|
3537
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1 #!/usr/bin/env python3 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 # Libervia: an XMPP client |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
4 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
5 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 # This program is free software: you can redistribute it and/or modify |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
7 # it under the terms of the GNU Affero General Public License as published by |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
8 # the Free Software Foundation, either version 3 of the License, or |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
9 # (at your option) any later version. |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 # This program is distributed in the hope that it will be useful, |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
14 # GNU Affero General Public License for more details. |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 # You should have received a copy of the GNU Affero General Public License |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
18 |
3796
24c1c06c865b
core (memory/mapping): add `origin_id` column to History + constraints update:
Goffi <goffi@goffi.org>
parents:
3744
diff
changeset
|
19 from typing import Dict, Any |
3593
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
20 from datetime import datetime |
3796
24c1c06c865b
core (memory/mapping): add `origin_id` column to History + constraints update:
Goffi <goffi@goffi.org>
parents:
3744
diff
changeset
|
21 import enum |
24c1c06c865b
core (memory/mapping): add `origin_id` column to History + constraints update:
Goffi <goffi@goffi.org>
parents:
3744
diff
changeset
|
22 import json |
24c1c06c865b
core (memory/mapping): add `origin_id` column to History + constraints update:
Goffi <goffi@goffi.org>
parents:
3744
diff
changeset
|
23 import pickle |
3593
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
24 import time |
3796
24c1c06c865b
core (memory/mapping): add `origin_id` column to History + constraints update:
Goffi <goffi@goffi.org>
parents:
3744
diff
changeset
|
25 |
3537
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
26 from sqlalchemy import ( |
3796
24c1c06c865b
core (memory/mapping): add `origin_id` column to History + constraints update:
Goffi <goffi@goffi.org>
parents:
3744
diff
changeset
|
27 Boolean, |
24c1c06c865b
core (memory/mapping): add `origin_id` column to History + constraints update:
Goffi <goffi@goffi.org>
parents:
3744
diff
changeset
|
28 Column, |
24c1c06c865b
core (memory/mapping): add `origin_id` column to History + constraints update:
Goffi <goffi@goffi.org>
parents:
3744
diff
changeset
|
29 DDL, |
24c1c06c865b
core (memory/mapping): add `origin_id` column to History + constraints update:
Goffi <goffi@goffi.org>
parents:
3744
diff
changeset
|
30 DateTime, |
24c1c06c865b
core (memory/mapping): add `origin_id` column to History + constraints update:
Goffi <goffi@goffi.org>
parents:
3744
diff
changeset
|
31 Enum, |
24c1c06c865b
core (memory/mapping): add `origin_id` column to History + constraints update:
Goffi <goffi@goffi.org>
parents:
3744
diff
changeset
|
32 Float, |
24c1c06c865b
core (memory/mapping): add `origin_id` column to History + constraints update:
Goffi <goffi@goffi.org>
parents:
3744
diff
changeset
|
33 ForeignKey, |
24c1c06c865b
core (memory/mapping): add `origin_id` column to History + constraints update:
Goffi <goffi@goffi.org>
parents:
3744
diff
changeset
|
34 Index, |
24c1c06c865b
core (memory/mapping): add `origin_id` column to History + constraints update:
Goffi <goffi@goffi.org>
parents:
3744
diff
changeset
|
35 Integer, |
24c1c06c865b
core (memory/mapping): add `origin_id` column to History + constraints update:
Goffi <goffi@goffi.org>
parents:
3744
diff
changeset
|
36 JSON, |
24c1c06c865b
core (memory/mapping): add `origin_id` column to History + constraints update:
Goffi <goffi@goffi.org>
parents:
3744
diff
changeset
|
37 MetaData, |
24c1c06c865b
core (memory/mapping): add `origin_id` column to History + constraints update:
Goffi <goffi@goffi.org>
parents:
3744
diff
changeset
|
38 Text, |
24c1c06c865b
core (memory/mapping): add `origin_id` column to History + constraints update:
Goffi <goffi@goffi.org>
parents:
3744
diff
changeset
|
39 UniqueConstraint, |
24c1c06c865b
core (memory/mapping): add `origin_id` column to History + constraints update:
Goffi <goffi@goffi.org>
parents:
3744
diff
changeset
|
40 event, |
3537
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
41 ) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
42 from sqlalchemy.orm import declarative_base, relationship |
3796
24c1c06c865b
core (memory/mapping): add `origin_id` column to History + constraints update:
Goffi <goffi@goffi.org>
parents:
3744
diff
changeset
|
43 from sqlalchemy.sql.functions import now |
3537
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
44 from sqlalchemy.types import TypeDecorator |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
45 from twisted.words.protocols.jabber import jid |
3593
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
46 from wokkel import generic |
3537
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
47 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
48 |
3583
16ade4ad63f3
core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents:
3581
diff
changeset
|
49 Base = declarative_base( |
16ade4ad63f3
core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents:
3581
diff
changeset
|
50 metadata=MetaData( |
16ade4ad63f3
core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents:
3581
diff
changeset
|
51 naming_convention={ |
16ade4ad63f3
core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents:
3581
diff
changeset
|
52 "ix": 'ix_%(column_0_label)s', |
16ade4ad63f3
core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents:
3581
diff
changeset
|
53 "uq": "uq_%(table_name)s_%(column_0_name)s", |
16ade4ad63f3
core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents:
3581
diff
changeset
|
54 "ck": "ck_%(table_name)s_%(constraint_name)s", |
16ade4ad63f3
core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents:
3581
diff
changeset
|
55 "fk": "fk_%(table_name)s_%(column_0_name)s_%(referred_table_name)s", |
16ade4ad63f3
core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents:
3581
diff
changeset
|
56 "pk": "pk_%(table_name)s" |
16ade4ad63f3
core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents:
3581
diff
changeset
|
57 } |
16ade4ad63f3
core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents:
3581
diff
changeset
|
58 ) |
16ade4ad63f3
core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents:
3581
diff
changeset
|
59 ) |
3537
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
60 # keys which are in message data extra but not stored in extra field this is |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
61 # because those values are stored in separate fields |
3796
24c1c06c865b
core (memory/mapping): add `origin_id` column to History + constraints update:
Goffi <goffi@goffi.org>
parents:
3744
diff
changeset
|
62 NOT_IN_EXTRA = ('origin_id', 'stanza_id', 'received_timestamp', 'update_uid') |
3537
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
63 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
64 |
3593
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
65 class SyncState(enum.Enum): |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
66 #: synchronisation is currently in progress |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
67 IN_PROGRESS = 1 |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
68 #: synchronisation is done |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
69 COMPLETED = 2 |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
70 #: something wrong happened during synchronisation, won't sync |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
71 ERROR = 3 |
3663
162866ca4be7
db (schema): create virtual table for FTS + migration
Goffi <goffi@goffi.org>
parents:
3639
diff
changeset
|
72 #: synchronisation won't be done even if a syncing analyser matches |
3593
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
73 NO_SYNC = 4 |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
74 |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
75 |
3744
658ddbabaf36
core (memory/sqla): new table/mapping to handle Pubsub node subscriptions:
Goffi <goffi@goffi.org>
parents:
3663
diff
changeset
|
76 class SubscriptionState(enum.Enum): |
658ddbabaf36
core (memory/sqla): new table/mapping to handle Pubsub node subscriptions:
Goffi <goffi@goffi.org>
parents:
3663
diff
changeset
|
77 SUBSCRIBED = 1 |
658ddbabaf36
core (memory/sqla): new table/mapping to handle Pubsub node subscriptions:
Goffi <goffi@goffi.org>
parents:
3663
diff
changeset
|
78 PENDING = 2 |
658ddbabaf36
core (memory/sqla): new table/mapping to handle Pubsub node subscriptions:
Goffi <goffi@goffi.org>
parents:
3663
diff
changeset
|
79 |
658ddbabaf36
core (memory/sqla): new table/mapping to handle Pubsub node subscriptions:
Goffi <goffi@goffi.org>
parents:
3663
diff
changeset
|
80 |
3537
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
81 class LegacyPickle(TypeDecorator): |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
82 """Handle troubles with data pickled by former version of SàT |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
83 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
84 This type is temporary until we do migration to a proper data type |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
85 """ |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
86 # Blob is used on SQLite but gives errors when used here, while Text works fine |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
87 impl = Text |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
88 cache_ok = True |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
89 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
90 def process_bind_param(self, value, dialect): |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
91 if value is None: |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
92 return None |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
93 return pickle.dumps(value, 0) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
94 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
95 def process_result_value(self, value, dialect): |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
96 if value is None: |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
97 return None |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
98 # value types are inconsistent (probably a consequence of Python 2/3 port |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
99 # and/or SQLite dynamic typing) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
100 try: |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
101 value = value.encode() |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
102 except AttributeError: |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
103 pass |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
104 # "utf-8" encoding is needed to handle Python 2 pickled data |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
105 return pickle.loads(value, encoding="utf-8") |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
106 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
107 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
108 class Json(TypeDecorator): |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
109 """Handle JSON field in DB independant way""" |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
110 # Blob is used on SQLite but gives errors when used here, while Text works fine |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
111 impl = Text |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
112 cache_ok = True |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
113 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
114 def process_bind_param(self, value, dialect): |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
115 if value is None: |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
116 return None |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
117 return json.dumps(value) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
118 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
119 def process_result_value(self, value, dialect): |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
120 if value is None: |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
121 return None |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
122 return json.loads(value) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
123 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
124 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
125 class JsonDefaultDict(Json): |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
126 """Json type which convert NULL to empty dict instead of None""" |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
127 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
128 def process_result_value(self, value, dialect): |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
129 if value is None: |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
130 return {} |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
131 return json.loads(value) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
132 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
133 |
3593
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
134 class Xml(TypeDecorator): |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
135 impl = Text |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
136 cache_ok = True |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
137 |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
138 def process_bind_param(self, value, dialect): |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
139 if value is None: |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
140 return None |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
141 return value.toXml() |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
142 |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
143 def process_result_value(self, value, dialect): |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
144 if value is None: |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
145 return None |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
146 return generic.parseXml(value.encode()) |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
147 |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
148 |
3537
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
149 class JID(TypeDecorator): |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
150 """Store twisted JID in text fields""" |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
151 impl = Text |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
152 cache_ok = True |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
153 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
154 def process_bind_param(self, value, dialect): |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
155 if value is None: |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
156 return None |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
157 return value.full() |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
158 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
159 def process_result_value(self, value, dialect): |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
160 if value is None: |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
161 return None |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
162 return jid.JID(value) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
163 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
164 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
165 class Profile(Base): |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
166 __tablename__ = "profiles" |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
167 |
3581
84ea57a8d6b3
memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
168 id = Column( |
84ea57a8d6b3
memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
169 Integer, |
84ea57a8d6b3
memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
170 primary_key=True, |
84ea57a8d6b3
memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
171 nullable=True, |
84ea57a8d6b3
memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
172 ) |
3537
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
173 name = Column(Text, unique=True) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
174 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
175 params = relationship("ParamInd", back_populates="profile", passive_deletes=True) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
176 private_data = relationship( |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
177 "PrivateInd", back_populates="profile", passive_deletes=True |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
178 ) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
179 private_bin_data = relationship( |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
180 "PrivateIndBin", back_populates="profile", passive_deletes=True |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
181 ) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
182 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
183 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
184 class Component(Base): |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
185 __tablename__ = "components" |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
186 |
3581
84ea57a8d6b3
memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
187 profile_id = Column( |
84ea57a8d6b3
memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
188 ForeignKey("profiles.id", ondelete="CASCADE"), |
84ea57a8d6b3
memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
189 nullable=True, |
84ea57a8d6b3
memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
190 primary_key=True |
84ea57a8d6b3
memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
191 ) |
3537
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
192 entry_point = Column(Text, nullable=False) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
193 profile = relationship("Profile") |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
194 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
195 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
196 class History(Base): |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
197 __tablename__ = "history" |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
198 __table_args__ = ( |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
199 UniqueConstraint("profile_id", "stanza_id", "source", "dest"), |
3796
24c1c06c865b
core (memory/mapping): add `origin_id` column to History + constraints update:
Goffi <goffi@goffi.org>
parents:
3744
diff
changeset
|
200 UniqueConstraint("profile_id", "origin_id", "source", name="uq_origin_id"), |
3537
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
201 Index("history__profile_id_timestamp", "profile_id", "timestamp"), |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
202 Index( |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
203 "history__profile_id_received_timestamp", "profile_id", "received_timestamp" |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
204 ) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
205 ) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
206 |
3583
16ade4ad63f3
core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents:
3581
diff
changeset
|
207 uid = Column(Text, primary_key=True) |
3796
24c1c06c865b
core (memory/mapping): add `origin_id` column to History + constraints update:
Goffi <goffi@goffi.org>
parents:
3744
diff
changeset
|
208 origin_id = Column(Text) |
3537
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
209 stanza_id = Column(Text) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
210 update_uid = Column(Text) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
211 profile_id = Column(ForeignKey("profiles.id", ondelete="CASCADE")) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
212 source = Column(Text) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
213 dest = Column(Text) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
214 source_res = Column(Text) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
215 dest_res = Column(Text) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
216 timestamp = Column(Float, nullable=False) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
217 received_timestamp = Column(Float) |
3583
16ade4ad63f3
core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents:
3581
diff
changeset
|
218 type = Column( |
16ade4ad63f3
core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents:
3581
diff
changeset
|
219 Enum( |
16ade4ad63f3
core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents:
3581
diff
changeset
|
220 "chat", |
16ade4ad63f3
core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents:
3581
diff
changeset
|
221 "error", |
16ade4ad63f3
core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents:
3581
diff
changeset
|
222 "groupchat", |
16ade4ad63f3
core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents:
3581
diff
changeset
|
223 "headline", |
16ade4ad63f3
core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents:
3581
diff
changeset
|
224 "normal", |
16ade4ad63f3
core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents:
3581
diff
changeset
|
225 # info is not XMPP standard, but used to keep track of info like join/leave |
16ade4ad63f3
core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents:
3581
diff
changeset
|
226 # in a MUC |
16ade4ad63f3
core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents:
3581
diff
changeset
|
227 "info", |
16ade4ad63f3
core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents:
3581
diff
changeset
|
228 name="message_type", |
16ade4ad63f3
core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents:
3581
diff
changeset
|
229 create_constraint=True, |
16ade4ad63f3
core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents:
3581
diff
changeset
|
230 ), |
16ade4ad63f3
core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents:
3581
diff
changeset
|
231 nullable=False, |
16ade4ad63f3
core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents:
3581
diff
changeset
|
232 ) |
3537
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
233 extra = Column(LegacyPickle) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
234 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
235 profile = relationship("Profile") |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
236 messages = relationship("Message", backref="history", passive_deletes=True) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
237 subjects = relationship("Subject", backref="history", passive_deletes=True) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
238 thread = relationship( |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
239 "Thread", uselist=False, back_populates="history", passive_deletes=True |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
240 ) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
241 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
242 def __init__(self, *args, **kwargs): |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
243 source_jid = kwargs.pop("source_jid", None) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
244 if source_jid is not None: |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
245 kwargs["source"] = source_jid.userhost() |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
246 kwargs["source_res"] = source_jid.resource |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
247 dest_jid = kwargs.pop("dest_jid", None) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
248 if dest_jid is not None: |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
249 kwargs["dest"] = dest_jid.userhost() |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
250 kwargs["dest_res"] = dest_jid.resource |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
251 super().__init__(*args, **kwargs) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
252 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
253 @property |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
254 def source_jid(self) -> jid.JID: |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
255 return jid.JID(f"{self.source}/{self.source_res or ''}") |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
256 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
257 @source_jid.setter |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
258 def source_jid(self, source_jid: jid.JID) -> None: |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
259 self.source = source_jid.userhost |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
260 self.source_res = source_jid.resource |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
261 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
262 @property |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
263 def dest_jid(self): |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
264 return jid.JID(f"{self.dest}/{self.dest_res or ''}") |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
265 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
266 @dest_jid.setter |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
267 def dest_jid(self, dest_jid: jid.JID) -> None: |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
268 self.dest = dest_jid.userhost |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
269 self.dest_res = dest_jid.resource |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
270 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
271 def __repr__(self): |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
272 dt = datetime.fromtimestamp(self.timestamp) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
273 return f"History<{self.source_jid.full()}->{self.dest_jid.full()} [{dt}]>" |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
274 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
275 def serialise(self): |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
276 extra = self.extra |
3796
24c1c06c865b
core (memory/mapping): add `origin_id` column to History + constraints update:
Goffi <goffi@goffi.org>
parents:
3744
diff
changeset
|
277 if self.origin_id is not None: |
24c1c06c865b
core (memory/mapping): add `origin_id` column to History + constraints update:
Goffi <goffi@goffi.org>
parents:
3744
diff
changeset
|
278 extra["origin_id"] = self.origin_id |
3537
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
279 if self.stanza_id is not None: |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
280 extra["stanza_id"] = self.stanza_id |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
281 if self.update_uid is not None: |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
282 extra["update_uid"] = self.update_uid |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
283 if self.received_timestamp is not None: |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
284 extra["received_timestamp"] = self.received_timestamp |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
285 if self.thread is not None: |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
286 extra["thread"] = self.thread.thread_id |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
287 if self.thread.parent_id is not None: |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
288 extra["thread_parent"] = self.thread.parent_id |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
289 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
290 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
291 return { |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
292 "from": f"{self.source}/{self.source_res}" if self.source_res |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
293 else self.source, |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
294 "to": f"{self.dest}/{self.dest_res}" if self.dest_res else self.dest, |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
295 "uid": self.uid, |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
296 "message": {m.language or '': m.message for m in self.messages}, |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
297 "subject": {m.language or '': m.subject for m in self.subjects}, |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
298 "type": self.type, |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
299 "extra": extra, |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
300 "timestamp": self.timestamp, |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
301 } |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
302 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
303 def as_tuple(self): |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
304 d = self.serialise() |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
305 return ( |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
306 d['uid'], d['timestamp'], d['from'], d['to'], d['message'], d['subject'], |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
307 d['type'], d['extra'] |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
308 ) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
309 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
310 @staticmethod |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
311 def debug_collection(history_collection): |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
312 for idx, history in enumerate(history_collection): |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
313 history.debug_msg(idx) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
314 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
315 def debug_msg(self, idx=None): |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
316 """Print messages""" |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
317 dt = datetime.fromtimestamp(self.timestamp) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
318 if idx is not None: |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
319 dt = f"({idx}) {dt}" |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
320 parts = [] |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
321 parts.append(f"[{dt}]<{self.source_jid.full()}->{self.dest_jid.full()}> ") |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
322 for message in self.messages: |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
323 if message.language: |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
324 parts.append(f"[{message.language}] ") |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
325 parts.append(f"{message.message}\n") |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
326 print("".join(parts)) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
327 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
328 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
329 class Message(Base): |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
330 __tablename__ = "message" |
3581
84ea57a8d6b3
memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
331 __table_args__ = ( |
84ea57a8d6b3
memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
332 Index("message__history_uid", "history_uid"), |
84ea57a8d6b3
memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
333 ) |
3537
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
334 |
3581
84ea57a8d6b3
memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
335 id = Column( |
84ea57a8d6b3
memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
336 Integer, |
84ea57a8d6b3
memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
337 primary_key=True, |
84ea57a8d6b3
memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
338 ) |
3796
24c1c06c865b
core (memory/mapping): add `origin_id` column to History + constraints update:
Goffi <goffi@goffi.org>
parents:
3744
diff
changeset
|
339 history_uid = Column(ForeignKey("history.uid", ondelete="CASCADE"), nullable=False) |
24c1c06c865b
core (memory/mapping): add `origin_id` column to History + constraints update:
Goffi <goffi@goffi.org>
parents:
3744
diff
changeset
|
340 message = Column(Text, nullable=False) |
3537
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
341 language = Column(Text) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
342 |
3796
24c1c06c865b
core (memory/mapping): add `origin_id` column to History + constraints update:
Goffi <goffi@goffi.org>
parents:
3744
diff
changeset
|
343 def serialise(self) -> Dict[str, Any]: |
24c1c06c865b
core (memory/mapping): add `origin_id` column to History + constraints update:
Goffi <goffi@goffi.org>
parents:
3744
diff
changeset
|
344 s = {} |
24c1c06c865b
core (memory/mapping): add `origin_id` column to History + constraints update:
Goffi <goffi@goffi.org>
parents:
3744
diff
changeset
|
345 if self.message: |
24c1c06c865b
core (memory/mapping): add `origin_id` column to History + constraints update:
Goffi <goffi@goffi.org>
parents:
3744
diff
changeset
|
346 s["message"] = str(self.message) |
24c1c06c865b
core (memory/mapping): add `origin_id` column to History + constraints update:
Goffi <goffi@goffi.org>
parents:
3744
diff
changeset
|
347 if self.language: |
24c1c06c865b
core (memory/mapping): add `origin_id` column to History + constraints update:
Goffi <goffi@goffi.org>
parents:
3744
diff
changeset
|
348 s["language"] = str(self.language) |
24c1c06c865b
core (memory/mapping): add `origin_id` column to History + constraints update:
Goffi <goffi@goffi.org>
parents:
3744
diff
changeset
|
349 return s |
24c1c06c865b
core (memory/mapping): add `origin_id` column to History + constraints update:
Goffi <goffi@goffi.org>
parents:
3744
diff
changeset
|
350 |
3537
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
351 def __repr__(self): |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
352 lang_str = f"[{self.language}]" if self.language else "" |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
353 msg = f"{self.message[:20]}…" if len(self.message)>20 else self.message |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
354 content = f"{lang_str}{msg}" |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
355 return f"Message<{content}>" |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
356 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
357 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
358 class Subject(Base): |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
359 __tablename__ = "subject" |
3581
84ea57a8d6b3
memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
360 __table_args__ = ( |
84ea57a8d6b3
memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
361 Index("subject__history_uid", "history_uid"), |
84ea57a8d6b3
memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
362 ) |
3537
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
363 |
3581
84ea57a8d6b3
memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
364 id = Column( |
84ea57a8d6b3
memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
365 Integer, |
84ea57a8d6b3
memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
366 primary_key=True, |
84ea57a8d6b3
memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
367 ) |
3796
24c1c06c865b
core (memory/mapping): add `origin_id` column to History + constraints update:
Goffi <goffi@goffi.org>
parents:
3744
diff
changeset
|
368 history_uid = Column(ForeignKey("history.uid", ondelete="CASCADE"), nullable=False) |
24c1c06c865b
core (memory/mapping): add `origin_id` column to History + constraints update:
Goffi <goffi@goffi.org>
parents:
3744
diff
changeset
|
369 subject = Column(Text, nullable=False) |
3537
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
370 language = Column(Text) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
371 |
3796
24c1c06c865b
core (memory/mapping): add `origin_id` column to History + constraints update:
Goffi <goffi@goffi.org>
parents:
3744
diff
changeset
|
372 def serialise(self) -> Dict[str, Any]: |
24c1c06c865b
core (memory/mapping): add `origin_id` column to History + constraints update:
Goffi <goffi@goffi.org>
parents:
3744
diff
changeset
|
373 s = {} |
24c1c06c865b
core (memory/mapping): add `origin_id` column to History + constraints update:
Goffi <goffi@goffi.org>
parents:
3744
diff
changeset
|
374 if self.subject: |
24c1c06c865b
core (memory/mapping): add `origin_id` column to History + constraints update:
Goffi <goffi@goffi.org>
parents:
3744
diff
changeset
|
375 s["subject"] = str(self.subject) |
24c1c06c865b
core (memory/mapping): add `origin_id` column to History + constraints update:
Goffi <goffi@goffi.org>
parents:
3744
diff
changeset
|
376 if self.language: |
24c1c06c865b
core (memory/mapping): add `origin_id` column to History + constraints update:
Goffi <goffi@goffi.org>
parents:
3744
diff
changeset
|
377 s["language"] = str(self.language) |
24c1c06c865b
core (memory/mapping): add `origin_id` column to History + constraints update:
Goffi <goffi@goffi.org>
parents:
3744
diff
changeset
|
378 return s |
24c1c06c865b
core (memory/mapping): add `origin_id` column to History + constraints update:
Goffi <goffi@goffi.org>
parents:
3744
diff
changeset
|
379 |
3537
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
380 def __repr__(self): |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
381 lang_str = f"[{self.language}]" if self.language else "" |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
382 msg = f"{self.subject[:20]}…" if len(self.subject)>20 else self.subject |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
383 content = f"{lang_str}{msg}" |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
384 return f"Subject<{content}>" |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
385 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
386 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
387 class Thread(Base): |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
388 __tablename__ = "thread" |
3581
84ea57a8d6b3
memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
389 __table_args__ = ( |
84ea57a8d6b3
memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
390 Index("thread__history_uid", "history_uid"), |
84ea57a8d6b3
memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
391 ) |
3537
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
392 |
3581
84ea57a8d6b3
memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
393 id = Column( |
84ea57a8d6b3
memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
394 Integer, |
84ea57a8d6b3
memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
395 primary_key=True, |
84ea57a8d6b3
memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
396 ) |
84ea57a8d6b3
memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
397 history_uid = Column(ForeignKey("history.uid", ondelete="CASCADE")) |
3537
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
398 thread_id = Column(Text) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
399 parent_id = Column(Text) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
400 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
401 history = relationship("History", uselist=False, back_populates="thread") |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
402 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
403 def __repr__(self): |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
404 return f"Thread<{self.thread_id} [parent: {self.parent_id}]>" |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
405 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
406 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
407 class ParamGen(Base): |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
408 __tablename__ = "param_gen" |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
409 |
3583
16ade4ad63f3
core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents:
3581
diff
changeset
|
410 category = Column(Text, primary_key=True) |
16ade4ad63f3
core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents:
3581
diff
changeset
|
411 name = Column(Text, primary_key=True) |
3537
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
412 value = Column(Text) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
413 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
414 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
415 class ParamInd(Base): |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
416 __tablename__ = "param_ind" |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
417 |
3583
16ade4ad63f3
core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents:
3581
diff
changeset
|
418 category = Column(Text, primary_key=True) |
16ade4ad63f3
core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents:
3581
diff
changeset
|
419 name = Column(Text, primary_key=True) |
3537
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
420 profile_id = Column( |
3583
16ade4ad63f3
core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents:
3581
diff
changeset
|
421 ForeignKey("profiles.id", ondelete="CASCADE"), primary_key=True |
3537
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
422 ) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
423 value = Column(Text) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
424 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
425 profile = relationship("Profile", back_populates="params") |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
426 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
427 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
428 class PrivateGen(Base): |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
429 __tablename__ = "private_gen" |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
430 |
3583
16ade4ad63f3
core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents:
3581
diff
changeset
|
431 namespace = Column(Text, primary_key=True) |
16ade4ad63f3
core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents:
3581
diff
changeset
|
432 key = Column(Text, primary_key=True) |
3537
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
433 value = Column(Text) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
434 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
435 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
436 class PrivateInd(Base): |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
437 __tablename__ = "private_ind" |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
438 |
3583
16ade4ad63f3
core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents:
3581
diff
changeset
|
439 namespace = Column(Text, primary_key=True) |
16ade4ad63f3
core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents:
3581
diff
changeset
|
440 key = Column(Text, primary_key=True) |
3537
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
441 profile_id = Column( |
3583
16ade4ad63f3
core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents:
3581
diff
changeset
|
442 ForeignKey("profiles.id", ondelete="CASCADE"), primary_key=True |
3537
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
443 ) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
444 value = Column(Text) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
445 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
446 profile = relationship("Profile", back_populates="private_data") |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
447 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
448 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
449 class PrivateGenBin(Base): |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
450 __tablename__ = "private_gen_bin" |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
451 |
3583
16ade4ad63f3
core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents:
3581
diff
changeset
|
452 namespace = Column(Text, primary_key=True) |
16ade4ad63f3
core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents:
3581
diff
changeset
|
453 key = Column(Text, primary_key=True) |
3537
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
454 value = Column(LegacyPickle) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
455 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
456 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
457 class PrivateIndBin(Base): |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
458 __tablename__ = "private_ind_bin" |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
459 |
3583
16ade4ad63f3
core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents:
3581
diff
changeset
|
460 namespace = Column(Text, primary_key=True) |
16ade4ad63f3
core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents:
3581
diff
changeset
|
461 key = Column(Text, primary_key=True) |
3537
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
462 profile_id = Column( |
3583
16ade4ad63f3
core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents:
3581
diff
changeset
|
463 ForeignKey("profiles.id", ondelete="CASCADE"), primary_key=True |
3537
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
464 ) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
465 value = Column(LegacyPickle) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
466 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
467 profile = relationship("Profile", back_populates="private_bin_data") |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
468 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
469 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
470 class File(Base): |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
471 __tablename__ = "files" |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
472 __table_args__ = ( |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
473 Index("files__profile_id_owner_parent", "profile_id", "owner", "parent"), |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
474 Index( |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
475 "files__profile_id_owner_media_type_media_subtype", |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
476 "profile_id", |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
477 "owner", |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
478 "media_type", |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
479 "media_subtype" |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
480 ) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
481 ) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
482 |
3583
16ade4ad63f3
core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents:
3581
diff
changeset
|
483 id = Column(Text, primary_key=True) |
3537
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
484 public_id = Column(Text, unique=True) |
3583
16ade4ad63f3
core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents:
3581
diff
changeset
|
485 version = Column(Text, primary_key=True) |
3537
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
486 parent = Column(Text, nullable=False) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
487 type = Column( |
3583
16ade4ad63f3
core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents:
3581
diff
changeset
|
488 Enum( |
16ade4ad63f3
core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents:
3581
diff
changeset
|
489 "file", "directory", |
16ade4ad63f3
core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents:
3581
diff
changeset
|
490 name="file_type", |
16ade4ad63f3
core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents:
3581
diff
changeset
|
491 create_constraint=True |
16ade4ad63f3
core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents:
3581
diff
changeset
|
492 ), |
3537
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
493 nullable=False, |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
494 server_default="file", |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
495 ) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
496 file_hash = Column(Text) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
497 hash_algo = Column(Text) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
498 name = Column(Text, nullable=False) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
499 size = Column(Integer) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
500 namespace = Column(Text) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
501 media_type = Column(Text) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
502 media_subtype = Column(Text) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
503 created = Column(Float, nullable=False) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
504 modified = Column(Float) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
505 owner = Column(JID) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
506 access = Column(JsonDefaultDict) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
507 extra = Column(JsonDefaultDict) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
508 profile_id = Column(ForeignKey("profiles.id", ondelete="CASCADE")) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
509 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
510 profile = relationship("Profile") |
3593
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
511 |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
512 |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
513 class PubsubNode(Base): |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
514 __tablename__ = "pubsub_nodes" |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
515 __table_args__ = ( |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
516 UniqueConstraint("profile_id", "service", "name"), |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
517 ) |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
518 |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
519 id = Column(Integer, primary_key=True) |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
520 profile_id = Column( |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
521 ForeignKey("profiles.id", ondelete="CASCADE") |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
522 ) |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
523 service = Column(JID) |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
524 name = Column(Text, nullable=False) |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
525 subscribed = Column( |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
526 Boolean(create_constraint=True, name="subscribed_bool"), nullable=False |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
527 ) |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
528 analyser = Column(Text) |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
529 sync_state = Column( |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
530 Enum( |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
531 SyncState, |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
532 name="sync_state", |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
533 create_constraint=True, |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
534 ), |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
535 nullable=True |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
536 ) |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
537 sync_state_updated = Column( |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
538 Float, |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
539 nullable=False, |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
540 default=time.time() |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
541 ) |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
542 type_ = Column( |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
543 Text, name="type", nullable=True |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
544 ) |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
545 subtype = Column( |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
546 Text, nullable=True |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
547 ) |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
548 extra = Column(JSON) |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
549 |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
550 items = relationship("PubsubItem", back_populates="node", passive_deletes=True) |
3744
658ddbabaf36
core (memory/sqla): new table/mapping to handle Pubsub node subscriptions:
Goffi <goffi@goffi.org>
parents:
3663
diff
changeset
|
551 subscriptions = relationship("PubsubSub", back_populates="node", passive_deletes=True) |
3593
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
552 |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
553 def __str__(self): |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
554 return f"Pubsub node {self.name!r} at {self.service}" |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
555 |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
556 |
3744
658ddbabaf36
core (memory/sqla): new table/mapping to handle Pubsub node subscriptions:
Goffi <goffi@goffi.org>
parents:
3663
diff
changeset
|
557 class PubsubSub(Base): |
658ddbabaf36
core (memory/sqla): new table/mapping to handle Pubsub node subscriptions:
Goffi <goffi@goffi.org>
parents:
3663
diff
changeset
|
558 """Subscriptions to pubsub nodes |
658ddbabaf36
core (memory/sqla): new table/mapping to handle Pubsub node subscriptions:
Goffi <goffi@goffi.org>
parents:
3663
diff
changeset
|
559 |
658ddbabaf36
core (memory/sqla): new table/mapping to handle Pubsub node subscriptions:
Goffi <goffi@goffi.org>
parents:
3663
diff
changeset
|
560 Used by components managing a pubsub service |
658ddbabaf36
core (memory/sqla): new table/mapping to handle Pubsub node subscriptions:
Goffi <goffi@goffi.org>
parents:
3663
diff
changeset
|
561 """ |
658ddbabaf36
core (memory/sqla): new table/mapping to handle Pubsub node subscriptions:
Goffi <goffi@goffi.org>
parents:
3663
diff
changeset
|
562 __tablename__ = "pubsub_subs" |
658ddbabaf36
core (memory/sqla): new table/mapping to handle Pubsub node subscriptions:
Goffi <goffi@goffi.org>
parents:
3663
diff
changeset
|
563 __table_args__ = ( |
658ddbabaf36
core (memory/sqla): new table/mapping to handle Pubsub node subscriptions:
Goffi <goffi@goffi.org>
parents:
3663
diff
changeset
|
564 UniqueConstraint("node_id", "subscriber"), |
658ddbabaf36
core (memory/sqla): new table/mapping to handle Pubsub node subscriptions:
Goffi <goffi@goffi.org>
parents:
3663
diff
changeset
|
565 ) |
658ddbabaf36
core (memory/sqla): new table/mapping to handle Pubsub node subscriptions:
Goffi <goffi@goffi.org>
parents:
3663
diff
changeset
|
566 |
658ddbabaf36
core (memory/sqla): new table/mapping to handle Pubsub node subscriptions:
Goffi <goffi@goffi.org>
parents:
3663
diff
changeset
|
567 id = Column(Integer, primary_key=True) |
658ddbabaf36
core (memory/sqla): new table/mapping to handle Pubsub node subscriptions:
Goffi <goffi@goffi.org>
parents:
3663
diff
changeset
|
568 node_id = Column(ForeignKey("pubsub_nodes.id", ondelete="CASCADE"), nullable=False) |
658ddbabaf36
core (memory/sqla): new table/mapping to handle Pubsub node subscriptions:
Goffi <goffi@goffi.org>
parents:
3663
diff
changeset
|
569 subscriber = Column(JID) |
658ddbabaf36
core (memory/sqla): new table/mapping to handle Pubsub node subscriptions:
Goffi <goffi@goffi.org>
parents:
3663
diff
changeset
|
570 state = Column( |
658ddbabaf36
core (memory/sqla): new table/mapping to handle Pubsub node subscriptions:
Goffi <goffi@goffi.org>
parents:
3663
diff
changeset
|
571 Enum( |
658ddbabaf36
core (memory/sqla): new table/mapping to handle Pubsub node subscriptions:
Goffi <goffi@goffi.org>
parents:
3663
diff
changeset
|
572 SubscriptionState, |
658ddbabaf36
core (memory/sqla): new table/mapping to handle Pubsub node subscriptions:
Goffi <goffi@goffi.org>
parents:
3663
diff
changeset
|
573 name="state", |
658ddbabaf36
core (memory/sqla): new table/mapping to handle Pubsub node subscriptions:
Goffi <goffi@goffi.org>
parents:
3663
diff
changeset
|
574 create_constraint=True, |
658ddbabaf36
core (memory/sqla): new table/mapping to handle Pubsub node subscriptions:
Goffi <goffi@goffi.org>
parents:
3663
diff
changeset
|
575 ), |
658ddbabaf36
core (memory/sqla): new table/mapping to handle Pubsub node subscriptions:
Goffi <goffi@goffi.org>
parents:
3663
diff
changeset
|
576 nullable=True |
658ddbabaf36
core (memory/sqla): new table/mapping to handle Pubsub node subscriptions:
Goffi <goffi@goffi.org>
parents:
3663
diff
changeset
|
577 ) |
658ddbabaf36
core (memory/sqla): new table/mapping to handle Pubsub node subscriptions:
Goffi <goffi@goffi.org>
parents:
3663
diff
changeset
|
578 |
658ddbabaf36
core (memory/sqla): new table/mapping to handle Pubsub node subscriptions:
Goffi <goffi@goffi.org>
parents:
3663
diff
changeset
|
579 node = relationship("PubsubNode", back_populates="subscriptions") |
658ddbabaf36
core (memory/sqla): new table/mapping to handle Pubsub node subscriptions:
Goffi <goffi@goffi.org>
parents:
3663
diff
changeset
|
580 |
658ddbabaf36
core (memory/sqla): new table/mapping to handle Pubsub node subscriptions:
Goffi <goffi@goffi.org>
parents:
3663
diff
changeset
|
581 |
3593
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
582 class PubsubItem(Base): |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
583 __tablename__ = "pubsub_items" |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
584 __table_args__ = ( |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
585 UniqueConstraint("node_id", "name"), |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
586 ) |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
587 id = Column(Integer, primary_key=True) |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
588 node_id = Column(ForeignKey("pubsub_nodes.id", ondelete="CASCADE"), nullable=False) |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
589 name = Column(Text, nullable=False) |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
590 data = Column(Xml, nullable=False) |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
591 created = Column(DateTime, nullable=False, server_default=now()) |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
592 updated = Column(DateTime, nullable=False, server_default=now(), onupdate=now()) |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
593 parsed = Column(JSON) |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
594 |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
595 node = relationship("PubsubNode", back_populates="items") |
3663
162866ca4be7
db (schema): create virtual table for FTS + migration
Goffi <goffi@goffi.org>
parents:
3639
diff
changeset
|
596 |
162866ca4be7
db (schema): create virtual table for FTS + migration
Goffi <goffi@goffi.org>
parents:
3639
diff
changeset
|
597 |
162866ca4be7
db (schema): create virtual table for FTS + migration
Goffi <goffi@goffi.org>
parents:
3639
diff
changeset
|
598 ## Full-Text Search |
162866ca4be7
db (schema): create virtual table for FTS + migration
Goffi <goffi@goffi.org>
parents:
3639
diff
changeset
|
599 |
162866ca4be7
db (schema): create virtual table for FTS + migration
Goffi <goffi@goffi.org>
parents:
3639
diff
changeset
|
600 # create |
162866ca4be7
db (schema): create virtual table for FTS + migration
Goffi <goffi@goffi.org>
parents:
3639
diff
changeset
|
601 |
162866ca4be7
db (schema): create virtual table for FTS + migration
Goffi <goffi@goffi.org>
parents:
3639
diff
changeset
|
602 @event.listens_for(PubsubItem.__table__, "after_create") |
162866ca4be7
db (schema): create virtual table for FTS + migration
Goffi <goffi@goffi.org>
parents:
3639
diff
changeset
|
603 def fts_create(target, connection, **kw): |
162866ca4be7
db (schema): create virtual table for FTS + migration
Goffi <goffi@goffi.org>
parents:
3639
diff
changeset
|
604 """Full-Text Search table creation""" |
162866ca4be7
db (schema): create virtual table for FTS + migration
Goffi <goffi@goffi.org>
parents:
3639
diff
changeset
|
605 if connection.engine.name == "sqlite": |
162866ca4be7
db (schema): create virtual table for FTS + migration
Goffi <goffi@goffi.org>
parents:
3639
diff
changeset
|
606 # Using SQLite FTS5 |
162866ca4be7
db (schema): create virtual table for FTS + migration
Goffi <goffi@goffi.org>
parents:
3639
diff
changeset
|
607 queries = [ |
162866ca4be7
db (schema): create virtual table for FTS + migration
Goffi <goffi@goffi.org>
parents:
3639
diff
changeset
|
608 "CREATE VIRTUAL TABLE pubsub_items_fts " |
162866ca4be7
db (schema): create virtual table for FTS + migration
Goffi <goffi@goffi.org>
parents:
3639
diff
changeset
|
609 "USING fts5(data, content=pubsub_items, content_rowid=id)", |
162866ca4be7
db (schema): create virtual table for FTS + migration
Goffi <goffi@goffi.org>
parents:
3639
diff
changeset
|
610 "CREATE TRIGGER pubsub_items_fts_sync_ins AFTER INSERT ON pubsub_items BEGIN" |
162866ca4be7
db (schema): create virtual table for FTS + migration
Goffi <goffi@goffi.org>
parents:
3639
diff
changeset
|
611 " INSERT INTO pubsub_items_fts(rowid, data) VALUES (new.id, new.data);" |
162866ca4be7
db (schema): create virtual table for FTS + migration
Goffi <goffi@goffi.org>
parents:
3639
diff
changeset
|
612 "END", |
162866ca4be7
db (schema): create virtual table for FTS + migration
Goffi <goffi@goffi.org>
parents:
3639
diff
changeset
|
613 "CREATE TRIGGER pubsub_items_fts_sync_del AFTER DELETE ON pubsub_items BEGIN" |
162866ca4be7
db (schema): create virtual table for FTS + migration
Goffi <goffi@goffi.org>
parents:
3639
diff
changeset
|
614 " INSERT INTO pubsub_items_fts(pubsub_items_fts, rowid, data) " |
162866ca4be7
db (schema): create virtual table for FTS + migration
Goffi <goffi@goffi.org>
parents:
3639
diff
changeset
|
615 "VALUES('delete', old.id, old.data);" |
162866ca4be7
db (schema): create virtual table for FTS + migration
Goffi <goffi@goffi.org>
parents:
3639
diff
changeset
|
616 "END", |
162866ca4be7
db (schema): create virtual table for FTS + migration
Goffi <goffi@goffi.org>
parents:
3639
diff
changeset
|
617 "CREATE TRIGGER pubsub_items_fts_sync_upd AFTER UPDATE ON pubsub_items BEGIN" |
162866ca4be7
db (schema): create virtual table for FTS + migration
Goffi <goffi@goffi.org>
parents:
3639
diff
changeset
|
618 " INSERT INTO pubsub_items_fts(pubsub_items_fts, rowid, data) VALUES" |
162866ca4be7
db (schema): create virtual table for FTS + migration
Goffi <goffi@goffi.org>
parents:
3639
diff
changeset
|
619 "('delete', old.id, old.data);" |
162866ca4be7
db (schema): create virtual table for FTS + migration
Goffi <goffi@goffi.org>
parents:
3639
diff
changeset
|
620 " INSERT INTO pubsub_items_fts(rowid, data) VALUES(new.id, new.data);" |
162866ca4be7
db (schema): create virtual table for FTS + migration
Goffi <goffi@goffi.org>
parents:
3639
diff
changeset
|
621 "END" |
162866ca4be7
db (schema): create virtual table for FTS + migration
Goffi <goffi@goffi.org>
parents:
3639
diff
changeset
|
622 ] |
162866ca4be7
db (schema): create virtual table for FTS + migration
Goffi <goffi@goffi.org>
parents:
3639
diff
changeset
|
623 for q in queries: |
162866ca4be7
db (schema): create virtual table for FTS + migration
Goffi <goffi@goffi.org>
parents:
3639
diff
changeset
|
624 connection.execute(DDL(q)) |
162866ca4be7
db (schema): create virtual table for FTS + migration
Goffi <goffi@goffi.org>
parents:
3639
diff
changeset
|
625 |
162866ca4be7
db (schema): create virtual table for FTS + migration
Goffi <goffi@goffi.org>
parents:
3639
diff
changeset
|
626 # drop |
162866ca4be7
db (schema): create virtual table for FTS + migration
Goffi <goffi@goffi.org>
parents:
3639
diff
changeset
|
627 |
162866ca4be7
db (schema): create virtual table for FTS + migration
Goffi <goffi@goffi.org>
parents:
3639
diff
changeset
|
628 @event.listens_for(PubsubItem.__table__, "before_drop") |
162866ca4be7
db (schema): create virtual table for FTS + migration
Goffi <goffi@goffi.org>
parents:
3639
diff
changeset
|
629 def fts_drop(target, connection, **kw): |
162866ca4be7
db (schema): create virtual table for FTS + migration
Goffi <goffi@goffi.org>
parents:
3639
diff
changeset
|
630 "Full-Text Search table drop" "" |
162866ca4be7
db (schema): create virtual table for FTS + migration
Goffi <goffi@goffi.org>
parents:
3639
diff
changeset
|
631 if connection.engine.name == "sqlite": |
162866ca4be7
db (schema): create virtual table for FTS + migration
Goffi <goffi@goffi.org>
parents:
3639
diff
changeset
|
632 # Using SQLite FTS5 |
162866ca4be7
db (schema): create virtual table for FTS + migration
Goffi <goffi@goffi.org>
parents:
3639
diff
changeset
|
633 queries = [ |
162866ca4be7
db (schema): create virtual table for FTS + migration
Goffi <goffi@goffi.org>
parents:
3639
diff
changeset
|
634 "DROP TRIGGER IF EXISTS pubsub_items_fts_sync_ins", |
162866ca4be7
db (schema): create virtual table for FTS + migration
Goffi <goffi@goffi.org>
parents:
3639
diff
changeset
|
635 "DROP TRIGGER IF EXISTS pubsub_items_fts_sync_del", |
162866ca4be7
db (schema): create virtual table for FTS + migration
Goffi <goffi@goffi.org>
parents:
3639
diff
changeset
|
636 "DROP TRIGGER IF EXISTS pubsub_items_fts_sync_upd", |
162866ca4be7
db (schema): create virtual table for FTS + migration
Goffi <goffi@goffi.org>
parents:
3639
diff
changeset
|
637 "DROP TABLE IF EXISTS pubsub_items_fts", |
162866ca4be7
db (schema): create virtual table for FTS + migration
Goffi <goffi@goffi.org>
parents:
3639
diff
changeset
|
638 ] |
162866ca4be7
db (schema): create virtual table for FTS + migration
Goffi <goffi@goffi.org>
parents:
3639
diff
changeset
|
639 for q in queries: |
162866ca4be7
db (schema): create virtual table for FTS + migration
Goffi <goffi@goffi.org>
parents:
3639
diff
changeset
|
640 connection.execute(DDL(q)) |