merging jam-db into db

This commit is contained in:
Seth Call 2013-09-15 17:58:54 +00:00
commit a091c22aa6
85 changed files with 1158 additions and 0 deletions

6
db/.gitignore vendored Normal file
View File

@ -0,0 +1,6 @@
target
*~
*.swp
vendor
*.deb
.bundle

2
db/.pg_migrate Normal file
View File

@ -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

1
db/.ruby-gemset Normal file
View File

@ -0,0 +1 @@
jam-db

1
db/.ruby-version Normal file
View File

@ -0,0 +1 @@
ruby-2.0.0-p247

9
db/Gemfile Normal file
View File

@ -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'

20
db/Gemfile.lock Normal file
View File

@ -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)

59
db/README.md Normal file
View File

@ -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

36
db/build Executable file
View File

@ -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

44
db/jenkins Executable file
View File

@ -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

74
db/manifest Executable file
View File

@ -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

0
db/up/.gitkeep Normal file
View File

3
db/up/account_fields.sql Normal file
View File

@ -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);

View File

@ -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);

68
db/up/admin_users.sql Normal file
View File

@ -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);
---------------------------------

View File

@ -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;

View File

@ -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;

14
db/up/artifact_update.sql Normal file
View File

@ -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';

View File

@ -0,0 +1 @@
ALTER TABLE artifact_updates ALTER COLUMN sha1 DROP NOT NULL;

1
db/up/as_musician.sql Normal file
View File

@ -0,0 +1 @@
ALTER TABLE connections ADD COLUMN as_musician BOOLEAN;

View File

@ -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

View File

@ -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
);

View File

@ -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();

View File

@ -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();

View File

@ -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;

3
db/up/claimed_recordings2.sql Executable file
View File

@ -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;

View File

@ -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);

View File

@ -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;

19
db/up/comments.sql Normal file
View File

@ -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
);

View File

@ -0,0 +1,2 @@
-- connection state for supporting aasm gem
ALTER TABLE connections ADD COLUMN aasm_state VARCHAR(64) NOT NULL DEFAULT 'idle';

11
db/up/crash_dumps.sql Executable file
View File

@ -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
);

5
db/up/crash_dumps_idx.sql Executable file
View File

@ -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;

View File

@ -0,0 +1 @@
ALTER TABLE users ALTER gender DROP DEFAULT;

8
db/up/downloads.sql Normal file
View File

@ -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
);

View File

@ -0,0 +1 @@
alter table users drop column name;

9
db/up/favorites.sql Normal file
View File

@ -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);

View File

@ -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';

19
db/up/followers.sql Normal file
View File

@ -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);

View File

@ -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;

View File

@ -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;

27
db/up/genre_session.sql Normal file
View File

@ -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');

3
db/up/image_urls.sql Normal file
View File

@ -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);

4
db/up/instruments.sql Normal file
View File

@ -0,0 +1,4 @@
insert into instruments (description) values
('Guitar'),
('Vocals'),
('Drums');

10
db/up/invitations.sql Normal file
View File

@ -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);

12
db/up/invited_users.sql Normal file
View File

@ -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
);

View File

@ -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
);

12
db/up/join_request.sql Normal file
View File

@ -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;

43
db/up/likes.sql Normal file
View File

@ -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);

7
db/up/locations.sql Normal file
View File

@ -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);

View File

@ -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;

12
db/up/max_mind.sql Normal file
View File

@ -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);

11
db/up/max_mind_isp.sql Normal file
View File

@ -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;

View File

@ -0,0 +1 @@
ALTER TABLE max_mind_isp ADD COLUMN country VARCHAR(64);

18
db/up/mixes.sql Normal file
View File

@ -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);

View File

@ -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
);

View File

@ -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;

View File

@ -0,0 +1 @@
ALTER TABLE music_sessions ADD COLUMN musician_access BOOLEAN NOT NULL;

View File

@ -0,0 +1 @@
alter table notifications rename column type to description;

13
db/up/notifications.sql Normal file
View File

@ -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
);

View File

@ -0,0 +1 @@
alter table notifications add COLUMN friend_request_id varchar(64) REFERENCES friend_requests(id);

View File

@ -0,0 +1 @@
INSERT INTO instruments (id, description, popularity) VALUES ('other', 'Other', 1);

2
db/up/p2p.sql Normal file
View File

@ -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;

10
db/up/perf_data.sql Normal file
View File

@ -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
);

17
db/up/plays.sql Normal file
View File

@ -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
);

16
db/up/recorded_tracks.sql Normal file
View File

@ -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;

21
db/up/recordings.sql Normal file
View File

@ -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);

8
db/up/recordings2.sql Normal file
View File

@ -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;

View File

@ -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);

3
db/up/reset_password.sql Normal file
View File

@ -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;

11
db/up/saved_tracks.sql Normal file
View File

@ -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
);

View File

@ -0,0 +1 @@
ALTER TABLE saved_tracks ADD COLUMN upload_id VARCHAR(64);

20
db/up/session_history.sql Normal file
View File

@ -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
);

View File

@ -0,0 +1 @@
alter table users add column session_settings varchar(4000);

64
db/up/sessions.sql Normal file
View File

@ -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();

23
db/up/sessions_api_v1.sql Normal file
View File

@ -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
);

2
db/up/signup.sql Normal file
View File

@ -0,0 +1,2 @@
ALTER TABLE users ADD COLUMN signup_token VARCHAR(255) UNIQUE;
ALTER TABLE users ADD COLUMN email_confirmed BOOLEAN DEFAULT FALSE;

View File

@ -0,0 +1 @@
ALTER TABLE users ADD COLUMN subscribe_email BOOLEAN DEFAULT false;

41
db/up/tracks.sql Normal file
View File

@ -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);

1
db/up/tracks_rename.sql Normal file
View File

@ -0,0 +1 @@
alter table connections_tracks rename to tracks;

2
db/up/update_email.sql Normal file
View File

@ -0,0 +1,2 @@
ALTER TABLE users ADD COLUMN update_email VARCHAR(1024);
ALTER TABLE users ADD COLUMN update_email_token VARCHAR(1024) UNIQUE;

View File

@ -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;

View File

@ -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;

View File

@ -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);

View File

@ -0,0 +1 @@
ALTER TABLE users ALTER COLUMN state TYPE VARCHAR(100);

95
db/up/users.sql Normal file
View File

@ -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;

3
db/up/users_favorites.sql Executable file
View File

@ -0,0 +1,3 @@
DROP TABLE users_favorites;