|
|
|
@ -9,7 +9,7 @@ |
|
|
|
|
from . import bp_dbupgrades |
|
|
|
|
from flask_cors import cross_origin |
|
|
|
|
from flask_login import login_required |
|
|
|
|
from flask import render_template, jsonify, make_response, redirect, url_for, current_app |
|
|
|
|
from flask import render_template, jsonify, make_response, redirect, url_for |
|
|
|
|
from pathlib import Path |
|
|
|
|
from labertasche.database import labertasche_db as db |
|
|
|
|
from labertasche.models import TProjects, TComments, TLocation, TEmail, TVersion |
|
|
|
@ -22,8 +22,7 @@ from datetime import datetime |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def get_backup_folder() -> Path: |
|
|
|
|
path = Path(current_app.root_path) |
|
|
|
|
path = path / "backup" / "v1" |
|
|
|
|
path = Path('.').absolute() / "backup" / "v1" |
|
|
|
|
return path |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -55,7 +54,7 @@ def upgrade_db_to_v2_backup(): |
|
|
|
|
# Create path for backup |
|
|
|
|
try: |
|
|
|
|
if not path.exists(): |
|
|
|
|
path.mkdir(mode=777, exist_ok=True, parents=True) |
|
|
|
|
path.mkdir(mode=755, exist_ok=True, parents=True) |
|
|
|
|
except OSError as e: |
|
|
|
|
return make_response(jsonify(status='exception', msg=str(e)), 400) |
|
|
|
|
|
|
|
|
@ -136,9 +135,8 @@ def upgrade_db_to_v2_export(): |
|
|
|
|
if compare_digest(db_uri[0:6], "sqlite"): |
|
|
|
|
m = search("([/]{3})(.*)", db_uri) |
|
|
|
|
new_db = get_backup_folder() / "labertasche.db" |
|
|
|
|
old_db = Path(current_app.root_path) |
|
|
|
|
old_db = old_db / m.group(2) |
|
|
|
|
copy(old_db.absolute(), new_db.absolute()) |
|
|
|
|
old_db = Path(m.group(2)).absolute() |
|
|
|
|
copy(old_db, new_db) |
|
|
|
|
except Exception as e: |
|
|
|
|
return make_response(jsonify(status='exception-copy-db', msg=str(e)), 400) |
|
|
|
|
|
|
|
|
@ -214,6 +212,7 @@ def upgrade_db_to_v2_import(): |
|
|
|
|
|
|
|
|
|
# walk json and readd to database with project set to project 1 |
|
|
|
|
for each in mails: |
|
|
|
|
each.update({'project_id': 1}) |
|
|
|
|
db.session.add(TEmail(**each)) |
|
|
|
|
|
|
|
|
|
for each in locations: |
|
|
|
|