mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-09-24 16:30:27 +08:00
Merge pull request #12698 from ic4f/dev_sa20prep_1
Misc. fixes for SQLAlchemy 2.0
This commit is contained in:
@@ -9025,7 +9025,7 @@ mapper_registry.map_imperatively(
|
||||
# The following statements must not precede the mapped models defined above.
|
||||
|
||||
Job.any_output_dataset_collection_instances_deleted = column_property(
|
||||
exists([HistoryDatasetCollectionAssociation.id], and_(
|
||||
exists(HistoryDatasetCollectionAssociation.id).where(and_(
|
||||
Job.id == JobToOutputDatasetCollectionAssociation.job_id,
|
||||
HistoryDatasetCollectionAssociation.id == JobToOutputDatasetCollectionAssociation.dataset_collection_id,
|
||||
HistoryDatasetCollectionAssociation.deleted == true())
|
||||
@@ -9033,7 +9033,7 @@ Job.any_output_dataset_collection_instances_deleted = column_property(
|
||||
)
|
||||
|
||||
Job.any_output_dataset_deleted = column_property(
|
||||
exists([HistoryDatasetAssociation], and_(
|
||||
exists(HistoryDatasetAssociation).where(and_(
|
||||
Job.id == JobToOutputDatasetAssociation.job_id,
|
||||
HistoryDatasetAssociation.table.c.id == JobToOutputDatasetAssociation.dataset_id,
|
||||
HistoryDatasetAssociation.table.c.deleted == true())
|
||||
|
||||
@@ -200,4 +200,6 @@ def execute_statements(engine, raw_sql):
|
||||
statements = raw_sql if isinstance(raw_sql, list) else [raw_sql]
|
||||
for sql in statements:
|
||||
cmd = DDL(sql)
|
||||
cmd.execute(bind=engine)
|
||||
with engine.connect() as connection:
|
||||
with connection.begin():
|
||||
connection.execute(cmd)
|
||||
|
||||
@@ -1394,7 +1394,7 @@ class DirectoryModelExportStore(ModelExportStore):
|
||||
# Write datasets' attributes to file.
|
||||
query = (sa_session.query(model.HistoryDatasetAssociation)
|
||||
.filter(model.HistoryDatasetAssociation.history == history)
|
||||
.join("dataset")
|
||||
.join(model.Dataset)
|
||||
.options(joinedload("dataset").joinedload("actions"))
|
||||
.order_by(model.HistoryDatasetAssociation.hid)
|
||||
.filter(model.Dataset.purged == expression.false()))
|
||||
|
||||
@@ -2,12 +2,16 @@
|
||||
Galaxy sql view models
|
||||
"""
|
||||
from sqlalchemy import Integer
|
||||
from sqlalchemy.orm import mapper
|
||||
from sqlalchemy.orm import registry
|
||||
from sqlalchemy.sql import column, text
|
||||
|
||||
from galaxy.model.view.utils import View
|
||||
|
||||
AGGREGATE_STATE_QUERY = """
|
||||
|
||||
class HistoryDatasetCollectionJobStateSummary(View):
|
||||
name = 'collection_job_state_summary_view'
|
||||
|
||||
aggregate_state_query = """
|
||||
SELECT
|
||||
hdca_id,
|
||||
SUM(CASE WHEN state = 'new' THEN 1 ELSE 0 END) AS new,
|
||||
@@ -43,11 +47,7 @@ FROM (
|
||||
GROUP BY jobstates.hdca_id
|
||||
"""
|
||||
|
||||
|
||||
class HistoryDatasetCollectionJobStateSummary(View):
|
||||
name = 'collection_job_state_summary_view'
|
||||
|
||||
__view__ = text(AGGREGATE_STATE_QUERY).columns(
|
||||
__view__ = text(aggregate_state_query).columns(
|
||||
column('hdca_id', Integer),
|
||||
column('new', Integer),
|
||||
column('resubmitted', Integer),
|
||||
@@ -67,4 +67,6 @@ class HistoryDatasetCollectionJobStateSummary(View):
|
||||
__table__ = View._make_table(name, __view__, pkeys)
|
||||
|
||||
|
||||
mapper(HistoryDatasetCollectionJobStateSummary, HistoryDatasetCollectionJobStateSummary.__table__)
|
||||
mapper_registry = registry()
|
||||
mapper_registry.map_imperatively(
|
||||
HistoryDatasetCollectionJobStateSummary, HistoryDatasetCollectionJobStateSummary.__table__)
|
||||
|
||||
@@ -76,5 +76,6 @@ def install_views(engine):
|
||||
# it mocks the app and CreateView will attempt to rebuild an existing
|
||||
# view in a database that is already made, the right answer is probably
|
||||
# to change the sql that gest emitted when CreateView is rendered.
|
||||
engine.execute(DropView(view.name))
|
||||
engine.execute(CreateView(view.name, view.__view__))
|
||||
with engine.begin() as conn:
|
||||
conn.execute(DropView(view.name))
|
||||
conn.execute(CreateView(view.name, view.__view__))
|
||||
|
||||
@@ -82,8 +82,8 @@ def make_table(metadata):
|
||||
|
||||
def run_view_test(url, metadata, view, query):
|
||||
with sqlalchemy_engine(url) as engine:
|
||||
with engine.connect() as conn:
|
||||
with engine.begin() as conn:
|
||||
metadata.create_all(conn) # create table in database
|
||||
conn.execute(CreateView(view.name, view.__view__)) # create view in database
|
||||
result = conn.execute(query).fetchall()
|
||||
result = conn.execute(text(query)).fetchall()
|
||||
assert len(result) == 1 # assert that view exists in database
|
||||
|
||||
Reference in New Issue
Block a user