mirror of
https://github.com/GNS3/gns3-server
synced 2024-12-25 16:28:11 +00:00
Enable SQL foreign key support for SQLite
This commit is contained in:
parent
a1f3f6472a
commit
10164e262d
@ -17,7 +17,6 @@
|
||||
|
||||
import os
|
||||
import sys
|
||||
import json
|
||||
import uuid
|
||||
import socket
|
||||
import shutil
|
||||
@ -30,7 +29,6 @@ from .appliance_manager import ApplianceManager
|
||||
from .compute import Compute, ComputeError
|
||||
from .notification import Notification
|
||||
from .symbols import Symbols
|
||||
from ..version import __version__
|
||||
from .topology import load_topology
|
||||
from .gns3vm import GNS3VM
|
||||
from ..utils.get_resource import get_resource
|
||||
|
@ -22,6 +22,8 @@ from fastapi.encoders import jsonable_encoder
|
||||
from pydantic import ValidationError
|
||||
|
||||
from typing import List
|
||||
from sqlalchemy import event
|
||||
from sqlalchemy.engine import Engine
|
||||
from sqlalchemy.exc import SQLAlchemyError
|
||||
from sqlalchemy.ext.asyncio import create_async_engine, AsyncSession
|
||||
from gns3server.db.repositories.computes import ComputesRepository
|
||||
@ -49,6 +51,16 @@ async def connect_to_db(app: FastAPI) -> None:
|
||||
log.error(f"Error while connecting to database '{db_url}: {e}")
|
||||
|
||||
|
||||
@event.listens_for(Engine, "connect")
|
||||
def set_sqlite_pragma(dbapi_connection, connection_record):
|
||||
|
||||
# Enable SQL foreign key support for SQLite
|
||||
# https://docs.sqlalchemy.org/en/14/dialects/sqlite.html#foreign-key-support
|
||||
cursor = dbapi_connection.cursor()
|
||||
cursor.execute("PRAGMA foreign_keys=ON")
|
||||
cursor.close()
|
||||
|
||||
|
||||
async def get_computes(app: FastAPI) -> List[dict]:
|
||||
|
||||
computes = []
|
||||
|
@ -97,7 +97,7 @@ class TestTemplateRoutes:
|
||||
assert response.status_code == status.HTTP_200_OK
|
||||
assert response.json()["name"] == "VPCS_TEST_RENAMED"
|
||||
|
||||
async def test_template_delete(self, app: FastAPI, client: AsyncClient, controller: Controller) -> None:
|
||||
async def test_template_delete(self, app: FastAPI, client: AsyncClient) -> None:
|
||||
|
||||
template_id = str(uuid.uuid4())
|
||||
params = {"template_id": template_id,
|
||||
|
Loading…
Reference in New Issue
Block a user