Debian Codegraph @

taskflow/persistence/backends/sqlalchemy/alembic/versions/2ad4984f2864_switch_postgres_to_json_native.py

raw
1 # Copyright (C) 2012-2013 Yahoo! Inc. All Rights Reserved.
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License"); you may
4 # not use this file except in compliance with the License. You may obtain
5 # a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 # License for the specific language governing permissions and limitations
13 # under the License.
14
15 """Switch postgres to json native type.
16
17 Revision ID: 2ad4984f2864
18 Revises: 3162c0f3f8e4
19 Create Date: 2015-06-04 13:08:36.667948
20
21 """
22
23 # revision identifiers, used by Alembic.
24 revision = '2ad4984f2864'
25 down_revision = '3162c0f3f8e4'
26
27 from alembic import op
28
29
30 _ALTER_TO_JSON_TPL = 'ALTER TABLE %s ALTER COLUMN %s TYPE JSON USING %s::JSON'
31 _TABLES_COLS = tuple([
32 ('logbooks', 'meta'),
33 ('flowdetails', 'meta'),
34 ('atomdetails', 'meta'),
35 ('atomdetails', 'failure'),
36 ('atomdetails', 'revert_failure'),
37 ('atomdetails', 'results'),
38 ('atomdetails', 'revert_results'),
39 ])
40 _ALTER_TO_TEXT_TPL = 'ALTER TABLE %s ALTER COLUMN %s TYPE TEXT'
41
42
43 def upgrade():
44 b = op.get_bind()
45 if b.dialect.name.startswith('postgresql'):
46 for (table_name, col_name) in _TABLES_COLS:
47 q = _ALTER_TO_JSON_TPL % (table_name, col_name, col_name)
48 op.execute(q)
49
50
51 def downgrade():
52 b = op.get_bind()
53 if b.dialect.name.startswith('postgresql'):
54 for (table_name, col_name) in _TABLES_COLS:
55 q = _ALTER_TO_TEXT_TPL % (table_name, col_name)
56 op.execute(q)