Script 19ca0c14096e_status_to_order_function_py
|
|
1 """status_to_order function
2
3 Revision ID: 19ca0c14096e
4 Revises: 3ec22e1db75a
5 Create Date: 2015-11-16 21:20:46.498155
6
7 """
8
9
10 revision = '19ca0c14096e'
11 down_revision = '3ec22e1db75a'
12
13 from alembic import op
14 import sqlalchemy as sa
15
16
18 status_to_order = """
19 CREATE OR REPLACE FUNCTION status_to_order (x integer)
20 RETURNS integer AS $$ BEGIN
21 RETURN CASE WHEN x = 0 THEN 0
22 WHEN x = 3 THEN 1
23 WHEN x = 6 THEN 2
24 WHEN x = 7 THEN 3
25 WHEN x = 4 THEN 4
26 WHEN x = 1 THEN 5
27 WHEN x = 5 THEN 6
28 ELSE 1000
29 END; END;
30 $$ LANGUAGE plpgsql;
31 """
32
33 order_to_status = """
34 CREATE OR REPLACE FUNCTION order_to_status (x integer)
35 RETURNS integer AS $$ BEGIN
36 RETURN CASE WHEN x = 0 THEN 0
37 WHEN x = 1 THEN 3
38 WHEN x = 2 THEN 6
39 WHEN x = 3 THEN 7
40 WHEN x = 4 THEN 4
41 WHEN x = 5 THEN 1
42 WHEN x = 6 THEN 5
43 ELSE 1000
44 END; END;
45 $$ LANGUAGE plpgsql;
46 """
47
48 if op.get_bind().dialect.name == "postgresql":
49 op.execute(status_to_order)
50 op.execute(order_to_status)
51
52
54 query = """DROP FUNCTION status_to_order (x integer);
55 DROP FUNCTION order_to_status (x integer);
56 """
57 if op.get_bind().dialect.name == "postgresql":
58 op.execute(sa.text(query))
59