#!/usr/bin/env python
"""
Automatically handle migrations with defaults
"""
import os
import sys

# Answer 'n' for rename question and '1' for default value
responses = ['n', '1', '1']  # n for rename, 1 for one-off default twice
response_index = 0

class AutoResponder:
    def readline(self):
        global response_index
        if response_index < len(responses):
            response = responses[response_index]
            response_index += 1
            print(response)
            return response + '\n'
        return '\n'

# Replace stdin with auto-responder
sys.stdin = AutoResponder()

# Now run makemigrations
os.system('python manage.py makemigrations')

# Reset stdin
sys.stdin = sys.__stdin__

print("\n" + "=" * 80)
print("Now applying migrations...")
print("=" * 80)
os.system('python manage.py migrate')
