Rayman / fusic-meteor

Fusic: Realtime Social Music Collaboration
MIT License
27 stars 12 forks source link

Song metadata: Added date and author #49

Closed pepf closed 10 years ago

pepf commented 10 years ago

Big but necessary change to database. I have also written a small snippet that allows to convert the "old style playlists" to the new type. Trying to open an old playlist results in a white screen, because the changed schema basically fails to validate ("songs" property has changed from a [String] to a [Object]).

I've tested the following snippet; it shouldn't give any problems:

Playlists.find({}).fetch().forEach(function(playlist) {
    if(Match.test(playlist.songs,[String])) { //if playlist is "old"
        console.log("old playlist");

        var newSongObject =[];
        playlist.songs.forEach(function(song) {
            var songObject = {songId:song, added:new Date(), author:""};
            newSongObject.push(songObject);
        });

        console.log(newSongObject);

        Playlists.update({_id:playlist._id},{$set: {songs:newSongObject}});
    }
});

It is probably best to run the code on startup on the server once, to make sure all playlists get updated, not just the ones published to the client. :wink:

(Fixes #43 )

Rayman commented 10 years ago

Nice, that was a necessary change indeed. I'll take a look at this tonight and see if I can get it deployed.

Btw what kind of editor are you using? You're inserting tags and I'm inserting double spaces. If you're using Sublime, open a JavaScript file -> Preferences -> Settings - More -> Syntax Specific - User and enter the following snippet:

{
    "tab_size": 2,
    "translate_tabs_to_spaces": true
}
Rayman commented 10 years ago

Or you can install EditorConfig for Sublime

pepf commented 10 years ago

I use notepad++, but there will probably be a similar option in there as well. Btw: what is wrong with using tabs?

Rayman commented 10 years ago

Well, nothing really, it's just a matter of preference. But in de Meteor community (and also in nodejs) they use double spaces so that's what I use.

For notepad++, take a look at this: https://github.com/editorconfig/editorconfig-notepad-plus-plus#readme

pepf commented 10 years ago

Thanks, it works :+1: