Repository :
http://git.fedorahosted.org/cgit/copr.git
On branch : master
---------------------------------------------------------------
commit 0d4343815e25fc92e5c2d0a6e15070bcc7bf8cef
Author: Miroslav Such�� <msuchy(a)redhat.com>
Date: Mon Nov 16 22:43:40 2015 +0100
move status_to_order() definition to alembic
---------------------------------------------------------------
.../19ca0c14096e_status_to_order_function.py | 52 ++++++++++++++++++++
.../coprs_frontend/coprs/logic/builds_logic.py | 30 +-----------
2 files changed, 53 insertions(+), 29 deletions(-)
diff --git
a/frontend/coprs_frontend/alembic/versions/19ca0c14096e_status_to_order_function.py
b/frontend/coprs_frontend/alembic/versions/19ca0c14096e_status_to_order_function.py
new file mode 100644
index 0000000..6db6ad5
--- /dev/null
+++ b/frontend/coprs_frontend/alembic/versions/19ca0c14096e_status_to_order_function.py
@@ -0,0 +1,52 @@
+"""status_to_order function
+
+Revision ID: 19ca0c14096e
+Revises: 3ec22e1db75a
+Create Date: 2015-11-16 21:20:46.498155
+
+"""
+
+# revision identifiers, used by Alembic.
+revision = '19ca0c14096e'
+down_revision = '3ec22e1db75a'
+
+from alembic import op
+import sqlalchemy as sa
+
+
+def upgrade():
+ query_functions = """
+CREATE OR REPLACE FUNCTION status_to_order (x integer)
+RETURNS integer AS $$ BEGIN
+ RETURN CASE WHEN x = 0 THEN 0
+ WHEN x = 3 THEN 1
+ WHEN x = 6 THEN 2
+ WHEN x = 7 THEN 3
+ WHEN x = 4 THEN 4
+ WHEN x = 1 THEN 5
+ WHEN x = 5 THEN 6
+ ELSE 1000
+ END; END;
+ $$ LANGUAGE plpgsql;
+
+CREATE OR REPLACE FUNCTION order_to_status (x integer)
+RETURNS integer AS $$ BEGIN
+ RETURN CASE WHEN x = 0 THEN 0
+ WHEN x = 1 THEN 3
+ WHEN x = 2 THEN 6
+ WHEN x = 3 THEN 7
+ WHEN x = 4 THEN 4
+ WHEN x = 5 THEN 1
+ WHEN x = 6 THEN 5
+ ELSE 1000
+ END; END;
+ $$ LANGUAGE plpgsql;
+"""
+ op.execute(sa.text(query_functions))
+
+
+def downgrade():
+ query = """DROP FUNCTION status_to_order (x integer);
+ DROP FUNCTION order_to_status (x integer);
+ """
+ op.execute(sa.text(query))
diff --git a/frontend/coprs_frontend/coprs/logic/builds_logic.py
b/frontend/coprs_frontend/coprs/logic/builds_logic.py
index 335175c..bda8aeb 100644
--- a/frontend/coprs_frontend/coprs/logic/builds_logic.py
+++ b/frontend/coprs_frontend/coprs/logic/builds_logic.py
@@ -125,33 +125,6 @@ class BuildsLogic(object):
@classmethod
def get_copr_builds_list(cls, copr):
- query_functions = """
-CREATE OR REPLACE FUNCTION status_to_order (x integer)
-RETURNS integer AS $$ BEGIN
- RETURN CASE WHEN x = 0 THEN 0
- WHEN x = 3 THEN 1
- WHEN x = 6 THEN 2
- WHEN x = 7 THEN 3
- WHEN x = 4 THEN 4
- WHEN x = 1 THEN 5
- WHEN x = 5 THEN 6
- ELSE 1000
- END; END;
- $$ LANGUAGE plpgsql;
-
-CREATE OR REPLACE FUNCTION order_to_status (x integer)
-RETURNS integer AS $$ BEGIN
- RETURN CASE WHEN x = 0 THEN 0
- WHEN x = 1 THEN 3
- WHEN x = 2 THEN 6
- WHEN x = 3 THEN 7
- WHEN x = 4 THEN 4
- WHEN x = 5 THEN 1
- WHEN x = 6 THEN 5
- ELSE 1000
- END; END;
- $$ LANGUAGE plpgsql;
-"""
query_select = """
SELECT build.id, MAX(package.name) AS pkg_name, build.pkg_version, build.submitted_on,
MIN(statuses.started_on) AS started_on, MAX(statuses.ended_on) AS ended_on,
order_to_status(MIN(statuses.st)) AS status,
@@ -211,9 +184,8 @@ GROUP BY
conn.connection.create_function("status_to_order", 1,
sqlite_status_to_order)
conn.connection.create_function("order_to_status", 1,
sqlite_order_to_status)
result = conn.execute(text(query_select))
-
else:
- result = db.engine.execute(text(query_functions+query_select))
+ result = db.engine.execute(text(query_select))
return result