Skip to content

Commit

Permalink
[Fix][Upgrade] Change NFS project folder from id to name"
Browse files Browse the repository at this point in the history
  • Loading branch information
john19968010 committed Nov 30, 2021
1 parent c678246 commit 578b57b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
19 changes: 17 additions & 2 deletions apis/migrate.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os

import shutil
import threading
import config
import model
Expand Down Expand Up @@ -32,7 +33,7 @@
'1.9.0.1', '1.9.0.2', '1.9.0.3', '1.9.0.4', '1.9.0.5', '1.9.0.6', '1.9.0.7', '1.9.0.8', '1.9.0.9', '1.9.1.0',
'1.9.1.1', '1.9.1.2', '1.9.1.3', '1.9.1.4', '1.9.1.5', '1.9.1.6', '1.9.1.7', '1.9.1.8', '1.9.1.9', '1.10.0.1',
'1.10.0.2', '1.10.0.3', '1.10.0.4', '1.10.0.5', '1.10.0.6', '1.10.0.7', '1.10.0.8', '1.10.0.9', '1.10.0.10',
'1.10.0.11', '1.10.0.12', '1.11.0.1', '1.11.0.2', '1.11.0.3', '1.11.0.4', '1.11.0.5', '1.11.0.6', '1.11.0.7']
'1.10.0.11', '1.10.0.12', '1.11.0.1', '1.11.0.2', '1.11.0.3', '1.11.0.4', '1.11.0.5', '1.11.0.6', '1.11.0.7', '1.11.0.8']
ONLY_UPDATE_DB_MODELS = [
'0.9.2.1', '0.9.2.2', '0.9.2.3', '0.9.2.5', '0.9.2.6', '0.9.2.a8',
'1.0.0.2', '1.3.0.1', '1.3.0.2', '1.3.0.3', '1.3.0.4', '1.3.1', '1.3.1.1', '1.3.1.2',
Expand Down Expand Up @@ -152,7 +153,21 @@ def upgrade(version):
elif version == '1.11.0.3':
insert_download_issues_in_lock()
elif version == '1.11.0.7':
add_project_nfs_path()
pass
elif version == '1.11.0.8':
add_project_nfs_path_real()


def add_project_nfs_path_real():
for pj in Project.query.all():
project_nfs_file_path = f"./project-data/{pj.name}"
os.makedirs(project_nfs_file_path, exist_ok=True)
os.chmod(project_nfs_file_path, 0o777)

fake_project_nfs_file_path = f"./project-data/{pj.id}"
if os.path.isdir(fake_project_nfs_file_path):
shutil.rmtree(fake_project_nfs_file_path)



def add_project_nfs_path():
Expand Down
10 changes: 8 additions & 2 deletions apis/resources/project.py
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,8 @@ def create_project(user_id, args):
template.tm_use_template_push_into_pj(args["template_id"], gitlab_pj_id,
args["tag_name"], args["arguments"])

project_nfs_file_path = f"./project-data/{project_id}"
# Create project NFS folder
project_nfs_file_path = f"./project-data/{gitlab_pj_name}"
os.makedirs(project_nfs_file_path, exist_ok=True)
os.chmod(project_nfs_file_path, 0o777)

Expand Down Expand Up @@ -420,6 +421,10 @@ def try_to_delete(delete_method, argument):
# 用project_id刪除redmine & gitlab的project並將db的相關table欄位一併刪除
@record_activity(ActionType.DELETE_PROJECT)
def delete_project(project_id):
# Get project name(for remove its NFS folder)
project_name = model.Project.query.get(project_id).name

# Check server is all alive
server_alive_output = Monitoring(project_id).check_project_alive()
if not server_alive_output["all_alive"]:
not_alive_server = [
Expand Down Expand Up @@ -488,7 +493,8 @@ def delete_project(project_id):
"DELETE FROM public.projects WHERE id = '{0}'".format(
project_id))

project_nfs_file_path = f"./project-data/{project_id}"
# Delete project NFS folder
project_nfs_file_path = f"./project-data/{project_name}"
if os.path.isdir(project_nfs_file_path):
shutil.rmtree(project_nfs_file_path)
return util.success()
Expand Down

0 comments on commit 578b57b

Please sign in to comment.