Support SQL Alchemy 2.0
Running gertty on a more modern OS like Fedora 38, you get the following error: sqlalchemy.exc.InvalidRequestError: The 'sqlalchemy.orm.mapper()' function is removed as of SQLAlchemy 2.0. Use the 'sqlalchemy.orm.registry.map_imperatively()` method of the ``sqlalchemy.orm.registry`` class to perform classical mapping. This updates Gertty to accomodate the changes in SQL Alchemy 2.0. Change-Id: I793e997d767c8419a0baaac9a074d6997b834a7c
This commit is contained in:
parent
559bcfdb33
commit
ad414c8410
41
gertty/db.py
41
gertty/db.py
@ -25,12 +25,13 @@ import six
|
||||
import sqlalchemy
|
||||
from sqlalchemy import create_engine, MetaData, Table, Column, Integer, String, Boolean, DateTime, Text, UniqueConstraint
|
||||
from sqlalchemy.schema import ForeignKey
|
||||
from sqlalchemy.orm import mapper, sessionmaker, relationship, scoped_session, joinedload
|
||||
from sqlalchemy.orm import registry, sessionmaker, relationship, scoped_session, joinedload
|
||||
from sqlalchemy.orm.session import Session
|
||||
from sqlalchemy.sql import exists
|
||||
from sqlalchemy.sql.expression import and_
|
||||
|
||||
metadata = MetaData()
|
||||
mapper_registry = registry()
|
||||
project_table = Table(
|
||||
'project', metadata,
|
||||
Column('key', Integer, primary_key=True),
|
||||
@ -713,8 +714,8 @@ class Check(object):
|
||||
self.created = created
|
||||
self.updated = updated
|
||||
|
||||
mapper(Account, account_table)
|
||||
mapper(Project, project_table, properties=dict(
|
||||
mapper_registry.map_imperatively(Account, account_table)
|
||||
mapper_registry.map_imperatively(Project, project_table, properties=dict(
|
||||
branches=relationship(Branch, backref='project',
|
||||
order_by=branch_table.c.name,
|
||||
cascade='all, delete-orphan'),
|
||||
@ -740,16 +741,16 @@ mapper(Project, project_table, properties=dict(
|
||||
order_by=change_table.c.number,
|
||||
),
|
||||
))
|
||||
mapper(Branch, branch_table)
|
||||
mapper(Topic, topic_table, properties=dict(
|
||||
mapper_registry.map_imperatively(Branch, branch_table)
|
||||
mapper_registry.map_imperatively(Topic, topic_table, properties=dict(
|
||||
projects=relationship(Project,
|
||||
secondary=project_topic_table,
|
||||
order_by=project_table.c.name,
|
||||
viewonly=True),
|
||||
project_topics=relationship(ProjectTopic),
|
||||
))
|
||||
mapper(ProjectTopic, project_topic_table)
|
||||
mapper(Change, change_table, properties=dict(
|
||||
mapper_registry.map_imperatively(ProjectTopic, project_topic_table)
|
||||
mapper_registry.map_imperatively(Change, change_table, properties=dict(
|
||||
owner=relationship(Account),
|
||||
conflicts1=relationship(Change,
|
||||
secondary=change_conflict_table,
|
||||
@ -787,7 +788,7 @@ mapper(Change, change_table, properties=dict(
|
||||
order_by=(approval_table.c.category,
|
||||
approval_table.c.value))
|
||||
))
|
||||
mapper(Revision, revision_table, properties=dict(
|
||||
mapper_registry.map_imperatively(Revision, revision_table, properties=dict(
|
||||
messages=relationship(Message, backref='revision',
|
||||
cascade='all, delete-orphan'),
|
||||
files=relationship(File, backref='revision',
|
||||
@ -798,9 +799,9 @@ mapper(Revision, revision_table, properties=dict(
|
||||
cascade='all, delete-orphan'),
|
||||
|
||||
))
|
||||
mapper(Message, message_table, properties=dict(
|
||||
mapper_registry.map_imperatively(Message, message_table, properties=dict(
|
||||
author=relationship(Account)))
|
||||
mapper(File, file_table, properties=dict(
|
||||
mapper_registry.map_imperatively(File, file_table, properties=dict(
|
||||
comments=relationship(Comment, backref='file',
|
||||
order_by=(comment_table.c.line,
|
||||
comment_table.c.created),
|
||||
@ -812,20 +813,20 @@ mapper(File, file_table, properties=dict(
|
||||
comment_table.c.created)),
|
||||
))
|
||||
|
||||
mapper(Comment, comment_table, properties=dict(
|
||||
mapper_registry.map_imperatively(Comment, comment_table, properties=dict(
|
||||
author=relationship(Account)))
|
||||
mapper(Label, label_table)
|
||||
mapper(PermittedLabel, permitted_label_table)
|
||||
mapper(Approval, approval_table, properties=dict(
|
||||
mapper_registry.map_imperatively(Label, label_table)
|
||||
mapper_registry.map_imperatively(PermittedLabel, permitted_label_table)
|
||||
mapper_registry.map_imperatively(Approval, approval_table, properties=dict(
|
||||
reviewer=relationship(Account)))
|
||||
mapper(PendingCherryPick, pending_cherry_pick_table)
|
||||
mapper(SyncQuery, sync_query_table)
|
||||
mapper(Hashtag, hashtag_table)
|
||||
mapper(Server, server_table, properties=dict(
|
||||
mapper_registry.map_imperatively(PendingCherryPick, pending_cherry_pick_table)
|
||||
mapper_registry.map_imperatively(SyncQuery, sync_query_table)
|
||||
mapper_registry.map_imperatively(Hashtag, hashtag_table)
|
||||
mapper_registry.map_imperatively(Server, server_table, properties=dict(
|
||||
own_account=relationship(Account)
|
||||
))
|
||||
mapper(Checker, checker_table)
|
||||
mapper(Check, check_table, properties=dict(
|
||||
mapper_registry.map_imperatively(Checker, checker_table)
|
||||
mapper_registry.map_imperatively(Check, check_table, properties=dict(
|
||||
checker=relationship(Checker)))
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user