-
Notifications
You must be signed in to change notification settings - Fork 18
WIP: Extend DB for controls table and a mapper table to map controls… #42
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
leon-schmid
wants to merge
10
commits into
main
Choose a base branch
from
ADM-398/Extend-DB-Schema-For-Controls
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
fa7cc9b
feat: extend DB for controls table and a mapper table to map controls…
leon-schmid a2c4ded
tests: add tests for new controls_workflows mapping
leon-schmid f184368
feat: add user_id as primary key to controls for future extensibility
leon-schmid bd8f26d
fix: wrongly autogenerated alembic command
leon-schmid 38a91e4
feat: add new test db for unit testing and some refactoring
leon-schmid dae1e4a
fix: tests
leon-schmid 2f3cf1b
refactor: only support postgres
leon-schmid 8c52142
refactor: switch to exec from deprecated execute
leon-schmid 9a43b57
fix: include user_id in control model and make cleanup after testing …
leon-schmid f79c918
chore: implement requested changes
leon-schmid File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -115,21 +115,20 @@ class SecretsManagerType(str, Enum): | |
|
|
||
|
|
||
| ENV_ADMYRAL_DATABASE_URL = "ADMYRAL_DATABASE_URL" | ||
| ENV_ADMYRAL_TEST_DATABASE_URL = "ADMYRAL_TEST_DATABASE_URL" | ||
| ENV_ADMYRAL_SECRETS_MANAGER_TYPE = "ADMYRAL_SECRETS_MANAGER" | ||
|
|
||
|
|
||
| ADMYRAL_DATABASE_URL = os.getenv( | ||
| ENV_ADMYRAL_DATABASE_URL, | ||
| "postgresql://postgres:your-super-secret-and-long-postgres-password@localhost:5432/admyral", | ||
| ) | ||
| if ADMYRAL_DATABASE_URL.startswith("postgresql"): | ||
| if ADMYRAL_DATABASE_URL.startswith("postgresql://"): | ||
| ADMYRAL_DATABASE_URL = ADMYRAL_DATABASE_URL.replace( | ||
| "postgresql://", "postgresql+asyncpg://" | ||
| ) | ||
| ADMYRAL_DATABASE_TYPE = DatabaseType.POSTGRES | ||
| else: | ||
| raise NotImplementedError(f"Unsupported database type: {ADMYRAL_DATABASE_URL}") | ||
| "postgresql://postgres:your-super-secret-and-long-postgres-password@localhost:5433/admyral", | ||
| ).replace("postgresql://", "postgresql+asyncpg://") | ||
|
|
||
| ADMYRAL_TEST_DATABASE_URL = os.getenv( | ||
| ENV_ADMYRAL_TEST_DATABASE_URL, | ||
| "postgresql://postgres:your-super-secret-and-long-postgres-password@localhost:5433/admyral", | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The default should point to the test postgres and not the actual postgres database. Can you also adapt |
||
| ).replace("postgresql://", "postgresql+asyncpg://") | ||
|
|
||
leon-schmid marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| ADMYRAL_SECRETS_MANAGER_TYPE = SecretsManagerType( | ||
| os.getenv(ENV_ADMYRAL_SECRETS_MANAGER_TYPE, SecretsManagerType.SQL) | ||
|
|
@@ -151,8 +150,8 @@ class GlobalConfig(BaseModel): | |
| default_user_email: str = "default.user@admyral.ai" | ||
| telemetry_disabled: bool = ADMYRAL_DISABLE_TELEMETRY | ||
| storage_directory: str = get_local_storage_path() | ||
| database_type: DatabaseType = ADMYRAL_DATABASE_TYPE | ||
| database_url: str = ADMYRAL_DATABASE_URL | ||
| test_database_url: str = ADMYRAL_TEST_DATABASE_URL | ||
| temporal_host: str = ADMYRAL_TEMPORAL_HOST | ||
| secrets_manager_type: SecretsManagerType = ADMYRAL_SECRETS_MANAGER_TYPE | ||
| posthog_api_key: str = ADMYRAL_POSTHOG_API_KEY | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
admyral/db/alembic/versions/3967e08c0051_add_controls_and_controls_workflows_.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| """add controls and controls_workflows tables | ||
| Revision ID: 3967e08c0051 | ||
| Revises: 7985f1c159a3 | ||
| Create Date: 2024-11-27 17:36:23.138028 | ||
| """ | ||
|
|
||
| from typing import Sequence, Union | ||
|
|
||
| from alembic import op | ||
| import sqlalchemy as sa | ||
| import sqlmodel # noqa F401 | ||
|
|
||
|
|
||
| # revision identifiers, used by Alembic. | ||
| revision: str = "3967e08c0051" | ||
| down_revision: Union[str, None] = "7985f1c159a3" | ||
| branch_labels: Union[str, Sequence[str], None] = None | ||
| depends_on: Union[str, Sequence[str], None] = None | ||
|
|
||
|
|
||
| def upgrade() -> None: | ||
| # ### commands auto generated by Alembic - please adjust! ### | ||
| op.create_table( | ||
| "controls", | ||
| 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, | ||
| ), | ||
leon-schmid marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| sa.Column("control_id", sa.TEXT(), nullable=False), | ||
| sa.Column("user_id", sa.TEXT(), nullable=False), | ||
| sa.Column("control_name", sa.TEXT(), nullable=False), | ||
| sa.Column("control_description", sa.TEXT(), nullable=False), | ||
| sa.ForeignKeyConstraint(["user_id"], ["User.id"], ondelete="CASCADE"), | ||
| sa.PrimaryKeyConstraint("control_id", "user_id"), | ||
| sa.UniqueConstraint("user_id", "control_id", name="unique_control_id"), | ||
leon-schmid marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| ) | ||
| op.create_index( | ||
| op.f("ix_controls_control_name"), "controls", ["control_name"], unique=False | ||
| ) | ||
| op.create_table( | ||
| "controls_workflows", | ||
| 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("control_id", sa.TEXT(), nullable=False), | ||
| sa.Column("user_id", sa.TEXT(), nullable=False), | ||
| sa.Column("workflow_id", sa.TEXT(), nullable=False), | ||
| sa.ForeignKeyConstraint( | ||
| ["control_id", "user_id"], | ||
| ["controls.control_id", "controls.user_id"], | ||
| ondelete="CASCADE", | ||
| ), | ||
| sa.ForeignKeyConstraint( | ||
| ["workflow_id"], ["workflows.workflow_id"], ondelete="CASCADE" | ||
| ), | ||
| sa.PrimaryKeyConstraint("control_id", "user_id", "workflow_id"), | ||
| ) | ||
| # ### end Alembic commands ### | ||
|
|
||
|
|
||
| def downgrade() -> None: | ||
| # ### commands auto generated by Alembic - please adjust! ### | ||
| op.drop_table("controls_workflows") | ||
| op.drop_index(op.f("ix_controls_control_name"), table_name="controls") | ||
| op.drop_table("controls") | ||
| # ### end Alembic commands ### | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.