Add new scheme application

This commit is contained in:
Ivan Vazhenin
2023-11-27 20:37:53 +03:00
parent 92dd8162c5
commit 3841f50628
2 changed files with 7 additions and 3 deletions

2
db.py
View File

@@ -96,6 +96,7 @@ class IncomeBranch(Base):
user_id: Mapped[int] = mapped_column(ForeignKey('users.id')) user_id: Mapped[int] = mapped_column(ForeignKey('users.id'))
scheme: Mapped[str] scheme: Mapped[str]
branch: Mapped[str] branch: Mapped[str]
local_scheme: Mapped[str]
user: Mapped['User'] = relationship(back_populates='income_branches') user: Mapped['User'] = relationship(back_populates='income_branches')
@@ -104,6 +105,7 @@ class IncomeBranch(Base):
'id': self.id, 'id': self.id,
'scheme': self.scheme, 'scheme': self.scheme,
'branch': self.branch, 'branch': self.branch,
'local_scheme': self.local_scheme,
} }

View File

@@ -67,8 +67,8 @@ def get_branch(bndname: str, scheme: str):
with Session(conn) as session: with Session(conn) as session:
item = session.query(db.IncomeBranch).filter_by(scheme=scheme).join(db.User).filter_by(bndname=bndname).one_or_none() item = session.query(db.IncomeBranch).filter_by(scheme=scheme).join(db.User).filter_by(bndname=bndname).one_or_none()
if item: if item:
return item.branch return item.branch,item.local_scheme
return None return None, None
def run_tasks(): def run_tasks():
@@ -570,7 +570,9 @@ def apply_commits(params, files, url):
repl = req.find('replication') repl = req.find('replication')
scheme = repl.get('scheme') scheme = repl.get('scheme')
commit = repl.get('id') commit = repl.get('id')
branch = get_branch(params['from'].replace('tcp://', ''), scheme) branch, new_scheme = get_branch(params['from'].replace('tcp://', ''), scheme)
if new_scheme:
scheme = new_scheme
if branch: if branch:
logging.warning(branch) logging.warning(branch)
con = OOConnectionParams(scheme, Config.oodb_host, Config.oodb_port, Config.oodb_dbname, con = OOConnectionParams(scheme, Config.oodb_host, Config.oodb_port, Config.oodb_dbname,