How to make a column as FK from two tables in two different and unrelated services?

Viewed 19

Assume that there are 2 unconnected and different services: Service-A & Service-B.

The table that I have in Service-A:

class ServiceATable(Base):
    id = Column(Integer, primary_key=True)
    received_encrypted = Column(Boolean)
    encryption_author = Column(String(150))
    decryption_state = Column(Boolean)

The table in Service-B:

class ServiceBTable(Base):
    id = Column(Integer, primary_key=True)
    id_from_service_a = Column(Integer) 
    filename = Column(String(200))
    forwarding_to = Column(String(150))

What I am trying to do is to use the id column in the Service-A table and make it a Foreign Key in the Service-B table in the column id_from_service_a, so that the Service-B table looks something like this:

from sqlalchemy import ForeignKey

class ServiceBTable(Base):
    id = Column(Integer, primary_key=True)
    id_from_service_a = Column(Integer, ForeignKey('id-from-service-a'))
    filename = Column(String(200))
    forwarding_to = Column(String(150))

Since both the tables are in 2 different services, I don't think I can use the Basic Relationship Patterns as it assumes that both the tables are created in the same service.

Is there a way I can achieve the following?

0 Answers
Related