
- Created FastAPI application with SQLite database - Implemented monitor management endpoints (CRUD operations) - Added uptime checking functionality with response time tracking - Included statistics endpoints for uptime percentage and metrics - Set up database models and Alembic migrations - Added comprehensive API documentation - Configured CORS and health check endpoints
75 lines
2.4 KiB
Python
75 lines
2.4 KiB
Python
"""Initial migration
|
|
|
|
Revision ID: 001
|
|
Revises:
|
|
Create Date: 2024-12-17 12:00:00.000000
|
|
|
|
"""
|
|
|
|
from alembic import op
|
|
import sqlalchemy as sa
|
|
|
|
# revision identifiers, used by Alembic.
|
|
revision = "001"
|
|
down_revision = None
|
|
branch_labels = None
|
|
depends_on = None
|
|
|
|
|
|
def upgrade() -> None:
|
|
# Create monitors table
|
|
op.create_table(
|
|
"monitors",
|
|
sa.Column("id", sa.Integer(), nullable=False),
|
|
sa.Column("name", sa.String(), nullable=False),
|
|
sa.Column("url", sa.String(), nullable=False),
|
|
sa.Column("method", sa.String(), nullable=True),
|
|
sa.Column("timeout", sa.Integer(), nullable=True),
|
|
sa.Column("interval", sa.Integer(), nullable=True),
|
|
sa.Column("is_active", sa.Boolean(), nullable=True),
|
|
sa.Column(
|
|
"created_at",
|
|
sa.DateTime(timezone=True),
|
|
server_default=sa.text("(CURRENT_TIMESTAMP)"),
|
|
nullable=True,
|
|
),
|
|
sa.Column("updated_at", sa.DateTime(timezone=True), nullable=True),
|
|
sa.PrimaryKeyConstraint("id"),
|
|
)
|
|
op.create_index(op.f("ix_monitors_id"), "monitors", ["id"], unique=False)
|
|
op.create_index(op.f("ix_monitors_name"), "monitors", ["name"], unique=False)
|
|
|
|
# Create uptime_checks table
|
|
op.create_table(
|
|
"uptime_checks",
|
|
sa.Column("id", sa.Integer(), nullable=False),
|
|
sa.Column("monitor_id", sa.Integer(), nullable=False),
|
|
sa.Column("status_code", sa.Integer(), nullable=True),
|
|
sa.Column("response_time", sa.Float(), nullable=True),
|
|
sa.Column("is_up", sa.Boolean(), nullable=False),
|
|
sa.Column("error_message", sa.Text(), nullable=True),
|
|
sa.Column(
|
|
"checked_at",
|
|
sa.DateTime(timezone=True),
|
|
server_default=sa.text("(CURRENT_TIMESTAMP)"),
|
|
nullable=True,
|
|
),
|
|
sa.PrimaryKeyConstraint("id"),
|
|
)
|
|
op.create_index(op.f("ix_uptime_checks_id"), "uptime_checks", ["id"], unique=False)
|
|
op.create_index(
|
|
op.f("ix_uptime_checks_monitor_id"),
|
|
"uptime_checks",
|
|
["monitor_id"],
|
|
unique=False,
|
|
)
|
|
|
|
|
|
def downgrade() -> None:
|
|
op.drop_index(op.f("ix_uptime_checks_monitor_id"), table_name="uptime_checks")
|
|
op.drop_index(op.f("ix_uptime_checks_id"), table_name="uptime_checks")
|
|
op.drop_table("uptime_checks")
|
|
op.drop_index(op.f("ix_monitors_name"), table_name="monitors")
|
|
op.drop_index(op.f("ix_monitors_id"), table_name="monitors")
|
|
op.drop_table("monitors")
|