From aec7bef504c53ec9da9c8a1db699d0773f655256 Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Sat, 10 Jul 2010 17:53:51 -0700 Subject: [PATCH] add MusicBrainz ID fields to database schema --- beets/library.py | 42 ++++++++++++++++++++----------------- test/rsrc/test.blb | Bin 4096 -> 4096 bytes test/test_db.py | 51 +++++++++++++++++++++++++++------------------ test/test_query.py | 24 ++------------------- test/test_ui.py | 24 ++------------------- 5 files changed, 58 insertions(+), 83 deletions(-) diff --git a/beets/library.py b/beets/library.py index 0209e6600..978589062 100644 --- a/beets/library.py +++ b/beets/library.py @@ -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() diff --git a/test/rsrc/test.blb b/test/rsrc/test.blb index 7a8abc5f70042f293122744701163bfd288a16ee..d3dd76ba8da0b5ab7c17cb1aa044729c0fd2d07e 100644 GIT binary patch delta 115 zcmZorXi%6SEy&J*3fL#=*m5#{WMB?wKFj!VV`DudS5q=GySTVGW2@?BeI|8A6CH)z or1->~q|)5X6or!1iW0CuNl{{QHnKosQAuWT2~=cr81pI~0OpY&`Tzg` delta 63 zcmZorXi%6SEy%)v3RouU*m5$dGBAfTpJh_rEXcB%k*i6cnO$65oUz4r^KV9V#?4{O Gt9Sq;K?`93 diff --git a/test/test_db.py b/test/test_db.py index 3751ce7f2..4106c61f9 100644 --- a/test/test_db.py +++ b/test/test_db.py @@ -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(): diff --git a/test/test_query.py b/test/test_query.py index 096da5982..09b0ba3f8 100644 --- a/test/test_query.py +++ b/test/test_query.py @@ -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): diff --git a/test/test_ui.py b/test/test_ui.py index 3d6c1bb3b..188ec6505 100644 --- a/test/test_ui.py +++ b/test/test_ui.py @@ -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):