Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add versioning to database; migrate if version is not current #4099

Merged
merged 4 commits into from
Jul 20, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions kalite/distributed/management/commands/initialize_kalite.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,19 @@ class Command(BaseCommand):
)

def setup_server_if_needed(self):
"""Run the setup command, if necessary."""

# Ensure that the database has been synced and a Device has been created
"""Run the setup command, if necessary.
It's necessary if the Settings model doesn't have a "database_version" or if that version doesn't match
kalite.version.VERSION, indicating the source has been changed. Then setup is run to create/migrate the db.
"""

try:
assert Settings.get("private_key") and Device.objects.count()
from kalite.version import VERSION

This comment was marked as spam.

This comment was marked as spam.

This comment was marked as spam.

assert Settings.get("database_version") == VERSION
except (DatabaseError, AssertionError):
# Otherwise, run the setup command
self.stdout.write("Setting up KA Lite; this may take a few minutes; please wait!\n")
logging.info("Setting up KA Lite; this may take a few minutes; please wait!\n")
call_command("setup", interactive=False)
# Double check that the setup process successfully created a Device
assert Settings.get("private_key") and Device.objects.count(), "There was an error configuring the server. Please report the output of this command to Learning Equality."
# Double check the setup process worked ok.
assert Settings.get("database_version") == VERSION, "There was an error configuring the server. Please report the output of this command to Learning Equality."

def reinitialize_server(self):
"""Reset the server state."""
Expand Down
15 changes: 10 additions & 5 deletions kalite/distributed/management/commands/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,15 @@ def handle(self, *args, **options):
# Should clean_pyc for (clean) reinstall purposes
# call_command("clean_pyc", interactive=False, verbosity=options.get("verbosity"), path=os.path.join(settings.PROJECT_PATH, ".."))

# Migrate the database
call_command(
"syncdb", interactive=False, verbosity=options.get("verbosity"))
call_command("migrate", merge=True, verbosity=options.get("verbosity"))
# Create *.json and friends database
call_command("syncdb", interactive=False, verbosity=options.get(
"verbosity"), database="assessment_items")
Settings.set("database_version", VERSION)

This comment was marked as spam.

This comment was marked as spam.


# download assessment items
# This can take a long time and lead to Travis stalling. None of this
# is required for tests, and does not apply to the central server.
Expand All @@ -373,11 +382,7 @@ def handle(self, *args, **options):
logging.warning("Skipping assessment item downloading and configuration.")

else:

# Migrate the database
call_command(
"syncdb", interactive=False, verbosity=options.get("verbosity"))
call_command("migrate", merge=True, verbosity=options.get("verbosity"))

# Outdated location of assessment items - move assessment items from their
# old location (CONTENT_ROOT/khan where they were mixed with other content
# items)
Expand Down