Mercurial > libervia-backend
comparison 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 |
comparison
equal
deleted
inserted
replaced
4129:51744ad00a42 | 4130:02f0adc745c6 |
---|---|
1 """create table for notifications | |
2 | |
3 Revision ID: 2ab01aa1f686 | |
4 Revises: 4b002773cf92 | |
5 Create Date: 2023-10-16 12:11:43.507295 | |
6 | |
7 """ | |
8 from alembic import op | |
9 import sqlalchemy as sa | |
10 | |
11 | |
12 # revision identifiers, used by Alembic. | |
13 revision = '2ab01aa1f686' | |
14 down_revision = '4b002773cf92' | |
15 branch_labels = None | |
16 depends_on = None | |
17 | |
18 | |
19 def upgrade(): | |
20 op.create_table('notifications', | |
21 sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), | |
22 sa.Column('timestamp', sa.Float(), nullable=False), | |
23 sa.Column('expire_at', sa.Float(), nullable=True), | |
24 sa.Column('profile_id', sa.Integer(), nullable=True), | |
25 sa.Column('type', sa.Enum('chat', 'blog', 'calendar', 'file', 'call', 'service', 'other', name='notificationtype'), nullable=False), | |
26 sa.Column('title', sa.Text(), nullable=True), | |
27 sa.Column('body_plain', sa.Text(), nullable=False), | |
28 sa.Column('body_rich', sa.Text(), nullable=True), | |
29 sa.Column('requires_action', sa.Boolean(), nullable=True), | |
30 sa.Column('priority', sa.Integer(), nullable=True), | |
31 sa.Column('extra_data', sa.JSON(), nullable=True), | |
32 sa.Column('status', sa.Enum('new', 'read', name='notificationstatus'), nullable=True), | |
33 sa.ForeignKeyConstraint(['profile_id'], ['profiles.id'], name=op.f('fk_notifications_profile_id_profiles'), ondelete='CASCADE'), | |
34 sa.PrimaryKeyConstraint('id', name=op.f('pk_notifications')) | |
35 ) | |
36 with op.batch_alter_table('notifications', schema=None) as batch_op: | |
37 batch_op.create_index(batch_op.f('ix_notifications_profile_id'), ['profile_id'], unique=False) | |
38 batch_op.create_index('notifications_profile_id_status', ['profile_id', 'status'], unique=False) | |
39 | |
40 | |
41 def downgrade(): | |
42 with op.batch_alter_table('notifications', schema=None) as batch_op: | |
43 batch_op.drop_index('notifications_profile_id_status') | |
44 batch_op.drop_index(batch_op.f('ix_notifications_profile_id')) | |
45 | |
46 op.drop_table('notifications') |