Skip to content

fix (db): update db-migration to create swaps i823#1301

Open
JustKuzya wants to merge 12 commits into
entrypoint-swapsfrom
jk/db-swaps-upgrade-i823
Open

fix (db): update db-migration to create swaps i823#1301
JustKuzya wants to merge 12 commits into
entrypoint-swapsfrom
jk/db-swaps-upgrade-i823

Conversation

@JustKuzya

Copy link
Copy Markdown
Collaborator
  • add guide for testing the database upgrade with containerized Postgres DBMS
  • create migration script for swaps
  • verify that the script works for SQLite and containerized Postgres

@jtsextonMITRE jtsextonMITRE self-assigned this Jun 4, 2026

@keithmanville keithmanville left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was expecting to see the JobSwaps ORM object in db/models/jobs.py and changes to the response schema in v1/jobs/schema.py. Did you forget to commit? It looks like you had this done if you generated the alembic script from the ORM.

JustKuzya and others added 10 commits June 18, 2026 14:53
- add guide for testing the database upgrade with containerized postgres DBMS
- create migration script for swaps
- verify that the script works for SQLite and containerized Posgres
Lint and format the frontend using npm run lint and npm run format from the src/frontend directory.
Perform check only using npm run lint:check and npm run format:check.

Updated `DEVELOPER.md` to note lint and format rules.

Updated all frontend packages.

Note: eslint is incompatible with node v23. Added .nvmrc so nvm can be used to to switch to node
v22. Added short explanation in frontend README.
Added frontend-checks.yml which runs the lint:check and format:check for PRs.
- added method doc-strings
- changed the commit messafge structure to space-less one
- create ORM mapping in model
- regenerate upgrade script
- update the model with job_id+
Comment thread src/dioptra/restapi/db/models/jobs.py Outdated
) # FK to plugin_files

# PK constraints settings
_table_args__ = (

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo: should be __table_args__

Comment thread src/dioptra/restapi/db/models/jobs.py Outdated
__tablename__ = "job_swaps"

# Table fields
job_id: Mapped["Job"] = mapped_column(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use job_resource_id instead of job_id to match the other ORM models like EntrypointJob and ExperimentJob.

The type should be an integer since it is an ID not the job ORM class.

Comment thread src/dioptra/restapi/db/models/jobs.py Outdated
# PK constraints settings
_table_args__ = (
PrimaryKeyConstraint("job_id", "swap_name"),
ForeignKeyConstraint(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

job_id should be with jobs.resource_id and plugin_file_resource_snapshot_id with plugin_files.resource_snapshot_id.

But in the end I don't think we need the FK Constraints here, as long as they are defined in the mapped_columns

Comment thread src/dioptra/restapi/db/models/jobs.py Outdated
ForeignKey("plugin_files.resource_snapshot_id"),
init=False,
) # FK to plugin_files

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need to add relationship with Jobs. Also requires the entry in Jobs ORM object:

job_swaps: Mapped[list["JobSwap"]] = relationship(
    init=False,
    back_populates="job",
)

from alembic import op

# revision identifiers, used by Alembic.
revision = '30e74c5564b3'

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seeing single quotes. need to run ruff on this file.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see in the latest version all of the changes you have suggested seem to be applied.

@keithmanville keithmanville force-pushed the jk/db-swaps-upgrade-i823 branch from 9ed9c34 to 92a7e10 Compare June 18, 2026 19:04
@keithmanville keithmanville changed the base branch from dev to entrypoint-swaps June 18, 2026 19:05
@keithmanville

Copy link
Copy Markdown
Collaborator

Left a review, but since changes were all minor, I went ahead and made and committed them.

Also change PR target to entrypoint-swaps branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants