annotate sat/memory/sqla_mapping.py @ 3593:cb8d0e8b917f

core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
author Goffi <goffi@goffi.org>
date Thu, 29 Jul 2021 21:38:37 +0200
parents 16ade4ad63f3
children 05db744f194f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
19 import pickle
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
20 import json
3593
cb8d0e8b917f core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents: 3583
diff changeset
21 from datetime import datetime
cb8d0e8b917f core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents: 3583
diff changeset
22 import time
cb8d0e8b917f core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents: 3583
diff changeset
23 import enum
3537
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
24 from sqlalchemy import (
3593
cb8d0e8b917f core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents: 3583
diff changeset
25 MetaData, Column, Integer, Text, Float, Boolean, DateTime, Enum, JSON, ForeignKey,
cb8d0e8b917f core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents: 3583
diff changeset
26 UniqueConstraint, Index
3537
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
27 )
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
28
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
29 from sqlalchemy.orm import declarative_base, relationship
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
30 from sqlalchemy.types import TypeDecorator
3593
cb8d0e8b917f core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents: 3583
diff changeset
31 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
32 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
33 from wokkel import generic
3537
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
34
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
35
3583
16ade4ad63f3 core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents: 3581
diff changeset
36 Base = declarative_base(
16ade4ad63f3 core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents: 3581
diff changeset
37 metadata=MetaData(
16ade4ad63f3 core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents: 3581
diff changeset
38 naming_convention={
16ade4ad63f3 core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents: 3581
diff changeset
39 "ix": 'ix_%(column_0_label)s',
16ade4ad63f3 core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents: 3581
diff changeset
40 "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
41 "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
42 "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
43 "pk": "pk_%(table_name)s"
16ade4ad63f3 core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents: 3581
diff changeset
44 }
16ade4ad63f3 core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents: 3581
diff changeset
45 )
16ade4ad63f3 core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents: 3581
diff changeset
46 )
3537
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
47 # 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
48 # because those values are stored in separate fields
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
49 NOT_IN_EXTRA = ('stanza_id', 'received_timestamp', 'update_uid')
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
50
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
51
3593
cb8d0e8b917f core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents: 3583
diff changeset
52 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
53 #: 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
54 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
55 #: 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
56 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
57 #: 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
58 ERROR = 3
cb8d0e8b917f core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents: 3583
diff changeset
59 #: synchronisation won't be done even if a syncing analyser match
cb8d0e8b917f core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents: 3583
diff changeset
60 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
61
cb8d0e8b917f core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents: 3583
diff changeset
62
3537
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
63 class LegacyPickle(TypeDecorator):
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
64 """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
65
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
66 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
67 """
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
68 # 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
69 impl = Text
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
70 cache_ok = True
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
71
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
72 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
73 if value is None:
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
74 return None
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
75 return pickle.dumps(value, 0)
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
76
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
77 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
78 if value is None:
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
79 return None
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
80 # 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
81 # and/or SQLite dynamic typing)
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
82 try:
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
83 value = value.encode()
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
84 except AttributeError:
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
85 pass
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
86 # "utf-8" encoding is needed to handle Python 2 pickled data
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
87 return pickle.loads(value, encoding="utf-8")
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
88
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 class Json(TypeDecorator):
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
91 """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
92 # 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
93 impl = Text
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
94 cache_ok = True
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
95
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
96 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
97 if value is None:
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
98 return None
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
99 return json.dumps(value)
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
100
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
101 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
102 if value is None:
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
103 return None
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
104 return json.loads(value)
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
105
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
106
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
107 class JsonDefaultDict(Json):
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
108 """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
109
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
110 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
111 if value is None:
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
112 return {}
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
113 return json.loads(value)
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
3593
cb8d0e8b917f core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents: 3583
diff changeset
116 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
117 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
118 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
119
cb8d0e8b917f core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents: 3583
diff changeset
120 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
121 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
122 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
123 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
124
cb8d0e8b917f core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents: 3583
diff changeset
125 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
126 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
127 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
128 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
129
cb8d0e8b917f core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents: 3583
diff changeset
130
3537
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
131 class JID(TypeDecorator):
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
132 """Store twisted JID in text fields"""
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
133 impl = Text
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
134 cache_ok = True
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_bind_param(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 None
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
139 return value.full()
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 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
142 if value is None:
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
143 return None
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
144 return jid.JID(value)
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
145
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
146
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
147 class Profile(Base):
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
148 __tablename__ = "profiles"
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
149
3581
84ea57a8d6b3 memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents: 3537
diff changeset
150 id = Column(
84ea57a8d6b3 memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents: 3537
diff changeset
151 Integer,
84ea57a8d6b3 memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents: 3537
diff changeset
152 primary_key=True,
84ea57a8d6b3 memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents: 3537
diff changeset
153 nullable=True,
84ea57a8d6b3 memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents: 3537
diff changeset
154 # settings autoincrement would have negative performance impact
84ea57a8d6b3 memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents: 3537
diff changeset
155 # cf. https://sqlite.org/autoinc.html
84ea57a8d6b3 memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents: 3537
diff changeset
156 autoincrement=False
84ea57a8d6b3 memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents: 3537
diff changeset
157 )
3537
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
158 name = Column(Text, unique=True)
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
159
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
160 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
161 private_data = relationship(
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
162 "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
163 )
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
164 private_bin_data = relationship(
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
165 "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
166 )
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
167
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
168
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
169 class Component(Base):
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
170 __tablename__ = "components"
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
171
3581
84ea57a8d6b3 memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents: 3537
diff changeset
172 profile_id = Column(
84ea57a8d6b3 memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents: 3537
diff changeset
173 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
174 nullable=True,
84ea57a8d6b3 memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents: 3537
diff changeset
175 primary_key=True
84ea57a8d6b3 memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents: 3537
diff changeset
176 )
3537
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
177 entry_point = Column(Text, nullable=False)
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
178 profile = relationship("Profile")
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
179
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
180
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
181 class History(Base):
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
182 __tablename__ = "history"
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
183 __table_args__ = (
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
184 UniqueConstraint("profile_id", "stanza_id", "source", "dest"),
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
185 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
186 Index(
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
187 "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
188 )
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
3583
16ade4ad63f3 core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents: 3581
diff changeset
191 uid = Column(Text, primary_key=True)
3537
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
192 stanza_id = Column(Text)
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
193 update_uid = Column(Text)
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
194 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
195 source = Column(Text)
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
196 dest = Column(Text)
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
197 source_res = Column(Text)
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
198 dest_res = Column(Text)
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
199 timestamp = Column(Float, nullable=False)
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
200 received_timestamp = Column(Float)
3583
16ade4ad63f3 core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents: 3581
diff changeset
201 type = Column(
16ade4ad63f3 core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents: 3581
diff changeset
202 Enum(
16ade4ad63f3 core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents: 3581
diff changeset
203 "chat",
16ade4ad63f3 core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents: 3581
diff changeset
204 "error",
16ade4ad63f3 core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents: 3581
diff changeset
205 "groupchat",
16ade4ad63f3 core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents: 3581
diff changeset
206 "headline",
16ade4ad63f3 core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents: 3581
diff changeset
207 "normal",
16ade4ad63f3 core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents: 3581
diff changeset
208 # 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
209 # in a MUC
16ade4ad63f3 core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents: 3581
diff changeset
210 "info",
16ade4ad63f3 core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents: 3581
diff changeset
211 name="message_type",
16ade4ad63f3 core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents: 3581
diff changeset
212 create_constraint=True,
16ade4ad63f3 core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents: 3581
diff changeset
213 ),
16ade4ad63f3 core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents: 3581
diff changeset
214 nullable=False,
16ade4ad63f3 core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents: 3581
diff changeset
215 )
3537
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
216 extra = Column(LegacyPickle)
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
217
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
218 profile = relationship("Profile")
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
219 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
220 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
221 thread = relationship(
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
222 "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
223 )
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
224
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
225 def __init__(self, *args, **kwargs):
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
226 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
227 if source_jid is not None:
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
228 kwargs["source"] = source_jid.userhost()
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
229 kwargs["source_res"] = source_jid.resource
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
230 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
231 if dest_jid is not None:
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
232 kwargs["dest"] = dest_jid.userhost()
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
233 kwargs["dest_res"] = dest_jid.resource
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
234 super().__init__(*args, **kwargs)
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
235
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
236 @property
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
237 def source_jid(self) -> jid.JID:
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
238 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
239
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
240 @source_jid.setter
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
241 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
242 self.source = source_jid.userhost
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
243 self.source_res = source_jid.resource
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
244
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
245 @property
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
246 def dest_jid(self):
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
247 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
248
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
249 @dest_jid.setter
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
250 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
251 self.dest = dest_jid.userhost
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
252 self.dest_res = dest_jid.resource
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
253
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
254 def __repr__(self):
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
255 dt = datetime.fromtimestamp(self.timestamp)
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
256 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
257
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
258 def serialise(self):
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
259 extra = self.extra
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
260 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
261 extra["stanza_id"] = self.stanza_id
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
262 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
263 extra["update_uid"] = self.update_uid
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
264 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
265 extra["received_timestamp"] = self.received_timestamp
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
266 if self.thread is not None:
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
267 extra["thread"] = self.thread.thread_id
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
268 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
269 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
270
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
271
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
272 return {
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
273 "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
274 else self.source,
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
275 "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
276 "uid": self.uid,
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
277 "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
278 "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
279 "type": self.type,
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
280 "extra": extra,
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
281 "timestamp": self.timestamp,
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
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
284 def as_tuple(self):
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
285 d = self.serialise()
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
286 return (
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
287 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
288 d['type'], d['extra']
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
289 )
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
290
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
291 @staticmethod
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
292 def debug_collection(history_collection):
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
293 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
294 history.debug_msg(idx)
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
295
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
296 def debug_msg(self, idx=None):
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
297 """Print messages"""
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
298 dt = datetime.fromtimestamp(self.timestamp)
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
299 if idx is not None:
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
300 dt = f"({idx}) {dt}"
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
301 parts = []
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
302 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
303 for message in self.messages:
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
304 if message.language:
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
305 parts.append(f"[{message.language}] ")
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
306 parts.append(f"{message.message}\n")
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
307 print("".join(parts))
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
308
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
309
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
310 class Message(Base):
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
311 __tablename__ = "message"
3581
84ea57a8d6b3 memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents: 3537
diff changeset
312 __table_args__ = (
84ea57a8d6b3 memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents: 3537
diff changeset
313 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
314 )
3537
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
315
3581
84ea57a8d6b3 memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents: 3537
diff changeset
316 id = Column(
84ea57a8d6b3 memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents: 3537
diff changeset
317 Integer,
84ea57a8d6b3 memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents: 3537
diff changeset
318 primary_key=True,
84ea57a8d6b3 memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents: 3537
diff changeset
319 # cf. note for Profile.id
84ea57a8d6b3 memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents: 3537
diff changeset
320 autoincrement=False
84ea57a8d6b3 memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents: 3537
diff changeset
321 )
84ea57a8d6b3 memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents: 3537
diff changeset
322 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
323 message = Column(Text)
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
324 language = Column(Text)
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
325
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
326 def __repr__(self):
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
327 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
328 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
329 content = f"{lang_str}{msg}"
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
330 return f"Message<{content}>"
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
331
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
332
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
333 class Subject(Base):
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
334 __tablename__ = "subject"
3581
84ea57a8d6b3 memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents: 3537
diff changeset
335 __table_args__ = (
84ea57a8d6b3 memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents: 3537
diff changeset
336 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
337 )
3537
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
338
3581
84ea57a8d6b3 memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents: 3537
diff changeset
339 id = Column(
84ea57a8d6b3 memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents: 3537
diff changeset
340 Integer,
84ea57a8d6b3 memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents: 3537
diff changeset
341 primary_key=True,
84ea57a8d6b3 memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents: 3537
diff changeset
342 # cf. note for Profile.id
84ea57a8d6b3 memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents: 3537
diff changeset
343 autoincrement=False,
84ea57a8d6b3 memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents: 3537
diff changeset
344 )
84ea57a8d6b3 memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents: 3537
diff changeset
345 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
346 subject = Column(Text)
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
347 language = Column(Text)
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
348
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
349 def __repr__(self):
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
350 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
351 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
352 content = f"{lang_str}{msg}"
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
353 return f"Subject<{content}>"
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
354
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
355
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
356 class Thread(Base):
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
357 __tablename__ = "thread"
3581
84ea57a8d6b3 memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents: 3537
diff changeset
358 __table_args__ = (
84ea57a8d6b3 memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents: 3537
diff changeset
359 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
360 )
3537
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
361
3581
84ea57a8d6b3 memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents: 3537
diff changeset
362 id = Column(
84ea57a8d6b3 memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents: 3537
diff changeset
363 Integer,
84ea57a8d6b3 memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents: 3537
diff changeset
364 primary_key=True,
84ea57a8d6b3 memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents: 3537
diff changeset
365 # cf. note for Profile.id
84ea57a8d6b3 memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents: 3537
diff changeset
366 autoincrement=False,
84ea57a8d6b3 memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents: 3537
diff changeset
367 )
84ea57a8d6b3 memory (storage): adjustements to SQLAlchemy mapping to match current state of database
Goffi <goffi@goffi.org>
parents: 3537
diff changeset
368 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
369 thread_id = Column(Text)
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
370 parent_id = Column(Text)
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
371
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
372 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
373
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
374 def __repr__(self):
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
375 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
376
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
377
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
378 class ParamGen(Base):
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
379 __tablename__ = "param_gen"
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
380
3583
16ade4ad63f3 core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents: 3581
diff changeset
381 category = Column(Text, primary_key=True)
16ade4ad63f3 core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents: 3581
diff changeset
382 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
383 value = Column(Text)
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
384
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
385
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
386 class ParamInd(Base):
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
387 __tablename__ = "param_ind"
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
388
3583
16ade4ad63f3 core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents: 3581
diff changeset
389 category = Column(Text, primary_key=True)
16ade4ad63f3 core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents: 3581
diff changeset
390 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
391 profile_id = Column(
3583
16ade4ad63f3 core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents: 3581
diff changeset
392 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
393 )
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
394 value = Column(Text)
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
395
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
396 profile = relationship("Profile", back_populates="params")
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
397
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
398
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
399 class PrivateGen(Base):
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
400 __tablename__ = "private_gen"
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
401
3583
16ade4ad63f3 core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents: 3581
diff changeset
402 namespace = Column(Text, primary_key=True)
16ade4ad63f3 core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents: 3581
diff changeset
403 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
404 value = Column(Text)
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
405
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
406
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
407 class PrivateInd(Base):
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
408 __tablename__ = "private_ind"
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
409
3583
16ade4ad63f3 core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents: 3581
diff changeset
410 namespace = Column(Text, primary_key=True)
16ade4ad63f3 core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents: 3581
diff changeset
411 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
412 profile_id = Column(
3583
16ade4ad63f3 core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents: 3581
diff changeset
413 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
414 )
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
415 value = Column(Text)
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
416
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
417 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
418
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
419
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
420 class PrivateGenBin(Base):
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
421 __tablename__ = "private_gen_bin"
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
422
3583
16ade4ad63f3 core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents: 3581
diff changeset
423 namespace = Column(Text, primary_key=True)
16ade4ad63f3 core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents: 3581
diff changeset
424 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
425 value = Column(LegacyPickle)
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
426
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
427
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
428 class PrivateIndBin(Base):
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
429 __tablename__ = "private_ind_bin"
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
430
3583
16ade4ad63f3 core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents: 3581
diff changeset
431 namespace = Column(Text, primary_key=True)
16ade4ad63f3 core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents: 3581
diff changeset
432 key = Column(Text, primary_key=True)
3537
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
433 profile_id = Column(
3583
16ade4ad63f3 core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents: 3581
diff changeset
434 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
435 )
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
436 value = Column(LegacyPickle)
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
437
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
438 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
439
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
440
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
441 class File(Base):
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
442 __tablename__ = "files"
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
443 __table_args__ = (
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
444 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
445 Index(
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
446 "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
447 "profile_id",
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
448 "owner",
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
449 "media_type",
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
450 "media_subtype"
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 )
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
453
3583
16ade4ad63f3 core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents: 3581
diff changeset
454 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
455 public_id = Column(Text, unique=True)
3583
16ade4ad63f3 core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents: 3581
diff changeset
456 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
457 parent = Column(Text, nullable=False)
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
458 type = Column(
3583
16ade4ad63f3 core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents: 3581
diff changeset
459 Enum(
16ade4ad63f3 core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents: 3581
diff changeset
460 "file", "directory",
16ade4ad63f3 core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents: 3581
diff changeset
461 name="file_type",
16ade4ad63f3 core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents: 3581
diff changeset
462 create_constraint=True
16ade4ad63f3 core (memory/sqla_mapping): fix some technical debt:
Goffi <goffi@goffi.org>
parents: 3581
diff changeset
463 ),
3537
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
464 nullable=False,
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
465 server_default="file",
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
466 )
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
467 file_hash = Column(Text)
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
468 hash_algo = Column(Text)
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
469 name = Column(Text, nullable=False)
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
470 size = Column(Integer)
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
471 namespace = Column(Text)
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
472 media_type = Column(Text)
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
473 media_subtype = Column(Text)
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
474 created = Column(Float, nullable=False)
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
475 modified = Column(Float)
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
476 owner = Column(JID)
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
477 access = Column(JsonDefaultDict)
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
478 extra = Column(JsonDefaultDict)
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
479 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
480
f9a5b810f14d core (memory/storage): backend storage is now based on SQLAlchemy
Goffi <goffi@goffi.org>
parents:
diff changeset
481 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
482
cb8d0e8b917f core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents: 3583
diff changeset
483
cb8d0e8b917f core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents: 3583
diff changeset
484 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
485 __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
486 __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
487 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
488 )
cb8d0e8b917f core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents: 3583
diff changeset
489
cb8d0e8b917f core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents: 3583
diff changeset
490 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
491 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
492 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
493 )
cb8d0e8b917f core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents: 3583
diff changeset
494 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
495 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
496 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
497 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
498 )
cb8d0e8b917f core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents: 3583
diff changeset
499 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
500 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
501 Enum(
cb8d0e8b917f core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents: 3583
diff changeset
502 SyncState,
cb8d0e8b917f core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents: 3583
diff changeset
503 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
504 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
505 ),
cb8d0e8b917f core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents: 3583
diff changeset
506 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
507 )
cb8d0e8b917f core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents: 3583
diff changeset
508 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
509 Float,
cb8d0e8b917f core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents: 3583
diff changeset
510 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
511 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
512 )
cb8d0e8b917f core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents: 3583
diff changeset
513 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
514 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
515 )
cb8d0e8b917f core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents: 3583
diff changeset
516 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
517 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
518 )
cb8d0e8b917f core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents: 3583
diff changeset
519 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
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 items = relationship("PubsubItem", back_populates="node", passive_deletes=True)
cb8d0e8b917f core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents: 3583
diff changeset
522
cb8d0e8b917f core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents: 3583
diff changeset
523 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
524 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
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 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
528 __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
529 __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
530 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
531 )
cb8d0e8b917f core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents: 3583
diff changeset
532 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
533 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
534 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
535 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
536 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
537 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
538 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
539
cb8d0e8b917f core (memory/sqla_mapping): mapping for PubsubNode and PubsubItem (will be used for caching)
Goffi <goffi@goffi.org>
parents: 3583
diff changeset
540 node = relationship("PubsubNode", back_populates="items")