1from autotest_lib.client.common_lib import global_config
2
3def migrate_up(manager):
4    # Add the column with a default first, and then drop the default.
5    # We cannot add the column, populate the values, and then specify NOT NULL
6    # because a record added while this is executing could enter a null value
7    # into the table before NOT NULL is specified.
8    manager.execute(ADD_COLUMN)
9    manager.execute(DROP_DEFAULT)
10
11def migrate_down(manager):
12    manager.execute(DROP_COLUMN)
13
14job_timeout_default = global_config.global_config.get_config_value(
15    'AUTOTEST_WEB', 'job_timeout_default')
16ADD_COLUMN = ('ALTER TABLE jobs ADD COLUMN timeout INT NOT NULL DEFAULT %s'
17              % job_timeout_default)
18DROP_DEFAULT = 'ALTER TABLE jobs ALTER COLUMN timeout DROP DEFAULT'
19DROP_COLUMN = 'ALTER TABLE jobs DROP COLUMN timeout'
20