Mercurial > libervia-backend
view libervia/backend/memory/migration/versions/79e5f3313fa4_create_table_for_pubsub_subscriptions.py @ 4212:5f2d496c633f
core: get rid of `pickle`:
Use of `pickle` to serialise data was a technical legacy that was causing trouble to store
in database, to update (if a class was serialised, a change could break update), and to
security (pickle can lead to code execution).
This patch remove all use of Pickle in favour in JSON, notably:
- for caching data, a Pydantic model is now used instead
- for SQLAlchemy model, the LegacyPickle is replaced by JSON serialisation
- in XEP-0373 a class `PublicKeyMetadata` was serialised. New method `from_dict` and
`to_dict` method have been implemented to do serialisation.
- new methods to (de)serialise data can now be specified with Identity data types. It is
notably used to (de)serialise `path` of avatars.
A migration script has been created to convert data (for upgrade or downgrade), with
special care for XEP-0373 case. Depending of size of database, this migration script can
be long to run.
rel 443
author | Goffi <goffi@goffi.org> |
---|---|
date | Fri, 23 Feb 2024 13:31:04 +0100 |
parents | 4b842c1fb686 |
children | 0d7bb4df2343 |
line wrap: on
line source
"""create table for pubsub subscriptions Revision ID: 79e5f3313fa4 Revises: 129ac51807e4 Create Date: 2022-03-14 17:15:00.689871 """ from alembic import op import sqlalchemy as sa from libervia.backend.memory.sqla_mapping import JID # revision identifiers, used by Alembic. revision = '79e5f3313fa4' down_revision = '129ac51807e4' branch_labels = None depends_on = None def upgrade(): op.create_table('pubsub_subs', sa.Column('id', sa.Integer(), nullable=False), sa.Column('node_id', sa.Integer(), nullable=False), sa.Column('subscriber', JID(), nullable=True), sa.Column('state', sa.Enum('SUBSCRIBED', 'PENDING', name='state'), nullable=True), sa.ForeignKeyConstraint(['node_id'], ['pubsub_nodes.id'], name=op.f('fk_pubsub_subs_node_id_pubsub_nodes'), ondelete='CASCADE'), sa.PrimaryKeyConstraint('id', name=op.f('pk_pubsub_subs')), sa.UniqueConstraint('node_id', 'subscriber', name=op.f('uq_pubsub_subs_node_id')) ) def downgrade(): op.drop_table('pubsub_subs')