forked from gateway4labs/labmanager
-
Notifications
You must be signed in to change notification settings - Fork 0
/
apply_migrations_apr_2019.py
42 lines (31 loc) · 1.46 KB
/
apply_migrations_apr_2019.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from __future__ import print_function
import os
import sys
import json
import datetime
import urlparse
import requests
from flask import url_for
from labmanager import app
from labmanager.db import db
from labmanager.models import EmbedApplication, EmbedApplicationTranslation, HttpsUnsupportedUrl, UseLog
if not os.path.exists('migration_apr_2019/embed_changes.json'):
print("migration_apr_2019/embed_changes.json not found")
sys.exit(-1)
embed_changes = json.load(open('migration_apr_2019/embed_changes.json'))
with app.app_context():
for embed_change in embed_changes:
embed_app = db.session.query(EmbedApplication).filter_by(id=embed_change['id']).one()
if embed_app.url != embed_change['old_url'] and embed_app.url != embed_change['old_url'].replace('http://', 'https://'):
print("WARNING: id {}; expected {} but found {}. Skipping".format(embed_change['id'], embed_change['old_url'], embed_app.url))
continue
new_url = embed_change['new_url']
proxy = embed_change['proxy']
print("Changing {} for {} and proxy {}".format(embed_app.url, new_url, proxy))
embed_app.uses_proxy = proxy
embed_app.url = new_url
if new_url.startswith('https://'):
for translation in embed_app.translations:
if translation.url.startswith('http://'):
translation.url = translation.url.replace('http://', 'https://', 1)
db.session.commit()