@cryptotaxi247 / CoPilot / commits / faa3d799

Add event sources table and model definition

taylorwalton committed Mar 13, 2026 at 17:02 UTC faa3d799bb44f13881a2fda23b71dc3458e6c855
2 files changed +81
backend/alembic/versions/85ea2970828c_add_event_sources_tables.py new
+44
@@ -0,0 +1,44 @@
1 +"""Add event sources tables
2 +
3 +Revision ID: 85ea2970828c
4 +Revises: fb51d610b306
5 +Create Date: 2026-03-13 17:00:07.745510
6 +
7 +"""
8 +from typing import Sequence, Union
9 +
10 +from alembic import op
11 +import sqlalchemy as sa
12 +from sqlalchemy.dialects import mysql
13 +
14 +# revision identifiers, used by Alembic.
15 +revision: str = '85ea2970828c'
16 +down_revision: Union[str, None] = 'fb51d610b306'
17 +branch_labels: Union[str, Sequence[str], None] = None
18 +depends_on: Union[str, Sequence[str], None] = None
19 +
20 +
21 +def upgrade() -> None:
22 + # ### commands auto generated by Alembic - please adjust! ###
23 + op.create_table('event_sources',
24 + sa.Column('id', sa.Integer(), nullable=False),
25 + sa.Column('customer_code', sa.String(length=50), nullable=False),
26 + sa.Column('name', sa.String(length=255), nullable=False),
27 + sa.Column('index_pattern', sa.String(length=1024), nullable=False),
28 + sa.Column('event_type', sa.String(length=50), nullable=False),
29 + sa.Column('time_field', sa.String(length=255), nullable=False),
30 + sa.Column('enabled', sa.Boolean(), nullable=False),
31 + sa.Column('created_at', sa.DateTime(), nullable=False),
32 + sa.Column('updated_at', sa.DateTime(), nullable=False),
33 + sa.ForeignKeyConstraint(['customer_code'], ['customers.customer_code'], ),
34 + sa.PrimaryKeyConstraint('id')
35 + )
36 + op.create_index(op.f('ix_event_sources_customer_code'), 'event_sources', ['customer_code'], unique=False)
37 + # ### end Alembic commands ###
38 +
39 +
40 +def downgrade() -> None:
41 + # ### commands auto generated by Alembic - please adjust! ###
42 + op.drop_index(op.f('ix_event_sources_customer_code'), table_name='event_sources')
43 + op.drop_table('event_sources')
44 + # ### end Alembic commands ###
backend/app/db/universal_models.py
+37
@@ -500,3 +500,40 @@ class SCAReport(SQLModel, table=True):
500
501 # Relationship to Customers table
502 customer: Optional["Customers"] = Relationship()
503 +
504 +class EventSources(SQLModel, table=True):
505 + __tablename__ = "event_sources"
506 +
507 + id: Optional[int] = Field(primary_key=True)
508 + customer_code: str = Field(
509 + foreign_key="customers.customer_code",
510 + max_length=50,
511 + index=True,
512 + nullable=False,
513 + )
514 + name: str = Field(max_length=255, nullable=False)
515 + index_pattern: str = Field(max_length=1024, nullable=False)
516 + event_type: str = Field(max_length=50, nullable=False) # EDR, EPP, Cloud Integration, Network Security
517 + time_field: str = Field(max_length=255, nullable=False, default="timestamp")
518 + enabled: bool = Field(default=True)
519 + created_at: datetime = Field(default_factory=datetime.utcnow)
520 + updated_at: datetime = Field(default_factory=datetime.utcnow)
521 +
522 + customer: Optional["Customers"] = Relationship()
523 +
524 + class Config:
525 + # Enforce event_type values at the application level
526 + pass
527 +
528 + def update_from_model(self, source_data):
529 + if hasattr(source_data, "name"):
530 + self.name = source_data.name
531 + if hasattr(source_data, "index_pattern"):
532 + self.index_pattern = source_data.index_pattern
533 + if hasattr(source_data, "event_type"):
534 + self.event_type = source_data.event_type
535 + if hasattr(source_data, "time_field"):
536 + self.time_field = source_data.time_field
537 + if hasattr(source_data, "enabled"):
538 + self.enabled = source_data.enabled
539 + self.updated_at = datetime.utcnow()