diff --git a/db/.gitignore b/db/.gitignore new file mode 100644 index 000000000..e2983ef18 --- /dev/null +++ b/db/.gitignore @@ -0,0 +1,6 @@ +target +*~ +*.swp +vendor +*.deb +.bundle diff --git a/db/.pg_migrate b/db/.pg_migrate new file mode 100644 index 000000000..f4e8722af --- /dev/null +++ b/db/.pg_migrate @@ -0,0 +1,2 @@ +build.connopts=dbname:jam_db_build user:postgres password:postgres host:127.0.0.1 +build.oob_connopts=dbname:postgres user:postgres password:postgres host:127.0.0.1 diff --git a/db/.ruby-gemset b/db/.ruby-gemset new file mode 100644 index 000000000..7477464db --- /dev/null +++ b/db/.ruby-gemset @@ -0,0 +1 @@ +jam-db diff --git a/db/.ruby-version b/db/.ruby-version new file mode 100644 index 000000000..abf2ccea0 --- /dev/null +++ b/db/.ruby-version @@ -0,0 +1 @@ +ruby-2.0.0-p247 diff --git a/db/Gemfile b/db/Gemfile new file mode 100644 index 000000000..70c0e1813 --- /dev/null +++ b/db/Gemfile @@ -0,0 +1,9 @@ +source 'https://rubygems.org' + +# Look for $WORKSPACE, otherwise use "workspace" as dev path. +workspace = ENV["WORKSPACE"] || "~/workspace" + +# Assumes you have already cloned pg_migrate_ruby in your workspace +# $ cd [workspace] +# $ git clone https://github.com/sethcall/pg_migrate_ruby +gem 'pg_migrate', '0.1.11' diff --git a/db/Gemfile.lock b/db/Gemfile.lock new file mode 100644 index 000000000..e9646a77c --- /dev/null +++ b/db/Gemfile.lock @@ -0,0 +1,20 @@ +GEM + remote: https://rubygems.org/ + specs: + little-plugger (1.1.3) + logging (1.7.2) + little-plugger (>= 1.1.3) + pg (0.15.1) + pg (0.15.1-x86-mingw32) + pg_migrate (0.1.11) + logging (= 1.7.2) + pg (= 0.15.1) + thor (= 0.15.4) + thor (0.15.4) + +PLATFORMS + ruby + x86-mingw32 + +DEPENDENCIES + pg_migrate (= 0.1.11) diff --git a/db/README.md b/db/README.md new file mode 100644 index 000000000..7ca4b55e6 --- /dev/null +++ b/db/README.md @@ -0,0 +1,59 @@ +jam-db +====== + +Schema migrations for the jam-db database. Uses the [pg_migrate tool](https://github.com/sethcall/pg_migrate) tool. The github page of pg_migrate also has some documentation and rationale behind this approach of migrations. + +Overview +-------- +am-db defines the migrations that comprise the jam-db database. It uses pg_migrate to package up the migrations into a gem or (TODO) jar. You can then use those packaged up versions of the schemas in downstream projects. + +The main reason the 'pg_migrate' approach is taken is to make to possible to use the database like an interface, freed from any one project or language. + +Environment +----------- +* [rvm](https://rvm.io/) with ruby 1.9.3 installed and activated. rvm needs to be activated in your shell (the installation process does this) +* bash . If on windows, use git bash or cygwin. Bash is used as the build script technology. (could change very easily) +* Definition of location for your developer workspace. Default is ~/workspace, but if you define an env variable, you can override. +* pg_migrate_ruby - $ cd [workspace] && git clone https://github.com/sethcall/pg_migrate_ruby +* The current logged in OS user has access to the 'postgres' database and is a super user in the database. In other words, you want to make sure your current logged in user can do the following at the command line: 'psql postgres'. If you can do that, you should be OK. There are two reasons this may not work for you. +1) Your current user is not a superuser. If not, do `sudo su postgres -c "createuser YOURUSER"` and answer 'y' with the first question. +2) If your user already is a superuser, then the postgres database may not exist yet. In that case, do `psql` then `create database postgres` +* NOT YET: $IVY defined as path to the [apache ivy jar](http://ant.apache.org/ivy/download.cgi). Download the latest ivy from here, extract somewhere, and create an IVY environment variable with a path to the ivy.jar. For example, in my bash.profile: `export IVY=/Users/seth/workspace/apache-ivy-2.3.0-rc1/ivy-2.3.0-rc1.jar` + +Building +-------- +# one-time: if you just installed rvm, cd into this project's base directory. rvm will ask you to trust the .rvmrc. Do so. +# type: + ./build # this will clean your 'target' directory, and rebuild from scratch. It takes seconds. + +Using +----- + +In a ruby project, create in your gemfile something like: +` +https 'https://rubygems.org' + +gem 'jam_db', :path => '~/workspace/jam-db/target/ruby_package' +` +Then, to cause a migration, do something like: + +# make sure you have the jam_db gem +bundle install + +# migrate the database (assumes you've created the 'jam' database already). +bundle exec jam_db up --connopts="dbname:jam host:localhost user:postgres password:postgres" --verbose + +# you can see if it worked by typing: + +psql jam +> select * from pgmigrate.pg_migrate; + + + +# If your database is screwed up, do this: +dropdb jam +createdb jam +migrate.sh + +END + diff --git a/db/build b/db/build new file mode 100755 index 000000000..be6b59275 --- /dev/null +++ b/db/build @@ -0,0 +1,36 @@ +#!/bin/bash -l + +TARGET=target +PG_BUILD_OUT=$TARGET/build +PG_RUBY_PACKAGE_OUT=$TARGET/ruby_package +PROJECT_NAME="jam_db" + +if [ -z $BUILD_NUMBER ]; then + BUILD_NUMBER="1" +fi + +VERSION="0.0.${BUILD_NUMBER}" + +set -e + +# remove the output directory +rm -rf $TARGET + +mkdir -p $PG_BUILD_OUT +mkdir -p $PG_RUBY_PACKAGE_OUT + +bundle update + +echo "building migrations" +bundle exec pg_migrate build --source . --out $PG_BUILD_OUT --test --verbose + +echo "packaging migrations for ruby"bundle exec pg_migrate package --source $PG_BUILD_OUT --out $PG_RUBY_PACKAGE_OUT --name jam-db --version "$VERSION" +bundle exec pg_migrate package --source $PG_BUILD_OUT --out $PG_RUBY_PACKAGE_OUT --name $PROJECT_NAME --version $VERSION + +if [ ! -z "$PACKAGE" ]; then + bundle install --path target/vendor/bundle + pushd target + fpm -s gem -t deb ruby_package/jam_db-$VERSION.gem + find vendor/bundle/ruby/2.0.0/cache -name '*.gem' | xargs -rn1 fpm -s gem -t deb + popd +fi diff --git a/db/jenkins b/db/jenkins new file mode 100755 index 000000000..8d2afbc49 --- /dev/null +++ b/db/jenkins @@ -0,0 +1,44 @@ +#!/bin/bash + +GEM_SERVER=http://localhost:9000/gems +DEB_SERVER=http://localhost:9010/apt-`uname -p` + +echo "starting build..." +./build + +if [ "$?" = "0" ]; then + echo "build succeeded" + echo "publishing gem" + pushd "target/ruby_package" + find . -name *.gem -exec curl -f -T {} $GEM_SERVER/{} \; + + if [ "$?" != "0" ]; then + echo "publish failed" + exit 1 + fi + popd + echo "done publishing gems" + + if [ ! -z "$PACKAGE" ]; then + echo "publishing ubuntu packages (.deb)" + for f in `find target -name '*.deb'`; do + DEBNAME=`basename $f` + DEBPATH="$f" + echo "publishing $DEBPATH to deb server" + curl -f -T $DEBPATH $DEB_SERVER/$DEBNAME + + if [ "$?" != "0" ]; then + echo "deb publish failed of $DEBPATH" + exit 1 + fi + done + + echo "done publishing debs" + fi + +else + echo "build failed" + exit 1 +fi + + diff --git a/db/manifest b/db/manifest new file mode 100755 index 000000000..9808e5748 --- /dev/null +++ b/db/manifest @@ -0,0 +1,74 @@ +sessions.sql +users.sql +sessions_api_v1.sql +p2p.sql +collapse_participants.sql +genre_session.sql +invitations.sql +instruments.sql +musician_access.sql +tracks.sql +followers.sql +locations.sql +first_last_name.sql +account_fields.sql +signup.sql +bootstrap_users_v2.sql +drop_users_name.sql +recordings.sql +favorites.sql +user_authorizations.sql +music_session_all_params.sql +as_musician.sql +bootstrap_users_v3.sql +update_user_band_fields.sql +add_recording_creator_id.sql +make_location_nullable.sql +band_invitations.sql +image_urls.sql +max_mind.sql +recordings_genres.sql +join_request.sql +user_state_lengthen.sql +likes.sql +comments.sql +downloads.sql +plays.sql +session_settings.sql +tracks_rename.sql +reset_password.sql +friend_request_changes.sql +session_history.sql +user_add_can_invite.sql +admin_users.sql +full_text_search.sql +saved_tracks.sql +saved_tracks_upload_id.sql +artifact_update.sql +connection_aasm_state.sql +artifact_update_modified.sql +recorded_tracks.sql +allow_null_first_last_name.sql +invited_users.sql +collapse_user_and_admin.sql +default_gender_to_null.sql +subscribe_email.sql +notifications.sql +notification_type_col_rename.sql +notifications_add_friend_req_id.sql +artifact_metadata.sql +mixes.sql +perf_data.sql +claimed_recordings.sql +recordings2.sql +update_email.sql +claimed_recordings2.sql +users_favorites.sql +max_mind_isp.sql +other_instrument.sql +max_mind_isp_add_country.sql +avatar_using_filepicker.sql +isp_score_batch.sql +crash_dumps.sql +crash_dumps_idx.sql +music_sessions_user_history_add_session_removed_at.sql diff --git a/db/up/.gitkeep b/db/up/.gitkeep new file mode 100644 index 000000000..e69de29bb diff --git a/db/up/account_fields.sql b/db/up/account_fields.sql new file mode 100644 index 000000000..94568227e --- /dev/null +++ b/db/up/account_fields.sql @@ -0,0 +1,3 @@ +ALTER TABLE users ADD COLUMN birth_date DATE NOT NULL DEFAULT '07/07/1978'; +ALTER TABLE users ADD COLUMN gender CHAR(1) NOT NULL DEFAULT 'M'; +ALTER TABLE users ADD COLUMN internet_service_provider VARCHAR(50); \ No newline at end of file diff --git a/db/up/add_recording_creator_id.sql b/db/up/add_recording_creator_id.sql new file mode 100644 index 000000000..5322e463a --- /dev/null +++ b/db/up/add_recording_creator_id.sql @@ -0,0 +1,2 @@ +ALTER TABLE recordings ADD COLUMN creator_id VARCHAR(64) NOT NULL REFERENCES users (id); +ALTER TABLE recordings ADD COLUMN updater_id VARCHAR(64) NOT NULL REFERENCES users (id); diff --git a/db/up/admin_users.sql b/db/up/admin_users.sql new file mode 100644 index 000000000..8933ceaeb --- /dev/null +++ b/db/up/admin_users.sql @@ -0,0 +1,68 @@ + +CREATE TABLE admin_users ( + id integer NOT NULL, + email character varying(255) DEFAULT ''::character varying NOT NULL, + encrypted_password character varying(255) DEFAULT ''::character varying NOT NULL, + reset_password_token character varying(255), + reset_password_sent_at timestamp without time zone, + remember_created_at timestamp without time zone, + sign_in_count integer DEFAULT 0, + current_sign_in_at timestamp without time zone, + last_sign_in_at timestamp without time zone, + current_sign_in_ip character varying(255), + last_sign_in_ip character varying(255), + created_at timestamp without time zone NOT NULL, + updated_at timestamp without time zone NOT NULL +); + +ALTER TABLE public.admin_users OWNER TO postgres; +CREATE SEQUENCE admin_users_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER TABLE public.admin_users_id_seq OWNER TO postgres; +ALTER SEQUENCE admin_users_id_seq OWNED BY admin_users.id; +SELECT pg_catalog.setval('admin_users_id_seq', 2, true); +ALTER TABLE ONLY admin_users ALTER COLUMN id SET DEFAULT nextval('admin_users_id_seq'::regclass); +ALTER TABLE ONLY admin_users + ADD CONSTRAINT admin_users_pkey PRIMARY KEY (id); +CREATE UNIQUE INDEX index_admin_users_on_email ON admin_users USING btree (email); +CREATE UNIQUE INDEX index_admin_users_on_reset_password_token ON admin_users USING btree (reset_password_token); + +--------------------------------- + +CREATE TABLE active_admin_comments ( + id integer NOT NULL, + resource_id character varying(255) NOT NULL, + resource_type character varying(255) NOT NULL, + author_id integer, + author_type character varying(255), + body text, + created_at timestamp without time zone NOT NULL, + updated_at timestamp without time zone NOT NULL, + namespace character varying(255) +); +ALTER TABLE public.active_admin_comments OWNER TO postgres; +CREATE SEQUENCE active_admin_comments_id_seq + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + +ALTER TABLE public.active_admin_comments_id_seq OWNER TO postgres; +ALTER SEQUENCE active_admin_comments_id_seq OWNED BY active_admin_comments.id; +SELECT pg_catalog.setval('active_admin_comments_id_seq', 1, false); +ALTER TABLE ONLY active_admin_comments ALTER COLUMN id SET DEFAULT nextval('active_admin_comments_id_seq'::regclass); +ALTER TABLE ONLY active_admin_comments + ADD CONSTRAINT admin_comments_pkey PRIMARY KEY (id); +CREATE INDEX index_active_admin_comments_on_author_type_and_author_id ON active_admin_comments USING btree (author_type, author_id); +CREATE INDEX index_active_admin_comments_on_namespace ON active_admin_comments USING btree (namespace); +CREATE INDEX index_admin_comments_on_resource_type_and_resource_id ON active_admin_comments USING btree (resource_type, resource_id); + + +--------------------------------- + diff --git a/db/up/allow_null_first_last_name.sql b/db/up/allow_null_first_last_name.sql new file mode 100644 index 000000000..02c5c3327 --- /dev/null +++ b/db/up/allow_null_first_last_name.sql @@ -0,0 +1,6 @@ +-- allow null first names and last names so that administrators can invite users +-- with a minimum of fields filled out +ALTER TABLE users ALTER COLUMN first_name DROP NOT NULL; +ALTER TABLE users ALTER COLUMN last_name DROP NOT NULL; +ALTER TABLE users ALTER COLUMN gender DROP NOT NULL; +ALTER TABLE users ALTER COLUMN gender DROP DEFAULT; diff --git a/db/up/artifact_metadata.sql b/db/up/artifact_metadata.sql new file mode 100644 index 000000000..77905a8d3 --- /dev/null +++ b/db/up/artifact_metadata.sql @@ -0,0 +1,3 @@ +-- add a size field and make md5 required +ALTER TABLE artifact_updates ADD COLUMN size INTEGER NOT NULL; +ALTER TABLE artifact_updates ALTER COLUMN sha1 SET NOT NULL; diff --git a/db/up/artifact_update.sql b/db/up/artifact_update.sql new file mode 100644 index 000000000..e4a6ced5d --- /dev/null +++ b/db/up/artifact_update.sql @@ -0,0 +1,14 @@ +-- artifact 'pointer' table + +CREATE TABLE artifact_updates ( + id character varying(64) NOT NULL DEFAULT uuid_generate_v4(), + product varchar(255) NOT NULL, + version varchar(255) NOT NULL, + uri varchar(2000) NOT NULL, + sha1 varchar(255) NOT NULL, + environment varchar(255) NOT NULL DEFAULT 'public' +); + +ALTER TABLE artifact_updates ADD CONSTRAINT artifact_updates_uniqkey UNIQUE (product, version); + +ALTER TABLE users ADD COLUMN environment varchar(255) NOT NULL DEFAULT 'public'; diff --git a/db/up/artifact_update_modified.sql b/db/up/artifact_update_modified.sql new file mode 100644 index 000000000..0d69f0d6d --- /dev/null +++ b/db/up/artifact_update_modified.sql @@ -0,0 +1 @@ +ALTER TABLE artifact_updates ALTER COLUMN sha1 DROP NOT NULL; diff --git a/db/up/as_musician.sql b/db/up/as_musician.sql new file mode 100644 index 000000000..9a52de0c2 --- /dev/null +++ b/db/up/as_musician.sql @@ -0,0 +1 @@ +ALTER TABLE connections ADD COLUMN as_musician BOOLEAN; diff --git a/db/up/avatar_using_filepicker.sql b/db/up/avatar_using_filepicker.sql new file mode 100644 index 000000000..258f50cee --- /dev/null +++ b/db/up/avatar_using_filepicker.sql @@ -0,0 +1,8 @@ +-- add columns necessary to store a filepicker original file, cropped file, and original s3 paths to each + +ALTER TABLE users ADD COLUMN original_fpfile VARCHAR(8000) DEFAULT NULL; +ALTER TABLE users ADD COLUMN cropped_fpfile VARCHAR(8000) DEFAULT NULL; +ALTER TABLE users ADD COLUMN cropped_s3_path VARCHAR(512) DEFAULT NULL; +ALTER TABLE users ADD COLUMN crop_selection VARCHAR(256) DEFAULT NULL; +-- photo_url, which already exists on users, is now just the http accessible version of the cropped_s3_path + diff --git a/db/up/band_invitations.sql b/db/up/band_invitations.sql new file mode 100644 index 000000000..ff135bcaf --- /dev/null +++ b/db/up/band_invitations.sql @@ -0,0 +1,9 @@ +CREATE TABLE band_invitations ( + id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(), + user_id VARCHAR(64) REFERENCES users(id) ON DELETE CASCADE, + band_id VARCHAR(64) REFERENCES bands(id) ON DELETE CASCADE, + accepted BOOLEAN, + creator_id VARCHAR(64) REFERENCES users(id) ON DELETE CASCADE, + created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP +); \ No newline at end of file diff --git a/db/up/bootstrap_users_v2.sql b/db/up/bootstrap_users_v2.sql new file mode 100644 index 000000000..a8e686d48 --- /dev/null +++ b/db/up/bootstrap_users_v2.sql @@ -0,0 +1,22 @@ +-- create a utility that bootstraps a user +CREATE OR REPLACE FUNCTION bootstrap_users() RETURNS void AS $$ +DECLARE + test_user VARCHAR(64); +BEGIN +-- non guid used for test user. test user won't be in actual database, but '1' is much easier to script that 242423-42-4-24234 +-- password is jam123 + SELECT id INTO STRICT test_user FROM users WHERE id = '1'; + + UPDATE users SET name = 'test', email = 'test@jamkazam.com', remember_token = 'NQubl-z16Em94tnSdofObw', password_digest = '$2a$10$QyaNTLVX5DAaJ.JL21kDWeUQqdh3Qh7JQbdRgE82x1Cib7HWNcHXC', email_confirmed=true WHERE id = '1'; + + EXCEPTION + WHEN NO_DATA_FOUND THEN + INSERT INTO users (id, name, email, remember_token, password_digest, email_confirmed) VALUES ('1', 'test', 'test@jamkazam.com', 'NQubl-z16Em94tnSdofObw', '$2a$10$QyaNTLVX5DAaJ.JL21kDWeUQqdh3Qh7JQbdRgE82x1Cib7HWNcHXC', true); + RETURN; + WHEN TOO_MANY_ROWS THEN + RAISE EXCEPTION 'user id 1 not unique'; +END; +$$ LANGUAGE plpgsql; + +select bootstrap_users(); + diff --git a/db/up/bootstrap_users_v3.sql b/db/up/bootstrap_users_v3.sql new file mode 100644 index 000000000..d3e0f3e60 --- /dev/null +++ b/db/up/bootstrap_users_v3.sql @@ -0,0 +1,22 @@ +-- create a utility that bootstraps a user +CREATE OR REPLACE FUNCTION bootstrap_users() RETURNS void AS $$ +DECLARE + test_user VARCHAR(64); +BEGIN +-- non guid used for test user. test user won't be in actual database, but '1' is much easier to script that 242423-42-4-24234 +-- password is jam123 + SELECT id INTO STRICT test_user FROM users WHERE id = '1'; + + UPDATE users SET first_name = 'Test', last_name = 'User', email = 'test@jamkazam.com', remember_token = 'NQubl-z16Em94tnSdofObw', password_digest = '$2a$10$QyaNTLVX5DAaJ.JL21kDWeUQqdh3Qh7JQbdRgE82x1Cib7HWNcHXC', email_confirmed=true, musician=true WHERE id = '1'; + + EXCEPTION + WHEN NO_DATA_FOUND THEN + INSERT INTO users (id, first_name, last_name, email, remember_token, password_digest, email_confirmed, musician) VALUES ('1', 'Test', 'User', 'test@jamkazam.com', 'NQubl-z16Em94tnSdofObw', '$2a$10$QyaNTLVX5DAaJ.JL21kDWeUQqdh3Qh7JQbdRgE82x1Cib7HWNcHXC', true, true); + RETURN; + WHEN TOO_MANY_ROWS THEN + RAISE EXCEPTION 'user id 1 not unique'; +END; +$$ LANGUAGE plpgsql; + +select bootstrap_users(); + diff --git a/db/up/claimed_recordings.sql b/db/up/claimed_recordings.sql new file mode 100644 index 000000000..923e3617b --- /dev/null +++ b/db/up/claimed_recordings.sql @@ -0,0 +1,17 @@ +ALTER TABLE recordings_users RENAME TO claimed_recordings; +ALTER TABLE claimed_recordings ADD COLUMN id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(); +ALTER TABLE claimed_recordings ADD COLUMN name VARCHAR(200) NOT NULL; +ALTER TABLE claimed_recordings ADD COLUMN is_public BOOLEAN NOT NULL DEFAULT true; +ALTER TABLE claimed_recordings ADD COLUMN is_downloadable BOOLEAN NOT NULL DEFAULT true; +ALTER TABLE claimed_recordings ADD COLUMN genre_id VARCHAR(64) NOT NULL REFERENCES genres(id); +ALTER TABLE recordings DROP COLUMN description_tsv; +ALTER TABLE recordings DROP COLUMN description; +ALTER TABLE recordings DROP COLUMN name; +ALTER TABLE recordings DROP COLUMN public; +ALTER TABLE recordings DROP COLUMN is_public; +ALTER TABLE recordings DROP COLUMN is_downloadable; +DROP TRIGGER tsvectorupdate ON recordings; +ALTER TABLE recordings ADD COLUMN duration INTEGER; +ALTER TABLE mixes RENAME COLUMN spec TO manifest; +ALTER TABLE mixes DROP COLUMN url; + diff --git a/db/up/claimed_recordings2.sql b/db/up/claimed_recordings2.sql new file mode 100755 index 000000000..52306fb0a --- /dev/null +++ b/db/up/claimed_recordings2.sql @@ -0,0 +1,3 @@ +ALTER TABLE claimed_recordings ADD COLUMN created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP; +ALTER TABLE claimed_recordings ADD COLUMN updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP; + diff --git a/db/up/collapse_participants.sql b/db/up/collapse_participants.sql new file mode 100644 index 000000000..691b0018a --- /dev/null +++ b/db/up/collapse_participants.sql @@ -0,0 +1,4 @@ +DROP TABLE music_session_clients; + +ALTER TABLE connections ADD COLUMN music_session_id VARCHAR(64) REFERENCES music_sessions(id) ON DELETE SET NULL; +ALTER TABLE connections ADD COLUMN ip_address VARCHAR(64); diff --git a/db/up/collapse_user_and_admin.sql b/db/up/collapse_user_and_admin.sql new file mode 100644 index 000000000..654fa8777 --- /dev/null +++ b/db/up/collapse_user_and_admin.sql @@ -0,0 +1,4 @@ +-- make your life easy and use this name for your encrypted password +ALTER TABLE users RENAME COLUMN password_digest TO encrypted_password; + +DROP TABLE admin_users; diff --git a/db/up/comments.sql b/db/up/comments.sql new file mode 100644 index 000000000..28520ac57 --- /dev/null +++ b/db/up/comments.sql @@ -0,0 +1,19 @@ +-- recordings +CREATE TABLE recordings_comments( + id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(), + recording_id VARCHAR(64) NOT NULL REFERENCES recordings(id) ON DELETE CASCADE, + creator_id VARCHAR(64) NOT NULL REFERENCES users(id) ON DELETE CASCADE, + comment VARCHAR(4000) NOT NULL, + created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP +); + +-- sessions +CREATE TABLE music_sessions_comments ( + id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(), + music_session_id VARCHAR(64) NOT NULL REFERENCES music_sessions(id) ON DELETE CASCADE, + creator_id VARCHAR(64) NOT NULL REFERENCES users(id) ON DELETE CASCADE, + comment VARCHAR(4000) NOT NULL, + created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP +); \ No newline at end of file diff --git a/db/up/connection_aasm_state.sql b/db/up/connection_aasm_state.sql new file mode 100644 index 000000000..dc5f6ed2d --- /dev/null +++ b/db/up/connection_aasm_state.sql @@ -0,0 +1,2 @@ +-- connection state for supporting aasm gem +ALTER TABLE connections ADD COLUMN aasm_state VARCHAR(64) NOT NULL DEFAULT 'idle'; diff --git a/db/up/crash_dumps.sql b/db/up/crash_dumps.sql new file mode 100755 index 000000000..4f7b2a3c5 --- /dev/null +++ b/db/up/crash_dumps.sql @@ -0,0 +1,11 @@ +CREATE TABLE crash_dumps ( + id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(), + client_type VARCHAR(64) NOT NULL, + client_id VARCHAR(64), + user_id VARCHAR(64) REFERENCES users(id), + session_id VARCHAR(64), + timestamp TIMESTAMP, + uri VARCHAR(1000), + created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP +); diff --git a/db/up/crash_dumps_idx.sql b/db/up/crash_dumps_idx.sql new file mode 100755 index 000000000..5825f6822 --- /dev/null +++ b/db/up/crash_dumps_idx.sql @@ -0,0 +1,5 @@ +CREATE INDEX crash_dumps_user_id_idx ON crash_dumps(user_id); +CREATE INDEX crash_dumps_client_id_idx ON crash_dumps(client_id); +CREATE INDEX crash_dumps_timestamp_idx ON crash_dumps(timestamp); + +ALTER TABLE crash_dumps ADD COLUMN client_version VARCHAR(100) NOT NULL; diff --git a/db/up/default_gender_to_null.sql b/db/up/default_gender_to_null.sql new file mode 100644 index 000000000..6c2f1ab35 --- /dev/null +++ b/db/up/default_gender_to_null.sql @@ -0,0 +1 @@ +ALTER TABLE users ALTER gender DROP DEFAULT; diff --git a/db/up/downloads.sql b/db/up/downloads.sql new file mode 100644 index 000000000..049c0feb3 --- /dev/null +++ b/db/up/downloads.sql @@ -0,0 +1,8 @@ +-- downloads +CREATE TABLE recordings_downloads( + id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(), + recording_id VARCHAR(64) NOT NULL REFERENCES recordings(id) ON DELETE CASCADE, + downloader_id VARCHAR(64) NOT NULL REFERENCES users(id) ON DELETE CASCADE, + created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP +); \ No newline at end of file diff --git a/db/up/drop_users_name.sql b/db/up/drop_users_name.sql new file mode 100644 index 000000000..0b41693e6 --- /dev/null +++ b/db/up/drop_users_name.sql @@ -0,0 +1 @@ +alter table users drop column name; \ No newline at end of file diff --git a/db/up/favorites.sql b/db/up/favorites.sql new file mode 100644 index 000000000..6cf4083f8 --- /dev/null +++ b/db/up/favorites.sql @@ -0,0 +1,9 @@ +CREATE TABLE users_favorites ( + id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(), + user_id VARCHAR(64) NOT NULL REFERENCES users(id) ON DELETE CASCADE, + recording_id VARCHAR(64) NOT NULL REFERENCES recordings(id) ON DELETE CASCADE, + created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP +); + +ALTER TABLE users_favorites ADD CONSTRAINT user_favorite_uniqkey UNIQUE (user_id, recording_id); diff --git a/db/up/first_last_name.sql b/db/up/first_last_name.sql new file mode 100644 index 000000000..e8f6db7ee --- /dev/null +++ b/db/up/first_last_name.sql @@ -0,0 +1,2 @@ +ALTER TABLE users ADD COLUMN first_name varchar(50) NOT NULL DEFAULT 'Test'; +ALTER TABLE users ADD COLUMN last_name varchar(50) NOT NULL DEFAULT 'User'; \ No newline at end of file diff --git a/db/up/followers.sql b/db/up/followers.sql new file mode 100644 index 000000000..367201b8a --- /dev/null +++ b/db/up/followers.sql @@ -0,0 +1,19 @@ +CREATE TABLE users_followers ( + id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(), + user_id VARCHAR(64) NOT NULL REFERENCES users(id) ON DELETE CASCADE, + follower_id VARCHAR(64) NOT NULL REFERENCES users(id) ON DELETE CASCADE, + created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP +); + +ALTER TABLE users_followers ADD CONSTRAINT user_follower_uniqkey UNIQUE (user_id, follower_id); + +CREATE TABLE bands_followers ( + id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(), + band_id VARCHAR(64) NOT NULL REFERENCES bands(id) ON DELETE CASCADE, + follower_id VARCHAR(64) NOT NULL REFERENCES users(id) ON DELETE CASCADE, + created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP +); + +ALTER TABLE bands_followers ADD CONSTRAINT band_follower_uniqkey UNIQUE (band_id, follower_id); \ No newline at end of file diff --git a/db/up/friend_request_changes.sql b/db/up/friend_request_changes.sql new file mode 100644 index 000000000..a11a09d18 --- /dev/null +++ b/db/up/friend_request_changes.sql @@ -0,0 +1,4 @@ +alter table friend_requests drop column accepted; +alter table friend_requests add column status varchar(50); +alter table friend_requests add column message varchar(4000); +alter table friend_requests drop constraint user_friend_request_uniqkey; \ No newline at end of file diff --git a/db/up/full_text_search.sql b/db/up/full_text_search.sql new file mode 100644 index 000000000..79ef32a94 --- /dev/null +++ b/db/up/full_text_search.sql @@ -0,0 +1,46 @@ + +-- as a result of these migrations, you can do the following: + +-- find a band with a word starting with 'Par' +-- select name from bands where name_tsv @@ to_tsquery('jamenglish', 'Par:*'); +-- find a user with first or last name starting with 'Cal' +-- select first_name FROM users where name_tsv @@ to_tsquery('jamenglish', 'Cal:*'); +-- find a recording with descriptio start with 'Fu' +-- select description FROM descriptions where description_tsv @@ to_tsquery('jamenglish', 'Fu:*'); + +CREATE TEXT SEARCH DICTIONARY english_stem ( + TEMPLATE = snowball, + Language = english, + StopWords = english); + +-- create a new configuration based on the standard 'english' configuration +CREATE TEXT SEARCH CONFIGURATION public.jamenglish ( COPY = pg_catalog.english ); +-- use snowball for word-y things +ALTER TEXT SEARCH CONFIGURATION public.jamenglish ALTER MAPPING FOR asciiword, asciihword, hword_asciipart, + word, hword, hword_part WITH english_stem; +-- don't worry about parsing character junk +ALTER TEXT SEARCH CONFIGURATION public.jamenglish DROP MAPPING FOR email, url, url_path, sfloat, float; + +-- add relevant rows to users, bands, recordings +ALTER TABLE users ADD COLUMN name_tsv tsvector; +CREATE TRIGGER tsvectorupdate BEFORE INSERT OR UPDATE +ON users FOR EACH ROW EXECUTE PROCEDURE +tsvector_update_trigger(name_tsv, 'public.jamenglish', first_name, last_name); +CREATE INDEX users_name_tsv_index ON users USING gin(name_tsv); + +ALTER TABLE bands ADD COLUMN name_tsv tsvector; +CREATE TRIGGER tsvectorupdate BEFORE INSERT OR UPDATE +ON bands FOR EACH ROW EXECUTE PROCEDURE +tsvector_update_trigger(name_tsv, 'public.jamenglish', name); +CREATE INDEX bands_name_tsv_index ON bands USING gin(name_tsv); + +ALTER TABLE recordings ADD COLUMN description_tsv tsvector; +CREATE TRIGGER tsvectorupdate BEFORE INSERT OR UPDATE +ON recordings FOR EACH ROW EXECUTE PROCEDURE +tsvector_update_trigger(description_tsv, 'public.jamenglish', description); +CREATE INDEX recordings_description_tsv_index ON recordings USING gin(description_tsv); + +-- update all existing data to invoke triggers +update users set first_name=first_name, last_name=last_name; +update bands set name=name; +update recordings set description=description; diff --git a/db/up/genre_session.sql b/db/up/genre_session.sql new file mode 100644 index 000000000..cf18064cd --- /dev/null +++ b/db/up/genre_session.sql @@ -0,0 +1,27 @@ +-- sessions -> genre mapping +CREATE TABLE genres_music_sessions ( + id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(), + genre_id VARCHAR(64) REFERENCES genres(id) ON DELETE CASCADE, + music_session_id VARCHAR(64) REFERENCES music_sessions(id) ON DELETE CASCADE +); + +INSERT INTO genres (description) VALUES + ('African'), + ('Ambient'), + ('Asian'), + ('Blues'), + ('Classical'), + ('Country'), + ('Electronic'), + ('Folk'), + ('Hip Hop'), + ('Jazz'), + ('Latin'), + ('Metal'), + ('Pop'), + ('R&B'), + ('Reggae'), + ('Religious'), + ('Rock'), + ('Ska'), + ('Other'); diff --git a/db/up/image_urls.sql b/db/up/image_urls.sql new file mode 100644 index 000000000..58bc69067 --- /dev/null +++ b/db/up/image_urls.sql @@ -0,0 +1,3 @@ +alter table users add column photo_url varchar(2048); +alter table bands add column photo_url varchar(2048); +alter table bands add column logo_url varchar(2048); \ No newline at end of file diff --git a/db/up/instruments.sql b/db/up/instruments.sql new file mode 100644 index 000000000..d02b79fa1 --- /dev/null +++ b/db/up/instruments.sql @@ -0,0 +1,4 @@ +insert into instruments (description) values +('Guitar'), +('Vocals'), +('Drums'); diff --git a/db/up/invitations.sql b/db/up/invitations.sql new file mode 100644 index 000000000..10d8f8c10 --- /dev/null +++ b/db/up/invitations.sql @@ -0,0 +1,10 @@ +CREATE TABLE invitations ( + id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(), + sender_id VARCHAR(64) REFERENCES users(id) ON DELETE CASCADE, + receiver_id VARCHAR(64) REFERENCES users(id) ON DELETE CASCADE, + music_session_id VARCHAR(64) REFERENCES music_sessions(id) ON DELETE CASCADE, + created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP +); + +ALTER TABLE invitations ADD CONSTRAINT invitations_uniqkey UNIQUE (sender_id, receiver_id, music_session_id); diff --git a/db/up/invited_users.sql b/db/up/invited_users.sql new file mode 100644 index 000000000..e691c1903 --- /dev/null +++ b/db/up/invited_users.sql @@ -0,0 +1,12 @@ +-- a table to manage invitations from one user to another +CREATE TABLE invited_users ( + id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(), + sender_id VARCHAR(64) REFERENCES users(id) ON DELETE CASCADE, + autofriend BOOLEAN NOT NULL, + email VARCHAR(256) NOT NULL, + invitation_code VARCHAR(256) UNIQUE NOT NULL, + accepted BOOLEAN DEFAULT FALSE, + note text, + created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP +); diff --git a/db/up/isp_score_batch.sql b/db/up/isp_score_batch.sql new file mode 100644 index 000000000..6475fb585 --- /dev/null +++ b/db/up/isp_score_batch.sql @@ -0,0 +1,5 @@ +CREATE TABLE isp_score_batch( + id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(), + json_scoring_data TEXT NOT NULL, + created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP +); diff --git a/db/up/join_request.sql b/db/up/join_request.sql new file mode 100644 index 000000000..fdc5f65ca --- /dev/null +++ b/db/up/join_request.sql @@ -0,0 +1,12 @@ +CREATE TABLE join_requests ( + id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(), + user_id VARCHAR(64) REFERENCES users(id) ON DELETE CASCADE, + music_session_id VARCHAR(64) REFERENCES music_sessions(id) ON DELETE CASCADE, + text VARCHAR(2000), + created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP +); + +ALTER TABLE join_requests ADD CONSTRAINT user_music_session_uniqkey UNIQUE (user_id, music_session_id); + +ALTER TABLE invitations ADD COLUMN join_request_id VARCHAR(64) REFERENCES join_requests(id) ON DELETE CASCADE; diff --git a/db/up/likes.sql b/db/up/likes.sql new file mode 100644 index 000000000..054fea454 --- /dev/null +++ b/db/up/likes.sql @@ -0,0 +1,43 @@ +-- musicians +CREATE TABLE users_likers ( + id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(), + user_id VARCHAR(64) NOT NULL REFERENCES users(id) ON DELETE CASCADE, + liker_id VARCHAR(64) NOT NULL REFERENCES users(id) ON DELETE CASCADE, + created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP +); + +ALTER TABLE users_likers ADD CONSTRAINT user_liker_uniqkey UNIQUE (user_id, liker_id); + +-- bands +CREATE TABLE bands_likers ( + id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(), + band_id VARCHAR(64) NOT NULL REFERENCES bands(id) ON DELETE CASCADE, + liker_id VARCHAR(64) NOT NULL REFERENCES users(id) ON DELETE CASCADE, + created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP +); + +ALTER TABLE bands_likers ADD CONSTRAINT band_liker_uniqkey UNIQUE (band_id, liker_id); + +-- recordings +CREATE TABLE recordings_likers ( + id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(), + recording_id VARCHAR(64) NOT NULL REFERENCES recordings(id) ON DELETE CASCADE, + liker_id VARCHAR(64) NOT NULL REFERENCES users(id) ON DELETE CASCADE, + created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP +); + +ALTER TABLE recordings_likers ADD CONSTRAINT recording_liker_uniqkey UNIQUE (recording_id, liker_id); + +-- sessions +CREATE TABLE music_sessions_likers ( + id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(), + music_session_id VARCHAR(64) NOT NULL REFERENCES music_sessions(id) ON DELETE CASCADE, + liker_id VARCHAR(64) NOT NULL REFERENCES users(id) ON DELETE CASCADE, + created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP +); + +ALTER TABLE music_sessions_likers ADD CONSTRAINT music_sessions_liker_uniqkey UNIQUE (music_session_id, liker_id); \ No newline at end of file diff --git a/db/up/locations.sql b/db/up/locations.sql new file mode 100644 index 000000000..ac961480a --- /dev/null +++ b/db/up/locations.sql @@ -0,0 +1,7 @@ +ALTER TABLE users ADD COLUMN city VARCHAR(100) NOT NULL DEFAULT 'City'; +ALTER TABLE users ADD COLUMN state VARCHAR(2); +ALTER TABLE users ADD COLUMN country VARCHAR(100); + +ALTER TABLE bands ADD COLUMN city VARCHAR(100) NOT NULL DEFAULT 'City'; +ALTER TABLE bands ADD COLUMN state VARCHAR(2); +ALTER TABLE bands ADD COLUMN country VARCHAR(100); \ No newline at end of file diff --git a/db/up/make_location_nullable.sql b/db/up/make_location_nullable.sql new file mode 100644 index 000000000..1bd8e455c --- /dev/null +++ b/db/up/make_location_nullable.sql @@ -0,0 +1,7 @@ +alter table users alter column city drop not null; +alter table users alter column state drop not null; +alter table users alter column country drop not null; + +alter table bands alter column city drop not null; +alter table bands alter column state drop not null; +alter table bands alter column country drop not null; \ No newline at end of file diff --git a/db/up/max_mind.sql b/db/up/max_mind.sql new file mode 100644 index 000000000..4bbcc2121 --- /dev/null +++ b/db/up/max_mind.sql @@ -0,0 +1,12 @@ +CREATE TABLE max_mind ( + ip_bottom INTEGER, + ip_top INTEGER, + country VARCHAR(64), + region VARCHAR(64), + city VARCHAR(255) +); + +CREATE INDEX max_mind_ip_bottom_idx ON max_mind(ip_bottom); +CREATE INDEX max_mind_ip_top_idx ON max_mind(ip_top); + + diff --git a/db/up/max_mind_isp.sql b/db/up/max_mind_isp.sql new file mode 100644 index 000000000..698feb735 --- /dev/null +++ b/db/up/max_mind_isp.sql @@ -0,0 +1,11 @@ +CREATE TABLE max_mind_isp ( + ip_bottom INTEGER, + ip_top INTEGER, + isp VARCHAR(255) +); + +CREATE INDEX max_mind_isp_ip_bottom_idx ON max_mind_isp(ip_bottom); +CREATE INDEX max_mind_isp_ip_top_idx ON max_mind_isp(ip_top); + + +ALTER TABLE max_mind RENAME TO max_mind_geo; diff --git a/db/up/max_mind_isp_add_country.sql b/db/up/max_mind_isp_add_country.sql new file mode 100644 index 000000000..e71cd3efa --- /dev/null +++ b/db/up/max_mind_isp_add_country.sql @@ -0,0 +1 @@ +ALTER TABLE max_mind_isp ADD COLUMN country VARCHAR(64); diff --git a/db/up/mixes.sql b/db/up/mixes.sql new file mode 100644 index 000000000..376dc2d30 --- /dev/null +++ b/db/up/mixes.sql @@ -0,0 +1,18 @@ +-- mixes +CREATE TABLE mixes( + id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(), + recording_id VARCHAR(64) NOT NULL REFERENCES recordings(id) ON DELETE CASCADE, + owner_id VARCHAR(64) NOT NULL REFERENCES users(id) ON DELETE CASCADE, + description VARCHAR(1024) NOT NULL, + spec TEXT NOT NULL, + url VARCHAR(512) DEFAULT NULL, + mix_server VARCHAR(64) DEFAULT NULL, + started_at TIMESTAMP DEFAULT NULL, + completed_at TIMESTAMP DEFAULT NULL, + created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP +); + +CREATE INDEX index_started_at ON mixes USING btree (started_at); +CREATE INDEX index_completed_at ON mixes USING btree (completed_at); + diff --git a/db/up/music_session_all_params.sql b/db/up/music_session_all_params.sql new file mode 100644 index 000000000..5ba065fb5 --- /dev/null +++ b/db/up/music_session_all_params.sql @@ -0,0 +1,12 @@ +ALTER TABLE music_sessions ADD COLUMN band_id VARCHAR(64) REFERENCES bands(id); +ALTER TABLE music_sessions ADD COLUMN approval_required BOOLEAN NOT NULL; +ALTER TABLE music_sessions ADD COLUMN fan_access BOOLEAN NOT NULL; +ALTER TABLE music_sessions ADD COLUMN fan_chat BOOLEAN NOT NULL; +CREATE TABLE fan_invitations ( + id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(), + sender_id VARCHAR(64) REFERENCES users(id) ON DELETE CASCADE, + receiver_id VARCHAR(64) REFERENCES users(id) ON DELETE CASCADE, + music_session_id VARCHAR(64) REFERENCES music_sessions(id) ON DELETE CASCADE, + created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP +); diff --git a/db/up/music_sessions_user_history_add_session_removed_at.sql b/db/up/music_sessions_user_history_add_session_removed_at.sql new file mode 100644 index 000000000..e1f9c800b --- /dev/null +++ b/db/up/music_sessions_user_history_add_session_removed_at.sql @@ -0,0 +1,2 @@ +-- add session_removed_at to track end of users music_session connection +ALTER TABLE music_sessions_user_history ADD COLUMN session_removed_at TIMESTAMP; diff --git a/db/up/musician_access.sql b/db/up/musician_access.sql new file mode 100644 index 000000000..77b4e94ae --- /dev/null +++ b/db/up/musician_access.sql @@ -0,0 +1 @@ +ALTER TABLE music_sessions ADD COLUMN musician_access BOOLEAN NOT NULL; diff --git a/db/up/notification_type_col_rename.sql b/db/up/notification_type_col_rename.sql new file mode 100644 index 000000000..5befa0477 --- /dev/null +++ b/db/up/notification_type_col_rename.sql @@ -0,0 +1 @@ +alter table notifications rename column type to description; \ No newline at end of file diff --git a/db/up/notifications.sql b/db/up/notifications.sql new file mode 100644 index 000000000..416d0aa7a --- /dev/null +++ b/db/up/notifications.sql @@ -0,0 +1,13 @@ +CREATE TABLE notifications ( + id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(), + type VARCHAR(32) NOT NULL, + source_user_id VARCHAR(64) REFERENCES users(id) ON DELETE CASCADE, + target_user_id VARCHAR(64) REFERENCES users(id) ON DELETE CASCADE, + band_id VARCHAR(64) REFERENCES bands(id) ON DELETE CASCADE, + session_id VARCHAR(64) REFERENCES music_sessions(id) ON DELETE CASCADE, + recording_id VARCHAR(64) REFERENCES recordings(id) ON DELETE CASCADE, + invitation_id VARCHAR(64) REFERENCES invitations(id) ON DELETE CASCADE, + join_request_id VARCHAR(64) REFERENCES join_requests(id) ON DELETE CASCADE, + created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP +); \ No newline at end of file diff --git a/db/up/notifications_add_friend_req_id.sql b/db/up/notifications_add_friend_req_id.sql new file mode 100644 index 000000000..c1e1f53f5 --- /dev/null +++ b/db/up/notifications_add_friend_req_id.sql @@ -0,0 +1 @@ +alter table notifications add COLUMN friend_request_id varchar(64) REFERENCES friend_requests(id); \ No newline at end of file diff --git a/db/up/other_instrument.sql b/db/up/other_instrument.sql new file mode 100644 index 000000000..18fb6c9b3 --- /dev/null +++ b/db/up/other_instrument.sql @@ -0,0 +1 @@ +INSERT INTO instruments (id, description, popularity) VALUES ('other', 'Other', 1); diff --git a/db/up/p2p.sql b/db/up/p2p.sql new file mode 100644 index 000000000..f57113970 --- /dev/null +++ b/db/up/p2p.sql @@ -0,0 +1,2 @@ +-- begin storing a client_id in each music_session_client +ALTER TABLE music_session_clients ADD COLUMN client_id VARCHAR(64) UNIQUE; diff --git a/db/up/perf_data.sql b/db/up/perf_data.sql new file mode 100644 index 000000000..3aa6052b1 --- /dev/null +++ b/db/up/perf_data.sql @@ -0,0 +1,10 @@ +-- this is a history table, so no fk's declared +-- data/datum. but I don't care +CREATE TABLE music_session_perf_data ( + id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(), + music_session_id VARCHAR(64), + client_id VARCHAR(64), + uri VARCHAR(1000), + created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP +); diff --git a/db/up/plays.sql b/db/up/plays.sql new file mode 100644 index 000000000..52f91ef06 --- /dev/null +++ b/db/up/plays.sql @@ -0,0 +1,17 @@ +-- recordings +CREATE TABLE recordings_plays( + id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(), + recording_id VARCHAR(64) NOT NULL REFERENCES recordings(id) ON DELETE CASCADE, + player_id VARCHAR(64) NOT NULL REFERENCES users(id) ON DELETE CASCADE, + created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP +); + +-- sessions +CREATE TABLE sessions_plays ( + id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(), + music_session_id VARCHAR(64) NOT NULL REFERENCES music_sessions(id) ON DELETE CASCADE, + player_id VARCHAR(64) NOT NULL REFERENCES users(id) ON DELETE CASCADE, + created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP +); \ No newline at end of file diff --git a/db/up/recorded_tracks.sql b/db/up/recorded_tracks.sql new file mode 100644 index 000000000..7d83f61f9 --- /dev/null +++ b/db/up/recorded_tracks.sql @@ -0,0 +1,16 @@ +ALTER TABLE saved_tracks RENAME TO recorded_tracks; +ALTER TABLE recorded_tracks ADD COLUMN recording_id VARCHAR(64) NOT NULL REFERENCES recordings(id) ON DELETE CASCADE; + +DROP TABLE bands_recordings; + +ALTER TABLE musicians_recordings RENAME TO recordings_users; + +ALTER TABLE recordings RENAME COLUMN creator_id TO owner_id; +ALTER TABLE recordings DROP COLUMN updater_id; +ALTER TABLE recordings ADD COLUMN music_session_id VARCHAR(64) REFERENCES music_sessions(id); +ALTER TABLE recordings ADD COLUMN band_id VARCHAR(64) REFERENCES bands(id); +ALTER TABLE recordings ALTER COLUMN description DROP NOT NULL; +ALTER TABLE recordings ADD COLUMN name VARCHAR(100); +ALTER TABLE recordings ADD COLUMN is_public BOOLEAN; +ALTER TABLE recordings ADD COLUMN is_downloadable BOOLEAN; + diff --git a/db/up/recordings.sql b/db/up/recordings.sql new file mode 100644 index 000000000..f5776a073 --- /dev/null +++ b/db/up/recordings.sql @@ -0,0 +1,21 @@ +CREATE TABLE recordings ( + id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(), + description VARCHAR(200) NOT NULL, + public BOOLEAN NOT NULL DEFAULT true, + created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP +); + +CREATE TABLE musicians_recordings ( + user_id VARCHAR(64) NOT NULL REFERENCES users(id) ON DELETE CASCADE, + recording_id VARCHAR(64) NOT NULL REFERENCES recordings(id) ON DELETE CASCADE +); + +ALTER TABLE musicians_recordings ADD CONSTRAINT musician_recording_uniqkey UNIQUE (user_id, recording_id); + +CREATE TABLE bands_recordings ( + band_id VARCHAR(64) NOT NULL REFERENCES bands(id) ON DELETE CASCADE, + recording_id VARCHAR(64) NOT NULL REFERENCES recordings(id) ON DELETE CASCADE +); + +ALTER TABLE bands_recordings ADD CONSTRAINT band_recording_uniqkey UNIQUE (band_id, recording_id); \ No newline at end of file diff --git a/db/up/recordings2.sql b/db/up/recordings2.sql new file mode 100644 index 000000000..271a3df07 --- /dev/null +++ b/db/up/recordings2.sql @@ -0,0 +1,8 @@ +ALTER TABLE recorded_tracks ADD COLUMN md5 VARCHAR(100); +ALTER TABLE recorded_tracks ADD COLUMN length INT; +ALTER TABLE mixes DROP COLUMN owner_id; +ALTER TABLE mixes DROP COLUMN description; +ALTER TABLE mixes ADD COLUMN md5 VARCHAR(100); +ALTER TABLE mixes ADD COLUMN length INT; +DROP TABLE recordings_genres; + diff --git a/db/up/recordings_genres.sql b/db/up/recordings_genres.sql new file mode 100644 index 000000000..becc7d5f9 --- /dev/null +++ b/db/up/recordings_genres.sql @@ -0,0 +1,7 @@ +-- recording -> genre mapping +CREATE TABLE recordings_genres ( + recording_id VARCHAR(64) NOT NULL REFERENCES recordings(id) ON DELETE CASCADE, + genre_id VARCHAR(64) NOT NULL REFERENCES genres(id) ON DELETE CASCADE +); + +ALTER TABLE recordings_genres ADD CONSTRAINT recording_genre_uniqkey UNIQUE (recording_id, genre_id); \ No newline at end of file diff --git a/db/up/reset_password.sql b/db/up/reset_password.sql new file mode 100644 index 000000000..cf5de9950 --- /dev/null +++ b/db/up/reset_password.sql @@ -0,0 +1,3 @@ +-- Add columns for handling password resets. +ALTER TABLE users ADD COLUMN reset_password_token VARCHAR(64); +ALTER TABLE users ADD COLUMN reset_password_token_created TIMESTAMP; diff --git a/db/up/saved_tracks.sql b/db/up/saved_tracks.sql new file mode 100644 index 000000000..c91ca5002 --- /dev/null +++ b/db/up/saved_tracks.sql @@ -0,0 +1,11 @@ +CREATE TABLE saved_tracks ( + id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(), + user_id VARCHAR(64) REFERENCES users(id) ON DELETE CASCADE, + instrument_id VARCHAR(64) REFERENCES instruments(id) ON DELETE CASCADE, + sound VARCHAR(64) NOT NULL, + next_part_to_upload INTEGER NOT NULL DEFAULT 0, + fully_uploaded BOOLEAN NOT NULL DEFAULT FALSE, + created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP +); + diff --git a/db/up/saved_tracks_upload_id.sql b/db/up/saved_tracks_upload_id.sql new file mode 100644 index 000000000..5121c63b2 --- /dev/null +++ b/db/up/saved_tracks_upload_id.sql @@ -0,0 +1 @@ +ALTER TABLE saved_tracks ADD COLUMN upload_id VARCHAR(64); diff --git a/db/up/session_history.sql b/db/up/session_history.sql new file mode 100644 index 000000000..d195ae90b --- /dev/null +++ b/db/up/session_history.sql @@ -0,0 +1,20 @@ +CREATE TABLE music_sessions_history ( + id character varying(64) NOT NULL DEFAULT uuid_generate_v4(), + music_session_id varchar(64) NOT NULL, + description character varying(8000), + user_id character varying(64) NOT NULL references users(id), + band_id character varying(64) references bands(id) on delete cascade, + genres VARCHAR(255), + created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + session_removed_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP +); + +ALTER TABLE music_sessions_history ADD CONSTRAINT music_session_uniqkey UNIQUE (music_session_id); + +CREATE TABLE music_sessions_user_history ( + id character varying(64) NOT NULL DEFAULT uuid_generate_v4(), + music_session_id varchar(64) NOT NULL references music_sessions_history(music_session_id), + user_id character varying(64) NOT NULL references users(id), + client_id character varying(64) NOT NULL, + created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP +); diff --git a/db/up/session_settings.sql b/db/up/session_settings.sql new file mode 100644 index 000000000..65f72bbe6 --- /dev/null +++ b/db/up/session_settings.sql @@ -0,0 +1 @@ +alter table users add column session_settings varchar(4000); \ No newline at end of file diff --git a/db/up/sessions.sql b/db/up/sessions.sql new file mode 100644 index 000000000..e5a30c132 --- /dev/null +++ b/db/up/sessions.sql @@ -0,0 +1,64 @@ +-- so we can default uuid fields using uuid_generate_v4. nice to have. +CREATE EXTENSION "uuid-ossp"; + +CREATE TABLE users ( + id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(), + name VARCHAR(50) NOT NULL, + email VARCHAR(255) NOT NULL UNIQUE, + remember_token VARCHAR(255) UNIQUE, + password_digest VARCHAR(255) NOT NULL, + admin boolean NOT NULL DEFAULT false, + created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP +); + +CREATE INDEX remember_token_idx ON users(remember_token); + +-- adhoc jam sessions +CREATE TABLE jam_sessions ( + id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(), + name VARCHAR(8000), + public boolean NOT NULL DEFAULT true, + user_id VARCHAR(64) NOT NULL REFERENCES users(id), + created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP +); + +-- users currently in the jam session +CREATE TABLE jam_session_members ( + id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(), + user_id VARCHAR(64) REFERENCES users(id) ON DELETE CASCADE, + jam_session_id VARCHAR(64) REFERENCES jam_sessions(id) ON DELETE CASCADE, + created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP +); + +ALTER TABLE jam_session_members ADD CONSTRAINT user_jam_session_uniqkey UNIQUE (user_id, jam_session_id); + +-- create a utility method to truncate all tables + +CREATE OR REPLACE FUNCTION truncate_tables() RETURNS void AS $$ +DECLARE + statements CURSOR FOR + SELECT tablename FROM pg_tables + WHERE schemaname = 'public'; +BEGIN + FOR stmt IN statements LOOP + EXECUTE 'TRUNCATE TABLE ' || quote_ident(stmt.tablename) || ' CASCADE;'; + END LOOP; +END; +$$ LANGUAGE plpgsql; + +-- create a utility that bootstraps a user +CREATE OR REPLACE FUNCTION bootstrap_users() RETURNS void AS $$ +DECLARE + +BEGIN + -- non guid used for test user. test user won't be in actual database, but '1' is much easier to script that 242423-42-4-24234 + -- password is jam123 + INSERT INTO users (id, name, email, remember_token, password_digest) VALUES ('1', 'test', 'test@jamkazam.com', 'NQubl-z16Em94tnSdofObw', '$2a$10$QyaNTLVX5DAaJ.JL21kDWeUQqdh3Qh7JQbdRgE82x1Cib7HWNcHXC'); +END; +$$ LANGUAGE plpgsql; + +select bootstrap_users(); + diff --git a/db/up/sessions_api_v1.sql b/db/up/sessions_api_v1.sql new file mode 100644 index 000000000..f602b27be --- /dev/null +++ b/db/up/sessions_api_v1.sql @@ -0,0 +1,23 @@ +ALTER TABLE jam_sessions DROP COLUMN public; + +-- rename 'name' to 'description' to match product specification terminology +ALTER TABLE jam_sessions RENAME name TO description; + +-- rename jam_sessions to more generic 'music_sessions' +ALTER TABLE jam_sessions RENAME TO music_sessions; + +-- get rid of early version of member table +DROP TABLE jam_session_members; + +-- one row is created per connected client +CREATE TABLE music_session_clients ( + id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(), + user_id VARCHAR(64) REFERENCES users(id) ON DELETE CASCADE, + music_session_id VARCHAR(64) REFERENCES music_sessions(id) ON DELETE CASCADE, + ip_address VARCHAR(64) NOT NULL, + created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP +); + + + diff --git a/db/up/signup.sql b/db/up/signup.sql new file mode 100644 index 000000000..ba2ae59ba --- /dev/null +++ b/db/up/signup.sql @@ -0,0 +1,2 @@ +ALTER TABLE users ADD COLUMN signup_token VARCHAR(255) UNIQUE; +ALTER TABLE users ADD COLUMN email_confirmed BOOLEAN DEFAULT FALSE; diff --git a/db/up/subscribe_email.sql b/db/up/subscribe_email.sql new file mode 100644 index 000000000..b97cde88a --- /dev/null +++ b/db/up/subscribe_email.sql @@ -0,0 +1 @@ +ALTER TABLE users ADD COLUMN subscribe_email BOOLEAN DEFAULT false; diff --git a/db/up/tracks.sql b/db/up/tracks.sql new file mode 100644 index 000000000..af261a328 --- /dev/null +++ b/db/up/tracks.sql @@ -0,0 +1,41 @@ +CREATE TABLE connections_tracks ( + id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(), + connection_id VARCHAR(64) REFERENCES connections(id) ON DELETE CASCADE, + instrument_id VARCHAR(64) REFERENCES instruments(id) ON DELETE CASCADE, + sound VARCHAR(64) NOT NULL, + created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP +); + +UPDATE genres set id = lower(description); + +DELETE FROM instruments; + +--popularity: 3 High, 2 Mid, 1 Low, 0 user-defined +ALTER TABLE instruments ADD COLUMN popularity INTEGER NOT NULL DEFAULT 0; + +INSERT INTO instruments (id, description, popularity) VALUES + ('acoustic guitar', 'Acoustic Guitar', 3), + ('bass guitar', 'Bass Guitar', 3), + ('computer', 'Computer', 3), + ('drums', 'Drums', 3), + ('electric guitar', 'Electric Guitar', 3), + ('keyboard', 'Keyboard', 3), + ('voice', 'Voice', 3), + ('flute', 'Flute', 2), + ('clarinet', 'Clarinet', 2), + ('saxophone', 'Saxophone', 2), + ('trumpet', 'Trumpet', 2), + ('violin', 'Violin', 2), + ('trombone', 'Trombone', 2), + ('banjo', 'Banjo', 2), + ('harmonica', 'Harmonica', 2), + ('accordion', 'Accordion', 2), + ('french horn', 'French Horn', 1), + ('euphonium', 'Euphonium', 1), + ('tuba', 'Tuba', 1), + ('oboe', 'Oboe', 1), + ('ukulele', 'Ukulele', 1), + ('cello', 'Cello', 1), + ('viola', 'Viola', 1), + ('mandolin', 'Mandolin', 1); diff --git a/db/up/tracks_rename.sql b/db/up/tracks_rename.sql new file mode 100644 index 000000000..3b072f596 --- /dev/null +++ b/db/up/tracks_rename.sql @@ -0,0 +1 @@ +alter table connections_tracks rename to tracks; \ No newline at end of file diff --git a/db/up/update_email.sql b/db/up/update_email.sql new file mode 100644 index 000000000..e5f711891 --- /dev/null +++ b/db/up/update_email.sql @@ -0,0 +1,2 @@ +ALTER TABLE users ADD COLUMN update_email VARCHAR(1024); +ALTER TABLE users ADD COLUMN update_email_token VARCHAR(1024) UNIQUE; diff --git a/db/up/update_user_band_fields.sql b/db/up/update_user_band_fields.sql new file mode 100644 index 000000000..a7899817f --- /dev/null +++ b/db/up/update_user_band_fields.sql @@ -0,0 +1,23 @@ +alter table users alter column city drop default; +alter table users alter column first_name drop default; +alter table users alter column last_name drop default; +alter table users alter column birth_date drop default; +alter table users alter column birth_date drop not null; + +update users set state = 'NC'; +alter table users alter column state set not null; + +update users set country = 'USA'; +alter table users alter column country set not null; + +alter table bands alter column city drop default; + +update users set state = 'NC'; +alter table bands alter column state set not null; + +update users set country = 'USA'; +alter table bands alter column country set not null; + +--alter table users drop column account_id; + +--drop table accounts; \ No newline at end of file diff --git a/db/up/user_add_can_invite.sql b/db/up/user_add_can_invite.sql new file mode 100644 index 000000000..3fa3c9af4 --- /dev/null +++ b/db/up/user_add_can_invite.sql @@ -0,0 +1,2 @@ +-- add can_invite flag to users; for beta retrict +ALTER TABLE users ADD COLUMN can_invite BOOLEAN NOT NULL DEFAULT true; diff --git a/db/up/user_authorizations.sql b/db/up/user_authorizations.sql new file mode 100644 index 000000000..588c00c5e --- /dev/null +++ b/db/up/user_authorizations.sql @@ -0,0 +1,14 @@ +CREATE TABLE user_authorizations ( + id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(), + user_id VARCHAR(64) REFERENCES users(id) ON DELETE CASCADE, + uid VARCHAR(255) NOT NULL, + provider VARCHAR(255) NOT NULL, + token VARCHAR(255) NULL, + token_expiration TIMESTAMP NULL, + created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP +); + +CREATE INDEX user_authorizations_user_id_idx ON user_authorizations(user_id); + + diff --git a/db/up/user_state_lengthen.sql b/db/up/user_state_lengthen.sql new file mode 100644 index 000000000..e01be646f --- /dev/null +++ b/db/up/user_state_lengthen.sql @@ -0,0 +1 @@ +ALTER TABLE users ALTER COLUMN state TYPE VARCHAR(100); diff --git a/db/up/users.sql b/db/up/users.sql new file mode 100644 index 000000000..0af957a9c --- /dev/null +++ b/db/up/users.sql @@ -0,0 +1,95 @@ +CREATE TABLE connections ( + id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(), + user_id VARCHAR(64) REFERENCES users(id) ON DELETE CASCADE, + client_id VARCHAR(64) NOT NULL UNIQUE, + created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP +); + +-- friendships +CREATE TABLE friendships ( + id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(), + user_id VARCHAR(64) REFERENCES users(id) ON DELETE CASCADE, + friend_id VARCHAR(64) REFERENCES users(id) ON DELETE CASCADE, + created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP +); + +ALTER TABLE friendships ADD CONSTRAINT user_friend_uniqkey UNIQUE (user_id, friend_id); + +-- friend requests +CREATE TABLE friend_requests ( + id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(), + user_id VARCHAR(64) REFERENCES users(id) ON DELETE CASCADE, + friend_id VARCHAR(64) REFERENCES users(id) ON DELETE CASCADE, + accepted BOOLEAN, + created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP +); + +ALTER TABLE friend_requests ADD CONSTRAINT user_friend_request_uniqkey UNIQUE (user_id, friend_id); + +-- bands +CREATE TABLE bands ( + id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(), + name VARCHAR(1024) NOT NULL, + website VARCHAR(4000) NULL, + biography VARCHAR(4000) NOT NULL, + created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP +); + +-- genres +CREATE TABLE genres ( + id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(), + description VARCHAR(1024) NOT NULL, + created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP +); + +-- band -> genre mapping +CREATE TABLE bands_genres ( + id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(), + band_id VARCHAR(64) NOT NULL REFERENCES bands(id) ON DELETE CASCADE, + genre_id VARCHAR(64) NOT NULL REFERENCES genres(id) ON DELETE CASCADE, + created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP +); + +ALTER TABLE bands_genres ADD CONSTRAINT band_genre_uniqkey UNIQUE (band_id, genre_id); + +-- musician -> band mapping +CREATE TABLE bands_musicians ( + id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(), + band_id VARCHAR(64) NOT NULL REFERENCES bands(id) ON DELETE CASCADE, + user_id VARCHAR(64) NOT NULL REFERENCES users(id) ON DELETE CASCADE, + admin BOOLEAN NOT NULL DEFAULT false, + created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP +); + +ALTER TABLE bands_musicians ADD CONSTRAINT band_musician_uniqkey UNIQUE (band_id, user_id); + +-- instruments +CREATE TABLE instruments ( + id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(), + description VARCHAR(1024) NOT NULL, + created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP +); + +-- musician -> instrument mapping +CREATE TABLE musicians_instruments ( + id VARCHAR(64) PRIMARY KEY DEFAULT uuid_generate_v4(), + user_id VARCHAR(64) NOT NULL REFERENCES users(id) ON DELETE CASCADE, + instrument_id VARCHAR(64) NOT NULL REFERENCES instruments(id) ON DELETE CASCADE, + proficiency_level SMALLINT NOT NULL, + priority SMALLINT NOT NULL DEFAULT 1, + created_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP, + updated_at TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP +); + +ALTER TABLE musicians_instruments ADD CONSTRAINT musician_instrument_uniqkey UNIQUE (user_id, instrument_id); + +-- add musician flag to users table +ALTER TABLE users ADD COLUMN musician BOOLEAN NOT NULL DEFAULT false; diff --git a/db/up/users_favorites.sql b/db/up/users_favorites.sql new file mode 100755 index 000000000..156ea8131 --- /dev/null +++ b/db/up/users_favorites.sql @@ -0,0 +1,3 @@ +DROP TABLE users_favorites; + +