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

Added support for python migrations

This commit is contained in:
spl0k 2018-09-02 17:26:18 +02:00
parent 659e46611a
commit 670bef6a91

View File

@ -7,10 +7,11 @@
#
# Distributed under terms of the GNU AGPLv3 license.
import time
import importlib
import mimetypes
import os.path
import pkg_resources
import time
from datetime import datetime
from hashlib import sha1
@ -535,9 +536,13 @@ def init_database(database_uri):
migrations = sorted(pkg_resources.resource_listdir(__package__, 'schema/migration/' + settings['provider']))
for migration in migrations:
date, ext = os.path.splitext(migration)
if date <= version.value or ext != '.sql':
if date <= version.value:
continue
execute_sql_resource_script('schema/migration/{}/{}'.format(settings['provider'], migration))
if ext == '.sql':
execute_sql_resource_script('schema/migration/{}/{}'.format(settings['provider'], migration))
elif ext == '.py':
m = importlib.import_module('.schema.migration.{}.{}'.format(settings['provider'], date), __package__)
m.apply(settings.copy())
version.value = SCHEMA_VERSION
# Hack for in-memory SQLite databases (used in tests), otherwise 'db' and 'metadb' would be two distinct databases