From dea36d897f23cb697842278da53c1beb746e020b Mon Sep 17 00:00:00 2001 From: Seth Call Date: Sun, 19 Jan 2014 05:17:30 +0000 Subject: [PATCH] * VRFS-982 and VRFS-1003 - making every table that's directly related to music_session be UNLOGGED --- db/build | 2 +- db/manifest | 3 +- db/up/integrate_icecast_into_sessions.sql | 129 ++++++++++++++++++ ruby/lib/jam_ruby/message_factory.rb | 2 +- ruby/lib/jam_ruby/models/notification.rb | 13 +- ruby/spec/jam_ruby/connection_manager_spec.rb | 5 - 6 files changed, 145 insertions(+), 9 deletions(-) diff --git a/db/build b/db/build index 259aea93b..e0ece07a9 100755 --- a/db/build +++ b/db/build @@ -19,7 +19,7 @@ rm -rf $TARGET mkdir -p $PG_BUILD_OUT mkdir -p $PG_RUBY_PACKAGE_OUT -bundle update +#bundle update echo "building migrations" bundle exec pg_migrate build --source . --out $PG_BUILD_OUT --test --verbose diff --git a/db/manifest b/db/manifest index 5a9d3c4c8..bf2b2ead6 100755 --- a/db/manifest +++ b/db/manifest @@ -88,4 +88,5 @@ icecast.sql home_page_promos.sql mix_job_watch.sql music_session_constraints.sql -mixes_drop_manifest_add_retry.sql \ No newline at end of file +mixes_drop_manifest_add_retry.sql +integrate_icecast_into_sessions.sql \ No newline at end of file diff --git a/db/up/integrate_icecast_into_sessions.sql b/db/up/integrate_icecast_into_sessions.sql index e69de29bb..d92fa96c5 100644 --- a/db/up/integrate_icecast_into_sessions.sql +++ b/db/up/integrate_icecast_into_sessions.sql @@ -0,0 +1,129 @@ +-- this manifest update makes every table associated with music_sessions UNLOGGED + +-- tables to mark UNLOGGED +-- connections, fan_invitations, invitations, genres_music_sessions, join_requests, tracks, music_sessions + +-- tables to just get rid of +-- session_plays + +-- breaking foreign keys for tables +-- connections: user_id +-- fan_invitations: receiver_id, sender_id +-- music_session: user_id, band_id, claimed_recording_id, claimed_recording_initiator_id +-- genres_music_sessions: genre_id +-- invitations: sender_id, receiver_id +-- fan_invitations: user_id +-- notifications: invitation_id, join_request_id, session_id + +DROP TABLE sessions_plays; + +-- divorce notifications from UNLOGGED tables + +-- NOTIFICATIONS +---------------- +-- "notifications_session_id_fkey" FOREIGN KEY (session_id) REFERENCES music_sessions(id) ON DELETE CASCADE +ALTER TABLE notifications DROP CONSTRAINT notifications_session_id_fkey; +-- "notifications_join_request_id_fkey" FOREIGN KEY (join_request_id) REFERENCES join_requests(id) ON DELETE CASCADE +ALTER TABLE notifications DROP CONSTRAINT notifications_join_request_id_fkey; +-- "notifications_invitation_id_fkey" FOREIGN KEY (invitation_id) REFERENCES invitations(id) ON DELETE CASCADE +ALTER TABLE notifications DROP CONSTRAINT notifications_invitation_id_fkey; + +-- FAN_INVITATIONS +------------------ +DROP TABLE fan_invitations; +DROP TABLE invitations; +DROP TABLE join_requests; +DROP TABLE genres_music_sessions; +DROP TABLE tracks; +DROP TABLE connections; +DROP TABLE music_sessions; + +-- MUSIC_SESSIONS +----------------- +CREATE UNLOGGED TABLE music_sessions ( + id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4() NOT NULL, + description VARCHAR(8000), + user_id VARCHAR(64) NOT NULL, + created_at TIMESTAMP WITHOUT TIME ZONE DEFAULT NOW() NOT NULL, + updated_at TIMESTAMP WITHOUT TIME ZONE DEFAULT NOW() NOT NULL, + musician_access BOOLEAN NOT NULL, + band_id VARCHAR(64), + approval_required BOOLEAN NOT NULL, + fan_access BOOLEAN NOT NULL, + fan_chat BOOLEAN NOT NULL, + claimed_recording_id VARCHAR(64), + claimed_recording_initiator_id VARCHAR(64) +); + +-- CONNECTIONS +-------------- +CREATE UNLOGGED TABLE connections ( + id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4() NOT NULL, + user_id VARCHAR(64), + client_id VARCHAR(64) UNIQUE NOT NULL, + created_at TIMESTAMP WITHOUT TIME ZONE DEFAULT NOW() NOT NULL, + updated_at TIMESTAMP WITHOUT TIME ZONE DEFAULT NOW() NOT NULL, + music_session_id VARCHAR(64), + ip_address VARCHAR(64), + as_musician BOOLEAN, + aasm_state VARCHAR(64) DEFAULT 'idle'::VARCHAR NOT NULL +); +ALTER TABLE ONLY connections ADD CONSTRAINT connections_music_session_id_fkey FOREIGN KEY (music_session_id) REFERENCES music_sessions(id) ON DELETE SET NULL; + +-- GENRES_MUSIC_SESSIONS +------------------------ +CREATE UNLOGGED TABLE genres_music_sessions ( + id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4() NOT NULL, + genre_id VARCHAR(64), + music_session_id VARCHAR(64) +); +ALTER TABLE ONLY genres_music_sessions ADD CONSTRAINT genres_music_sessions_music_session_id_fkey FOREIGN KEY (music_session_id) REFERENCES music_sessions(id) ON DELETE CASCADE; + +CREATE UNLOGGED TABLE fan_invitations ( + id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4() NOT NULL, + sender_id VARCHAR(64), + receiver_id VARCHAR(64), + music_session_id VARCHAR(64), + created_at TIMESTAMP WITHOUT TIME ZONE DEFAULT NOW() NOT NULL, + updated_at TIMESTAMP WITHOUT TIME ZONE DEFAULT NOW() NOT NULL +); +ALTER TABLE ONLY fan_invitations ADD CONSTRAINT fan_invitations_music_session_id_fkey FOREIGN KEY (music_session_id) REFERENCES music_sessions(id) ON DELETE CASCADE; + +CREATE UNLOGGED TABLE join_requests ( + id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4() NOT NULL, + user_id VARCHAR(64), + music_session_id VARCHAR(64), + text VARCHAR(2000), + created_at TIMESTAMP WITHOUT TIME ZONE DEFAULT NOW() NOT NULL, + updated_at TIMESTAMP WITHOUT TIME ZONE DEFAULT NOW() NOT NULL +); +ALTER TABLE ONLY join_requests ADD CONSTRAINT user_music_session_uniqkey UNIQUE (user_id, music_session_id); +ALTER TABLE ONLY join_requests ADD CONSTRAINT join_requests_music_session_id_fkey FOREIGN KEY (music_session_id) REFERENCES music_sessions(id) ON DELETE CASCADE; + +-- INVITATIONS +-------------- +CREATE UNLOGGED TABLE invitations ( + id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4() NOT NULL, + sender_id VARCHAR(64), + receiver_id VARCHAR(64), + music_session_id VARCHAR(64), + created_at TIMESTAMP WITHOUT TIME ZONE DEFAULT NOW() NOT NULL, + updated_at TIMESTAMP WITHOUT TIME ZONE DEFAULT NOW() NOT NULL, + join_request_id VARCHAR(64) +); +ALTER TABLE ONLY invitations ADD CONSTRAINT invitations_uniqkey UNIQUE (sender_id, receiver_id, music_session_id); +ALTER TABLE ONLY invitations ADD CONSTRAINT invitations_join_request_id_fkey FOREIGN KEY (join_request_id) REFERENCES join_requests(id) ON DELETE CASCADE; +ALTER TABLE ONLY invitations ADD CONSTRAINT invitations_music_session_id_fkey FOREIGN KEY (music_session_id) REFERENCES music_sessions(id) ON DELETE CASCADE; + +-- TRACKS +--------- +CREATE UNLOGGED TABLE tracks ( + id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4() NOT NULL, + connection_id VARCHAR(64), + instrument_id VARCHAR(64), + sound VARCHAR(64) NOT NULL, + created_at TIMESTAMP WITHOUT TIME ZONE DEFAULT NOW() NOT NULL, + updated_at TIMESTAMP WITHOUT TIME ZONE DEFAULT NOW() NOT NULL, + client_track_id VARCHAR(64) NOT NULL +); +ALTER TABLE ONLY tracks ADD CONSTRAINT connections_tracks_connection_id_fkey FOREIGN KEY (connection_id) REFERENCES connections(id) ON DELETE CASCADE; diff --git a/ruby/lib/jam_ruby/message_factory.rb b/ruby/lib/jam_ruby/message_factory.rb index 7f3125da2..f23eb7087 100644 --- a/ruby/lib/jam_ruby/message_factory.rb +++ b/ruby/lib/jam_ruby/message_factory.rb @@ -558,7 +558,7 @@ module JamRuby # create a source up requested message to send to clients in a session, # so that one of the clients will start sending source audio to icecast - def source_up_requested (session_id, host, port, mount, source_user, source_pass) + def source_up_requested (session_id, host, port, mount, source_user, source_pass) source_up_requested = Jampb::SourceUpRequested.new( host: host, port: port, diff --git a/ruby/lib/jam_ruby/models/notification.rb b/ruby/lib/jam_ruby/models/notification.rb index c439d1672..6587fcc25 100644 --- a/ruby/lib/jam_ruby/models/notification.rb +++ b/ruby/lib/jam_ruby/models/notification.rb @@ -760,12 +760,23 @@ module JamRuby @@mq_router.server_publish_to_session(music_session, msg, sender = {:client_id => client_id}) end - def send_download_available(user_id) msg = @@message_factory.download_available @@mq_router.publish_to_user(user_id, msg) end + + def send_source_up_requested(music_session, host, port, mount, source_user, source_pass) + msg = @@message_factory.source_up_requested(music_session.id, host, port, mount, source_user, source_pass) + + @@mg_router.server_publish_to_session(music_session, msg) + end + + def send_source_down_requested(music_session, mount) + msg = @@message_factory.source_down_requested(music_session.id, mount) + + @@mq_router.server_publish_to_session(music_session, msg) + end end end end \ No newline at end of file diff --git a/ruby/spec/jam_ruby/connection_manager_spec.rb b/ruby/spec/jam_ruby/connection_manager_spec.rb index 392807675..dc093a0cb 100644 --- a/ruby/spec/jam_ruby/connection_manager_spec.rb +++ b/ruby/spec/jam_ruby/connection_manager_spec.rb @@ -45,10 +45,6 @@ describe ConnectionManager do end end - it "can't create bogus user_id" do - expect { @connman.create_connection("aeonuthaoentuh", "client_id", "1.1.1.1") }.to raise_error(PG::Error) - end - it "can't create two client_ids of same value" do client_id = "client_id1" @@ -428,7 +424,6 @@ describe ConnectionManager do @connman.delete_connection(client_id) assert_num_connections(client_id, 0) - end end