1
0
mirror of https://github.com/spl0k/supysonic.git synced 2024-12-22 08:56:17 +00:00

Enforce foreign keys on SQLite

This commit is contained in:
Alban Féron 2023-01-14 16:45:44 +01:00
parent 4bbd7e94b0
commit b57b086e04
No known key found for this signature in database
GPG Key ID: 8CE0313646D16165
3 changed files with 8 additions and 6 deletions

View File

@ -588,6 +588,7 @@ def init_database(database_uri):
provider = "postgres" provider = "postgres"
elif uri.scheme.startswith("sqlite"): elif uri.scheme.startswith("sqlite"):
provider = "sqlite" provider = "sqlite"
args["pragmas"] = {"foreign_keys": 1}
else: else:
raise RuntimeError(f"Unsupported database: {uri.scheme}") raise RuntimeError(f"Unsupported database: {uri.scheme}")

View File

@ -137,6 +137,7 @@ class AlbumSongsTestCase(ApiTestBase):
) )
self.assertEqual(len(child), 0) self.assertEqual(len(child), 0)
Track.delete().execute()
Folder[1].delete_instance() Folder[1].delete_instance()
rv, child = self._make_request( rv, child = self._make_request(
"getAlbumList", {"type": "random"}, tag="albumList" "getAlbumList", {"type": "random"}, tag="albumList"

View File

@ -1,7 +1,7 @@
# This file is part of Supysonic. # This file is part of Supysonic.
# Supysonic is a Python implementation of the Subsonic server API. # Supysonic is a Python implementation of the Subsonic server API.
# #
# Copyright (C) 2017-2022 Alban 'spl0k' Féron # Copyright (C) 2017-2023 Alban 'spl0k' Féron
# #
# Distributed under terms of the GNU AGPLv3 license. # Distributed under terms of the GNU AGPLv3 license.
@ -10,6 +10,7 @@ import unittest
import uuid import uuid
from collections import namedtuple from collections import namedtuple
from peewee import IntegrityError
from supysonic import db from supysonic import db
@ -20,11 +21,6 @@ class DbTestCase(unittest.TestCase):
def setUp(self): def setUp(self):
db.init_database("sqlite:") db.init_database("sqlite:")
try:
self.assertRegex
except AttributeError:
self.assertRegex = self.assertRegexpMatches
def tearDown(self): def tearDown(self):
db.release_database() db.release_database()
@ -114,6 +110,10 @@ class DbTestCase(unittest.TestCase):
return playlist return playlist
def test_ensure_sqlite_foreign_keys(self):
root, _, _ = self.create_some_folders()
self.assertRaises(IntegrityError, root.delete_instance)
def test_folder_base(self): def test_folder_base(self):
root_folder, child_folder, child_noart = self.create_some_folders() root_folder, child_folder, child_noart = self.create_some_folders()
track_embededart = self.create_track_in(child_noart, root_folder) track_embededart = self.create_track_in(child_noart, root_folder)