Add a script and make command to detect if there are any migration changes

This commit is contained in:
Imdad Ahad
2017-05-26 16:44:23 +01:00
parent 263adac805
commit a58e724d21
2 changed files with 39 additions and 0 deletions

View File

@@ -303,3 +303,8 @@ cf-rollback: ## Rollbacks the app to the previous release
cf-push:
$(if ${CF_APP},,$(error Must specify CF_APP))
cf push ${CF_APP} -f ${CF_MANIFEST_FILE}
.PHONY: check-if-migrations-to-run
check-if-migrations-to-run:
@echo $(shell python scripts/check_if_new_migration.py)

View File

@@ -0,0 +1,34 @@
import os
from os.path import dirname, abspath
import requests
import sys
def get_latest_db_migration_to_apply():
project_dir = dirname(dirname(abspath(__file__))) # Get the main project directory
migrations_dir = '{}/migrations/versions/'.format(project_dir)
migration_files = [migration_file for migration_file in os.listdir(migrations_dir) if migration_file.endswith('py')]
latest_file = sorted(migration_files, reverse=True)[0].replace('.py', '')
return latest_file
def get_current_db_version():
api_status_url = '{}/_status'.format(os.getenv('API_HOST_NAME'))
response = requests.get(api_status_url)
if response.status_code != 200:
sys.exit('Could not make a request to the API: {}'.format())
current_db_version = response.json()['db_version']
return current_db_version
def run():
if get_current_db_version() == get_latest_db_migration_to_apply():
print('no')
else:
print('yes')
if __name__ == "__main__":
run()