Initial MinerOps working checkpoint
This commit is contained in:
commit
4c854374e0
103 files changed
+2400932
No files matched your search
@@ -0,0 +1,50 @@
|
||||
"""create audit logs table
|
||||
|
||||
Revision ID: 0002_audit_logs
|
||||
Revises: 0001_foundation
|
||||
Create Date: 2026-07-08
|
||||
"""
|
||||
|
||||
from typing import Sequence, Union
|
||||
|
||||
import sqlalchemy as sa
|
||||
from alembic import op
|
||||
from sqlalchemy.dialects import postgresql
|
||||
|
||||
|
||||
revision: str = "0002_audit_logs"
|
||||
down_revision: Union[str, None] = "0001_foundation"
|
||||
branch_labels: Union[str, Sequence[str], None] = None
|
||||
depends_on: Union[str, Sequence[str], None] = None
|
||||
|
||||
|
||||
def upgrade() -> None:
|
||||
op.create_table(
|
||||
"audit_logs",
|
||||
sa.Column("id", postgresql.UUID(as_uuid=True), primary_key=True, server_default=sa.text("gen_random_uuid()")),
|
||||
sa.Column("actor_user_id", postgresql.UUID(as_uuid=True), sa.ForeignKey("users.id", ondelete="SET NULL"), nullable=True),
|
||||
sa.Column("action", sa.Text(), nullable=False),
|
||||
sa.Column("entity_type", sa.Text(), nullable=False),
|
||||
sa.Column("entity_id", postgresql.UUID(as_uuid=True), nullable=True),
|
||||
sa.Column("old_value_json", postgresql.JSONB(), nullable=True),
|
||||
sa.Column("new_value_json", postgresql.JSONB(), nullable=True),
|
||||
sa.Column("related_miner_asset_id", postgresql.UUID(as_uuid=True), nullable=True),
|
||||
sa.Column("ip_address", postgresql.INET(), nullable=True),
|
||||
sa.Column("user_agent", sa.Text(), nullable=True),
|
||||
sa.Column("created_at", sa.DateTime(timezone=True), nullable=False, server_default=sa.text("now()")),
|
||||
)
|
||||
|
||||
op.create_index("idx_audit_logs_actor_user_id", "audit_logs", ["actor_user_id"])
|
||||
op.create_index("idx_audit_logs_action", "audit_logs", ["action"])
|
||||
op.create_index("idx_audit_logs_entity", "audit_logs", ["entity_type", "entity_id"])
|
||||
op.create_index("idx_audit_logs_related_miner", "audit_logs", ["related_miner_asset_id"])
|
||||
op.create_index("idx_audit_logs_created_at", "audit_logs", ["created_at"])
|
||||
|
||||
|
||||
def downgrade() -> None:
|
||||
op.drop_index("idx_audit_logs_created_at", table_name="audit_logs")
|
||||
op.drop_index("idx_audit_logs_related_miner", table_name="audit_logs")
|
||||
op.drop_index("idx_audit_logs_entity", table_name="audit_logs")
|
||||
op.drop_index("idx_audit_logs_action", table_name="audit_logs")
|
||||
op.drop_index("idx_audit_logs_actor_user_id", table_name="audit_logs")
|
||||
op.drop_table("audit_logs")
|
||||
Reference in new issue
Block a user