Mercurial > libervia-backend
comparison libervia/backend/memory/migration/versions/2ab01aa1f686_create_table_for_notifications.py @ 4270:0d7bb4df2343
Reformatted code base using black.
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 19 Jun 2024 18:44:57 +0200 |
parents | 02f0adc745c6 |
children |
comparison
equal
deleted
inserted
replaced
4269:64a85ce8be70 | 4270:0d7bb4df2343 |
---|---|
3 Revision ID: 2ab01aa1f686 | 3 Revision ID: 2ab01aa1f686 |
4 Revises: 4b002773cf92 | 4 Revises: 4b002773cf92 |
5 Create Date: 2023-10-16 12:11:43.507295 | 5 Create Date: 2023-10-16 12:11:43.507295 |
6 | 6 |
7 """ | 7 """ |
8 | |
8 from alembic import op | 9 from alembic import op |
9 import sqlalchemy as sa | 10 import sqlalchemy as sa |
10 | 11 |
11 | 12 |
12 # revision identifiers, used by Alembic. | 13 # revision identifiers, used by Alembic. |
13 revision = '2ab01aa1f686' | 14 revision = "2ab01aa1f686" |
14 down_revision = '4b002773cf92' | 15 down_revision = "4b002773cf92" |
15 branch_labels = None | 16 branch_labels = None |
16 depends_on = None | 17 depends_on = None |
17 | 18 |
18 | 19 |
19 def upgrade(): | 20 def upgrade(): |
20 op.create_table('notifications', | 21 op.create_table( |
21 sa.Column('id', sa.Integer(), autoincrement=True, nullable=False), | 22 "notifications", |
22 sa.Column('timestamp', sa.Float(), nullable=False), | 23 sa.Column("id", sa.Integer(), autoincrement=True, nullable=False), |
23 sa.Column('expire_at', sa.Float(), nullable=True), | 24 sa.Column("timestamp", sa.Float(), nullable=False), |
24 sa.Column('profile_id', sa.Integer(), nullable=True), | 25 sa.Column("expire_at", sa.Float(), nullable=True), |
25 sa.Column('type', sa.Enum('chat', 'blog', 'calendar', 'file', 'call', 'service', 'other', name='notificationtype'), nullable=False), | 26 sa.Column("profile_id", sa.Integer(), nullable=True), |
26 sa.Column('title', sa.Text(), nullable=True), | 27 sa.Column( |
27 sa.Column('body_plain', sa.Text(), nullable=False), | 28 "type", |
28 sa.Column('body_rich', sa.Text(), nullable=True), | 29 sa.Enum( |
29 sa.Column('requires_action', sa.Boolean(), nullable=True), | 30 "chat", |
30 sa.Column('priority', sa.Integer(), nullable=True), | 31 "blog", |
31 sa.Column('extra_data', sa.JSON(), nullable=True), | 32 "calendar", |
32 sa.Column('status', sa.Enum('new', 'read', name='notificationstatus'), nullable=True), | 33 "file", |
33 sa.ForeignKeyConstraint(['profile_id'], ['profiles.id'], name=op.f('fk_notifications_profile_id_profiles'), ondelete='CASCADE'), | 34 "call", |
34 sa.PrimaryKeyConstraint('id', name=op.f('pk_notifications')) | 35 "service", |
36 "other", | |
37 name="notificationtype", | |
38 ), | |
39 nullable=False, | |
40 ), | |
41 sa.Column("title", sa.Text(), nullable=True), | |
42 sa.Column("body_plain", sa.Text(), nullable=False), | |
43 sa.Column("body_rich", sa.Text(), nullable=True), | |
44 sa.Column("requires_action", sa.Boolean(), nullable=True), | |
45 sa.Column("priority", sa.Integer(), nullable=True), | |
46 sa.Column("extra_data", sa.JSON(), nullable=True), | |
47 sa.Column( | |
48 "status", sa.Enum("new", "read", name="notificationstatus"), nullable=True | |
49 ), | |
50 sa.ForeignKeyConstraint( | |
51 ["profile_id"], | |
52 ["profiles.id"], | |
53 name=op.f("fk_notifications_profile_id_profiles"), | |
54 ondelete="CASCADE", | |
55 ), | |
56 sa.PrimaryKeyConstraint("id", name=op.f("pk_notifications")), | |
35 ) | 57 ) |
36 with op.batch_alter_table('notifications', schema=None) as batch_op: | 58 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) | 59 batch_op.create_index( |
38 batch_op.create_index('notifications_profile_id_status', ['profile_id', 'status'], unique=False) | 60 batch_op.f("ix_notifications_profile_id"), ["profile_id"], unique=False |
61 ) | |
62 batch_op.create_index( | |
63 "notifications_profile_id_status", ["profile_id", "status"], unique=False | |
64 ) | |
39 | 65 |
40 | 66 |
41 def downgrade(): | 67 def downgrade(): |
42 with op.batch_alter_table('notifications', schema=None) as batch_op: | 68 with op.batch_alter_table("notifications", schema=None) as batch_op: |
43 batch_op.drop_index('notifications_profile_id_status') | 69 batch_op.drop_index("notifications_profile_id_status") |
44 batch_op.drop_index(batch_op.f('ix_notifications_profile_id')) | 70 batch_op.drop_index(batch_op.f("ix_notifications_profile_id")) |
45 | 71 |
46 op.drop_table('notifications') | 72 op.drop_table("notifications") |