Skip to content

Commit 843d1c1

Browse files
authored
chore(engine): Run migration for 0.7.3 (TracecatHQ#345)
1 parent 35430b3 commit 843d1c1

File tree

6 files changed

+80
-20
lines changed

6 files changed

+80
-20
lines changed

Dockerfile.dev

+7
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,16 @@ COPY ./tracecat /app/tracecat
1515
COPY ./pyproject.toml /app/pyproject.toml
1616
COPY ./README.md /app/README.md
1717
COPY ./LICENSE /app/LICENSE
18+
COPY ./alembic.ini /app/alembic.ini
19+
COPY ./alembic /app/alembic
20+
21+
COPY scripts/entrypoint.sh /app/entrypoint.sh
22+
RUN chmod +x /app/entrypoint.sh
1823

1924
# Install package
2025
RUN pip install --upgrade pip && pip install -e .
2126

27+
ENTRYPOINT ["/app/entrypoint.sh"]
28+
2229
# Command to run the application
2330
CMD ["sh", "-c", "python3 -m uvicorn tracecat.api.app:app --host $HOST --port $PORT --reload"]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
"""Remove CaseAction and CaseContext and remove workspace ID from CaseEvent
2+
3+
Revision ID: 9331e7a72410
4+
Revises: ebf7613506e0
5+
Create Date: 2024-08-22 21:22:39.732969
6+
7+
"""
8+
from typing import Sequence, Union
9+
10+
from alembic import op
11+
import sqlalchemy as sa
12+
from sqlalchemy.dialects import postgresql
13+
14+
# revision identifiers, used by Alembic.
15+
revision: str = '9331e7a72410'
16+
down_revision: Union[str, None] = 'ebf7613506e0'
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.drop_index('ix_casecontext_id', table_name='casecontext')
24+
op.drop_table('casecontext')
25+
op.drop_index('ix_caseaction_id', table_name='caseaction')
26+
op.drop_table('caseaction')
27+
op.alter_column('caseevent', 'case_id',
28+
existing_type=sa.VARCHAR(),
29+
nullable=True)
30+
op.create_foreign_key(None, 'caseevent', 'case', ['case_id'], ['id'], ondelete='CASCADE')
31+
op.drop_column('caseevent', 'workflow_id')
32+
# ### end Alembic commands ###
33+
34+
35+
def downgrade() -> None:
36+
# ### commands auto generated by Alembic - please adjust! ###
37+
op.add_column('caseevent', sa.Column('workflow_id', sa.VARCHAR(), autoincrement=False, nullable=False))
38+
op.drop_constraint(None, 'caseevent', type_='foreignkey')
39+
op.alter_column('caseevent', 'case_id',
40+
existing_type=sa.VARCHAR(),
41+
nullable=False)
42+
op.create_table('caseaction',
43+
sa.Column('surrogate_id', sa.INTEGER(), autoincrement=True, nullable=False),
44+
sa.Column('owner_id', sa.UUID(), autoincrement=False, nullable=False),
45+
sa.Column('created_at', postgresql.TIMESTAMP(timezone=True), server_default=sa.text("(now() AT TIME ZONE 'utc'::text)"), autoincrement=False, nullable=False),
46+
sa.Column('updated_at', postgresql.TIMESTAMP(timezone=True), server_default=sa.text("(now() AT TIME ZONE 'utc'::text)"), autoincrement=False, nullable=False),
47+
sa.Column('id', sa.VARCHAR(), autoincrement=False, nullable=False),
48+
sa.Column('tag', sa.VARCHAR(), autoincrement=False, nullable=False),
49+
sa.Column('value', sa.VARCHAR(), autoincrement=False, nullable=False),
50+
sa.Column('user_id', sa.UUID(), autoincrement=False, nullable=True),
51+
sa.ForeignKeyConstraint(['user_id'], ['user.id'], name='caseaction_user_id_fkey'),
52+
sa.PrimaryKeyConstraint('surrogate_id', name='caseaction_pkey')
53+
)
54+
op.create_index('ix_caseaction_id', 'caseaction', ['id'], unique=True)
55+
op.create_table('casecontext',
56+
sa.Column('surrogate_id', sa.INTEGER(), autoincrement=True, nullable=False),
57+
sa.Column('owner_id', sa.UUID(), autoincrement=False, nullable=False),
58+
sa.Column('created_at', postgresql.TIMESTAMP(timezone=True), server_default=sa.text("(now() AT TIME ZONE 'utc'::text)"), autoincrement=False, nullable=False),
59+
sa.Column('updated_at', postgresql.TIMESTAMP(timezone=True), server_default=sa.text("(now() AT TIME ZONE 'utc'::text)"), autoincrement=False, nullable=False),
60+
sa.Column('id', sa.VARCHAR(), autoincrement=False, nullable=False),
61+
sa.Column('tag', sa.VARCHAR(), autoincrement=False, nullable=False),
62+
sa.Column('value', sa.VARCHAR(), autoincrement=False, nullable=False),
63+
sa.Column('user_id', sa.UUID(), autoincrement=False, nullable=True),
64+
sa.ForeignKeyConstraint(['user_id'], ['user.id'], name='casecontext_user_id_fkey'),
65+
sa.PrimaryKeyConstraint('surrogate_id', name='casecontext_pkey')
66+
)
67+
op.create_index('ix_casecontext_id', 'casecontext', ['id'], unique=True)
68+
# ### end Alembic commands ###

docker-compose.dev.yml

+2
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ services:
4949
SMTP_AUTH_ENABLED: ${SMTP_AUTH_ENABLED}
5050
SMTP_USER: ${SMTP_USER}
5151
SMTP_PASS: ${SMTP_PASS}
52+
# Migrations
53+
RUN_MIGRATIONS: true
5254
volumes:
5355
- ./tracecat:/app/tracecat
5456

docker-compose.yml

+2-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ services:
3838
OAUTH_CLIENT_ID: ${OAUTH_CLIENT_ID}
3939
OAUTH_CLIENT_SECRET: ${OAUTH_CLIENT_SECRET}
4040
USER_AUTH_SECRET: ${USER_AUTH_SECRET}
41+
RUN_MIGRATIONS: true
4142
# Temporal
4243
TEMPORAL__CLUSTER_URL: ${TEMPORAL__CLUSTER_URL}
4344
TEMPORAL__CLUSTER_QUEUE: ${TEMPORAL__CLUSTER_QUEUE}
@@ -148,4 +149,4 @@ networks:
148149
internal: true
149150
temporal:
150151
temporal-db:
151-
internal: true
152+
internal: true

scripts/entrypoint.sh

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ set -euo pipefail
44
# Function to run migrations
55
run_migrations() {
66
echo "Running database migrations..."
7-
if ! alembic upgrade head; then
7+
if ! python3 -m alembic upgrade head; then
88
echo "Migration failed!"
99
return 1
1010
fi

tracecat/db/schemas.py

-18
Original file line numberDiff line numberDiff line change
@@ -180,24 +180,6 @@ class Case(Resource, table=True):
180180
tags: dict[str, str] | None = Field(sa_column=Column(JSONB))
181181

182182

183-
class CaseAction(Resource, table=True):
184-
id: str = Field(
185-
default_factory=id_factory("case-act"), nullable=False, unique=True, index=True
186-
)
187-
tag: str
188-
value: str
189-
user_id: UUID4 | None = Field(sa_column=Column(UUID, ForeignKey("user.id")))
190-
191-
192-
class CaseContext(Resource, table=True):
193-
id: str = Field(
194-
default_factory=id_factory("case-ctx"), nullable=False, unique=True, index=True
195-
)
196-
tag: str
197-
value: str
198-
user_id: UUID4 | None = Field(sa_column=Column(UUID, ForeignKey("user.id")))
199-
200-
201183
class CaseEvent(Resource, table=True):
202184
id: str = Field(
203185
default_factory=id_factory("case-evt"), nullable=False, unique=True, index=True

0 commit comments

Comments
 (0)