Skip to content
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

Db up downgrade snapshot #703

Open
wants to merge 23 commits into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
70daae4
feat: remove/add resource_snapshot from enum table
JustKuzya Dec 25, 2024
d4898cc
feat: remove/add resource_snapshot from enum table
JustKuzya Jan 16, 2025
523e7bc
fix: update worker health check
etrapnell-nist Dec 3, 2024
1826f75
feat: implement dioptra v1 rest api python client
jkglasbrenner Dec 16, 2024
3104777
test: add unit tests for experiment and entrypoints endpoints
jkglasbrenner Dec 16, 2024
ffd9b21
fix(frontend): fix issue preventing modification of plugin files in UI
Dec 18, 2024
5e100f6
feat(restapi): add endpoints for storing and retrieving metrics
jtsextonMITRE Dec 20, 2024
19b7732
chore: fix mypy errors in task-plugins and task_engine
keithmanville Dec 23, 2024
8f98894
feat(frontend): redesign common Job creation form
Dec 4, 2024
2f4d2ea
feat(restapi): add snapshot_created_on field to resource schemas
keithmanville Dec 10, 2024
9e9090f
feat(frontend): add UI element to browse queue history
Dec 6, 2024
d9e890c
docs: fix broken links
mtrapnell-nist Jan 13, 2025
b7f2c12
refactor: resolve mypy type annotation error
jkglasbrenner Jan 14, 2025
3e6eaaf
build: add requests-toolbelt as dependency and regenerate lockfiles
jkglasbrenner Jan 14, 2025
d5403dc
feat: add file upload support and utility functions to client library
jkglasbrenner Jan 15, 2025
4b8c047
fix: add monkey-patch for flask-restx swagger multipart form support
jkglasbrenner Jan 9, 2025
4c7acd8
feat: add a MultiFileUpload custom marshmallow schema field type
jkglasbrenner Jan 16, 2025
f343b03
feat: remove/add resource_snapshot from enum table + rebase
JustKuzya Jan 22, 2025
60fe549
fix: modify up/downgrade code to use only ORM alembic functionality
JustKuzya Jan 29, 2025
2817a70
fix: clean-up the comments
JustKuzya Jan 29, 2025
70b896c
Merge branch 'dev' into db-up-downgrade-snapshot
JustKuzya Jan 29, 2025
cb89816
fix: "de-tox-ed" the quote marks and white-spaces
JustKuzya Jan 29, 2025
524e7d6
fix: fixing space complaints from tox
JustKuzya Jan 30, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
"""Up/Down-grade resource snapshot types as delete/insert 'resource_snapshot' [GH-Issue #474]

Revision ID: 0ca6eca33569
Revises: 6a75ede23821
Create Date: 2024-12-12 00:47:23.575103

"""

from typing import Annotated, Any

import sqlalchemy as sa
from alembic import op
from sqlalchemy.engine.cursor import CursorResult
from sqlalchemy.orm import (
DeclarativeBase,
Mapped,
MappedAsDataclass,
mapped_column,
sessionmaker,
)

### To test upgrade run:
"""
dioptra-db upgrade --revision 0ca6eca33569
"""
### Or if on version 6a75ede23821 and the only newer version is 0ca6eca33569
"""
dioptra-db upgrade
"""
### To downgrade run:
"""
dioptra-db downgrade 6a75ede23821
"""

# revision identifiers, used by Alembic.
revision = "0ca6eca33569"
down_revision = "6a75ede23821"
branch_labels = None
depends_on = None


text_ = Annotated[str, mapped_column(sa.Text())]


# The data to up/down-grade
ENUM_TABLE = "resource_types" ### The table to up/down-grade
TABLE_ENTRY = "resource_snapshot" ### The entry to up/down-grade


class UpgradeBase(DeclarativeBase, MappedAsDataclass):
pass


class DowngradeBase(DeclarativeBase, MappedAsDataclass):
pass


class ResourceTypeUpgrade(UpgradeBase):
__tablename__ = ENUM_TABLE
resource_type: Mapped[text_] = mapped_column(primary_key=True)


class ResourceTypeDowngrade(DowngradeBase):
__tablename__ = ENUM_TABLE
resource_type: Mapped[text_] = mapped_column(primary_key=True)


def upgrade():
"""Alembic Upgrade Hook-Point that deletes the entry from
resource_types table with value 'resource_snapshot'
"""
bind = op.get_bind()
Session = sessionmaker(bind=bind)

with Session() as session:
stmt = sa.select(ResourceTypeUpgrade).where(
ResourceTypeUpgrade.resource_type == TABLE_ENTRY
)
resource_snapshot_type = session.scalar(stmt)

if resource_snapshot_type is not None:
session.delete(resource_snapshot_type)

session.commit()
# -----------------------------------------------------------------------------


def downgrade():
"""Alembic Downgrade Hook-Point that reinstates the entry to
resource_types table with value 'resource_snapshot'
"""
bind = op.get_bind()
Session = sessionmaker(bind=bind)

with Session() as session:
stmt = sa.select(ResourceTypeUpgrade).where(
ResourceTypeUpgrade.resource_type == TABLE_ENTRY
)
resource_snapshot_type = session.scalar(stmt)

if resource_snapshot_type is None:
session.add(ResourceTypeUpgrade(resource_type=TABLE_ENTRY))

session.commit()
# -----------------------------------------------------------------------------