|
| 1 | +"""Dashboards |
| 2 | +
|
| 3 | +Revision ID: a0c659e45929 |
| 4 | +Revises: da3a1ca5e029 |
| 5 | +Create Date: 2022-12-16 12:48:36.243572+00:00 |
| 6 | +
|
| 7 | +""" |
| 8 | +from alembic import op |
| 9 | +import sqlalchemy as sa |
| 10 | + |
| 11 | +# revision identifiers, used by Alembic. |
| 12 | +revision = "a0c659e45929" |
| 13 | +down_revision = "da3a1ca5e029" |
| 14 | +branch_labels = None |
| 15 | +depends_on = None |
| 16 | + |
| 17 | + |
| 18 | +def upgrade(): |
| 19 | + op.create_table( |
| 20 | + "team_dashboards", |
| 21 | + sa.Column( |
| 22 | + "created_at", |
| 23 | + sa.TIMESTAMP(timezone=True), |
| 24 | + server_default=sa.func.now(), |
| 25 | + nullable=False, |
| 26 | + ), |
| 27 | + sa.Column( |
| 28 | + "updated_at", |
| 29 | + sa.TIMESTAMP(timezone=True), |
| 30 | + server_default=sa.func.now(), |
| 31 | + nullable=False, |
| 32 | + ), |
| 33 | + sa.Column("id", sa.Integer(), nullable=False), |
| 34 | + sa.Column( |
| 35 | + "team_id", sa.Integer(), nullable=False, comment="The team this dashboard belongs to.", |
| 36 | + ), |
| 37 | + sa.ForeignKeyConstraint( |
| 38 | + ["team_id"], ["teams.id"], name="fk_team_dashboard_team", ondelete="CASCADE", |
| 39 | + ), |
| 40 | + sa.PrimaryKeyConstraint("id"), |
| 41 | + ) |
| 42 | + |
| 43 | + if op.get_bind().dialect.name == "postgresql": |
| 44 | + chart_position_uc = sa.UniqueConstraint( |
| 45 | + "dashboard_id", "position", deferrable="True", name="uc_chart_dashboard_id_position", |
| 46 | + ) |
| 47 | + else: |
| 48 | + chart_position_uc = ( |
| 49 | + sa.UniqueConstraint("dashboard_id", "position", name="uc_chart_dashboard_id_position"), |
| 50 | + ) |
| 51 | + |
| 52 | + op.create_table( |
| 53 | + "dashboard_charts", |
| 54 | + sa.Column( |
| 55 | + "created_at", |
| 56 | + sa.TIMESTAMP(timezone=True), |
| 57 | + server_default=sa.func.now(), |
| 58 | + nullable=False, |
| 59 | + ), |
| 60 | + sa.Column( |
| 61 | + "updated_at", |
| 62 | + sa.TIMESTAMP(timezone=True), |
| 63 | + server_default=sa.func.now(), |
| 64 | + nullable=False, |
| 65 | + ), |
| 66 | + sa.Column("id", sa.Integer(), nullable=False), |
| 67 | + sa.Column("dashboard_id", sa.Integer(), nullable=False), |
| 68 | + sa.Column( |
| 69 | + "position", |
| 70 | + sa.Integer(), |
| 71 | + nullable=False, |
| 72 | + comment="Position of the chart in the containing dashboard.", |
| 73 | + ), |
| 74 | + sa.Column( |
| 75 | + "metric", sa.String(), nullable=False, comment="The metric this chart is displaying.", |
| 76 | + ), |
| 77 | + sa.Column( |
| 78 | + "time_from", |
| 79 | + sa.TIMESTAMP(timezone=True), |
| 80 | + nullable=True, |
| 81 | + comment="Start of the fixed time interval of the chart", |
| 82 | + ), |
| 83 | + sa.Column( |
| 84 | + "time_to", |
| 85 | + sa.TIMESTAMP(timezone=True), |
| 86 | + nullable=True, |
| 87 | + comment="End of the fixed time interval of the chart", |
| 88 | + ), |
| 89 | + sa.Column( |
| 90 | + "time_interval", |
| 91 | + sa.String(), |
| 92 | + nullable=True, |
| 93 | + comment="The relative time interval of the chart in ISO-8601 format.", |
| 94 | + ), |
| 95 | + sa.Column("name", sa.String(), nullable=False), |
| 96 | + sa.Column("description", sa.String(), nullable=False), |
| 97 | + sa.ForeignKeyConstraint( |
| 98 | + ["dashboard_id"], |
| 99 | + ["team_dashboards.id"], |
| 100 | + name="fk_chart_dashboard", |
| 101 | + ondelete="CASCADE", |
| 102 | + ), |
| 103 | + sa.PrimaryKeyConstraint("id"), |
| 104 | + chart_position_uc, |
| 105 | + ) |
| 106 | + |
| 107 | + |
| 108 | +def downgrade(): |
| 109 | + op.drop_table("dashboard_charts") |
| 110 | + op.drop_table("team_dashboards") |
0 commit comments