1
0
Fork 0

Work on import from discogs. Switching to mysql in local dev

This commit is contained in:
magnolia-fan 2011-09-21 22:59:39 +04:00
parent 5798955b01
commit da003cad12
15 changed files with 110 additions and 13 deletions

View File

@ -20,7 +20,7 @@ gem 'musicbrainz'
gem 'bitmask_attributes' gem 'bitmask_attributes'
group :development do group :development do
gem 'sqlite3' gem 'mysql2', '0.3.7'
end end
group :production do group :production do

View File

@ -54,7 +54,7 @@ GEM
activesupport (~> 3.0) activesupport (~> 3.0)
daemons daemons
erubis (2.7.0) erubis (2.7.0)
execjs (1.2.7) execjs (1.2.8)
multi_json (~> 1.0) multi_json (~> 1.0)
haml (3.1.3) haml (3.1.3)
hike (1.2.1) hike (1.2.1)
@ -67,8 +67,9 @@ GEM
treetop (~> 1.4.8) treetop (~> 1.4.8)
mime-types (1.16) mime-types (1.16)
multi_json (1.0.3) multi_json (1.0.3)
musicbrainz (0.4.9) musicbrainz (0.4.10)
nokogiri nokogiri
mysql2 (0.3.7)
nokogiri (1.5.0) nokogiri (1.5.0)
pg (0.11.0) pg (0.11.0)
polyglot (0.3.2) polyglot (0.3.2)
@ -103,7 +104,6 @@ GEM
hike (~> 1.2) hike (~> 1.2)
rack (~> 1.0) rack (~> 1.0)
tilt (!= 1.3.0, ~> 1.1) tilt (!= 1.3.0, ~> 1.1)
sqlite3 (1.3.4)
therubyracer (0.9.4) therubyracer (0.9.4)
libv8 (~> 3.3.10) libv8 (~> 3.3.10)
thor (0.14.6) thor (0.14.6)
@ -129,10 +129,10 @@ DEPENDENCIES
json json
lastfm-client! lastfm-client!
musicbrainz musicbrainz
mysql2 (= 0.3.7)
nokogiri nokogiri
pg pg
rails (= 3.1.0) rails (= 3.1.0)
sass sass
sqlite3
therubyracer therubyracer
uglifier uglifier

View File

@ -0,0 +1,2 @@
class ArtistAlias < ActiveRecord::Base
end

View File

@ -0,0 +1,2 @@
class TrackArtist < ActiveRecord::Base
end

View File

@ -1,8 +1,9 @@
development: development:
adapter: sqlite3 adapter: mysql2
database: db/development-discogs.sqlite3 database: beathaven
pool: 5 username: root
timeout: 5000 password: test
host: localhost
test: test:
adapter: sqlite3 adapter: sqlite3

View File

@ -0,0 +1,5 @@
class AddMasterToAlbum < ActiveRecord::Migration
def change
add_column :albums, :master, :boolean
end
end

View File

@ -0,0 +1,10 @@
class CreateArtistAliases < ActiveRecord::Migration
def change
create_table :artist_aliases do |t|
t.integer :artist_id
t.string :name
t.timestamps
end
end
end

View File

@ -0,0 +1,5 @@
class AddOriginalNameToArtist < ActiveRecord::Migration
def change
add_column :artists, :original_name, :string
end
end

View File

@ -0,0 +1,12 @@
class CreateTrackArtists < ActiveRecord::Migration
def change
create_table :track_artists do |t|
t.integer :track_id
t.integer :artist_id
t.boolean :main
t.string :join
t.timestamps
end
end
end

View File

@ -11,7 +11,7 @@
# #
# It's strongly recommended to check this file into your version control system. # It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20110920164044) do ActiveRecord::Schema.define(:version => 20110921182606) do
create_table "albums", :force => true do |t| create_table "albums", :force => true do |t|
t.string "name" t.string "name"
@ -24,6 +24,14 @@ ActiveRecord::Schema.define(:version => 20110920164044) do
t.string "mbid" t.string "mbid"
t.integer "has_pic" t.integer "has_pic"
t.integer "status" t.integer "status"
t.boolean "master"
end
create_table "artist_aliases", :force => true do |t|
t.integer "artist_id"
t.string "name"
t.datetime "created_at"
t.datetime "updated_at"
end end
create_table "artist_links", :force => true do |t| create_table "artist_links", :force => true do |t|
@ -45,6 +53,7 @@ ActiveRecord::Schema.define(:version => 20110920164044) do
t.integer "status" t.integer "status"
t.integer "listeners" t.integer "listeners"
t.integer "approved" t.integer "approved"
t.string "original_name"
end end
create_table "delayed_jobs", :force => true do |t| create_table "delayed_jobs", :force => true do |t|
@ -114,6 +123,15 @@ ActiveRecord::Schema.define(:version => 20110920164044) do
t.datetime "updated_at" t.datetime "updated_at"
end end
create_table "track_artists", :force => true do |t|
t.integer "track_id"
t.integer "artist_id"
t.boolean "main"
t.string "join"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "tracks", :force => true do |t| create_table "tracks", :force => true do |t|
t.string "name" t.string "name"
t.integer "album_id" t.integer "album_id"

View File

@ -10,12 +10,18 @@ class Discogs
end end
def self.process_artist node def self.process_artist node
Artist.new( artist = Artist.new(
:name => (node.css('name').first.text), :name => (node.css('name').first.text),
:pic_url => (node.css('images > image[type="primary"]').first.text unless node.css('images > image[type="primary"]').empty?), :pic_url => (node.css('images > image[type="primary"]').first.text unless node.css('images > image[type="primary"]').empty?),
:status => 1 :status => 1
).save )
p node.css('name').first.text artist.save
node.css('namevariations > name, aliases > name').each do |v|
ArtistAlias.new(
:artist_id => artist.id,
:name => v.text
).save
end
end end
def self.releases def self.releases

9
test/fixtures/artist_aliases.yml vendored Normal file
View File

@ -0,0 +1,9 @@
# Read about fixtures at http://api.rubyonrails.org/classes/Fixtures.html
one:
artist_id: 1
name: MyString
two:
artist_id: 1
name: MyString

13
test/fixtures/track_artists.yml vendored Normal file
View File

@ -0,0 +1,13 @@
# Read about fixtures at http://api.rubyonrails.org/classes/Fixtures.html
one:
track_id: 1
artist_id: 1
main: false
join: MyString
two:
track_id: 1
artist_id: 1
main: false
join: MyString

View File

@ -0,0 +1,7 @@
require 'test_helper'
class ArtistAliasTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end

View File

@ -0,0 +1,7 @@
require 'test_helper'
class TrackArtistTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end