Skip to content

Commit

Permalink
feat(app): Add OrganizationSetting table to db
Browse files Browse the repository at this point in the history
  • Loading branch information
daryllimyt committed Jan 8, 2025
1 parent 247d4aa commit a55f8a2
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 0 deletions.
71 changes: 71 additions & 0 deletions alembic/versions/496c162975d7_add_organization_settings_table.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
"""Add organization settings table
Revision ID: 496c162975d7
Revises: 9194fb66b4ea
Create Date: 2025-01-09 00:02:47.484038
"""
from collections.abc import Sequence

import sqlalchemy as sa
import sqlmodel.sql.sqltypes

from alembic import op

# revision identifiers, used by Alembic.
revision: str = "496c162975d7"
down_revision: str | None = "9194fb66b4ea"
branch_labels: str | Sequence[str] | None = None
depends_on: str | Sequence[str] | None = None


def upgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.create_table(
"organization_settings",
sa.Column("surrogate_id", sa.Integer(), nullable=False),
sa.Column("owner_id", sqlmodel.sql.sqltypes.GUID(), nullable=False),
sa.Column(
"created_at",
sa.TIMESTAMP(timezone=True),
server_default=sa.text("now()"),
nullable=False,
),
sa.Column(
"updated_at",
sa.TIMESTAMP(timezone=True),
server_default=sa.text("now()"),
nullable=False,
),
sa.Column("id", sqlmodel.sql.sqltypes.GUID(), nullable=False),
sa.Column("key", sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.Column("value", sa.LargeBinary(), nullable=False),
sa.Column("value_type", sqlmodel.sql.sqltypes.AutoString(), nullable=False),
sa.Column("is_encrypted", sa.Boolean(), nullable=False),
sa.PrimaryKeyConstraint("surrogate_id"),
)
op.create_index(
op.f("ix_organization_settings_id"),
"organization_settings",
["id"],
unique=True,
)
op.create_index(
op.f("ix_organization_settings_key"),
"organization_settings",
["key"],
unique=True,
)
# ### end Alembic commands ###


def downgrade() -> None:
# ### commands auto generated by Alembic - please adjust! ###
op.drop_index(
op.f("ix_organization_settings_key"), table_name="organization_settings"
)
op.drop_index(
op.f("ix_organization_settings_id"), table_name="organization_settings"
)
op.drop_table("organization_settings")
# ### end Alembic commands ###
27 changes: 27 additions & 0 deletions tracecat/db/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,3 +538,30 @@ class RegistryAction(Resource, table=True):
@property
def action(self):
return f"{self.namespace}.{self.name}"


class OrganizationSetting(Resource, table=True):
"""An organization setting."""

__tablename__: str = "organization_settings"

id: UUID4 = Field(
default_factory=uuid.uuid4,
nullable=False,
unique=True,
index=True,
)
key: str = Field(
...,
description="A unique key that identifies the setting",
index=True,
unique=True,
)
value: bytes
value_type: str = Field(
...,
description="The data type of the setting value",
)
is_encrypted: bool = Field(
default=False, description="Whether the setting is encrypted"
)

0 comments on commit a55f8a2

Please sign in to comment.