mirror of
https://github.com/GSA/notifications-api.git
synced 2025-12-10 23:32:27 -05:00
36 lines
1.1 KiB
Python
36 lines
1.1 KiB
Python
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')]
|
|
# sometimes there's a trailing underscore, if script was created with `flask db migrate --rev-id=...`
|
|
latest_file = sorted(migration_files, reverse=True)[0].replace('_.py', '').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()
|