diff --git a/migrations/versions/885123e6a2d6_remove_fk_relation_from_device_to_.py b/migrations/versions/885123e6a2d6_remove_fk_relation_from_device_to_.py new file mode 100644 index 0000000..8cad4b0 --- /dev/null +++ b/migrations/versions/885123e6a2d6_remove_fk_relation_from_device_to_.py @@ -0,0 +1,28 @@ +"""Remove FK relation from device to device_info + +Revision ID: 885123e6a2d6 +Revises: 002656878233 +Create Date: 2019-04-27 14:22:30.841969 + +""" +from alembic import op +import sqlalchemy as sa +from sqlalchemy.dialects import postgresql + +# revision identifiers, used by Alembic. +revision = '885123e6a2d6' +down_revision = '002656878233' +branch_labels = None +depends_on = None + + +def upgrade(): + op.drop_index('ix_device_infos_device_id', table_name='device_infos') + op.drop_constraint('device_infos_device_id_fkey', 'device_infos', type_='foreignkey') + op.drop_column('device_infos', 'device_id') + + +def downgrade(): + op.add_column('device_infos', sa.Column('device_id', sa.INTEGER(), autoincrement=False, nullable=True)) + op.create_foreign_key('device_infos_device_id_fkey', 'device_infos', 'devices', ['device_id'], ['id'], ondelete='SET NULL') + op.create_index('ix_device_infos_device_id', 'device_infos', ['device_id'], unique=False) diff --git a/ogn_python/model/device.py b/ogn_python/model/device.py index f668655..09128dc 100644 --- a/ogn_python/model/device.py +++ b/ogn_python/model/device.py @@ -39,7 +39,6 @@ class Device(db.Model): return query.first() - # Todo: remove FK from DeviceInfo def get_infos(self): query = db.session.query(DeviceInfo) \ .filter(DeviceInfo.address == self.address) \ diff --git a/ogn_python/model/device_info.py b/ogn_python/model/device_info.py index 76fe440..88ed4d9 100644 --- a/ogn_python/model/device_info.py +++ b/ogn_python/model/device_info.py @@ -17,10 +17,6 @@ class DeviceInfo(db.Model): address_origin = db.Column(db.SmallInteger) - # Relations (deprecated) - device_id = db.Column(db.Integer, db.ForeignKey('devices.id', ondelete='SET NULL'), index=True) - device = db.relationship('Device', foreign_keys=[device_id], backref=db.backref('infos', order_by='DeviceInfo.address_origin.asc()')) - def __repr__(self): return "" % ( self.address_type,