summaryrefslogtreecommitdiffstats
path: root/kittystore/storm/schema/patch_7.py
blob: 9607d1da5db0b6c6502672e2fbb40a4e98500a93 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# -*- coding: utf-8 -*-

from __future__ import absolute_import

from . import get_db_type


SQL = {
    "sqlite": [
        # No 'ALTER TABLE DROP COLUMN' in SQLite
        'ALTER TABLE "list" ADD COLUMN subject_prefix TEXT;',
        'UPDATE "list" SET subject_prefix = \'[\' || display_name || \']\';'
        ],
    "postgres": [
        'ALTER TABLE "list" DROP COLUMN "description";',
        'ALTER TABLE "list" ADD COLUMN subject_prefix TEXT;',
        'UPDATE "list" SET subject_prefix = \'[\' || display_name || \']\';',
        ],
    "mysql": [
        'ALTER TABLE `list` DROP COLUMN `description`;',
        'ALTER TABLE `list` ADD COLUMN subject_prefix TEXT;',
        'UPDATE `list`" SET subject_prefix = CONCAT(\'[\', display_name, \']\');',
        ],
    }


def apply(store):
    """Add the subject_prefix column and delete the description column"""
    dbtype = get_db_type(store)
    for statement in SQL[dbtype]:
        store.execute(statement)
    store.commit()