mirror of
https://github.com/zulip/zulip.git
synced 2025-10-23 04:52:12 +00:00
test_fixtures: Add DB function to write database digest.
This will give help up write new digest only if the db rebuild succeeds. We were relying on the caller to be successful in building db, this was hacky and unreliable. We write new db digest once the caller succeeds, this ensures that we write new digest after every successful attempt. This fixes the anomality we were facing that Databases were rebuild on the 2nd provision attempt with no changes to files or migrations. This was happening because we didn't write a new digest for db after the first provision (The case of DB didn't exist). During the 1st provision, we check the template_status() of Database both Dev and Test, but database_exists() of Databases obviously returned false, and we rebuild the database, but forgot to write_new_digest and hence the anomaly in the second provision explained above.
This commit is contained in:
@@ -251,6 +251,7 @@ def main(options: argparse.Namespace) -> int:
|
||||
if options.is_force or dev_template_db_status == 'needs_rebuild':
|
||||
run(["tools/setup/postgres-init-dev-db"])
|
||||
run(["tools/rebuild-dev-database"])
|
||||
DEV_DATABASE.write_new_db_digest()
|
||||
elif dev_template_db_status == 'run_migrations':
|
||||
DEV_DATABASE.run_db_migrations()
|
||||
elif dev_template_db_status == 'current':
|
||||
@@ -260,6 +261,7 @@ def main(options: argparse.Namespace) -> int:
|
||||
if options.is_force or test_template_db_status == 'needs_rebuild':
|
||||
run(["tools/setup/postgres-init-test-db"])
|
||||
run(["tools/rebuild-test-database"])
|
||||
TEST_DATABASE.write_new_db_digest()
|
||||
elif test_template_db_status == 'run_migrations':
|
||||
TEST_DATABASE.run_db_migrations()
|
||||
elif test_template_db_status == 'current':
|
||||
|
@@ -187,15 +187,6 @@ class Database:
|
||||
return 'needs_rebuild'
|
||||
|
||||
if self.files_or_settings_have_changed():
|
||||
# Write the new hash, relying on our callers to
|
||||
# actually rebuild the db successfully.
|
||||
# TODO: Move this code to the callers, and write
|
||||
# the digest only AFTER the rebuild succeeds.
|
||||
write_new_digest(
|
||||
self.digest_name,
|
||||
IMPORTANT_FILES,
|
||||
self.important_settings(),
|
||||
)
|
||||
return 'needs_rebuild'
|
||||
|
||||
# Here we hash and compare our migration files before doing
|
||||
@@ -238,6 +229,13 @@ class Database:
|
||||
migration_paths(),
|
||||
)
|
||||
|
||||
def write_new_db_digest(self) -> None:
|
||||
write_new_digest(
|
||||
self.digest_name,
|
||||
IMPORTANT_FILES,
|
||||
self.important_settings(),
|
||||
)
|
||||
|
||||
DEV_DATABASE = Database(
|
||||
platform='dev',
|
||||
database_name='zulip',
|
||||
@@ -271,6 +269,7 @@ def update_test_databases_if_required(rebuild_test_database: bool=False) -> None
|
||||
|
||||
if test_template_db_status == 'needs_rebuild':
|
||||
run(['tools/rebuild-test-database'])
|
||||
TEST_DATABASE.write_new_db_digest()
|
||||
return
|
||||
|
||||
if test_template_db_status == 'run_migrations':
|
||||
|
Reference in New Issue
Block a user