mirror of
https://github.com/spl0k/supysonic.git
synced 2024-12-22 17:06:17 +00:00
Added a small table to store the schema version
Defined in a dedicated 'pony database', allowing to check only this table to determine if we need to create the tables, and so existing tables getting a new attribute won't trigger a table creation
This commit is contained in:
parent
dbf817ea9e
commit
2568b9bc91
@ -28,9 +28,18 @@ try:
|
|||||||
except ImportError:
|
except ImportError:
|
||||||
from urlparse import urlparse, parse_qsl
|
from urlparse import urlparse, parse_qsl
|
||||||
|
|
||||||
|
SCHEMA_VERSION = '20180829'
|
||||||
|
|
||||||
def now():
|
def now():
|
||||||
return datetime.now().replace(microsecond = 0)
|
return datetime.now().replace(microsecond = 0)
|
||||||
|
|
||||||
|
metadb = Database()
|
||||||
|
|
||||||
|
class Meta(metadb.Entity):
|
||||||
|
_table_ = 'meta'
|
||||||
|
key = PrimaryKey(str, 32)
|
||||||
|
value = Required(str, 256)
|
||||||
|
|
||||||
db = Database()
|
db = Database()
|
||||||
|
|
||||||
@db.on_connect(provider = 'sqlite')
|
@db.on_connect(provider = 'sqlite')
|
||||||
@ -500,18 +509,25 @@ def parse_uri(database_uri):
|
|||||||
|
|
||||||
def init_database(database_uri):
|
def init_database(database_uri):
|
||||||
settings = parse_uri(database_uri)
|
settings = parse_uri(database_uri)
|
||||||
db.bind(**settings)
|
|
||||||
db.generate_mapping(check_tables = False)
|
metadb.bind(**settings)
|
||||||
|
metadb.generate_mapping(check_tables = False)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
db.check_tables()
|
metadb.check_tables()
|
||||||
except DatabaseError:
|
except DatabaseError:
|
||||||
sql = pkg_resources.resource_string(__package__, 'schema/' + settings['provider'] + '.sql').decode('utf-8')
|
sql = pkg_resources.resource_string(__package__, 'schema/' + settings['provider'] + '.sql').decode('utf-8')
|
||||||
with db_session:
|
with db_session:
|
||||||
for statement in sql.split(';'):
|
for statement in sql.split(';'):
|
||||||
statement = statement.strip()
|
statement = statement.strip()
|
||||||
if statement:
|
if statement:
|
||||||
db.execute(statement)
|
metadb.execute(statement)
|
||||||
|
Meta(key = 'schema_version', value = SCHEMA_VERSION)
|
||||||
|
finally:
|
||||||
|
metadb.disconnect()
|
||||||
|
|
||||||
|
db.bind(**settings)
|
||||||
|
db.generate_mapping(check_tables = False)
|
||||||
|
|
||||||
def release_database():
|
def release_database():
|
||||||
db.disconnect()
|
db.disconnect()
|
||||||
|
@ -123,3 +123,8 @@ CREATE TABLE IF NOT EXISTS playlist (
|
|||||||
tracks TEXT
|
tracks TEXT
|
||||||
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||||
|
|
||||||
|
CREATE TABLE meta (
|
||||||
|
key VARCHAR(32) PRIMARY KEY,
|
||||||
|
value VARCHAR(256) NOT NULL
|
||||||
|
) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
|
||||||
|
|
||||||
|
@ -123,3 +123,8 @@ CREATE TABLE IF NOT EXISTS playlist (
|
|||||||
tracks TEXT
|
tracks TEXT
|
||||||
);
|
);
|
||||||
|
|
||||||
|
CREATE TABLE meta (
|
||||||
|
key VARCHAR(32) PRIMARY KEY,
|
||||||
|
value VARCHAR(256) NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
@ -127,3 +127,8 @@ CREATE TABLE IF NOT EXISTS playlist (
|
|||||||
tracks TEXT
|
tracks TEXT
|
||||||
);
|
);
|
||||||
|
|
||||||
|
CREATE TABLE meta (
|
||||||
|
key CHAR(32) PRIMARY KEY,
|
||||||
|
value CHAR(256) NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user