main
py 71 lines 3.3 KB
Raw
1 """Add agent datastore
2
3 Revision ID: 5c588e7cb55c
4 Revises: 1dd1c055ee06
5 Create Date: 2025-11-27 09:39:47.952715
6
7 """
8 from typing import Sequence
9 from typing import Union
10
11 import sqlalchemy as sa
12
13 from alembic import op
14
15 # revision identifiers, used by Alembic.
16 revision: str = "5c588e7cb55c"
17 down_revision: Union[str, None] = "1dd1c055ee06"
18 branch_labels: Union[str, Sequence[str], None] = None
19 depends_on: Union[str, Sequence[str], None] = None
20
21
22 def upgrade() -> None:
23 # ### commands auto generated by Alembic - please adjust! ###
24 op.create_table(
25 "agent_datastore",
26 sa.Column("notes", sa.Text(), nullable=True),
27 sa.Column("error_message", sa.Text(), nullable=True),
28 sa.Column("id", sa.Integer(), nullable=False),
29 sa.Column("agent_id", sa.String(length=256), nullable=False),
30 sa.Column("velociraptor_id", sa.String(length=256), nullable=False),
31 sa.Column("customer_code", sa.String(length=50), nullable=False),
32 sa.Column("artifact_name", sa.String(length=255), nullable=False),
33 sa.Column("flow_id", sa.String(length=255), nullable=False),
34 sa.Column("collection_time", sa.DateTime(), nullable=False),
35 sa.Column("bucket_name", sa.String(length=255), nullable=False),
36 sa.Column("object_key", sa.String(length=1024), nullable=False),
37 sa.Column("file_name", sa.String(length=255), nullable=False),
38 sa.Column("content_type", sa.String(length=100), nullable=False),
39 sa.Column("file_size", sa.Integer(), nullable=False),
40 sa.Column("file_hash", sa.String(length=128), nullable=False),
41 sa.Column("uploaded_by", sa.Integer(), nullable=True),
42 sa.Column("status", sa.String(length=50), nullable=False),
43 sa.ForeignKeyConstraint(
44 ["agent_id"],
45 ["agents.agent_id"],
46 ),
47 sa.ForeignKeyConstraint(
48 ["customer_code"],
49 ["customers.customer_code"],
50 ),
51 sa.PrimaryKeyConstraint("id"),
52 )
53 op.create_index(op.f("ix_agent_datastore_agent_id"), "agent_datastore", ["agent_id"], unique=False)
54 op.create_index(op.f("ix_agent_datastore_artifact_name"), "agent_datastore", ["artifact_name"], unique=False)
55 op.create_index(op.f("ix_agent_datastore_collection_time"), "agent_datastore", ["collection_time"], unique=False)
56 op.create_index(op.f("ix_agent_datastore_customer_code"), "agent_datastore", ["customer_code"], unique=False)
57 op.create_index(op.f("ix_agent_datastore_flow_id"), "agent_datastore", ["flow_id"], unique=False)
58 op.create_index(op.f("ix_agent_datastore_status"), "agent_datastore", ["status"], unique=False)
59 # ### end Alembic commands ###
60
61
62 def downgrade() -> None:
63 # ### commands auto generated by Alembic - please adjust! ###
64 op.drop_index(op.f("ix_agent_datastore_status"), table_name="agent_datastore")
65 op.drop_index(op.f("ix_agent_datastore_flow_id"), table_name="agent_datastore")
66 op.drop_index(op.f("ix_agent_datastore_customer_code"), table_name="agent_datastore")
67 op.drop_index(op.f("ix_agent_datastore_collection_time"), table_name="agent_datastore")
68 op.drop_index(op.f("ix_agent_datastore_artifact_name"), table_name="agent_datastore")
69 op.drop_index(op.f("ix_agent_datastore_agent_id"), table_name="agent_datastore")
70 op.drop_table("agent_datastore")
71 # ### end Alembic commands ###