database removed outside

This commit is contained in:
2026-06-08 14:48:14 +08:00
parent bf8e72f5b6
commit 75dd78aa33
68 changed files with 679 additions and 1815 deletions
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
+1 -3
View File
@@ -10,9 +10,7 @@ import os
from werkzeug.security import generate_password_hash
from datetime import datetime
# Store application data in the shared database folder so all backend modules
# use the same SQLite file regardless of their import path.
DB_FILE = os.path.abspath(os.path.join(os.path.dirname(__file__), "..", "database", "mxpic_data.db"))
from storage_paths import DB_FILE
def connect_db():
"""Open a SQLite connection with row-style access for application data queries."""
Binary file not shown.
+3 -7
View File
@@ -26,6 +26,7 @@ from pdk_access import (
)
from router_dependency import RouterStackUnavailable
from routed_layout_preview import create_routed_layout_svg
from storage_paths import DATABASE_ROOT, EXPORT_ROOT
from technology_manifest import TechnologyManifestError, read_technology_manifest
# --- Path Configurations ---
@@ -38,11 +39,6 @@ REPO_ROOT = os.path.abspath(os.path.join(BASE_DIR, '..', '..'))
# Component/category icons are served from backend/icons for the library panel.
ICONS_DIR = os.path.join(BASE_DIR, 'icons')
# Saved project YAML, generated previews, and temporary exports live under the
# database folder so each user can have isolated project storage.
DATABASE_ROOT = os.path.abspath(os.path.join(BASE_DIR, '..', 'database'))
EXPORT_ROOT = os.path.abspath(os.path.join(DATABASE_ROOT, '_exports'))
# Flask serves the HTML/CSS/JS frontend and exposes JSON APIs for persistence,
# PDK lookup, preview generation, and GDS export.
@@ -586,7 +582,7 @@ def user_logs():
@app.route('/api/projects', methods=['GET'])
@login_required_json
def list_projects():
"""List projects stored under database/<username>/layout."""
"""List projects stored under the external runtime database root."""
root = user_layout_root()
os.makedirs(root, exist_ok=True)
@@ -676,7 +672,7 @@ def get_project(project_name):
@app.route('/api/projects/<project_name>', methods=['DELETE'])
@login_required_json
def delete_project(project_name):
"""Delete a user's project folder under database/<username>/layout."""
"""Delete a user's project folder under the external runtime database root."""
root = project_root(project_name)
layout_root = os.path.abspath(user_layout_root())
target = os.path.abspath(root)
+49
View File
@@ -0,0 +1,49 @@
# -----------------------------------------------------------------------------
# Description: Runtime storage path resolution for SQLite data, saved layouts, and temporary exports.
# Inside functions: resolve_database_root
# Developer : Qin Yue @ 2026
# Organization : OptiHK Limited
# -----------------------------------------------------------------------------
import os
BACKEND_DIR = os.path.dirname(os.path.abspath(__file__))
REPO_ROOT = os.path.abspath(os.path.join(BACKEND_DIR, ".."))
DEFAULT_DATABASE_ROOT = os.path.abspath(os.path.join(REPO_ROOT, "..", "mxpic_EDA_database"))
def _is_inside_repo(path: str) -> bool:
"""Return True when a candidate runtime data folder lives inside this repo."""
repo_root = os.path.normcase(REPO_ROOT)
candidate = os.path.normcase(os.path.abspath(path))
try:
return os.path.commonpath([repo_root, candidate]) == repo_root
except ValueError:
return False
def resolve_database_root() -> str:
"""Resolve and validate the external runtime database root."""
configured_root = os.environ.get("MXPIC_DATABASE_ROOT", "").strip()
database_root = os.path.abspath(configured_root or DEFAULT_DATABASE_ROOT)
if _is_inside_repo(database_root):
raise RuntimeError(
"Runtime database root must live outside the mxpic_EDA repository. "
f"Resolved path: {database_root}. Move the database beside the repo as "
"mxpic_EDA_database or set MXPIC_DATABASE_ROOT to an external path."
)
if not os.path.isdir(database_root):
raise RuntimeError(
"Runtime database root is missing. Move the existing database folder "
f"beside mxpic_EDA and rename it to mxpic_EDA_database, or set "
f"MXPIC_DATABASE_ROOT to the moved folder. Expected path: {database_root}"
)
return database_root
DATABASE_ROOT = resolve_database_root()
DB_FILE = os.path.join(DATABASE_ROOT, "mxpic_data.db")
EXPORT_ROOT = os.path.join(DATABASE_ROOT, "_exports")