diff --git a/ERD.png b/ERD.png index d13e460..bad92a2 100644 Binary files a/ERD.png and b/ERD.png differ diff --git a/migrate/versions/2023_11_23_1eea59d91fea_link_package_to_provider.py b/migrate/versions/2023_11_23_1eea59d91fea_link_package_to_provider.py new file mode 100644 index 0000000..34ac376 --- /dev/null +++ b/migrate/versions/2023_11_23_1eea59d91fea_link_package_to_provider.py @@ -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 ### diff --git a/odp/db/models/package.py b/odp/db/models/package.py index 57e644f..60e130b 100644 --- a/odp/db/models/package.py +++ b/odp/db/models/package.py @@ -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):