Skip to content

Commit

Permalink
initialize_db command now handles all db initialization for localdev
Browse files Browse the repository at this point in the history
  • Loading branch information
jlaney committed May 3, 2024
1 parent b884f8a commit 1d4bae1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
26 changes: 26 additions & 0 deletions compass/management/commands/initialize_db.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,37 @@

from django.core.management.base import BaseCommand
from django.core.management import call_command
from django.db import connections
from django.apps import apps


class Command(BaseCommand):

def create_person_models(self):
unmanaged_models = [m for m in apps.get_models() if (
m._meta.app_label == 'uw_person_client' and
m._meta.managed is False)]

connection = connections['uw_person']
existing_tables = connection.introspection.table_names()

with connection.schema_editor() as schema_editor:
for model in unmanaged_models:
if model._meta.db_table not in existing_tables:
schema_editor.create_model(model)

def handle(self, *args, **options):
self.create_person_models()

# Load uw_person data
for fixture in [
'person.json', 'employee.json', 'term.json', 'major.json',
'student.json', 'adviser.json', 'transfer.json',
'transcript.json', 'hold.json', 'degree.json', 'sport.json']:
call_command('loaddata', fixture, '--database', 'uw_person',
'--app', 'uw_person_client')

# Load compass data
call_command('loaddata', 'initial_data/access-groups.json')
call_command('loaddata', 'initial_data/affiliations.json')
call_command('loaddata', 'initial_data/cohorts.json')
Expand Down
2 changes: 0 additions & 2 deletions docker/app_start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ then
source "/app/bin/activate"

cd /app
python manage.py migrate
python manage.py initialize_db
python manage.py loaddata person employee term major student adviser transfer transcript hold degree sport

fi

0 comments on commit 1d4bae1

Please sign in to comment.