Mercurial > libervia-backend
annotate libervia/backend/memory/sqla_mapping.py @ 4118:07370d2a9bde
plugin XEP-0167: keep media order when starting a call:
media content order is relevant when building Jingle contents/SDP notably for bundling.
This patch fixes the previous behaviour of always using the same order by keeping the
order of the data (i.e. order of original SDP offer). Previous behaviour could lead to
call failure.
rel 424
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 03 Oct 2023 15:15:24 +0200 |
parents | 684ba556a617 |
children | 02f0adc745c6 |
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 |
4095
684ba556a617
core (memory/sqla_mapping): fix legacy pickled values:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
105 try: |
684ba556a617
core (memory/sqla_mapping): fix legacy pickled values:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
106 return pickle.loads(value, encoding="utf-8") |
684ba556a617
core (memory/sqla_mapping): fix legacy pickled values:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
107 except ModuleNotFoundError: |
684ba556a617
core (memory/sqla_mapping): fix legacy pickled values:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
108 # FIXME: workaround due to package renaming, need to move all pickle code to |
684ba556a617
core (memory/sqla_mapping): fix legacy pickled values:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
109 # JSON |
684ba556a617
core (memory/sqla_mapping): fix legacy pickled values:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
110 return pickle.loads( |
684ba556a617
core (memory/sqla_mapping): fix legacy pickled values:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
111 value.replace(b"sat.plugins", b"libervia.backend.plugins"), |
684ba556a617
core (memory/sqla_mapping): fix legacy pickled values:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
112 encoding="utf-8" |
684ba556a617
core (memory/sqla_mapping): fix legacy pickled values:
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
113 ) |
3537
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
114 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
115 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
116 class Json(TypeDecorator): |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
117 """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
|
118 # 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
|
119 impl = Text |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
120 cache_ok = True |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
121 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
122 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
|
123 if value is None: |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
124 return None |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
125 return json.dumps(value) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
126 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
127 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
|
128 if value is None: |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
129 return None |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
130 return json.loads(value) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
131 |
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 class JsonDefaultDict(Json): |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
134 """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
|
135 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
136 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
|
137 if value is None: |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
138 return {} |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
139 return json.loads(value) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
140 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
141 |
3593
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
142 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
|
143 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
|
144 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
|
145 |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
146 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
|
147 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
|
148 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
|
149 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
|
150 |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
151 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
|
152 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
|
153 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
|
154 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
|
155 |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
156 |
3537
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
157 class JID(TypeDecorator): |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
158 """Store twisted JID in text fields""" |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
159 impl = Text |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
160 cache_ok = True |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
161 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
162 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
|
163 if value is None: |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
164 return None |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
165 return value.full() |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
166 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
167 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
|
168 if value is None: |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
169 return None |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
170 return jid.JID(value) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
171 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
172 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
173 class Profile(Base): |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
174 __tablename__ = "profiles" |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
175 |
3581
84ea57a8d6b3
memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
176 id = Column( |
84ea57a8d6b3
memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
177 Integer, |
84ea57a8d6b3
memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
178 primary_key=True, |
84ea57a8d6b3
memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
179 nullable=True, |
84ea57a8d6b3
memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
180 ) |
3537
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
181 name = Column(Text, unique=True) |
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 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
|
184 private_data = relationship( |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
185 "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
|
186 ) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
187 private_bin_data = relationship( |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
188 "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
|
189 ) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
190 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
191 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
192 class Component(Base): |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
193 __tablename__ = "components" |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
194 |
3581
84ea57a8d6b3
memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
195 profile_id = Column( |
84ea57a8d6b3
memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
196 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
|
197 nullable=True, |
84ea57a8d6b3
memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
198 primary_key=True |
84ea57a8d6b3
memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
199 ) |
3537
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
200 entry_point = Column(Text, nullable=False) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
201 profile = relationship("Profile") |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
202 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
203 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
204 class History(Base): |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
205 __tablename__ = "history" |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
206 __table_args__ = ( |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
207 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
|
208 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
|
209 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
|
210 Index( |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
211 "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
|
212 ) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
213 ) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
214 |
3583
16ade4ad63f3
core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents:
3581
diff
changeset
|
215 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
|
216 origin_id = Column(Text) |
3537
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
217 stanza_id = Column(Text) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
218 update_uid = Column(Text) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
219 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
|
220 source = Column(Text) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
221 dest = Column(Text) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
222 source_res = Column(Text) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
223 dest_res = Column(Text) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
224 timestamp = Column(Float, nullable=False) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
225 received_timestamp = Column(Float) |
3583
16ade4ad63f3
core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents:
3581
diff
changeset
|
226 type = Column( |
16ade4ad63f3
core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents:
3581
diff
changeset
|
227 Enum( |
16ade4ad63f3
core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents:
3581
diff
changeset
|
228 "chat", |
16ade4ad63f3
core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents:
3581
diff
changeset
|
229 "error", |
16ade4ad63f3
core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents:
3581
diff
changeset
|
230 "groupchat", |
16ade4ad63f3
core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents:
3581
diff
changeset
|
231 "headline", |
16ade4ad63f3
core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents:
3581
diff
changeset
|
232 "normal", |
16ade4ad63f3
core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents:
3581
diff
changeset
|
233 # 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
|
234 # in a MUC |
16ade4ad63f3
core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents:
3581
diff
changeset
|
235 "info", |
16ade4ad63f3
core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents:
3581
diff
changeset
|
236 name="message_type", |
16ade4ad63f3
core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents:
3581
diff
changeset
|
237 create_constraint=True, |
16ade4ad63f3
core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents:
3581
diff
changeset
|
238 ), |
16ade4ad63f3
core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents:
3581
diff
changeset
|
239 nullable=False, |
16ade4ad63f3
core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents:
3581
diff
changeset
|
240 ) |
3537
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
241 extra = Column(LegacyPickle) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
242 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
243 profile = relationship("Profile") |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
244 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
|
245 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
|
246 thread = relationship( |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
247 "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
|
248 ) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
249 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
250 def __init__(self, *args, **kwargs): |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
251 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
|
252 if source_jid is not None: |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
253 kwargs["source"] = source_jid.userhost() |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
254 kwargs["source_res"] = source_jid.resource |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
255 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
|
256 if dest_jid is not None: |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
257 kwargs["dest"] = dest_jid.userhost() |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
258 kwargs["dest_res"] = dest_jid.resource |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
259 super().__init__(*args, **kwargs) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
260 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
261 @property |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
262 def source_jid(self) -> jid.JID: |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
263 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
|
264 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
265 @source_jid.setter |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
266 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
|
267 self.source = source_jid.userhost |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
268 self.source_res = source_jid.resource |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
269 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
270 @property |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
271 def dest_jid(self): |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
272 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
|
273 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
274 @dest_jid.setter |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
275 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
|
276 self.dest = dest_jid.userhost |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
277 self.dest_res = dest_jid.resource |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
278 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
279 def __repr__(self): |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
280 dt = datetime.fromtimestamp(self.timestamp) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
281 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
|
282 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
283 def serialise(self): |
4026
fe4725bf42fb
core (memory/sqla): be sure to have a dict when serialising History.extra:
Goffi <goffi@goffi.org>
parents:
3796
diff
changeset
|
284 extra = self.extra or {} |
3796
24c1c06c865b
core (memory/mapping): add `origin_id` column to History + constraints update:
Goffi <goffi@goffi.org>
parents:
3744
diff
changeset
|
285 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
|
286 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
|
287 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
|
288 extra["stanza_id"] = self.stanza_id |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
289 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
|
290 extra["update_uid"] = self.update_uid |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
291 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
|
292 extra["received_timestamp"] = self.received_timestamp |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
293 if self.thread is not None: |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
294 extra["thread"] = self.thread.thread_id |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
295 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
|
296 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
|
297 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
298 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
299 return { |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
300 "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
|
301 else self.source, |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
302 "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
|
303 "uid": self.uid, |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
304 "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
|
305 "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
|
306 "type": self.type, |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
307 "extra": extra, |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
308 "timestamp": self.timestamp, |
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 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
311 def as_tuple(self): |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
312 d = self.serialise() |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
313 return ( |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
314 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
|
315 d['type'], d['extra'] |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
316 ) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
317 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
318 @staticmethod |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
319 def debug_collection(history_collection): |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
320 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
|
321 history.debug_msg(idx) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
322 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
323 def debug_msg(self, idx=None): |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
324 """Print messages""" |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
325 dt = datetime.fromtimestamp(self.timestamp) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
326 if idx is not None: |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
327 dt = f"({idx}) {dt}" |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
328 parts = [] |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
329 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
|
330 for message in self.messages: |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
331 if message.language: |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
332 parts.append(f"[{message.language}] ") |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
333 parts.append(f"{message.message}\n") |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
334 print("".join(parts)) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
335 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
336 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
337 class Message(Base): |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
338 __tablename__ = "message" |
3581
84ea57a8d6b3
memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
339 __table_args__ = ( |
84ea57a8d6b3
memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
340 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
|
341 ) |
3537
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
342 |
3581
84ea57a8d6b3
memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
343 id = Column( |
84ea57a8d6b3
memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
344 Integer, |
84ea57a8d6b3
memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
345 primary_key=True, |
84ea57a8d6b3
memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
346 ) |
3796
24c1c06c865b
core (memory/mapping): add `origin_id` column to History + constraints update:
Goffi <goffi@goffi.org>
parents:
3744
diff
changeset
|
347 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
|
348 message = Column(Text, nullable=False) |
3537
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
349 language = Column(Text) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
350 |
3796
24c1c06c865b
core (memory/mapping): add `origin_id` column to History + constraints update:
Goffi <goffi@goffi.org>
parents:
3744
diff
changeset
|
351 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
|
352 s = {} |
24c1c06c865b
core (memory/mapping): add `origin_id` column to History + constraints update:
Goffi <goffi@goffi.org>
parents:
3744
diff
changeset
|
353 if self.message: |
24c1c06c865b
core (memory/mapping): add `origin_id` column to History + constraints update:
Goffi <goffi@goffi.org>
parents:
3744
diff
changeset
|
354 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
|
355 if self.language: |
24c1c06c865b
core (memory/mapping): add `origin_id` column to History + constraints update:
Goffi <goffi@goffi.org>
parents:
3744
diff
changeset
|
356 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
|
357 return s |
24c1c06c865b
core (memory/mapping): add `origin_id` column to History + constraints update:
Goffi <goffi@goffi.org>
parents:
3744
diff
changeset
|
358 |
3537
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
359 def __repr__(self): |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
360 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
|
361 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
|
362 content = f"{lang_str}{msg}" |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
363 return f"Message<{content}>" |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
364 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
365 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
366 class Subject(Base): |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
367 __tablename__ = "subject" |
3581
84ea57a8d6b3
memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
368 __table_args__ = ( |
84ea57a8d6b3
memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
369 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
|
370 ) |
3537
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
371 |
3581
84ea57a8d6b3
memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
372 id = Column( |
84ea57a8d6b3
memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
373 Integer, |
84ea57a8d6b3
memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
374 primary_key=True, |
84ea57a8d6b3
memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
375 ) |
3796
24c1c06c865b
core (memory/mapping): add `origin_id` column to History + constraints update:
Goffi <goffi@goffi.org>
parents:
3744
diff
changeset
|
376 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
|
377 subject = Column(Text, nullable=False) |
3537
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
378 language = Column(Text) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
379 |
3796
24c1c06c865b
core (memory/mapping): add `origin_id` column to History + constraints update:
Goffi <goffi@goffi.org>
parents:
3744
diff
changeset
|
380 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
|
381 s = {} |
24c1c06c865b
core (memory/mapping): add `origin_id` column to History + constraints update:
Goffi <goffi@goffi.org>
parents:
3744
diff
changeset
|
382 if self.subject: |
24c1c06c865b
core (memory/mapping): add `origin_id` column to History + constraints update:
Goffi <goffi@goffi.org>
parents:
3744
diff
changeset
|
383 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
|
384 if self.language: |
24c1c06c865b
core (memory/mapping): add `origin_id` column to History + constraints update:
Goffi <goffi@goffi.org>
parents:
3744
diff
changeset
|
385 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
|
386 return s |
24c1c06c865b
core (memory/mapping): add `origin_id` column to History + constraints update:
Goffi <goffi@goffi.org>
parents:
3744
diff
changeset
|
387 |
3537
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
388 def __repr__(self): |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
389 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
|
390 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
|
391 content = f"{lang_str}{msg}" |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
392 return f"Subject<{content}>" |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
393 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
394 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
395 class Thread(Base): |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
396 __tablename__ = "thread" |
3581
84ea57a8d6b3
memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
397 __table_args__ = ( |
84ea57a8d6b3
memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
398 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
|
399 ) |
3537
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
400 |
3581
84ea57a8d6b3
memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
401 id = Column( |
84ea57a8d6b3
memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
402 Integer, |
84ea57a8d6b3
memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
403 primary_key=True, |
84ea57a8d6b3
memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
404 ) |
84ea57a8d6b3
memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents:
3537
diff
changeset
|
405 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
|
406 thread_id = Column(Text) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
407 parent_id = Column(Text) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
408 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
409 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
|
410 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
411 def __repr__(self): |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
412 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
|
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 ParamGen(Base): |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
416 __tablename__ = "param_gen" |
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 value = Column(Text) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
421 |
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 class ParamInd(Base): |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
424 __tablename__ = "param_ind" |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
425 |
3583
16ade4ad63f3
core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents:
3581
diff
changeset
|
426 category = Column(Text, primary_key=True) |
16ade4ad63f3
core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents:
3581
diff
changeset
|
427 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
|
428 profile_id = Column( |
3583
16ade4ad63f3
core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents:
3581
diff
changeset
|
429 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
|
430 ) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
431 value = Column(Text) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
432 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
433 profile = relationship("Profile", back_populates="params") |
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 PrivateGen(Base): |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
437 __tablename__ = "private_gen" |
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 value = Column(Text) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
442 |
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 class PrivateInd(Base): |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
445 __tablename__ = "private_ind" |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
446 |
3583
16ade4ad63f3
core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents:
3581
diff
changeset
|
447 namespace = Column(Text, primary_key=True) |
16ade4ad63f3
core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents:
3581
diff
changeset
|
448 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
|
449 profile_id = Column( |
3583
16ade4ad63f3
core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents:
3581
diff
changeset
|
450 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
|
451 ) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
452 value = Column(Text) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
453 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
454 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
|
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 PrivateGenBin(Base): |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
458 __tablename__ = "private_gen_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 value = Column(LegacyPickle) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
463 |
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 class PrivateIndBin(Base): |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
466 __tablename__ = "private_ind_bin" |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
467 |
3583
16ade4ad63f3
core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents:
3581
diff
changeset
|
468 namespace = Column(Text, primary_key=True) |
16ade4ad63f3
core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents:
3581
diff
changeset
|
469 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
|
470 profile_id = Column( |
3583
16ade4ad63f3
core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents:
3581
diff
changeset
|
471 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
|
472 ) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
473 value = Column(LegacyPickle) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
474 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
475 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
|
476 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
477 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
478 class File(Base): |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
479 __tablename__ = "files" |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
480 __table_args__ = ( |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
481 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
|
482 Index( |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
483 "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
|
484 "profile_id", |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
485 "owner", |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
486 "media_type", |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
487 "media_subtype" |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
488 ) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
489 ) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
490 |
3583
16ade4ad63f3
core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents:
3581
diff
changeset
|
491 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
|
492 public_id = Column(Text, unique=True) |
3583
16ade4ad63f3
core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents:
3581
diff
changeset
|
493 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
|
494 parent = Column(Text, nullable=False) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
495 type = Column( |
3583
16ade4ad63f3
core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents:
3581
diff
changeset
|
496 Enum( |
16ade4ad63f3
core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents:
3581
diff
changeset
|
497 "file", "directory", |
16ade4ad63f3
core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents:
3581
diff
changeset
|
498 name="file_type", |
16ade4ad63f3
core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents:
3581
diff
changeset
|
499 create_constraint=True |
16ade4ad63f3
core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents:
3581
diff
changeset
|
500 ), |
3537
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
501 nullable=False, |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
502 server_default="file", |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
503 ) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
504 file_hash = Column(Text) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
505 hash_algo = Column(Text) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
506 name = Column(Text, nullable=False) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
507 size = Column(Integer) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
508 namespace = Column(Text) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
509 media_type = Column(Text) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
510 media_subtype = Column(Text) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
511 created = Column(Float, nullable=False) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
512 modified = Column(Float) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
513 owner = Column(JID) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
514 access = Column(JsonDefaultDict) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
515 extra = Column(JsonDefaultDict) |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
516 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
|
517 |
f9a5b810f14d
core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
518 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
|
519 |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
520 |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
521 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
|
522 __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
|
523 __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
|
524 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
|
525 ) |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
526 |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
527 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
|
528 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
|
529 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
|
530 ) |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
531 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
|
532 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
|
533 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
|
534 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
|
535 ) |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
536 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
|
537 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
|
538 Enum( |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
539 SyncState, |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
540 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
|
541 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
|
542 ), |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
543 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 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
|
546 Float, |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
547 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
|
548 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
|
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 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
|
551 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
|
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 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
|
554 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
|
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 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
|
557 |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
558 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
|
559 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
|
560 |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
561 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
|
562 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
|
563 |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
564 |
3744
658ddbabaf36
core (memory/sqla): new table/mapping to handle Pubsub node subscriptions:
Goffi <goffi@goffi.org>
parents:
3663
diff
changeset
|
565 class PubsubSub(Base): |
658ddbabaf36
core (memory/sqla): new table/mapping to handle Pubsub node subscriptions:
Goffi <goffi@goffi.org>
parents:
3663
diff
changeset
|
566 """Subscriptions to pubsub nodes |
658ddbabaf36
core (memory/sqla): new table/mapping to handle Pubsub node subscriptions:
Goffi <goffi@goffi.org>
parents:
3663
diff
changeset
|
567 |
658ddbabaf36
core (memory/sqla): new table/mapping to handle Pubsub node subscriptions:
Goffi <goffi@goffi.org>
parents:
3663
diff
changeset
|
568 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
|
569 """ |
658ddbabaf36
core (memory/sqla): new table/mapping to handle Pubsub node subscriptions:
Goffi <goffi@goffi.org>
parents:
3663
diff
changeset
|
570 __tablename__ = "pubsub_subs" |
658ddbabaf36
core (memory/sqla): new table/mapping to handle Pubsub node subscriptions:
Goffi <goffi@goffi.org>
parents:
3663
diff
changeset
|
571 __table_args__ = ( |
658ddbabaf36
core (memory/sqla): new table/mapping to handle Pubsub node subscriptions:
Goffi <goffi@goffi.org>
parents:
3663
diff
changeset
|
572 UniqueConstraint("node_id", "subscriber"), |
658ddbabaf36
core (memory/sqla): new table/mapping to handle Pubsub node subscriptions:
Goffi <goffi@goffi.org>
parents:
3663
diff
changeset
|
573 ) |
658ddbabaf36
core (memory/sqla): new table/mapping to handle Pubsub node subscriptions:
Goffi <goffi@goffi.org>
parents:
3663
diff
changeset
|
574 |
658ddbabaf36
core (memory/sqla): new table/mapping to handle Pubsub node subscriptions:
Goffi <goffi@goffi.org>
parents:
3663
diff
changeset
|
575 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
|
576 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
|
577 subscriber = Column(JID) |
658ddbabaf36
core (memory/sqla): new table/mapping to handle Pubsub node subscriptions:
Goffi <goffi@goffi.org>
parents:
3663
diff
changeset
|
578 state = Column( |
658ddbabaf36
core (memory/sqla): new table/mapping to handle Pubsub node subscriptions:
Goffi <goffi@goffi.org>
parents:
3663
diff
changeset
|
579 Enum( |
658ddbabaf36
core (memory/sqla): new table/mapping to handle Pubsub node subscriptions:
Goffi <goffi@goffi.org>
parents:
3663
diff
changeset
|
580 SubscriptionState, |
658ddbabaf36
core (memory/sqla): new table/mapping to handle Pubsub node subscriptions:
Goffi <goffi@goffi.org>
parents:
3663
diff
changeset
|
581 name="state", |
658ddbabaf36
core (memory/sqla): new table/mapping to handle Pubsub node subscriptions:
Goffi <goffi@goffi.org>
parents:
3663
diff
changeset
|
582 create_constraint=True, |
658ddbabaf36
core (memory/sqla): new table/mapping to handle Pubsub node subscriptions:
Goffi <goffi@goffi.org>
parents:
3663
diff
changeset
|
583 ), |
658ddbabaf36
core (memory/sqla): new table/mapping to handle Pubsub node subscriptions:
Goffi <goffi@goffi.org>
parents:
3663
diff
changeset
|
584 nullable=True |
658ddbabaf36
core (memory/sqla): new table/mapping to handle Pubsub node subscriptions:
Goffi <goffi@goffi.org>
parents:
3663
diff
changeset
|
585 ) |
658ddbabaf36
core (memory/sqla): new table/mapping to handle Pubsub node subscriptions:
Goffi <goffi@goffi.org>
parents:
3663
diff
changeset
|
586 |
658ddbabaf36
core (memory/sqla): new table/mapping to handle Pubsub node subscriptions:
Goffi <goffi@goffi.org>
parents:
3663
diff
changeset
|
587 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
|
588 |
658ddbabaf36
core (memory/sqla): new table/mapping to handle Pubsub node subscriptions:
Goffi <goffi@goffi.org>
parents:
3663
diff
changeset
|
589 |
3593
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
590 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
|
591 __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
|
592 __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
|
593 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
|
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 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
|
596 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
|
597 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
|
598 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
|
599 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
|
600 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
|
601 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
|
602 |
cb8d0e8b917f
core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents:
3583
diff
changeset
|
603 node = relationship("PubsubNode", back_populates="items") |
3663
162866ca4be7
db (schema): create virtual table for FTS + migration
Goffi <goffi@goffi.org>
parents:
3639
diff
changeset
|
604 |
162866ca4be7
db (schema): create virtual table for FTS + migration
Goffi <goffi@goffi.org>
parents:
3639
diff
changeset
|
605 |
162866ca4be7
db (schema): create virtual table for FTS + migration
Goffi <goffi@goffi.org>
parents:
3639
diff
changeset
|
606 ## Full-Text Search |
162866ca4be7
db (schema): create virtual table for FTS + migration
Goffi <goffi@goffi.org>
parents:
3639
diff
changeset
|
607 |
162866ca4be7
db (schema): create virtual table for FTS + migration
Goffi <goffi@goffi.org>
parents:
3639
diff
changeset
|
608 # create |
162866ca4be7
db (schema): create virtual table for FTS + migration
Goffi <goffi@goffi.org>
parents:
3639
diff
changeset
|
609 |
162866ca4be7
db (schema): create virtual table for FTS + migration
Goffi <goffi@goffi.org>
parents:
3639
diff
changeset
|
610 @event.listens_for(PubsubItem.__table__, "after_create") |
162866ca4be7
db (schema): create virtual table for FTS + migration
Goffi <goffi@goffi.org>
parents:
3639
diff
changeset
|
611 def fts_create(target, connection, **kw): |
162866ca4be7
db (schema): create virtual table for FTS + migration
Goffi <goffi@goffi.org>
parents:
3639
diff
changeset
|
612 """Full-Text Search table creation""" |
162866ca4be7
db (schema): create virtual table for FTS + migration
Goffi <goffi@goffi.org>
parents:
3639
diff
changeset
|
613 if connection.engine.name == "sqlite": |
162866ca4be7
db (schema): create virtual table for FTS + migration
Goffi <goffi@goffi.org>
parents:
3639
diff
changeset
|
614 # Using SQLite FTS5 |
162866ca4be7
db (schema): create virtual table for FTS + migration
Goffi <goffi@goffi.org>
parents:
3639
diff
changeset
|
615 queries = [ |
162866ca4be7
db (schema): create virtual table for FTS + migration
Goffi <goffi@goffi.org>
parents:
3639
diff
changeset
|
616 "CREATE VIRTUAL TABLE pubsub_items_fts " |
162866ca4be7
db (schema): create virtual table for FTS + migration
Goffi <goffi@goffi.org>
parents:
3639
diff
changeset
|
617 "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
|
618 "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
|
619 " 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
|
620 "END", |
162866ca4be7
db (schema): create virtual table for FTS + migration
Goffi <goffi@goffi.org>
parents:
3639
diff
changeset
|
621 "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
|
622 " 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
|
623 "VALUES('delete', old.id, old.data);" |
162866ca4be7
db (schema): create virtual table for FTS + migration
Goffi <goffi@goffi.org>
parents:
3639
diff
changeset
|
624 "END", |
162866ca4be7
db (schema): create virtual table for FTS + migration
Goffi <goffi@goffi.org>
parents:
3639
diff
changeset
|
625 "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
|
626 " 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
|
627 "('delete', old.id, old.data);" |
162866ca4be7
db (schema): create virtual table for FTS + migration
Goffi <goffi@goffi.org>
parents:
3639
diff
changeset
|
628 " 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
|
629 "END" |
162866ca4be7
db (schema): create virtual table for FTS + migration
Goffi <goffi@goffi.org>
parents:
3639
diff
changeset
|
630 ] |
162866ca4be7
db (schema): create virtual table for FTS + migration
Goffi <goffi@goffi.org>
parents:
3639
diff
changeset
|
631 for q in queries: |
162866ca4be7
db (schema): create virtual table for FTS + migration
Goffi <goffi@goffi.org>
parents:
3639
diff
changeset
|
632 connection.execute(DDL(q)) |
162866ca4be7
db (schema): create virtual table for FTS + migration
Goffi <goffi@goffi.org>
parents:
3639
diff
changeset
|
633 |
162866ca4be7
db (schema): create virtual table for FTS + migration
Goffi <goffi@goffi.org>
parents:
3639
diff
changeset
|
634 # drop |
162866ca4be7
db (schema): create virtual table for FTS + migration
Goffi <goffi@goffi.org>
parents:
3639
diff
changeset
|
635 |
162866ca4be7
db (schema): create virtual table for FTS + migration
Goffi <goffi@goffi.org>
parents:
3639
diff
changeset
|
636 @event.listens_for(PubsubItem.__table__, "before_drop") |
162866ca4be7
db (schema): create virtual table for FTS + migration
Goffi <goffi@goffi.org>
parents:
3639
diff
changeset
|
637 def fts_drop(target, connection, **kw): |
162866ca4be7
db (schema): create virtual table for FTS + migration
Goffi <goffi@goffi.org>
parents:
3639
diff
changeset
|
638 "Full-Text Search table drop" "" |
162866ca4be7
db (schema): create virtual table for FTS + migration
Goffi <goffi@goffi.org>
parents:
3639
diff
changeset
|
639 if connection.engine.name == "sqlite": |
162866ca4be7
db (schema): create virtual table for FTS + migration
Goffi <goffi@goffi.org>
parents:
3639
diff
changeset
|
640 # Using SQLite FTS5 |
162866ca4be7
db (schema): create virtual table for FTS + migration
Goffi <goffi@goffi.org>
parents:
3639
diff
changeset
|
641 queries = [ |
162866ca4be7
db (schema): create virtual table for FTS + migration
Goffi <goffi@goffi.org>
parents:
3639
diff
changeset
|
642 "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
|
643 "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
|
644 "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
|
645 "DROP TABLE IF EXISTS pubsub_items_fts", |
162866ca4be7
db (schema): create virtual table for FTS + migration
Goffi <goffi@goffi.org>
parents:
3639
diff
changeset
|
646 ] |
162866ca4be7
db (schema): create virtual table for FTS + migration
Goffi <goffi@goffi.org>
parents:
3639
diff
changeset
|
647 for q in queries: |
162866ca4be7
db (schema): create virtual table for FTS + migration
Goffi <goffi@goffi.org>
parents:
3639
diff
changeset
|
648 connection.execute(DDL(q)) |