Revert "[autotest] Remove synch_id from database"

This reverts commit eb97ee7fffb4a2ef3155b07f2aa71f04d574b642.
But not quite. We never revert DB migration scripts, especially if
they've been run on any servers. So, this CL adds a new migration (111)
to revert the migration (110) that was already applied to the test
servers.
To reland, remove synch_id once again via a new migration.

Reason for revert:
This CL requires lab downtime for push-to-prod because host_scheduler
can not be cleanly restarted across this CL.

To push this CL to lab, one must:
- close the lab.
- migrate DB to the new schema (host_scheduler starts failing)
- push the CL to lab (host_scheduler recovers)
- open the lab.

Now is not the time to do this dance, so reverting with the hope to
reland at a better time.

BUG=chromium:696691
TEST=test_push host_scheduler can start with tip-of-tree code and with
tip-of-prod after applying both migration 110 and 111.

Change-Id: If2f5428f100af400d498eded9dfb08d6f22aa4dc
Reviewed-on: https://chromium-review.googlesource.com/447200
Tested-by: Prathmesh Prabhu <pprabhu@chromium.org>
Reviewed-by: Dan Shi <dshi@google.com>
diff --git a/frontend/afe/doctests/001_rpc_test.txt b/frontend/afe/doctests/001_rpc_test.txt
index c944353..89e29d6 100644
--- a/frontend/afe/doctests/001_rpc_test.txt
+++ b/frontend/afe/doctests/001_rpc_test.txt
@@ -109,6 +109,7 @@
 >>> data == [{'id': 1,
 ...           'hostname': 'ipaj1',
 ...           'locked': 1,
+...           'synch_id': None,
 ...           'status': 'Ready',
 ...           'labels': [],
 ...           'atomic_group': None,
@@ -469,6 +470,7 @@
 ...           'invalid': 0,
 ...           'locked': 0,
 ...           'status': 'Ready',
+...           'synch_id': None,
 ...           'protection': 'No protection',
 ...           'locked_by': None,
 ...           'lock_time': None,
diff --git a/frontend/afe/models_test.py b/frontend/afe/models_test.py
index f0cf5ab..a4eabfd 100755
--- a/frontend/afe/models_test.py
+++ b/frontend/afe/models_test.py
@@ -1,14 +1,13 @@
 #!/usr/bin/python
 
+import datetime
 import unittest
-
 import common
-from autotest_lib.client.common_lib import control_data
-from autotest_lib.client.common_lib import global_config
 from autotest_lib.frontend import setup_django_environment
 from autotest_lib.frontend.afe import frontend_test_utils
-from autotest_lib.frontend.afe import model_logic
-from autotest_lib.frontend.afe import models
+from autotest_lib.frontend.afe import models, model_attributes, model_logic
+from autotest_lib.client.common_lib import global_config
+from autotest_lib.client.common_lib import control_data
 
 
 class AclGroupTest(unittest.TestCase,
@@ -447,7 +446,8 @@
                            'locked': False,
                            'protection': 0,
                            'shard': {'hostname': '1', 'id': 1},
-                           'status': 'Ready'}],
+                           'status': 'Ready',
+                           'synch_id': None}],
                 'jobs': [{'control_file': 'some control file\n\n\n',
                           'control_type': 2,
                           'created_on': '2014-09-04T13:09:35',
diff --git a/frontend/afe/rdb_model_extensions.py b/frontend/afe/rdb_model_extensions.py
index 4444122..12ba892 100644
--- a/frontend/afe/rdb_model_extensions.py
+++ b/frontend/afe/rdb_model_extensions.py
@@ -184,6 +184,9 @@
     hostname = dbmodels.CharField(max_length=255, unique=True)
     locked = dbmodels.BooleanField(default=False)
     leased = dbmodels.BooleanField(default=True)
+    # TODO(ayatane): This is needed until synch_id is removed from Host._fields
+    synch_id = dbmodels.IntegerField(blank=True, null=True,
+                                     editable=settings.FULL_ADMIN)
     status = dbmodels.CharField(max_length=255, default=Status.READY,
                                 choices=Status.choices(),
                                 editable=settings.FULL_ADMIN)
diff --git a/frontend/migrations/111_add_back_synch_id_temporarily.py b/frontend/migrations/111_add_back_synch_id_temporarily.py
new file mode 100644
index 0000000..839b8d2
--- /dev/null
+++ b/frontend/migrations/111_add_back_synch_id_temporarily.py
@@ -0,0 +1,7 @@
+UP_SQL = """
+ALTER TABLE `afe_hosts` ADD `synch_id` int(11) default NULL;
+"""
+
+DOWN_SQL = """
+ALTER TABLE `afe_hosts` DROP COLUMN `synch_id`;
+"""
diff --git a/scheduler/scheduler_models.py b/scheduler/scheduler_models.py
index 80c8a47..60436b8 100644
--- a/scheduler/scheduler_models.py
+++ b/scheduler/scheduler_models.py
@@ -390,7 +390,8 @@
 
 class Host(DBObject):
     _table_name = 'afe_hosts'
-    _fields = ('id', 'hostname', 'locked', 'status',
+    # TODO(ayatane): synch_id is not used, remove after fixing DB.
+    _fields = ('id', 'hostname', 'locked', 'synch_id', 'status',
                'invalid', 'protection', 'locked_by_id', 'lock_time', 'dirty',
                'leased', 'shard_id', 'lock_reason')