Closed elear closed 4 months ago
@rohitmohan96 I am not 100% thrilled with one aspect here. I essentially use an additive process for building out the objects that are returned, starting with core and then building with Ble. I don't think this is amenable to some sort of multiple inheritance class, because it could turn into a combinatoric problem.
I took a quick look at the changes and I'm not sure if this is ideal. Instead of having a CoreDevice, BleDevice, etc where each has a unique ID, I think it makes sense to do something like this:
class Device(db.Model):
id = mapped_column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4)
schemas = mapped_column(String())
...
ble_extension: Mapped[Optional["BleExtension"]] = relationship("BleExtension", back_populates="device")
fdo_extension: Mapped[Optional["FdoExtension"]] = relationship("FdoExtension", back_populates="device")
...
class BleExtension(db.Model):
device_id = mapped_column(ForeignKey("device.id"), primary_key=True)
...
class FdoExtension(db.Model):
device_id = mapped_column(ForeignKey("device.id"), primary_key=True)
voucher = mapped_column(String())
With this, we should be able to create a single object and commit it once into the DB. Something like this:
device = Device(...)
if 'urn:ietf:params:scim:schemas:extension:ble:2.0:Device' in schemas:
device.ble_extension = BleExtension(...)
if 'urn:ietf:params:scim:schemas:extension:fdo:2.0:Device' in schemas:
device.fdo_extension = FdoExtension(voucher=voucher)
session.add(device)
session.commit()
I can get with that. Give me a few more days.
Not quite clear to me what we back_populate and why. Otherwise I get it.
I don't think you need it. I initially had a device object in the extension along with the device id but I removed that pasting that snippet.
Ok. I have a plan for all calls. There were two issues to work out: serialization and search.
Still a work in progress.
More work is needed, but this PR is already huge.
This PR is the first round of normalization for other technologies. More work will be needed, but the databases are separated, and BLE is somewhat more walled off than it was.
Also changed: