aboutsummaryrefslogtreecommitdiff
path: root/frontend/migrations/010_add_protection_to_hosts.py
blob: fc01b77112e1a9d5d8fa6db9efaf7da5495a0c65 (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
from autotest_lib.client.common_lib import global_config, host_protections

def migrate_up(manager):
    manager.execute_script(ADD_PROTECTION_COLUMN)

def migrate_down(manager):
    manager.execute(DROP_COLUMN)

default_protection = global_config.global_config.get_config_value(
    'HOSTS', 'default_protection')
default_protection_value = host_protections.Protection.get_value(
    default_protection)

ADD_PROTECTION_COLUMN = """ALTER TABLE hosts
                           ADD COLUMN protection INT NOT NULL
                           DEFAULT %s;

                           ALTER TABLE hosts
                           ALTER COLUMN protection
                           DROP DEFAULT;
                           """ % default_protection_value

DROP_COLUMN = """ALTER TABLE hosts
                 DROP COLUMN protection"""