Add default value to updated field (#2453)
* Add default value to updated field * change name * commas * explicit dates in testing
This commit is contained in:
Родитель
560c14351a
Коммит
deed5e0d78
|
@ -356,7 +356,7 @@ class FeatureEntry(ndb.Model): # Copy from Feature
|
|||
|
||||
# Metadata: Creation and updates.
|
||||
created = ndb.DateTimeProperty(auto_now_add=True)
|
||||
updated = ndb.DateTimeProperty()
|
||||
updated = ndb.DateTimeProperty(auto_now_add=True)
|
||||
accurate_as_of = ndb.DateTimeProperty()
|
||||
creator_email = ndb.StringProperty()
|
||||
updater_email = ndb.StringProperty()
|
||||
|
|
|
@ -12,6 +12,7 @@
|
|||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
|
||||
from datetime import datetime
|
||||
import testing_config # Must be imported before the module under test.
|
||||
|
||||
from api import converters
|
||||
|
@ -49,22 +50,26 @@ class FeatureTest(testing_config.CustomTestCase):
|
|||
def setUp(self):
|
||||
self.feature_2 = core_models.FeatureEntry(
|
||||
name='feature b', summary='sum',
|
||||
owner_emails=['feature_owner@example.com'], category=1)
|
||||
owner_emails=['feature_owner@example.com'], category=1,
|
||||
updated=datetime(2020, 4, 1))
|
||||
self.feature_2.put()
|
||||
|
||||
self.feature_1 = core_models.FeatureEntry(
|
||||
name='feature a', summary='sum', impl_status_chrome=3,
|
||||
owner_emails=['feature_owner@example.com'], category=1)
|
||||
owner_emails=['feature_owner@example.com'], category=1,
|
||||
updated=datetime(2020, 3, 1))
|
||||
self.feature_1.put()
|
||||
|
||||
self.feature_4 = core_models.FeatureEntry(
|
||||
name='feature d', summary='sum', category=1, impl_status_chrome=2,
|
||||
owner_emails=['feature_owner@example.com'])
|
||||
owner_emails=['feature_owner@example.com'],
|
||||
updated=datetime(2020, 2, 1))
|
||||
self.feature_4.put()
|
||||
|
||||
self.feature_3 = core_models.FeatureEntry(
|
||||
name='feature c', summary='sum', category=1, impl_status_chrome=2,
|
||||
owner_emails=['feature_owner@example.com'])
|
||||
owner_emails=['feature_owner@example.com'],
|
||||
updated=datetime(2020, 1, 1))
|
||||
self.feature_3.put()
|
||||
|
||||
# Legacy entities for testing legacy functions.
|
||||
|
|
|
@ -425,3 +425,18 @@ class DeleteNewEntities(FlaskHandler):
|
|||
count += 1
|
||||
|
||||
return f'{count} entities deleted.'
|
||||
|
||||
class WriteUpdatedField(FlaskHandler):
|
||||
|
||||
def get_template_data(self, **kwargs) -> str:
|
||||
"""Sets the FeatureEntry updated field if it is not initialized."""
|
||||
self.require_cron_header()
|
||||
|
||||
count = 0
|
||||
for fe in FeatureEntry.query():
|
||||
if fe.updated is None:
|
||||
fe.updated = fe.created
|
||||
fe.put()
|
||||
count += 1
|
||||
|
||||
return f'{count} FeatureEntry entities given updated field values.'
|
||||
|
|
3
main.py
3
main.py
|
@ -210,7 +210,8 @@ internals_routes: list[tuple] = [
|
|||
('/admin/schema_migration_comment_activity', schema_migration.MigrateCommentsToActivities),
|
||||
('/admin/schema_migration_write_entities', schema_migration.MigrateEntities),
|
||||
('/admin/schema_migration_approval_vote', schema_migration.MigrateApprovalsToVotes),
|
||||
('/admin/schema_migration_gate_status', schema_migration.EvaluateGateStatus)
|
||||
('/admin/schema_migration_gate_status', schema_migration.EvaluateGateStatus),
|
||||
('/admin/schema_migration_updated_field', schema_migration.WriteUpdatedField),
|
||||
]
|
||||
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче