mirror of
https://github.com/beetbox/beets.git
synced 2025-12-25 18:13:17 +01:00
add MusicBrainz ID fields to database schema
This commit is contained in:
parent
f4d7d68e57
commit
aec7bef504
5 changed files with 58 additions and 83 deletions
|
|
@ -30,23 +30,26 @@ MAX_FILENAME_LENGTH = 200
|
|||
# metadata, all metadata (inlcuding read-only attributes), and all
|
||||
# fields (i.e., including non-metadata attributes).
|
||||
metadata_rw_fields = [
|
||||
('title', 'text'),
|
||||
('artist', 'text'),
|
||||
('album', 'text'),
|
||||
('genre', 'text'),
|
||||
('composer', 'text'),
|
||||
('grouping', 'text'),
|
||||
('year', 'int'),
|
||||
('month', 'int'),
|
||||
('day', 'int'),
|
||||
('track', 'int'),
|
||||
('tracktotal', 'int'),
|
||||
('disc', 'int'),
|
||||
('disctotal', 'int'),
|
||||
('lyrics', 'text'),
|
||||
('comments', 'text'),
|
||||
('bpm', 'int'),
|
||||
('comp', 'bool'),
|
||||
('title', 'text'),
|
||||
('artist', 'text'),
|
||||
('album', 'text'),
|
||||
('genre', 'text'),
|
||||
('composer', 'text'),
|
||||
('grouping', 'text'),
|
||||
('year', 'int'),
|
||||
('month', 'int'),
|
||||
('day', 'int'),
|
||||
('track', 'int'),
|
||||
('tracktotal', 'int'),
|
||||
('disc', 'int'),
|
||||
('disctotal', 'int'),
|
||||
('lyrics', 'text'),
|
||||
('comments', 'text'),
|
||||
('bpm', 'int'),
|
||||
('comp', 'bool'),
|
||||
('mb_trackid', 'text'),
|
||||
('mb_albumid', 'text'),
|
||||
('mb_artistid', 'text'),
|
||||
]
|
||||
metadata_fields = [
|
||||
('length', 'real'),
|
||||
|
|
@ -649,14 +652,15 @@ class Library(BaseLibrary):
|
|||
|
||||
else:
|
||||
# Table exists but is missing fields.
|
||||
setup_sql = ''
|
||||
for fname in field_names - current_fields:
|
||||
for field in fields:
|
||||
if field[0] == fname:
|
||||
break
|
||||
else:
|
||||
assert False
|
||||
setup_sql = 'ALTER TABLE items ADD COLUMN ' + \
|
||||
' '.join(field) + ';'
|
||||
setup_sql += 'ALTER TABLE items ADD COLUMN ' + \
|
||||
' '.join(field) + ';\n'
|
||||
|
||||
self.conn.executescript(setup_sql)
|
||||
self.conn.commit()
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -23,26 +23,29 @@ def lib(): return beets.library.Library('rsrc' + os.sep + 'test.blb')
|
|||
def boracay(l): return beets.library.Item(l.conn.execute('select * from items '
|
||||
'where id=3').fetchone())
|
||||
def item(): return beets.library.Item({
|
||||
'title': u'the title',
|
||||
'artist': u'the artist',
|
||||
'album': u'the album',
|
||||
'genre': u'the genre',
|
||||
'composer': u'the composer',
|
||||
'grouping': u'the grouping',
|
||||
'year': 1,
|
||||
'month': 2,
|
||||
'day': 3,
|
||||
'track': 4,
|
||||
'tracktotal': 5,
|
||||
'disc': 6,
|
||||
'disctotal': 7,
|
||||
'lyrics': u'the lyrics',
|
||||
'comments': u'the comments',
|
||||
'bpm': 8,
|
||||
'comp': True,
|
||||
'path': 'somepath',
|
||||
'length': 60.0,
|
||||
'bitrate': 128000,
|
||||
'title': u'the title',
|
||||
'artist': u'the artist',
|
||||
'album': u'the album',
|
||||
'genre': u'the genre',
|
||||
'composer': u'the composer',
|
||||
'grouping': u'the grouping',
|
||||
'year': 1,
|
||||
'month': 2,
|
||||
'day': 3,
|
||||
'track': 4,
|
||||
'tracktotal': 5,
|
||||
'disc': 6,
|
||||
'disctotal': 7,
|
||||
'lyrics': u'the lyrics',
|
||||
'comments': u'the comments',
|
||||
'bpm': 8,
|
||||
'comp': True,
|
||||
'path': 'somepath',
|
||||
'length': 60.0,
|
||||
'bitrate': 128000,
|
||||
'mb_trackid': 'someID-1',
|
||||
'mb_albumid': 'someID-2',
|
||||
'mb_artistid': 'someID-3',
|
||||
})
|
||||
np = beets.library._normpath
|
||||
|
||||
|
|
@ -216,6 +219,7 @@ class MigrationTest(unittest.TestCase):
|
|||
self.older_fields = [('field_one', 'int')]
|
||||
self.old_fields = self.older_fields + [('field_two', 'int')]
|
||||
self.new_fields = self.old_fields + [('field_three', 'int')]
|
||||
self.newer_fields = self.new_fields + [('field_four', 'int')]
|
||||
|
||||
# Set up a library with old_fields.
|
||||
self.libfile = os.path.join('rsrc', 'templib.blb')
|
||||
|
|
@ -250,6 +254,13 @@ class MigrationTest(unittest.TestCase):
|
|||
c.execute("select * from items")
|
||||
row = c.fetchone()
|
||||
self.assertEqual(len(row), len(self.old_fields))
|
||||
|
||||
def test_open_with_multiple_new_fields(self):
|
||||
new_lib = beets.library.Library(self.libfile, fields=self.newer_fields)
|
||||
c = new_lib.conn.cursor()
|
||||
c.execute("select * from items")
|
||||
row = c.fetchone()
|
||||
self.assertEqual(len(row), len(self.newer_fields))
|
||||
|
||||
|
||||
def suite():
|
||||
|
|
|
|||
|
|
@ -18,31 +18,11 @@
|
|||
import unittest, sys, os
|
||||
sys.path.append('..')
|
||||
import beets.library
|
||||
import test_db
|
||||
|
||||
parse_query = beets.library.CollectionQuery._parse_query
|
||||
|
||||
some_item = beets.library.Item({
|
||||
'title': u'the title',
|
||||
'artist': u'the artist',
|
||||
'album': u'the album',
|
||||
'genre': u'the genre',
|
||||
'composer': u'the composer',
|
||||
'grouping': u'the grouping',
|
||||
'year': 1,
|
||||
'month': 2,
|
||||
'day': 3,
|
||||
'track': 4,
|
||||
'tracktotal': 5,
|
||||
'disc': 6,
|
||||
'disctotal': 7,
|
||||
'lyrics': u'the lyrics',
|
||||
'comments': u'the comments',
|
||||
'bpm': 8,
|
||||
'comp': True,
|
||||
'path': 'somepath',
|
||||
'length': 60.0,
|
||||
'bitrate': 128000,
|
||||
})
|
||||
some_item = test_db.item()
|
||||
|
||||
class QueryParseTest(unittest.TestCase):
|
||||
def test_one_basic_term(self):
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ sys.path.append('..')
|
|||
from beets import library
|
||||
from beets import ui
|
||||
from beets.ui import commands
|
||||
import test_db
|
||||
|
||||
# Dummy printing so we can get the commands' output.
|
||||
outbuffer = []
|
||||
|
|
@ -37,28 +38,7 @@ class ListTest(unittest.TestCase):
|
|||
def setUp(self):
|
||||
clear_buffer()
|
||||
self.lib = library.Library(':memory:')
|
||||
i = library.Item({
|
||||
'title': u'the title',
|
||||
'artist': u'the artist',
|
||||
'album': u'the album',
|
||||
'genre': u'the genre',
|
||||
'composer': u'the composer',
|
||||
'grouping': u'the grouping',
|
||||
'year': 1,
|
||||
'month': 2,
|
||||
'day': 3,
|
||||
'track': 4,
|
||||
'tracktotal': 5,
|
||||
'disc': 6,
|
||||
'disctotal': 7,
|
||||
'lyrics': u'the lyrics',
|
||||
'comments': u'the comments',
|
||||
'bpm': 8,
|
||||
'comp': True,
|
||||
'path': 'somepath',
|
||||
'length': 60.0,
|
||||
'bitrate': 128000,
|
||||
})
|
||||
i = test_db.item()
|
||||
self.lib.add(i)
|
||||
|
||||
def test_list_outputs_item(self):
|
||||
|
|
|
|||
Loading…
Reference in a new issue