Skip to content

Commit

Permalink
Associate packages with a provider
Browse files Browse the repository at this point in the history
A package originates from - or is created on behalf of - a data provider, and should only be linked with a record associated (via collection) with that same provider.
  • Loading branch information
marksparkza committed Nov 23, 2023
1 parent 6704684 commit 0b08dba
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 1 deletion.
Binary file modified ERD.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
"""Link package to provider
Revision ID: 1eea59d91fea
Revises: 220060b4adb3
Create Date: 2023-11-23 14:48:06.777908
"""
from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision = '1eea59d91fea'
down_revision = '220060b4adb3'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - adjusted ###
op.add_column('package', sa.Column('provider_id', sa.String(), nullable=False))
op.create_foreign_key('package_provider_id_fkey', 'package', 'provider', ['provider_id'], ['id'], ondelete='CASCADE')
# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - adjusted ###
op.drop_constraint('package_provider_id_fkey', 'package', type_='foreignkey')
op.drop_column('package', 'provider_id')
# ### end Alembic commands ###
5 changes: 4 additions & 1 deletion odp/db/models/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,13 @@ class Package(Base):
metadata_ = Column(JSONB)
timestamp = Column(TIMESTAMP(timezone=True), nullable=False)

provider_id = Column(String, ForeignKey('provider.id', ondelete='CASCADE'), nullable=False)
provider = relationship('Provider')

record_id = Column(String, ForeignKey('record.id', ondelete='SET NULL'))
record = relationship('Record')

_repr_ = 'id', 'record_id',
_repr_ = 'id', 'provider_id', 'record_id',


class PackageResource(Base):
Expand Down

0 comments on commit 0b08dba

Please sign in to comment.