Mercurial > libervia-backend
comparison sat/memory/sqla_mapping.py @ 3581:84ea57a8d6b3
memory (storage): adjustements to SQLAlchemy mapping to match current state of database
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 25 Jun 2021 10:17:34 +0200 |
parents | f9a5b810f14d |
children | 16ade4ad63f3 |
comparison
equal
deleted
inserted
replaced
3580:8dd5e1bac9c3 | 3581:84ea57a8d6b3 |
---|---|
104 | 104 |
105 | 105 |
106 class Profile(Base): | 106 class Profile(Base): |
107 __tablename__ = "profiles" | 107 __tablename__ = "profiles" |
108 | 108 |
109 id = Column(Integer, primary_key=True) | 109 id = Column( |
110 Integer, | |
111 primary_key=True, | |
112 nullable=True, | |
113 # settings autoincrement would have negative performance impact | |
114 # cf. https://sqlite.org/autoinc.html | |
115 autoincrement=False | |
116 ) | |
110 name = Column(Text, unique=True) | 117 name = Column(Text, unique=True) |
111 | 118 |
112 params = relationship("ParamInd", back_populates="profile", passive_deletes=True) | 119 params = relationship("ParamInd", back_populates="profile", passive_deletes=True) |
113 private_data = relationship( | 120 private_data = relationship( |
114 "PrivateInd", back_populates="profile", passive_deletes=True | 121 "PrivateInd", back_populates="profile", passive_deletes=True |
119 | 126 |
120 | 127 |
121 class Component(Base): | 128 class Component(Base): |
122 __tablename__ = "components" | 129 __tablename__ = "components" |
123 | 130 |
124 profile_id = Column(ForeignKey("profiles.id", ondelete="CASCADE"), primary_key=True) | 131 profile_id = Column( |
132 ForeignKey("profiles.id", ondelete="CASCADE"), | |
133 nullable=True, | |
134 primary_key=True | |
135 ) | |
125 entry_point = Column(Text, nullable=False) | 136 entry_point = Column(Text, nullable=False) |
126 profile = relationship("Profile") | 137 profile = relationship("Profile") |
127 | 138 |
128 | 139 |
129 class MessageType(Base): | 140 class MessageType(Base): |
130 __tablename__ = "message_types" | 141 __tablename__ = "message_types" |
131 | 142 |
132 type = Column(Text, primary_key=True) | 143 type = Column(Text, primary_key=True, nullable=True) |
133 | 144 |
134 | 145 |
135 class History(Base): | 146 class History(Base): |
136 __tablename__ = "history" | 147 __tablename__ = "history" |
137 __table_args__ = ( | 148 __table_args__ = ( |
140 Index( | 151 Index( |
141 "history__profile_id_received_timestamp", "profile_id", "received_timestamp" | 152 "history__profile_id_received_timestamp", "profile_id", "received_timestamp" |
142 ) | 153 ) |
143 ) | 154 ) |
144 | 155 |
145 uid = Column(Text, primary_key=True) | 156 uid = Column(Text, primary_key=True, nullable=True) |
146 stanza_id = Column(Text) | 157 stanza_id = Column(Text) |
147 update_uid = Column(Text) | 158 update_uid = Column(Text) |
148 profile_id = Column(ForeignKey("profiles.id", ondelete="CASCADE")) | 159 profile_id = Column(ForeignKey("profiles.id", ondelete="CASCADE")) |
149 source = Column(Text) | 160 source = Column(Text) |
150 dest = Column(Text) | 161 dest = Column(Text) |
248 print("".join(parts)) | 259 print("".join(parts)) |
249 | 260 |
250 | 261 |
251 class Message(Base): | 262 class Message(Base): |
252 __tablename__ = "message" | 263 __tablename__ = "message" |
253 | 264 __table_args__ = ( |
254 id = Column(Integer, primary_key=True) | 265 Index("message__history_uid", "history_uid"), |
255 history_uid = Column(ForeignKey("history.uid", ondelete="CASCADE"), index=True) | 266 ) |
267 | |
268 id = Column( | |
269 Integer, | |
270 primary_key=True, | |
271 nullable=True, | |
272 # cf. note for Profile.id | |
273 autoincrement=False | |
274 ) | |
275 history_uid = Column(ForeignKey("history.uid", ondelete="CASCADE")) | |
256 message = Column(Text) | 276 message = Column(Text) |
257 language = Column(Text) | 277 language = Column(Text) |
258 | 278 |
259 def __repr__(self): | 279 def __repr__(self): |
260 lang_str = f"[{self.language}]" if self.language else "" | 280 lang_str = f"[{self.language}]" if self.language else "" |
263 return f"Message<{content}>" | 283 return f"Message<{content}>" |
264 | 284 |
265 | 285 |
266 class Subject(Base): | 286 class Subject(Base): |
267 __tablename__ = "subject" | 287 __tablename__ = "subject" |
268 | 288 __table_args__ = ( |
269 id = Column(Integer, primary_key=True) | 289 Index("subject__history_uid", "history_uid"), |
270 history_uid = Column(ForeignKey("history.uid", ondelete="CASCADE"), index=True) | 290 ) |
291 | |
292 id = Column( | |
293 Integer, | |
294 primary_key=True, | |
295 nullable=True, | |
296 # cf. note for Profile.id | |
297 autoincrement=False, | |
298 ) | |
299 history_uid = Column(ForeignKey("history.uid", ondelete="CASCADE")) | |
271 subject = Column(Text) | 300 subject = Column(Text) |
272 language = Column(Text) | 301 language = Column(Text) |
273 | 302 |
274 def __repr__(self): | 303 def __repr__(self): |
275 lang_str = f"[{self.language}]" if self.language else "" | 304 lang_str = f"[{self.language}]" if self.language else "" |
278 return f"Subject<{content}>" | 307 return f"Subject<{content}>" |
279 | 308 |
280 | 309 |
281 class Thread(Base): | 310 class Thread(Base): |
282 __tablename__ = "thread" | 311 __tablename__ = "thread" |
283 | 312 __table_args__ = ( |
284 id = Column(Integer, primary_key=True) | 313 Index("thread__history_uid", "history_uid"), |
285 history_uid = Column(ForeignKey("history.uid", ondelete="CASCADE"), index=True) | 314 ) |
315 | |
316 id = Column( | |
317 Integer, | |
318 primary_key=True, | |
319 nullable=True, | |
320 # cf. note for Profile.id | |
321 autoincrement=False, | |
322 ) | |
323 history_uid = Column(ForeignKey("history.uid", ondelete="CASCADE")) | |
286 thread_id = Column(Text) | 324 thread_id = Column(Text) |
287 parent_id = Column(Text) | 325 parent_id = Column(Text) |
288 | 326 |
289 history = relationship("History", uselist=False, back_populates="thread") | 327 history = relationship("History", uselist=False, back_populates="thread") |
290 | 328 |
293 | 331 |
294 | 332 |
295 class ParamGen(Base): | 333 class ParamGen(Base): |
296 __tablename__ = "param_gen" | 334 __tablename__ = "param_gen" |
297 | 335 |
298 category = Column(Text, primary_key=True, nullable=False) | 336 category = Column(Text, primary_key=True, nullable=True) |
299 name = Column(Text, primary_key=True, nullable=False) | 337 name = Column(Text, primary_key=True, nullable=True) |
300 value = Column(Text) | 338 value = Column(Text) |
301 | 339 |
302 | 340 |
303 class ParamInd(Base): | 341 class ParamInd(Base): |
304 __tablename__ = "param_ind" | 342 __tablename__ = "param_ind" |
305 | 343 |
306 category = Column(Text, primary_key=True, nullable=False) | 344 category = Column(Text, primary_key=True, nullable=True) |
307 name = Column(Text, primary_key=True, nullable=False) | 345 name = Column(Text, primary_key=True, nullable=True) |
308 profile_id = Column( | 346 profile_id = Column( |
309 ForeignKey("profiles.id", ondelete="CASCADE"), primary_key=True, nullable=False | 347 ForeignKey("profiles.id", ondelete="CASCADE"), primary_key=True, nullable=True |
310 ) | 348 ) |
311 value = Column(Text) | 349 value = Column(Text) |
312 | 350 |
313 profile = relationship("Profile", back_populates="params") | 351 profile = relationship("Profile", back_populates="params") |
314 | 352 |
315 | 353 |
316 class PrivateGen(Base): | 354 class PrivateGen(Base): |
317 __tablename__ = "private_gen" | 355 __tablename__ = "private_gen" |
318 | 356 |
319 namespace = Column(Text, primary_key=True, nullable=False) | 357 namespace = Column(Text, primary_key=True, nullable=True) |
320 key = Column(Text, primary_key=True, nullable=False) | 358 key = Column(Text, primary_key=True, nullable=True) |
321 value = Column(Text) | 359 value = Column(Text) |
322 | 360 |
323 | 361 |
324 class PrivateInd(Base): | 362 class PrivateInd(Base): |
325 __tablename__ = "private_ind" | 363 __tablename__ = "private_ind" |
326 | 364 |
327 namespace = Column(Text, primary_key=True, nullable=False) | 365 namespace = Column(Text, primary_key=True, nullable=True) |
328 key = Column(Text, primary_key=True, nullable=False) | 366 key = Column(Text, primary_key=True, nullable=True) |
329 profile_id = Column( | 367 profile_id = Column( |
330 ForeignKey("profiles.id", ondelete="CASCADE"), primary_key=True, nullable=False | 368 ForeignKey("profiles.id", ondelete="CASCADE"), primary_key=True, nullable=True |
331 ) | 369 ) |
332 value = Column(Text) | 370 value = Column(Text) |
333 | 371 |
334 profile = relationship("Profile", back_populates="private_data") | 372 profile = relationship("Profile", back_populates="private_data") |
335 | 373 |
336 | 374 |
337 class PrivateGenBin(Base): | 375 class PrivateGenBin(Base): |
338 __tablename__ = "private_gen_bin" | 376 __tablename__ = "private_gen_bin" |
339 | 377 |
340 namespace = Column(Text, primary_key=True, nullable=False) | 378 namespace = Column(Text, primary_key=True, nullable=True) |
341 key = Column(Text, primary_key=True, nullable=False) | 379 key = Column(Text, primary_key=True, nullable=True) |
342 value = Column(LegacyPickle) | 380 value = Column(LegacyPickle) |
343 | 381 |
344 | 382 |
345 class PrivateIndBin(Base): | 383 class PrivateIndBin(Base): |
346 __tablename__ = "private_ind_bin" | 384 __tablename__ = "private_ind_bin" |
347 | 385 |
348 namespace = Column(Text, primary_key=True, nullable=False) | 386 namespace = Column(Text, primary_key=True, nullable=True) |
349 key = Column(Text, primary_key=True, nullable=False) | 387 key = Column(Text, primary_key=True, nullable=True) |
350 profile_id = Column( | 388 profile_id = Column( |
351 ForeignKey("profiles.id", ondelete="CASCADE"), primary_key=True, nullable=False | 389 ForeignKey("profiles.id", ondelete="CASCADE"), primary_key=True, nullable=True |
352 ) | 390 ) |
353 value = Column(LegacyPickle) | 391 value = Column(LegacyPickle) |
354 | 392 |
355 profile = relationship("Profile", back_populates="private_bin_data") | 393 profile = relationship("Profile", back_populates="private_bin_data") |
356 | 394 |