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:
Daniel Smith 2022-11-08 13:09:54 -08:00 коммит произвёл GitHub
Родитель 560c14351a
Коммит deed5e0d78
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 27 добавлений и 6 удалений

Просмотреть файл

@ -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.'

Просмотреть файл

@ -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),
]