[Slim-Checkins] r11102 - in /branches/6.5/server: Changelog6.html SQL/mysql/schema_3_down.sql SQL/mysql/schema_3_up.sql Slim/Schema.pm Slim/Schema/Album.pm Slim/Schema/ResultSet/Album.pm slimserver.pl

adrian at svn.slimdevices.com adrian at svn.slimdevices.com
Thu Jan 4 05:28:43 PST 2007


Author: adrian
Date: Thu Jan  4 05:28:42 2007
New Revision: 11102

URL: http://svn.slimdevices.com?rev=11102&view=rev
Log:
Bug: 3255
Description: fix sort albums by artist (hopefully!)
- add back a contributor column to the album table in the database
- populate this at scan time with VA or a album contributor & sort on
it for browse by album sorted on artist
- add logic to do a wipecache if the database schema is migrated at startup
(NB schema migration downwards will still be problematic)

Added:
    branches/6.5/server/SQL/mysql/schema_3_down.sql   (with props)
    branches/6.5/server/SQL/mysql/schema_3_up.sql   (with props)
Modified:
    branches/6.5/server/Changelog6.html
    branches/6.5/server/Slim/Schema.pm
    branches/6.5/server/Slim/Schema/Album.pm
    branches/6.5/server/Slim/Schema/ResultSet/Album.pm
    branches/6.5/server/slimserver.pl

Modified: branches/6.5/server/Changelog6.html
URL: http://svn.slimdevices.com/branches/6.5/server/Changelog6.html?rev=11102&r1=11101&r2=11102&view=diff
==============================================================================
--- branches/6.5/server/Changelog6.html (original)
+++ branches/6.5/server/Changelog6.html Thu Jan  4 05:28:42 2007
@@ -33,6 +33,7 @@
 		<li><a href="http://bugs.slimdevices.com/show_bug.cgi?id=2314">#2314</a> - Volume zero when player paused</li>
 		<li><a href="http://bugs.slimdevices.com/show_bug.cgi?id=2985">#2985</a> - WMA transcoded to WAV truncated (not gapless)</li>
 		<li><a href="http://bugs.slimdevices.com/show_bug.cgi?id=3044">#3044</a> - Lyrics do not display with line spacing correctly (again)</li>
+		<li><a href="http://bugs.slimdevices.com/show_bug.cgi?id=3255">#3255</a> - alphapagebar links miss targets in browse artwork</li>
 		<li><a href="http://bugs.slimdevices.com/show_bug.cgi?id=3318">#3318</a> - MusicMagic: Songs with national chars get duplicated</li>
 		<li><a href="http://bugs.slimdevices.com/show_bug.cgi?id=3660">#3660</a> - DHCP bridging does not work sometimes</li>
 		<li><a href="http://bugs.slimdevices.com/show_bug.cgi?id=3696">#3696</a> - Random Mix fails</li>

Added: branches/6.5/server/SQL/mysql/schema_3_down.sql
URL: http://svn.slimdevices.com/branches/6.5/server/SQL/mysql/schema_3_down.sql?rev=11102&view=auto
==============================================================================
--- branches/6.5/server/SQL/mysql/schema_3_down.sql (added)
+++ branches/6.5/server/SQL/mysql/schema_3_down.sql Thu Jan  4 05:28:42 2007
@@ -1,0 +1,3 @@
+-- remove contributor column added for album sorting
+
+ALTER TABLE albums DROP contributor;

Propchange: branches/6.5/server/SQL/mysql/schema_3_down.sql
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: branches/6.5/server/SQL/mysql/schema_3_down.sql
------------------------------------------------------------------------------
    svn:keywords = Id Author LastChangedDate LastChangedBy

Propchange: branches/6.5/server/SQL/mysql/schema_3_down.sql
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: branches/6.5/server/SQL/mysql/schema_3_up.sql
URL: http://svn.slimdevices.com/branches/6.5/server/SQL/mysql/schema_3_up.sql?rev=11102&view=auto
==============================================================================
--- branches/6.5/server/SQL/mysql/schema_3_up.sql (added)
+++ branches/6.5/server/SQL/mysql/schema_3_up.sql Thu Jan  4 05:28:42 2007
@@ -1,0 +1,3 @@
+-- Add contributor column to albums to enable sorting by artist (bug3255)
+
+ALTER TABLE albums ADD contributor int(10) unsigned;

Propchange: branches/6.5/server/SQL/mysql/schema_3_up.sql
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: branches/6.5/server/SQL/mysql/schema_3_up.sql
------------------------------------------------------------------------------
    svn:keywords = Id Author LastChangedDate LastChangedBy

Propchange: branches/6.5/server/SQL/mysql/schema_3_up.sql
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: branches/6.5/server/Slim/Schema.pm
URL: http://svn.slimdevices.com/branches/6.5/server/Slim/Schema.pm?rev=11102&r1=11101&r2=11102&view=diff
==============================================================================
--- branches/6.5/server/Slim/Schema.pm (original)
+++ branches/6.5/server/Slim/Schema.pm Thu Jan  4 05:28:42 2007
@@ -154,7 +154,7 @@
 		}
 	}
 
-	$class->migrateDB;
+	my $update = $class->migrateDB;
 
 	# Load the DBIx::Class::Schema classes we've defined.
 	# If you add a class to the schema, you must add it here as well.
@@ -176,7 +176,7 @@
 	/);
 
 	# Build all our class accessors and populate them.
-	for my $accessor (qw(lastTrackURL lastTrack trackAttrs driver)) {
+	for my $accessor (qw(lastTrackURL lastTrack trackAttrs driver schemaUpdated)) {
 
 		$class->mk_classaccessor($accessor);
 	}
@@ -192,6 +192,8 @@
 	$class->toggleDebug($::d_sql);
 
 	$class->_buildValidHierarchies;
+
+	$class->schemaUpdated($update);
 
 	$initialized = 1;
 }
@@ -363,6 +365,7 @@
 
 sub migrateDB {
 	my $class = shift;
+	my $init  = shift;
 
 	my ($driver, $source, $username, $password) = $class->sourceInformation;
 
@@ -374,9 +377,31 @@
 		'dir'      => catdir(Slim::Utils::OSDetect::dirsFor('SQL'), $driver),
 	});
 
-	$dbix->migrate;
-
-	$::d_info && msgf("Connected to database $source - schema version: [%d]\n", $dbix->version);
+	my $old = $dbix->version || 0;
+ 
+	if ($dbix->migrate) {
+
+		my $new = $dbix->version || 0;
+
+		$::d_info && msgf("Connected to database $source - schema version: [%d]\n", $new);
+
+		if ($old != $new) {
+			
+			$::d_info && msgf("Migrated database from schema version: %d to version: %d\n", $old, $new);
+
+			return 1;
+
+		}
+
+	} else {
+
+		# this occurs if a user downgrades slimserver to a version with an older schema and which does not include
+		# the required downgrade sql scripts - should probably drop the whole database at this point
+		$::d_info && msgf("Unable to migrate database from schema version: %d\n", $old);
+
+	}
+
+	return 0;
 }
 
 =head2 rs( $class )
@@ -1211,6 +1236,7 @@
 			$::d_info && $_dump_postprocess_logic && msg("--- Album is a VA\n");
 
 			$albumObj->compilation(1);
+			$albumObj->contributor($vaObjId);
 			$albumObj->update;
 		}
 
@@ -2049,6 +2075,16 @@
 		# Bug 2393 - was fixed here (now obsolete due to further code rework)
 		$set{'compilation'} = $isCompilation;
 
+		# Bug 3255 - add album contributor which is either VA or the primary artist, used for sort by artist
+		if ($isCompilation && !scalar @{$contributors->{'ALBUMARTIST'}}) {
+
+			$set{'contributor'} = $self->variousArtistsObject->id;
+
+		} elsif (blessed($contributor)) {
+
+			$set{'contributor'} = $contributor->id;
+		}
+
 		$set{'musicbrainz_id'} = $attributes->{'MUSICBRAINZ_ALBUM_ID'};
 
 		# Handle album gain tags.

Modified: branches/6.5/server/Slim/Schema/Album.pm
URL: http://svn.slimdevices.com/branches/6.5/server/Slim/Schema/Album.pm?rev=11102&r1=11101&r2=11102&view=diff
==============================================================================
--- branches/6.5/server/Slim/Schema/Album.pm (original)
+++ branches/6.5/server/Slim/Schema/Album.pm Thu Jan  4 05:28:42 2007
@@ -15,6 +15,7 @@
 	$class->add_columns(qw(
 		id
 		titlesort
+		contributor
 		compilation
 		year
 		artwork
@@ -30,6 +31,8 @@
 	$class->set_primary_key('id');
 	$class->add_unique_constraint('titlesearch' => [qw/id titlesearch/]);
 
+	$class->belongs_to('contributor' => 'Slim::Schema::Contributor');
+
 	$class->has_many('tracks'            => 'Slim::Schema::Track'            => 'album');
 	$class->has_many('contributorAlbums' => 'Slim::Schema::ContributorAlbum' => 'album');
 

Modified: branches/6.5/server/Slim/Schema/ResultSet/Album.pm
URL: http://svn.slimdevices.com/branches/6.5/server/Slim/Schema/ResultSet/Album.pm?rev=11102&r1=11101&r2=11102&view=diff
==============================================================================
--- branches/6.5/server/Slim/Schema/ResultSet/Album.pm (original)
+++ branches/6.5/server/Slim/Schema/ResultSet/Album.pm Thu Jan  4 05:28:42 2007
@@ -94,7 +94,7 @@
 
 		if ($sort =~ /contributor/) {
 
-			push @join, { 'contributorAlbums' => 'contributor' };
+			push @join, 'contributor';
 		}
 
 		if ($sort =~ /genre/) {

Modified: branches/6.5/server/slimserver.pl
URL: http://svn.slimdevices.com/branches/6.5/server/slimserver.pl?rev=11102&r1=11101&r2=11102&view=diff
==============================================================================
--- branches/6.5/server/slimserver.pl (original)
+++ branches/6.5/server/slimserver.pl Thu Jan  4 05:28:42 2007
@@ -952,9 +952,9 @@
 			Slim::Utils::Prefs::set("audiodir",$audiodir);
 		}
 
-		if (Slim::Schema->count('Track') == 0) {
-
-			$::d_scan && msg("checkDataSource - no tracks in the database, initiating scan.\n");
+		if (Slim::Schema->schemaUpdated || Slim::Schema->count('Track') == 0) {
+
+			$::d_scan && msg("checkDataSource - updated schema or no tracks in the database, initiating scan.\n");
 
 			Slim::Control::Request::executeRequest(undef, ['wipecache']);
 		}



More information about the checkins mailing list