diff libervia/backend/memory/migration/versions/2ab01aa1f686_create_table_for_notifications.py @ 4130:02f0adc745c6

core: notifications implementation, first draft: add a new table for notifications, and methods/bridge methods to manipulate them.
author Goffi <goffi@goffi.org>
date Mon, 16 Oct 2023 17:29:31 +0200
parents
children 0d7bb4df2343
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libervia/backend/memory/migration/versions/2ab01aa1f686_create_table_for_notifications.py	Mon Oct 16 17:29:31 2023 +0200
@@ -0,0 +1,46 @@
+"""create table for notifications
+
+Revision ID: 2ab01aa1f686
+Revises: 4b002773cf92
+Create Date: 2023-10-16 12:11:43.507295
+
+"""
+from alembic import op
+import sqlalchemy as sa
+
+
+# revision identifiers, used by Alembic.
+revision = '2ab01aa1f686'
+down_revision = '4b002773cf92'
+branch_labels = None
+depends_on = None
+
+
+def upgrade():
+    op.create_table('notifications',
+    sa.Column('id', sa.Integer(), autoincrement=True, nullable=False),
+    sa.Column('timestamp', sa.Float(), nullable=False),
+    sa.Column('expire_at', sa.Float(), nullable=True),
+    sa.Column('profile_id', sa.Integer(), nullable=True),
+    sa.Column('type', sa.Enum('chat', 'blog', 'calendar', 'file', 'call', 'service', 'other', name='notificationtype'), nullable=False),
+    sa.Column('title', sa.Text(), nullable=True),
+    sa.Column('body_plain', sa.Text(), nullable=False),
+    sa.Column('body_rich', sa.Text(), nullable=True),
+    sa.Column('requires_action', sa.Boolean(), nullable=True),
+    sa.Column('priority', sa.Integer(), nullable=True),
+    sa.Column('extra_data', sa.JSON(), nullable=True),
+    sa.Column('status', sa.Enum('new', 'read', name='notificationstatus'), nullable=True),
+    sa.ForeignKeyConstraint(['profile_id'], ['profiles.id'], name=op.f('fk_notifications_profile_id_profiles'), ondelete='CASCADE'),
+    sa.PrimaryKeyConstraint('id', name=op.f('pk_notifications'))
+    )
+    with op.batch_alter_table('notifications', schema=None) as batch_op:
+        batch_op.create_index(batch_op.f('ix_notifications_profile_id'), ['profile_id'], unique=False)
+        batch_op.create_index('notifications_profile_id_status', ['profile_id', 'status'], unique=False)
+
+
+def downgrade():
+    with op.batch_alter_table('notifications', schema=None) as batch_op:
+        batch_op.drop_index('notifications_profile_id_status')
+        batch_op.drop_index(batch_op.f('ix_notifications_profile_id'))
+
+    op.drop_table('notifications')