--
-- PostgreSQL database dump
--

SET statement_timeout = 0;
SET lock_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SET check_function_bodies = false;
SET client_min_messages = warning;

--
-- Name: pgmigrate; Type: SCHEMA; Schema: -; Owner: -
--

CREATE SCHEMA pgmigrate;


--
-- Name: tiger; Type: SCHEMA; Schema: -; Owner: -
--

CREATE SCHEMA tiger;


--
-- Name: fuzzystrmatch; Type: EXTENSION; Schema: -; Owner: -
--

CREATE EXTENSION IF NOT EXISTS fuzzystrmatch WITH SCHEMA public;


--
-- Name: EXTENSION fuzzystrmatch; Type: COMMENT; Schema: -; Owner: -
--

COMMENT ON EXTENSION fuzzystrmatch IS 'determine similarities and distance between strings';


--
-- Name: postgis; Type: EXTENSION; Schema: -; Owner: -
--

CREATE EXTENSION IF NOT EXISTS postgis WITH SCHEMA public;


--
-- Name: EXTENSION postgis; Type: COMMENT; Schema: -; Owner: -
--

COMMENT ON EXTENSION postgis IS 'PostGIS geometry, geography, and raster spatial types and functions';


--
-- Name: postgis_tiger_geocoder; Type: EXTENSION; Schema: -; Owner: -
--

CREATE EXTENSION IF NOT EXISTS postgis_tiger_geocoder WITH SCHEMA tiger;


--
-- Name: EXTENSION postgis_tiger_geocoder; Type: COMMENT; Schema: -; Owner: -
--

COMMENT ON EXTENSION postgis_tiger_geocoder IS 'PostGIS tiger geocoder and reverse geocoder';


--
-- Name: topology; Type: SCHEMA; Schema: -; Owner: -
--

CREATE SCHEMA topology;


--
-- Name: plpgsql; Type: EXTENSION; Schema: -; Owner: -
--

CREATE EXTENSION IF NOT EXISTS plpgsql WITH SCHEMA pg_catalog;


--
-- Name: EXTENSION plpgsql; Type: COMMENT; Schema: -; Owner: -
--

COMMENT ON EXTENSION plpgsql IS 'PL/pgSQL procedural language';


--
-- Name: postgis_topology; Type: EXTENSION; Schema: -; Owner: -
--

CREATE EXTENSION IF NOT EXISTS postgis_topology WITH SCHEMA topology;


--
-- Name: EXTENSION postgis_topology; Type: COMMENT; Schema: -; Owner: -
--

COMMENT ON EXTENSION postgis_topology IS 'PostGIS topology spatial types and functions';


--
-- Name: uuid-ossp; Type: EXTENSION; Schema: -; Owner: -
--

CREATE EXTENSION IF NOT EXISTS "uuid-ossp" WITH SCHEMA public;


--
-- Name: EXTENSION "uuid-ossp"; Type: COMMENT; Schema: -; Owner: -
--

COMMENT ON EXTENSION "uuid-ossp" IS 'generate universally unique identifiers (UUIDs)';


SET search_path = pgmigrate, pg_catalog;

--
-- Name: bootstrap_pg_migrate(); Type: FUNCTION; Schema: pgmigrate; Owner: -
--

CREATE FUNCTION bootstrap_pg_migrate() RETURNS void
    LANGUAGE plpgsql
    AS $$ DECLARE found_pg_migrate information_schema.tables; found_pg_migrations information_schema.tables; BEGIN BEGIN SELECT * INTO STRICT found_pg_migrate FROM information_schema.tables WHERE table_name = 'pg_migrate' and table_schema = 'pgmigrate'; EXCEPTION WHEN NO_DATA_FOUND THEN CREATE TABLE pgmigrate.pg_migrate (id BIGSERIAL PRIMARY KEY, template_version VARCHAR(255), builder_version VARCHAR(255), migrator_version VARCHAR(255), database_version VARCHAR(1024)); CREATE INDEX pg_migrate_unique_index ON pgmigrate.pg_migrate (template_version, builder_version, migrator_version, database_version); WHEN TOO_MANY_ROWS THEN RAISE EXCEPTION 'Multiple pg_migrate tables.  Unique key on information_schema.tables should have prevented this.'; END; BEGIN SELECT * INTO STRICT found_pg_migrations FROM information_schema.tables WHERE table_name = 'pg_migrations' and table_schema = 'pgmigrate'; EXCEPTION WHEN NO_DATA_FOUND THEN CREATE TABLE pgmigrate.pg_migrations( name VARCHAR(255) PRIMARY KEY, ordinal INTEGER NOT NULL, created TIMESTAMP DEFAULT CURRENT_TIMESTAMP, finalized SMALLINT DEFAULT 1, pg_migrate_id BIGINT NOT NULL REFERENCES pgmigrate.pg_migrate(id)); WHEN TOO_MANY_ROWS THEN RAISE EXCEPTION 'Multiple pg_migrations tables.  Unique key on information_schema.tables should have prevented this.'; END; END; $$;


--
-- Name: bypass_existing_migration(character varying); Type: FUNCTION; Schema: pgmigrate; Owner: -
--

CREATE FUNCTION bypass_existing_migration(migration character varying) RETURNS void
    LANGUAGE plpgsql
    AS $_$ DECLARE found_migration pgmigrate.pg_migrations; BEGIN BEGIN EXECUTE 'SELECT * FROM pgmigrate.pg_migrations WHERE name=$1' INTO STRICT found_migration USING migration ; EXCEPTION WHEN NO_DATA_FOUND THEN RETURN; WHEN TOO_MANY_ROWS THEN RAISE EXCEPTION 'pg_migrate: code=pg_migrations_uniqueness_error, migration=%', migration; END; RAISE EXCEPTION 'pg_migrate: code=migration_exists, migration=%', migration; END; $_$;


--
-- Name: record_migration(character varying, integer, character varying, character varying); Type: FUNCTION; Schema: pgmigrate; Owner: -
--

CREATE FUNCTION record_migration(migration character varying, ordinal integer, template_version character varying, builder_version character varying) RETURNS void
    LANGUAGE plpgsql
    AS $_$ DECLARE found_pg_migrate_id BIGINT; migrator_version VARCHAR(255); BEGIN EXECUTE 'SELECT current_setting(''application_name'')' INTO migrator_version; BEGIN EXECUTE 'SELECT id FROM pgmigrate.pg_migrate WHERE template_version=$1 and builder_version=$2 and migrator_version=$3 and database_version=$4' INTO found_pg_migrate_id USING template_version, builder_version, migrator_version, (select version()); EXCEPTION WHEN NO_DATA_FOUND THEN found_pg_migrate_id = NULL; WHEN TOO_MANY_ROWS THEN RAISE EXCEPTION 'pg_migrate: code=pg_migrate_uniqueness_error, migration=%, ordinal=%, template_version=%, builder_version=%, migrator_version=%, database_version', migration, ordinal, template_version, builder_version, migrator_version, (select version()); END; IF found_pg_migrate_id IS NULL THEN INSERT INTO pgmigrate.pg_migrate(id, template_version, builder_version, migrator_version, database_version) VALUES (default, template_version, builder_version, migrator_version, (select version())) RETURNING id INTO found_pg_migrate_id; END IF; EXECUTE 'INSERT INTO pgmigrate.pg_migrations(name, ordinal, created, finalized, pg_migrate_id) VALUES ($1, $2, CURRENT_TIMESTAMP, 1, $3)' USING migration, ordinal, found_pg_migrate_id; END; $_$;


--
-- Name: verify_against_existing_migrations(character varying, integer); Type: FUNCTION; Schema: pgmigrate; Owner: -
--

CREATE FUNCTION verify_against_existing_migrations(migration character varying, ordinal integer) RETURNS void
    LANGUAGE plpgsql
    AS $_$ DECLARE found_migration pgmigrate.pg_migrations; BEGIN BEGIN EXECUTE 'SELECT * FROM pgmigrate.pg_migrations WHERE name=$1' INTO STRICT found_migration USING migration; EXCEPTION WHEN NO_DATA_FOUND THEN IF coalesce((SELECT MAX(p.ordinal) FROM pgmigrate.pg_migrations as p), -1) <> ordinal - 1 THEN RAISE EXCEPTION 'pg_migrate: code=missing_migration, migration=%, ordinal=%, last_ordinal=%', migration, ordinal, (SELECT MAX(p.ordinal) FROM pgmigrate.pg_migrations as p); END IF; RETURN; WHEN TOO_MANY_ROWS THEN RAISE EXCEPTION 'pg_migrate: code=pg_migrations_uniqueness_error, migration=%', migration; END; IF found_migration.ordinal <> ordinal THEN RAISE EXCEPTION 'pg_migrate: code=incorrect_ordinal, migration=%, expected_ordinal=%, actual_ordinal', migration, ordinal, found_migration.ordinal; END IF; END; $_$;


--
-- Name: verify_manifest_is_not_old(integer); Type: FUNCTION; Schema: pgmigrate; Owner: -
--

CREATE FUNCTION verify_manifest_is_not_old(manifest_version integer) RETURNS void
    LANGUAGE plpgsql
    AS $$ DECLARE max_ordinal INTEGER; BEGIN EXECUTE 'SELECT max(ordinal) FROM pgmigrate.pg_migrations' INTO max_ordinal; IF max_ordinal > manifest_version THEN RAISE EXCEPTION 'pg_migrate: code=old_manifest, max_ordinal_in_db=%, manifest_version=%', max_ordinal, manifest_version; END IF; END; $$;


SET search_path = public, pg_catalog;

--
-- Name: bootstrap_users(); Type: FUNCTION; Schema: public; Owner: -
--

CREATE FUNCTION bootstrap_users() RETURNS void
    LANGUAGE plpgsql
    AS $_$ DECLARE test_user VARCHAR(64); BEGIN 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-[REDACTED]', password_digest = '$2a$10$[REDACTED]', 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; $_$;


--
-- Name: get_work(bigint); Type: FUNCTION; Schema: public; Owner: -
--

CREATE FUNCTION get_work(mylocidispid bigint) RETURNS TABLE(client_id character varying)
    LANGUAGE plpgsql ROWS 5
    AS $$ BEGIN CREATE TEMPORARY TABLE foo (locidispid BIGINT, locid INT); INSERT INTO foo SELECT DISTINCT locidispid, locidispid/1000000 FROM connections where client_type = 'client'; DELETE FROM foo WHERE locidispid IN (SELECT DISTINCT blocidispid FROM current_scores WHERE alocidispid = mylocidispid AND (current_timestamp - score_dt) < interval '24 hours'); DELETE FROM foo WHERE locid NOT IN (SELECT locid FROM geoiplocations WHERE geog && st_buffer((SELECT geog from geoiplocations WHERE locid = mylocidispid/1000000), 806000)); CREATE TEMPORARY TABLE bar (client_id VARCHAR(64), locidispid BIGINT, r DOUBLE PRECISION); INSERT INTO bar SELECT l.client_id, l.locidispid, random() FROM connections l, foo f WHERE l.locidispid = f.locidispid and l.client_type = 'client'; DROP TABLE foo; DELETE FROM bar b WHERE r != (SELECT max(r) FROM bar b0 WHERE b0.locidispid = b.locidispid); RETURN QUERY SELECT b.client_id FROM bar b ORDER BY r LIMIT 5; DROP TABLE bar; RETURN; END; $$;


--
-- Name: truncate_tables(); Type: FUNCTION; Schema: public; Owner: -
--

CREATE FUNCTION truncate_tables() RETURNS void
    LANGUAGE plpgsql
    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; $$;


--
-- Name: english_stem; Type: TEXT SEARCH DICTIONARY; Schema: public; Owner: -
--

CREATE TEXT SEARCH DICTIONARY english_stem (
    TEMPLATE = pg_catalog.snowball,
    language = 'english', stopwords = 'english' );


--
-- Name: jamenglish; Type: TEXT SEARCH CONFIGURATION; Schema: public; Owner: -
--

CREATE TEXT SEARCH CONFIGURATION jamenglish (
    PARSER = pg_catalog."default" );

ALTER TEXT SEARCH CONFIGURATION jamenglish
    ADD MAPPING FOR asciiword WITH pg_catalog.english_stem;

ALTER TEXT SEARCH CONFIGURATION jamenglish
    ADD MAPPING FOR word WITH pg_catalog.english_stem;

ALTER TEXT SEARCH CONFIGURATION jamenglish
    ADD MAPPING FOR numword WITH simple;

ALTER TEXT SEARCH CONFIGURATION jamenglish
    ADD MAPPING FOR host WITH simple;

ALTER TEXT SEARCH CONFIGURATION jamenglish
    ADD MAPPING FOR version WITH simple;

ALTER TEXT SEARCH CONFIGURATION jamenglish
    ADD MAPPING FOR hword_numpart WITH simple;

ALTER TEXT SEARCH CONFIGURATION jamenglish
    ADD MAPPING FOR hword_part WITH pg_catalog.english_stem;

ALTER TEXT SEARCH CONFIGURATION jamenglish
    ADD MAPPING FOR hword_asciipart WITH pg_catalog.english_stem;

ALTER TEXT SEARCH CONFIGURATION jamenglish
    ADD MAPPING FOR numhword WITH simple;

ALTER TEXT SEARCH CONFIGURATION jamenglish
    ADD MAPPING FOR asciihword WITH pg_catalog.english_stem;

ALTER TEXT SEARCH CONFIGURATION jamenglish
    ADD MAPPING FOR hword WITH pg_catalog.english_stem;

ALTER TEXT SEARCH CONFIGURATION jamenglish
    ADD MAPPING FOR file WITH simple;

ALTER TEXT SEARCH CONFIGURATION jamenglish
    ADD MAPPING FOR "int" WITH simple;

ALTER TEXT SEARCH CONFIGURATION jamenglish
    ADD MAPPING FOR uint WITH simple;


SET search_path = pgmigrate, pg_catalog;

SET default_tablespace = '';

SET default_with_oids = false;

--
-- Name: pg_migrate; Type: TABLE; Schema: pgmigrate; Owner: -; Tablespace: 
--

CREATE TABLE pg_migrate (
    id bigint NOT NULL,
    template_version character varying(255),
    builder_version character varying(255),
    migrator_version character varying(255),
    database_version character varying(1024)
);


--
-- Name: pg_migrate_id_seq; Type: SEQUENCE; Schema: pgmigrate; Owner: -
--

CREATE SEQUENCE pg_migrate_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: pg_migrate_id_seq; Type: SEQUENCE OWNED BY; Schema: pgmigrate; Owner: -
--

ALTER SEQUENCE pg_migrate_id_seq OWNED BY pg_migrate.id;


--
-- Name: pg_migrations; Type: TABLE; Schema: pgmigrate; Owner: -; Tablespace: 
--

CREATE TABLE pg_migrations (
    name character varying(255) NOT NULL,
    ordinal integer NOT NULL,
    created timestamp without time zone DEFAULT now(),
    finalized smallint DEFAULT 1,
    pg_migrate_id bigint NOT NULL
);


SET search_path = public, pg_catalog;

--
-- Name: active_admin_comments; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

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


--
-- Name: active_admin_comments_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

CREATE SEQUENCE active_admin_comments_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: active_admin_comments_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--

ALTER SEQUENCE active_admin_comments_id_seq OWNED BY active_admin_comments.id;


--
-- Name: active_music_sessions; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE UNLOGGED TABLE active_music_sessions (
    id character varying(64) DEFAULT uuid_generate_v4() NOT NULL,
    user_id character varying(64) NOT NULL,
    created_at timestamp without time zone DEFAULT now() NOT NULL,
    updated_at timestamp without time zone DEFAULT now() NOT NULL,
    claimed_recording_id character varying(64),
    claimed_recording_initiator_id character varying(64),
    track_changes_counter integer DEFAULT 0
);


--
-- Name: affiliate_partners; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE affiliate_partners (
    id character varying(64) DEFAULT uuid_generate_v4() NOT NULL,
    partner_name character varying(128) NOT NULL,
    partner_code character varying(128) NOT NULL,
    partner_user_id character varying(64) NOT NULL,
    user_email character varying(255),
    referral_user_count integer DEFAULT 0 NOT NULL,
    created_at timestamp without time zone DEFAULT now() NOT NULL,
    updated_at timestamp without time zone DEFAULT now() NOT NULL
);


--
-- Name: artifact_updates; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE artifact_updates (
    id character varying(64) DEFAULT uuid_generate_v4() NOT NULL,
    product character varying(255) NOT NULL,
    version character varying(255) NOT NULL,
    uri character varying(2000) NOT NULL,
    sha1 character varying(255) NOT NULL,
    environment character varying(255) DEFAULT 'public'::character varying NOT NULL,
    size integer NOT NULL
);


--
-- Name: band_invitations; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE band_invitations (
    id character varying(64) DEFAULT uuid_generate_v4() NOT NULL,
    user_id character varying(64),
    band_id character varying(64),
    accepted boolean,
    creator_id character varying(64),
    created_at timestamp without time zone DEFAULT now() NOT NULL,
    updated_at timestamp without time zone DEFAULT now() NOT NULL
);


--
-- Name: bands; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE bands (
    id character varying(64) DEFAULT uuid_generate_v4() NOT NULL,
    name character varying(1024) NOT NULL,
    website character varying(4000),
    biography character varying(4000) NOT NULL,
    created_at timestamp without time zone DEFAULT now() NOT NULL,
    updated_at timestamp without time zone DEFAULT now() NOT NULL,
    city character varying(100),
    state character varying(100),
    country character varying(100),
    photo_url character varying(2048),
    logo_url character varying(2048),
    name_tsv tsvector,
    original_fpfile_photo character varying(8000) DEFAULT NULL::character varying,
    cropped_fpfile_photo character varying(8000) DEFAULT NULL::character varying,
    cropped_s3_path_photo character varying(512) DEFAULT NULL::character varying,
    crop_selection_photo character varying(256) DEFAULT NULL::character varying,
    lat numeric(15,10),
    lng numeric(15,10),
    large_photo_url character varying(2048),
    cropped_large_s3_path_photo character varying(512),
    cropped_large_fpfile_photo character varying(8000),
    did_real_session boolean DEFAULT false
);


--
-- Name: bands_genres; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE bands_genres (
    id character varying(64) DEFAULT uuid_generate_v4() NOT NULL,
    band_id character varying(64) NOT NULL,
    genre_id character varying(64) NOT NULL,
    created_at timestamp without time zone DEFAULT now() NOT NULL,
    updated_at timestamp without time zone DEFAULT now() NOT NULL
);


--
-- Name: bands_musicians; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE bands_musicians (
    id character varying(64) DEFAULT uuid_generate_v4() NOT NULL,
    band_id character varying(64) NOT NULL,
    user_id character varying(64) NOT NULL,
    admin boolean DEFAULT false NOT NULL,
    created_at timestamp without time zone DEFAULT now() NOT NULL,
    updated_at timestamp without time zone DEFAULT now() NOT NULL
);


--
-- Name: chat_messages; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE chat_messages (
    id character varying(64) DEFAULT uuid_generate_v4() NOT NULL,
    user_id character varying(64),
    music_session_id character varying(64),
    message text NOT NULL,
    created_at timestamp without time zone DEFAULT now() NOT NULL
);


--
-- Name: cities; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE cities (
    city character varying(255) NOT NULL,
    region character varying(2) NOT NULL,
    countrycode character varying(2) NOT NULL
);


--
-- Name: claimed_recordings; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE claimed_recordings (
    user_id character varying(64) NOT NULL,
    recording_id character varying(64) NOT NULL,
    id character varying(64) DEFAULT uuid_generate_v4() NOT NULL,
    name character varying(200) NOT NULL,
    is_public boolean DEFAULT true NOT NULL,
    genre_id character varying(64) NOT NULL,
    created_at timestamp without time zone DEFAULT now() NOT NULL,
    updated_at timestamp without time zone DEFAULT now() NOT NULL,
    description character varying(8000),
    description_tsv tsvector,
    name_tsv tsvector
);


--
-- Name: connections; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE UNLOGGED TABLE connections (
    id character varying(64) DEFAULT uuid_generate_v4() NOT NULL,
    user_id character varying(64) NOT NULL,
    client_id character varying(64) NOT NULL,
    created_at timestamp without time zone DEFAULT now() NOT NULL,
    updated_at timestamp without time zone DEFAULT now() NOT NULL,
    music_session_id character varying(64),
    ip_address character varying(64) NOT NULL,
    as_musician boolean,
    aasm_state character varying(64) DEFAULT 'idle'::character varying NOT NULL,
    addr bigint NOT NULL,
    locidispid bigint NOT NULL,
    joined_session_at timestamp without time zone,
    client_type character varying(256) NOT NULL,
    stale_time integer DEFAULT 40 NOT NULL,
    expire_time integer DEFAULT 60 NOT NULL
);


--
-- Name: countries; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE countries (
    countrycode character varying(2) NOT NULL,
    countryname character varying(64)
);


--
-- Name: crash_dumps; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE crash_dumps (
    id character varying(64) DEFAULT uuid_generate_v4() NOT NULL,
    client_type character varying(64) NOT NULL,
    client_id character varying(64),
    user_id character varying(64),
    session_id character varying(64),
    "timestamp" timestamp without time zone,
    uri character varying(1000),
    created_at timestamp without time zone DEFAULT now() NOT NULL,
    updated_at timestamp without time zone DEFAULT now() NOT NULL,
    client_version character varying(100) NOT NULL
);


--
-- Name: scores; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE scores (
    alocidispid bigint NOT NULL,
    anodeid character varying(64) NOT NULL,
    aaddr bigint NOT NULL,
    blocidispid bigint NOT NULL,
    bnodeid character varying(64) NOT NULL,
    baddr bigint NOT NULL,
    score integer NOT NULL,
    scorer integer NOT NULL,
    score_dt timestamp without time zone DEFAULT now() NOT NULL
);


--
-- Name: current_scores; Type: VIEW; Schema: public; Owner: -
--

CREATE VIEW current_scores AS
 SELECT s.alocidispid,
    s.anodeid,
    s.aaddr,
    s.blocidispid,
    s.bnodeid,
    s.baddr,
    s.score,
    s.scorer,
    s.score_dt
   FROM scores s
  WHERE (s.score_dt = ( SELECT max(s0.score_dt) AS max
           FROM scores s0
          WHERE ((s0.alocidispid = s.alocidispid) AND (s0.blocidispid = s.blocidispid))));


--
-- Name: diagnostics; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE diagnostics (
    id character varying(64) DEFAULT uuid_generate_v4() NOT NULL,
    user_id character varying(64) NOT NULL,
    type character varying(255) NOT NULL,
    creator character varying(255) NOT NULL,
    data text,
    created_at timestamp without time zone DEFAULT now() NOT NULL
);


--
-- Name: email_batch_sets; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE email_batch_sets (
    id character varying(64) DEFAULT uuid_generate_v4() NOT NULL,
    email_batch_id character varying(64),
    started_at timestamp without time zone,
    user_ids text DEFAULT ''::text NOT NULL,
    batch_count integer,
    created_at timestamp without time zone DEFAULT now() NOT NULL,
    updated_at timestamp without time zone DEFAULT now() NOT NULL,
    trigger_index integer DEFAULT 0 NOT NULL,
    sub_type character varying(64),
    user_id character varying(64)
);


--
-- Name: email_batches; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE email_batches (
    id character varying(64) DEFAULT uuid_generate_v4() NOT NULL,
    subject character varying(256),
    body text,
    from_email character varying(64) DEFAULT 'noreply@jamkazam.com'::character varying NOT NULL,
    aasm_state character varying(32) DEFAULT 'pending'::character varying NOT NULL,
    test_emails text DEFAULT 'test@jamkazam.com'::text NOT NULL,
    opt_in_count integer DEFAULT 0 NOT NULL,
    sent_count integer DEFAULT 0 NOT NULL,
    lock_version integer,
    started_at timestamp without time zone,
    completed_at timestamp without time zone,
    created_at timestamp without time zone DEFAULT now() NOT NULL,
    updated_at timestamp without time zone DEFAULT now() NOT NULL,
    type character varying(64) DEFAULT 'JamRuby::EmailBatch'::character varying NOT NULL,
    sub_type character varying(64)
);


--
-- Name: email_errors; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE email_errors (
    id character varying(64) DEFAULT uuid_generate_v4() NOT NULL,
    user_id character varying(64),
    error_type character varying(32),
    email_address character varying(256),
    status character varying(32),
    email_date timestamp without time zone DEFAULT now(),
    reason text,
    created_at timestamp without time zone DEFAULT now() NOT NULL,
    updated_at timestamp without time zone DEFAULT now() NOT NULL
);


--
-- Name: event_sessions; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE event_sessions (
    id character varying(64) DEFAULT uuid_generate_v4() NOT NULL,
    starts_at timestamp without time zone,
    ends_at timestamp without time zone,
    pinned_state character varying(255),
    img_url character varying(1024),
    img_width integer,
    img_height integer,
    event_id character varying(64),
    user_id character varying(64),
    band_id character varying(64),
    created_at timestamp without time zone DEFAULT now() NOT NULL,
    updated_at timestamp without time zone DEFAULT now() NOT NULL,
    ordinal integer
);


--
-- Name: events; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE events (
    id character varying(64) DEFAULT uuid_generate_v4() NOT NULL,
    slug character varying(512) NOT NULL,
    title text,
    description text,
    show_sponser boolean DEFAULT false NOT NULL,
    created_at timestamp without time zone DEFAULT now() NOT NULL,
    updated_at timestamp without time zone DEFAULT now() NOT NULL,
    social_description text
);


--
-- Name: facebook_signups; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE UNLOGGED TABLE facebook_signups (
    id character varying(64) DEFAULT uuid_generate_v4() NOT NULL,
    lookup_id character varying(255) NOT NULL,
    last_name character varying(100),
    first_name character varying(100),
    gender character varying(1),
    email character varying(1024),
    uid character varying(1024),
    token character varying(1024),
    token_expires_at timestamp without time zone,
    created_at timestamp without time zone DEFAULT now() NOT NULL,
    updated_at timestamp without time zone DEFAULT now() NOT NULL
);


--
-- Name: fan_invitations; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE fan_invitations (
    id character varying(64) DEFAULT uuid_generate_v4() NOT NULL,
    sender_id character varying(64),
    receiver_id character varying(64),
    music_session_id character varying(64),
    created_at timestamp without time zone DEFAULT now() NOT NULL,
    updated_at timestamp without time zone DEFAULT now() NOT NULL
);


--
-- Name: feeds; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE feeds (
    id bigint NOT NULL,
    recording_id character varying(64),
    music_session_id character varying(64),
    created_at timestamp without time zone DEFAULT now() NOT NULL,
    updated_at timestamp without time zone DEFAULT now() NOT NULL
);


--
-- Name: feeds_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--

CREATE SEQUENCE feeds_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: feeds_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--

ALTER SEQUENCE feeds_id_seq OWNED BY feeds.id;


--
-- Name: follows; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE follows (
    id character varying(64) DEFAULT uuid_generate_v4() NOT NULL,
    user_id character varying(64) NOT NULL,
    followable_id character varying(64) NOT NULL,
    followable_type character varying(25) NOT NULL,
    created_at timestamp without time zone DEFAULT now() NOT NULL,
    updated_at timestamp without time zone DEFAULT now() NOT NULL
);


--
-- Name: friend_requests; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE friend_requests (
    id character varying(64) DEFAULT uuid_generate_v4() NOT NULL,
    user_id character varying(64),
    friend_id character varying(64),
    created_at timestamp without time zone DEFAULT now() NOT NULL,
    updated_at timestamp without time zone DEFAULT now() NOT NULL,
    status character varying(50),
    message character varying(4000)
);


--
-- Name: friendships; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE friendships (
    id character varying(64) DEFAULT uuid_generate_v4() NOT NULL,
    user_id character varying(64),
    friend_id character varying(64),
    created_at timestamp without time zone DEFAULT now() NOT NULL,
    updated_at timestamp without time zone DEFAULT now() NOT NULL
);


--
-- Name: genres; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE genres (
    id character varying(64) DEFAULT uuid_generate_v4() NOT NULL,
    description character varying(1024) NOT NULL,
    created_at timestamp without time zone DEFAULT now() NOT NULL,
    updated_at timestamp without time zone DEFAULT now() NOT NULL
);


--
-- Name: genres_music_sessions; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE UNLOGGED TABLE genres_music_sessions (
    id character varying(64) DEFAULT uuid_generate_v4() NOT NULL,
    genre_id character varying(64),
    music_session_id character varying(64)
);


--
-- Name: geoipblocks; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE geoipblocks (
    beginip bigint NOT NULL,
    endip bigint NOT NULL,
    locid integer NOT NULL,
    geom geometry(Polygon)
);


--
-- Name: geoipisp; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE geoipisp (
    beginip bigint NOT NULL,
    endip bigint NOT NULL,
    company character varying(50) NOT NULL
);


--
-- Name: geoiplocations; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE geoiplocations (
    locid integer NOT NULL,
    countrycode character varying(2),
    region character varying(2),
    city character varying(255),
    postalcode character varying(8),
    latitude double precision NOT NULL,
    longitude double precision NOT NULL,
    metrocode integer,
    areacode character(3),
    geog geography(Point,4326)
);


--
-- Name: icecast_admin_authentications; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE icecast_admin_authentications (
    id character varying(64) DEFAULT uuid_generate_v4() NOT NULL,
    source_pass character varying(64) NOT NULL,
    relay_user character varying(64) NOT NULL,
    relay_pass character varying(64) NOT NULL,
    admin_user character varying(64) NOT NULL,
    admin_pass character varying(64) NOT NULL,
    created_at timestamp without time zone DEFAULT now() NOT NULL,
    updated_at timestamp without time zone DEFAULT now() NOT NULL
);


--
-- Name: icecast_directories; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE icecast_directories (
    id character varying(64) DEFAULT uuid_generate_v4() NOT NULL,
    yp_url_timeout integer DEFAULT 15 NOT NULL,
    yp_url character varying(1024) NOT NULL,
    created_at timestamp without time zone DEFAULT now() NOT NULL,
    updated_at timestamp without time zone DEFAULT now() NOT NULL
);


--
-- Name: icecast_limits; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE icecast_limits (
    id character varying(64) DEFAULT uuid_generate_v4() NOT NULL,
    clients integer DEFAULT 1000 NOT NULL,
    sources integer DEFAULT 50 NOT NULL,
    queue_size integer DEFAULT 102400 NOT NULL,
    client_timeout integer DEFAULT 30,
    header_timeout integer DEFAULT 15,
    source_timeout integer DEFAULT 10,
    burst_size integer DEFAULT 65536,
    created_at timestamp without time zone DEFAULT now() NOT NULL,
    updated_at timestamp without time zone DEFAULT now() NOT NULL
);


--
-- Name: icecast_listen_sockets; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE icecast_listen_sockets (
    id character varying(64) DEFAULT uuid_generate_v4() NOT NULL,
    port integer DEFAULT 8001 NOT NULL,
    bind_address character varying(1024),
    shoutcast_mount character varying(1024),
    shoutcast_compat integer,
    created_at timestamp without time zone DEFAULT now() NOT NULL,
    updated_at timestamp without time zone DEFAULT now() NOT NULL
);


--
-- Name: icecast_loggings; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE icecast_loggings (
    id character varying(64) DEFAULT uuid_generate_v4() NOT NULL,
    access_log character varying(1024) DEFAULT 'access.log'::character varying NOT NULL,
    error_log character varying(1024) DEFAULT 'error.log'::character varying NOT NULL,
    playlist_log character varying(1024),
    log_level integer DEFAULT 3 NOT NULL,
    log_archive integer,
    log_size integer DEFAULT 10000,
    created_at timestamp without time zone DEFAULT now() NOT NULL,
    updated_at timestamp without time zone DEFAULT now() NOT NULL
);


--
-- Name: icecast_master_server_relays; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE icecast_master_server_relays (
    id character varying(64) DEFAULT uuid_generate_v4() NOT NULL,
    master_server character varying(1024) NOT NULL,
    master_server_port integer DEFAULT 8001 NOT NULL,
    master_update_interval integer DEFAULT 120 NOT NULL,
    master_username character varying(64) NOT NULL,
    master_pass character varying(64) NOT NULL,
    relays_on_demand integer DEFAULT 1 NOT NULL,
    created_at timestamp without time zone DEFAULT now() NOT NULL,
    updated_at timestamp without time zone DEFAULT now() NOT NULL
);


--
-- Name: icecast_mount_templates; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE icecast_mount_templates (
    id character varying(64) DEFAULT uuid_generate_v4() NOT NULL,
    name character varying(256) NOT NULL,
    source_username character varying(64),
    source_pass character varying(64),
    max_listeners integer DEFAULT 4,
    max_listener_duration integer DEFAULT 3600,
    dump_file character varying(1024),
    intro character varying(1024),
    fallback_mount character varying(1024),
    fallback_override integer DEFAULT 1,
    fallback_when_full integer DEFAULT 1,
    charset character varying(1024) DEFAULT 'ISO8859-1'::character varying,
    is_public integer DEFAULT 0,
    stream_name character varying(1024),
    stream_description character varying(10000),
    stream_url character varying(1024),
    genre character varying(256),
    bitrate integer,
    mime_type character varying(64) DEFAULT 'audio/mpeg'::character varying NOT NULL,
    subtype character varying(64),
    burst_size integer,
    mp3_metadata_interval integer,
    hidden integer DEFAULT 1,
    on_connect character varying(1024),
    on_disconnect character varying(1024),
    authentication_id character varying(64) NOT NULL,
    created_at timestamp without time zone DEFAULT now() NOT NULL,
    updated_at timestamp without time zone DEFAULT now() NOT NULL
);


--
-- Name: icecast_mounts; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE UNLOGGED TABLE icecast_mounts (
    id character varying(64) DEFAULT uuid_generate_v4() NOT NULL,
    name character varying(1024) NOT NULL,
    source_username character varying(64),
    source_pass character varying(64),
    max_listeners integer DEFAULT 4,
    max_listener_duration integer DEFAULT 3600,
    dump_file character varying(1024),
    intro character varying(1024),
    fallback_mount character varying(1024),
    fallback_override integer DEFAULT 1,
    fallback_when_full integer DEFAULT 1,
    charset character varying(1024) DEFAULT 'ISO8859-1'::character varying,
    is_public integer DEFAULT 0,
    stream_name character varying(1024),
    stream_description character varying(10000),
    stream_url character varying(1024),
    genre character varying(256),
    bitrate integer,
    mime_type character varying(64),
    subtype character varying(64),
    burst_size integer,
    mp3_metadata_interval integer,
    hidden integer DEFAULT 1,
    on_connect character varying(1024),
    on_disconnect character varying(1024),
    authentication_id character varying(64) DEFAULT NULL::character varying,
    listeners integer DEFAULT 0 NOT NULL,
    sourced boolean DEFAULT false NOT NULL,
    created_at timestamp without time zone DEFAULT now() NOT NULL,
    updated_at timestamp without time zone DEFAULT now() NOT NULL,
    music_session_id character varying(64),
    icecast_server_id character varying(64) NOT NULL,
    icecast_mount_template_id character varying(64),
    sourced_needs_changing_at timestamp without time zone
);


--
-- Name: icecast_paths; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE icecast_paths (
    id character varying(64) DEFAULT uuid_generate_v4() NOT NULL,
    base_dir character varying(1024) DEFAULT './'::character varying NOT NULL,
    log_dir character varying(1024) DEFAULT './logs'::character varying NOT NULL,
    pid_file character varying(1024) DEFAULT './icecast.pid'::character varying,
    web_root character varying(1024) DEFAULT './web'::character varying NOT NULL,
    admin_root character varying(1024) DEFAULT './admin'::character varying NOT NULL,
    allow_ip character varying(1024),
    deny_ip character varying(1024),
    alias_source character varying(1024),
    alias_dest character varying(1024),
    created_at timestamp without time zone DEFAULT now() NOT NULL,
    updated_at timestamp without time zone DEFAULT now() NOT NULL
);


--
-- Name: icecast_relays; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE icecast_relays (
    id character varying(64) DEFAULT uuid_generate_v4() NOT NULL,
    server character varying(1024) NOT NULL,
    port integer DEFAULT 8001 NOT NULL,
    mount character varying(1024) NOT NULL,
    local_mount character varying(1024),
    relay_username character varying(64),
    relay_pass character varying(64),
    relay_shoutcast_metadata integer DEFAULT 0,
    on_demand integer DEFAULT 1,
    created_at timestamp without time zone DEFAULT now() NOT NULL,
    updated_at timestamp without time zone DEFAULT now() NOT NULL
);


--
-- Name: icecast_securities; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE icecast_securities (
    id character varying(64) DEFAULT uuid_generate_v4() NOT NULL,
    chroot integer DEFAULT 0 NOT NULL,
    change_owner_user character varying(64),
    change_owner_group character varying(64),
    created_at timestamp without time zone DEFAULT now() NOT NULL,
    updated_at timestamp without time zone DEFAULT now() NOT NULL
);


--
-- Name: icecast_server_groups; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE icecast_server_groups (
    id character varying(64) DEFAULT uuid_generate_v4() NOT NULL,
    name character varying(255) NOT NULL
);


--
-- Name: icecast_server_mounts; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE icecast_server_mounts (
    id character varying(64) DEFAULT uuid_generate_v4() NOT NULL,
    icecast_mount_id character varying(64),
    icecast_server_id character varying(64),
    created_at timestamp without time zone DEFAULT now() NOT NULL,
    updated_at timestamp without time zone DEFAULT now() NOT NULL
);


--
-- Name: icecast_server_relays; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE icecast_server_relays (
    id character varying(64) DEFAULT uuid_generate_v4() NOT NULL,
    icecast_relay_id character varying(64),
    icecast_server_id character varying(64),
    created_at timestamp without time zone DEFAULT now() NOT NULL,
    updated_at timestamp without time zone DEFAULT now() NOT NULL
);


--
-- Name: icecast_server_sockets; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE icecast_server_sockets (
    id character varying(64) DEFAULT uuid_generate_v4() NOT NULL,
    icecast_listen_socket_id character varying(64),
    icecast_server_id character varying(64),
    created_at timestamp without time zone DEFAULT now() NOT NULL,
    updated_at timestamp without time zone DEFAULT now() NOT NULL
);


--
-- Name: icecast_servers; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE icecast_servers (
    id character varying(64) DEFAULT uuid_generate_v4() NOT NULL,
    config_changed integer DEFAULT 0,
    limit_id character varying(64),
    admin_auth_id character varying(64),
    directory_id character varying(64),
    master_relay_id character varying(64),
    path_id character varying(64),
    logging_id character varying(64),
    security_id character varying(64),
    template_id character varying(64) NOT NULL,
    hostname character varying(1024) NOT NULL,
    server_id character varying(1024) NOT NULL,
    location character varying(1024),
    admin_email character varying(1024),
    fileserve integer,
    created_at timestamp without time zone DEFAULT now() NOT NULL,
    updated_at timestamp without time zone DEFAULT now() NOT NULL,
    icecast_server_group_id character varying(64) DEFAULT 'default'::character varying NOT NULL,
    mount_template_id character varying(64),
    config_updated_at timestamp without time zone
);


--
-- Name: icecast_template_sockets; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE icecast_template_sockets (
    id character varying(64) DEFAULT uuid_generate_v4() NOT NULL,
    icecast_listen_socket_id character varying(64),
    icecast_template_id character varying(64),
    created_at timestamp without time zone DEFAULT now() NOT NULL,
    updated_at timestamp without time zone DEFAULT now() NOT NULL
);


--
-- Name: icecast_templates; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE icecast_templates (
    id character varying(64) DEFAULT uuid_generate_v4() NOT NULL,
    limit_id character varying(64),
    admin_auth_id character varying(64),
    directory_id character varying(64),
    master_relay_id character varying(64),
    path_id character varying(64),
    logging_id character varying(64),
    security_id character varying(64),
    location character varying(1024) NOT NULL,
    name character varying(256) NOT NULL,
    admin_email character varying(1024) DEFAULT 'admin@jamkazam.com'::character varying NOT NULL,
    fileserve integer DEFAULT 1 NOT NULL,
    created_at timestamp without time zone DEFAULT now() NOT NULL,
    updated_at timestamp without time zone DEFAULT now() NOT NULL
);


--
-- Name: icecast_user_authentications; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE UNLOGGED TABLE icecast_user_authentications (
    id character varying(64) DEFAULT uuid_generate_v4() NOT NULL,
    authentication_type character varying(16) DEFAULT 'url'::character varying,
    filename character varying(1024),
    allow_duplicate_users integer,
    mount_add character varying(1024),
    mount_remove character varying(1024),
    listener_add character varying(1024),
    listener_remove character varying(1024),
    unused_username character varying(64),
    unused_pass character varying(64),
    auth_header character varying(64) DEFAULT 'icecast-auth-user: 1'::character varying,
    timelimit_header character varying(64) DEFAULT 'icecast-auth-timelimit:'::character varying,
    created_at timestamp without time zone DEFAULT now() NOT NULL,
    updated_at timestamp without time zone DEFAULT now() NOT NULL
);


--
-- Name: instruments; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE instruments (
    id character varying(64) DEFAULT uuid_generate_v4() NOT NULL,
    description character varying(1024) NOT NULL,
    created_at timestamp without time zone DEFAULT now() NOT NULL,
    updated_at timestamp without time zone DEFAULT now() NOT NULL,
    popularity integer DEFAULT 0 NOT NULL
);


--
-- Name: invitations; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE UNLOGGED TABLE invitations (
    id character varying(64) DEFAULT uuid_generate_v4() NOT NULL,
    sender_id character varying(64),
    receiver_id character varying(64),
    music_session_id character varying(64),
    created_at timestamp without time zone DEFAULT now() NOT NULL,
    updated_at timestamp without time zone DEFAULT now() NOT NULL,
    join_request_id character varying(64)
);


--
-- Name: invited_users; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE invited_users (
    id character varying(64) DEFAULT uuid_generate_v4() NOT NULL,
    sender_id character varying(64),
    autofriend boolean NOT NULL,
    email character varying(256),
    invitation_code character varying(256) NOT NULL,
    accepted boolean DEFAULT false,
    note text,
    created_at timestamp without time zone DEFAULT now() NOT NULL,
    updated_at timestamp without time zone DEFAULT now() NOT NULL,
    invite_medium character varying(64)
);


--
-- Name: isp_score_batch; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE isp_score_batch (
    id character varying(64) DEFAULT uuid_generate_v4() NOT NULL,
    json_scoring_data text NOT NULL,
    created_at timestamp without time zone DEFAULT now() NOT NULL
);


--
-- Name: jamcompany; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE jamcompany (
    coid integer NOT NULL,
    company character varying(50) NOT NULL
);


--
-- Name: jamcompany_coid_seq; Type: SEQUENCE; Schema: public; Owner: -
--

CREATE SEQUENCE jamcompany_coid_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: jamcompany_coid_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: -
--

ALTER SEQUENCE jamcompany_coid_seq OWNED BY jamcompany.coid;


--
-- Name: jamisp; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE jamisp (
    beginip bigint NOT NULL,
    endip bigint NOT NULL,
    coid integer NOT NULL,
    geom geometry(Polygon)
);


--
-- Name: join_requests; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE UNLOGGED TABLE join_requests (
    id character varying(64) DEFAULT uuid_generate_v4() NOT NULL,
    user_id character varying(64),
    music_session_id character varying(64),
    text character varying(2000),
    created_at timestamp without time zone DEFAULT now() NOT NULL,
    updated_at timestamp without time zone DEFAULT now() NOT NULL
);


--
-- Name: likes; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE likes (
    id character varying(64) DEFAULT uuid_generate_v4() NOT NULL,
    user_id character varying(64) NOT NULL,
    likable_id character varying(64) NOT NULL,
    likable_type character varying(25) NOT NULL,
    created_at timestamp without time zone DEFAULT now() NOT NULL,
    updated_at timestamp without time zone DEFAULT now() NOT NULL
);


--
-- Name: max_mind_geo; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE max_mind_geo (
    country character varying(2) NOT NULL,
    region character varying(2) NOT NULL,
    city character varying(255) NOT NULL,
    lat numeric(15,10) NOT NULL,
    lng numeric(15,10) NOT NULL,
    ip_start bigint NOT NULL,
    ip_end bigint NOT NULL
);


--
-- Name: max_mind_isp; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE max_mind_isp (
    ip_bottom bigint NOT NULL,
    ip_top bigint NOT NULL,
    isp character varying(64) NOT NULL,
    country character varying(2) NOT NULL
);


--
-- Name: tracks_next_tracker_seq; Type: SEQUENCE; Schema: public; Owner: -
--

CREATE SEQUENCE tracks_next_tracker_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


--
-- Name: mixes; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE mixes (
    id bigint DEFAULT nextval('tracks_next_tracker_seq'::regclass) NOT NULL,
    recording_id character varying(64) NOT NULL,
    mix_server character varying(64) DEFAULT NULL::character varying,
    started_at timestamp without time zone,
    completed_at timestamp without time zone,
    created_at timestamp without time zone DEFAULT now() NOT NULL,
    updated_at timestamp without time zone DEFAULT now() NOT NULL,
    ogg_md5 character varying(100),
    ogg_length integer,
    ogg_url character varying(1024),
    completed boolean DEFAULT false NOT NULL,
    error_count integer DEFAULT 0 NOT NULL,
    error_reason text,
    error_detail text,
    should_retry boolean DEFAULT false NOT NULL,
    mp3_md5 character varying(100),
    mp3_length integer,
    mp3_url character varying(1024),
    download_count integer DEFAULT 0 NOT NULL,
    last_downloaded_at timestamp without time zone
);


--
-- Name: music_session_perf_data; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE music_session_perf_data (
    id character varying(64) DEFAULT uuid_generate_v4() NOT NULL,
    music_session_id character varying(64),
    client_id character varying(64),
    uri character varying(1000),
    created_at timestamp without time zone DEFAULT now() NOT NULL,
    updated_at timestamp without time zone DEFAULT now() NOT NULL
);


--
-- Name: music_sessions; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE music_sessions (
    id character varying(64) DEFAULT uuid_generate_v4() NOT NULL,
    music_session_id character varying(64),
    description character varying(8000),
    user_id character varying(64) NOT NULL,
    band_id character varying(64),
    created_at timestamp without time zone DEFAULT now() NOT NULL,
    session_removed_at timestamp without time zone DEFAULT now(),
    play_count integer DEFAULT 0 NOT NULL,
    like_count integer DEFAULT 0 NOT NULL,
    fan_access boolean DEFAULT true NOT NULL,
    scheduled_start timestamp with time zone,
    scheduled_duration interval,
    musician_access boolean DEFAULT true NOT NULL,
    approval_required boolean DEFAULT false NOT NULL,
    fan_chat boolean DEFAULT true NOT NULL,
    genre_id character varying(64) NOT NULL,
    legal_policy character varying(255) DEFAULT 'standard'::character varying NOT NULL,
    language character varying(255) DEFAULT 'en'::character varying NOT NULL,
    name text NOT NULL,
    recurring_session_id character varying(64)
);


--
-- Name: music_sessions_comments; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE music_sessions_comments (
    id character varying(64) DEFAULT uuid_generate_v4() NOT NULL,
    creator_id character varying(64) NOT NULL,
    comment character varying(4000) NOT NULL,
    created_at timestamp without time zone DEFAULT now() NOT NULL,
    updated_at timestamp without time zone DEFAULT now() NOT NULL,
    ip_address inet,
    music_session_id character varying(64)
);


--
-- Name: music_sessions_likers; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE music_sessions_likers (
    id character varying(64) DEFAULT uuid_generate_v4() NOT NULL,
    liker_id character varying(64),
    created_at timestamp without time zone DEFAULT now() NOT NULL,
    updated_at timestamp without time zone DEFAULT now() NOT NULL,
    ip_address inet,
    music_session_id character varying(64)
);


--
-- Name: music_sessions_user_history; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE music_sessions_user_history (
    id character varying(64) DEFAULT uuid_generate_v4() NOT NULL,
    user_id character varying(64) NOT NULL,
    client_id character varying(64) NOT NULL,
    created_at timestamp without time zone DEFAULT now() NOT NULL,
    session_removed_at timestamp without time zone,
    max_concurrent_connections integer,
    rating integer,
    instruments character varying(255),
    rating_comment text,
    music_session_id character varying(64)
);


--
-- Name: musicians_instruments; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE musicians_instruments (
    id character varying(64) DEFAULT uuid_generate_v4() NOT NULL,
    user_id character varying(64) NOT NULL,
    instrument_id character varying(64) NOT NULL,
    proficiency_level smallint NOT NULL,
    priority smallint DEFAULT 1 NOT NULL,
    created_at timestamp without time zone DEFAULT now() NOT NULL,
    updated_at timestamp without time zone DEFAULT now() NOT NULL
);


--
-- Name: notifications; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE notifications (
    id character varying(64) DEFAULT uuid_generate_v4() NOT NULL,
    description character varying(32) NOT NULL,
    source_user_id character varying(64),
    target_user_id character varying(64),
    band_id character varying(64),
    session_id character varying(64),
    recording_id character varying(64),
    invitation_id character varying(64),
    join_request_id character varying(64),
    created_at timestamp without time zone DEFAULT now() NOT NULL,
    updated_at timestamp without time zone DEFAULT now() NOT NULL,
    friend_request_id character varying(64),
    band_invitation_id character varying(64),
    message text
);


--
-- Name: playable_plays; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE playable_plays (
    id character varying(64) DEFAULT uuid_generate_v4() NOT NULL,
    playable_id character varying(64) NOT NULL,
    playable_type character varying(128) NOT NULL,
    player_id character varying(64),
    claimed_recording_id character varying(64),
    ip_address inet,
    created_at timestamp without time zone DEFAULT now() NOT NULL,
    updated_at timestamp without time zone DEFAULT now() NOT NULL
);


--
-- Name: promotionals; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE promotionals (
    id character varying(64) DEFAULT uuid_generate_v4() NOT NULL,
    type character varying(128) DEFAULT 'JamRuby::PromoBuzz'::character varying NOT NULL,
    aasm_state character varying(64) DEFAULT 'hidden'::character varying,
    "position" integer DEFAULT 0 NOT NULL,
    created_at timestamp without time zone DEFAULT now() NOT NULL,
    updated_at timestamp without time zone DEFAULT now() NOT NULL,
    latest_id character varying(64) DEFAULT NULL::character varying,
    latest_type character varying(128) DEFAULT NULL::character varying,
    image character varying(1024) DEFAULT NULL::character varying,
    text_short character varying(512) DEFAULT NULL::character varying,
    text_long character varying(4096) DEFAULT NULL::character varying
);


--
-- Name: recorded_tracks; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE recorded_tracks (
    id bigint DEFAULT nextval('tracks_next_tracker_seq'::regclass) NOT NULL,
    user_id character varying(64) NOT NULL,
    instrument_id character varying(64) NOT NULL,
    sound character varying(64) NOT NULL,
    next_part_to_upload integer DEFAULT 0 NOT NULL,
    fully_uploaded boolean DEFAULT false NOT NULL,
    created_at timestamp without time zone DEFAULT now() NOT NULL,
    updated_at timestamp without time zone DEFAULT now() NOT NULL,
    upload_id character varying(1024),
    recording_id character varying(64) NOT NULL,
    md5 character varying(100),
    length bigint,
    client_id character varying(64) NOT NULL,
    track_id character varying(64) NOT NULL,
    url character varying(1024),
    file_offset bigint DEFAULT 0,
    client_track_id character varying(64) NOT NULL,
    is_part_uploading boolean DEFAULT false NOT NULL,
    upload_failures integer DEFAULT 0 NOT NULL,
    part_failures integer DEFAULT 0 NOT NULL,
    discard boolean,
    download_count integer DEFAULT 0 NOT NULL,
    last_downloaded_at timestamp without time zone
);


--
-- Name: recordings; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE recordings (
    id character varying(64) DEFAULT uuid_generate_v4() NOT NULL,
    created_at timestamp without time zone DEFAULT now() NOT NULL,
    updated_at timestamp without time zone DEFAULT now() NOT NULL,
    owner_id character varying(64) NOT NULL,
    music_session_id character varying(64),
    band_id character varying(64),
    duration integer,
    is_done boolean DEFAULT false,
    all_discarded boolean DEFAULT false NOT NULL,
    name character varying(1024),
    play_count integer DEFAULT 0 NOT NULL,
    like_count integer DEFAULT 0 NOT NULL
);


--
-- Name: recordings_comments; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE recordings_comments (
    id character varying(64) DEFAULT uuid_generate_v4() NOT NULL,
    recording_id character varying(64) NOT NULL,
    creator_id character varying(64) NOT NULL,
    comment character varying(4000) NOT NULL,
    created_at timestamp without time zone DEFAULT now() NOT NULL,
    updated_at timestamp without time zone DEFAULT now() NOT NULL,
    ip_address inet
);


--
-- Name: recordings_downloads; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE recordings_downloads (
    id character varying(64) DEFAULT uuid_generate_v4() NOT NULL,
    recording_id character varying(64) NOT NULL,
    downloader_id character varying(64) NOT NULL,
    created_at timestamp without time zone DEFAULT now() NOT NULL,
    updated_at timestamp without time zone DEFAULT now() NOT NULL
);


--
-- Name: recordings_likers; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE recordings_likers (
    id character varying(64) DEFAULT uuid_generate_v4() NOT NULL,
    recording_id character varying(64) NOT NULL,
    liker_id character varying(64),
    created_at timestamp without time zone DEFAULT now() NOT NULL,
    updated_at timestamp without time zone DEFAULT now() NOT NULL,
    ip_address inet,
    claimed_recording_id character varying(64) NOT NULL,
    favorite boolean DEFAULT true NOT NULL
);


--
-- Name: recurring_sessions; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE recurring_sessions (
    id character varying(64) DEFAULT uuid_generate_v4() NOT NULL,
    description character varying(8000),
    scheduled_start timestamp with time zone,
    scheduled_duration interval,
    musician_access boolean NOT NULL,
    approval_required boolean NOT NULL,
    fan_chat boolean NOT NULL,
    genre_id character varying(64),
    legal_policy character varying(255) DEFAULT 'standard'::character varying NOT NULL,
    language character varying(255) DEFAULT 'en'::character varying NOT NULL,
    name text,
    user_id character varying(64) NOT NULL,
    band_id character varying(64),
    created_at timestamp without time zone DEFAULT now() NOT NULL,
    updated_at timestamp without time zone DEFAULT now() NOT NULL
);


--
-- Name: regions; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE regions (
    region character varying(2) NOT NULL,
    regionname character varying(64),
    countrycode character varying(2) NOT NULL
);


--
-- Name: rsvp_requests; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE rsvp_requests (
    id character varying(64) DEFAULT uuid_generate_v4() NOT NULL,
    user_id character varying(64) NOT NULL,
    rsvp_slot_id character varying(64) NOT NULL,
    message text,
    chosen boolean DEFAULT false,
    canceled boolean DEFAULT false,
    created_at timestamp without time zone DEFAULT now() NOT NULL,
    updated_at timestamp without time zone DEFAULT now() NOT NULL
);


--
-- Name: rsvp_slots; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE rsvp_slots (
    id character varying(64) DEFAULT uuid_generate_v4() NOT NULL,
    instrument_id character varying(64),
    proficiency_level character varying(255) NOT NULL,
    music_session_id character varying(64) NOT NULL,
    created_at timestamp without time zone DEFAULT now() NOT NULL,
    updated_at timestamp without time zone DEFAULT now() NOT NULL
);


--
-- Name: share_tokens; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE share_tokens (
    id character varying(64) DEFAULT uuid_generate_v4() NOT NULL,
    token character varying(15) NOT NULL,
    shareable_id character varying(64) NOT NULL,
    shareable_type character varying(50) NOT NULL,
    created_at timestamp without time zone DEFAULT now() NOT NULL,
    updated_at timestamp without time zone DEFAULT now() NOT NULL
);


--
-- Name: tracks; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE UNLOGGED TABLE tracks (
    id character varying(64) DEFAULT uuid_generate_v4() NOT NULL,
    connection_id character varying(64) NOT NULL,
    instrument_id character varying(64),
    sound character varying(64) NOT NULL,
    created_at timestamp without time zone DEFAULT now() NOT NULL,
    updated_at timestamp without time zone DEFAULT now() NOT NULL,
    client_track_id character varying(64) NOT NULL
);


--
-- Name: user_authorizations; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE user_authorizations (
    id character varying(64) DEFAULT uuid_generate_v4() NOT NULL,
    user_id character varying(64),
    uid character varying(255) NOT NULL,
    provider character varying(255) NOT NULL,
    token character varying(255),
    token_expiration timestamp without time zone,
    created_at timestamp without time zone DEFAULT now() NOT NULL,
    updated_at timestamp without time zone DEFAULT now() NOT NULL,
    secret character varying(255)
);


--
-- Name: users; Type: TABLE; Schema: public; Owner: -; Tablespace: 
--

CREATE TABLE users (
    id character varying(64) DEFAULT uuid_generate_v4() NOT NULL,
    email character varying(255) NOT NULL,
    remember_token character varying(255),
    encrypted_password character varying(255) NOT NULL,
    admin boolean DEFAULT false NOT NULL,
    created_at timestamp without time zone DEFAULT now() NOT NULL,
    updated_at timestamp without time zone DEFAULT now() NOT NULL,
    musician boolean DEFAULT false NOT NULL,
    city character varying(100),
    state character varying(100),
    country character varying(100),
    first_name character varying(50),
    last_name character varying(50),
    birth_date date,
    gender character(1),
    internet_service_provider character varying(50),
    signup_token character varying(255),
    email_confirmed boolean DEFAULT false,
    photo_url character varying(2048),
    session_settings character varying(4000),
    reset_password_token character varying(64),
    reset_password_token_created timestamp without time zone,
    can_invite boolean DEFAULT true NOT NULL,
    name_tsv tsvector,
    environment character varying(255) DEFAULT 'public'::character varying NOT NULL,
    subscribe_email boolean DEFAULT true,
    update_email character varying(1024),
    update_email_token character varying(1024),
    original_fpfile character varying(8000) DEFAULT NULL::character varying,
    cropped_fpfile character varying(8000) DEFAULT NULL::character varying,
    cropped_s3_path character varying(512) DEFAULT NULL::character varying,
    crop_selection character varying(256) DEFAULT NULL::character varying,
    last_failed_certified_gear_at timestamp without time zone,
    last_failed_certified_gear_reason character varying(256),
    first_downloaded_client_at timestamp without time zone,
    first_ran_client_at timestamp without time zone,
    first_certified_gear_at timestamp without time zone,
    first_music_session_at timestamp without time zone,
    first_real_music_session_at timestamp without time zone,
    first_good_music_session_at timestamp without time zone,
    first_invited_at timestamp without time zone,
    first_friended_at timestamp without time zone,
    first_social_promoted_at timestamp without time zone,
    show_whats_next boolean DEFAULT true,
    biography text,
    lat numeric(15,10),
    lng numeric(15,10),
    icecast_server_group_id character varying(64) DEFAULT 'default'::character varying NOT NULL,
    first_recording_at timestamp without time zone,
    large_photo_url character varying(2048),
    cropped_large_s3_path character varying(512),
    cropped_large_fpfile character varying(8000),
    addr bigint DEFAULT 0 NOT NULL,
    locidispid bigint DEFAULT 0 NOT NULL,
    notification_seen_at timestamp without time zone,
    affiliate_referral_id character varying(64),
    mods json,
    audio_latency double precision,
    last_jam_addr bigint,
    last_jam_locidispid bigint,
    last_jam_updated_reason character(1),
    last_jam_updated_at timestamp without time zone
);


SET search_path = pgmigrate, pg_catalog;

--
-- Name: id; Type: DEFAULT; Schema: pgmigrate; Owner: -
--

ALTER TABLE ONLY pg_migrate ALTER COLUMN id SET DEFAULT nextval('pg_migrate_id_seq'::regclass);


SET search_path = public, pg_catalog;

--
-- Name: id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY active_admin_comments ALTER COLUMN id SET DEFAULT nextval('active_admin_comments_id_seq'::regclass);


--
-- Name: id; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY feeds ALTER COLUMN id SET DEFAULT nextval('feeds_id_seq'::regclass);


--
-- Name: coid; Type: DEFAULT; Schema: public; Owner: -
--

ALTER TABLE ONLY jamcompany ALTER COLUMN coid SET DEFAULT nextval('jamcompany_coid_seq'::regclass);


SET search_path = pgmigrate, pg_catalog;

--
-- Name: pg_migrate_pkey; Type: CONSTRAINT; Schema: pgmigrate; Owner: -; Tablespace: 
--

ALTER TABLE ONLY pg_migrate
    ADD CONSTRAINT pg_migrate_pkey PRIMARY KEY (id);


--
-- Name: pg_migrations_pkey; Type: CONSTRAINT; Schema: pgmigrate; Owner: -; Tablespace: 
--

ALTER TABLE ONLY pg_migrations
    ADD CONSTRAINT pg_migrations_pkey PRIMARY KEY (name);


SET search_path = public, pg_catalog;

--
-- Name: admin_comments_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY active_admin_comments
    ADD CONSTRAINT admin_comments_pkey PRIMARY KEY (id);


--
-- Name: affiliate_partners_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY affiliate_partners
    ADD CONSTRAINT affiliate_partners_pkey PRIMARY KEY (id);


--
-- Name: artifact_updates_uniqkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY artifact_updates
    ADD CONSTRAINT artifact_updates_uniqkey UNIQUE (product, version);


--
-- Name: band_genre_uniqkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY bands_genres
    ADD CONSTRAINT band_genre_uniqkey UNIQUE (band_id, genre_id);


--
-- Name: band_invitations_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY band_invitations
    ADD CONSTRAINT band_invitations_pkey PRIMARY KEY (id);


--
-- Name: band_musician_uniqkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY bands_musicians
    ADD CONSTRAINT band_musician_uniqkey UNIQUE (band_id, user_id);


--
-- Name: bands_genres_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY bands_genres
    ADD CONSTRAINT bands_genres_pkey PRIMARY KEY (id);


--
-- Name: bands_musicians_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY bands_musicians
    ADD CONSTRAINT bands_musicians_pkey PRIMARY KEY (id);


--
-- Name: bands_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY bands
    ADD CONSTRAINT bands_pkey PRIMARY KEY (id);


--
-- Name: claimed_recordings_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY claimed_recordings
    ADD CONSTRAINT claimed_recordings_pkey PRIMARY KEY (id);


--
-- Name: connections_client_id_key; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY connections
    ADD CONSTRAINT connections_client_id_key UNIQUE (client_id);


--
-- Name: connections_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY connections
    ADD CONSTRAINT connections_pkey PRIMARY KEY (id);


--
-- Name: crash_dumps_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY crash_dumps
    ADD CONSTRAINT crash_dumps_pkey PRIMARY KEY (id);


--
-- Name: email_batch_set_uniqkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY email_batch_sets
    ADD CONSTRAINT email_batch_set_uniqkey UNIQUE (email_batch_id, started_at);


--
-- Name: email_batch_sets_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY email_batch_sets
    ADD CONSTRAINT email_batch_sets_pkey PRIMARY KEY (id);


--
-- Name: email_batches_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY email_batches
    ADD CONSTRAINT email_batches_pkey PRIMARY KEY (id);


--
-- Name: email_errors_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY email_errors
    ADD CONSTRAINT email_errors_pkey PRIMARY KEY (id);


--
-- Name: event_sessions_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY event_sessions
    ADD CONSTRAINT event_sessions_pkey PRIMARY KEY (id);


--
-- Name: events_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY events
    ADD CONSTRAINT events_pkey PRIMARY KEY (id);


--
-- Name: events_slug_key; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY events
    ADD CONSTRAINT events_slug_key UNIQUE (slug);


--
-- Name: facebook_signups_lookup_id_key; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY facebook_signups
    ADD CONSTRAINT facebook_signups_lookup_id_key UNIQUE (lookup_id);


--
-- Name: facebook_signups_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY facebook_signups
    ADD CONSTRAINT facebook_signups_pkey PRIMARY KEY (id);


--
-- Name: fan_invitations_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY fan_invitations
    ADD CONSTRAINT fan_invitations_pkey PRIMARY KEY (id);


--
-- Name: feeds_music_session_id_key; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY feeds
    ADD CONSTRAINT feeds_music_session_id_key UNIQUE (music_session_id);


--
-- Name: feeds_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY feeds
    ADD CONSTRAINT feeds_pkey PRIMARY KEY (id);


--
-- Name: feeds_recording_id_key; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY feeds
    ADD CONSTRAINT feeds_recording_id_key UNIQUE (recording_id);


--
-- Name: follows_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY follows
    ADD CONSTRAINT follows_pkey PRIMARY KEY (id);


--
-- Name: follows_user_uniqkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY follows
    ADD CONSTRAINT follows_user_uniqkey UNIQUE (user_id, followable_id);


--
-- Name: friend_requests_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY friend_requests
    ADD CONSTRAINT friend_requests_pkey PRIMARY KEY (id);


--
-- Name: friendships_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY friendships
    ADD CONSTRAINT friendships_pkey PRIMARY KEY (id);


--
-- Name: genres_music_sessions_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY genres_music_sessions
    ADD CONSTRAINT genres_music_sessions_pkey PRIMARY KEY (id);


--
-- Name: genres_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY genres
    ADD CONSTRAINT genres_pkey PRIMARY KEY (id);


--
-- Name: geoiplocations_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY geoiplocations
    ADD CONSTRAINT geoiplocations_pkey PRIMARY KEY (locid);


--
-- Name: icecast_admin_authentications_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY icecast_admin_authentications
    ADD CONSTRAINT icecast_admin_authentications_pkey PRIMARY KEY (id);


--
-- Name: icecast_directories_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY icecast_directories
    ADD CONSTRAINT icecast_directories_pkey PRIMARY KEY (id);


--
-- Name: icecast_limits_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY icecast_limits
    ADD CONSTRAINT icecast_limits_pkey PRIMARY KEY (id);


--
-- Name: icecast_listen_sockets_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY icecast_listen_sockets
    ADD CONSTRAINT icecast_listen_sockets_pkey PRIMARY KEY (id);


--
-- Name: icecast_loggings_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY icecast_loggings
    ADD CONSTRAINT icecast_loggings_pkey PRIMARY KEY (id);


--
-- Name: icecast_master_server_relays_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY icecast_master_server_relays
    ADD CONSTRAINT icecast_master_server_relays_pkey PRIMARY KEY (id);


--
-- Name: icecast_mount_templates_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY icecast_mount_templates
    ADD CONSTRAINT icecast_mount_templates_pkey PRIMARY KEY (id);


--
-- Name: icecast_mounts_name_key; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY icecast_mounts
    ADD CONSTRAINT icecast_mounts_name_key UNIQUE (name);


--
-- Name: icecast_mounts_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY icecast_mounts
    ADD CONSTRAINT icecast_mounts_pkey PRIMARY KEY (id);


--
-- Name: icecast_paths_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY icecast_paths
    ADD CONSTRAINT icecast_paths_pkey PRIMARY KEY (id);


--
-- Name: icecast_relays_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY icecast_relays
    ADD CONSTRAINT icecast_relays_pkey PRIMARY KEY (id);


--
-- Name: icecast_securities_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY icecast_securities
    ADD CONSTRAINT icecast_securities_pkey PRIMARY KEY (id);


--
-- Name: icecast_server_groups_name_key; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY icecast_server_groups
    ADD CONSTRAINT icecast_server_groups_name_key UNIQUE (name);


--
-- Name: icecast_server_groups_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY icecast_server_groups
    ADD CONSTRAINT icecast_server_groups_pkey PRIMARY KEY (id);


--
-- Name: icecast_server_mounts_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY icecast_server_mounts
    ADD CONSTRAINT icecast_server_mounts_pkey PRIMARY KEY (id);


--
-- Name: icecast_server_relays_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY icecast_server_relays
    ADD CONSTRAINT icecast_server_relays_pkey PRIMARY KEY (id);


--
-- Name: icecast_server_sockets_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY icecast_server_sockets
    ADD CONSTRAINT icecast_server_sockets_pkey PRIMARY KEY (id);


--
-- Name: icecast_servers_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY icecast_servers
    ADD CONSTRAINT icecast_servers_pkey PRIMARY KEY (id);


--
-- Name: icecast_servers_server_id_key; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY icecast_servers
    ADD CONSTRAINT icecast_servers_server_id_key UNIQUE (server_id);


--
-- Name: icecast_template_sockets_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY icecast_template_sockets
    ADD CONSTRAINT icecast_template_sockets_pkey PRIMARY KEY (id);


--
-- Name: icecast_templates_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY icecast_templates
    ADD CONSTRAINT icecast_templates_pkey PRIMARY KEY (id);


--
-- Name: icecast_user_authentications_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY icecast_user_authentications
    ADD CONSTRAINT icecast_user_authentications_pkey PRIMARY KEY (id);


--
-- Name: instruments_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY instruments
    ADD CONSTRAINT instruments_pkey PRIMARY KEY (id);


--
-- Name: invitations_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY invitations
    ADD CONSTRAINT invitations_pkey PRIMARY KEY (id);


--
-- Name: invitations_uniqkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY invitations
    ADD CONSTRAINT invitations_uniqkey UNIQUE (sender_id, receiver_id, music_session_id);


--
-- Name: invited_users_invitation_code_key; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY invited_users
    ADD CONSTRAINT invited_users_invitation_code_key UNIQUE (invitation_code);


--
-- Name: invited_users_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY invited_users
    ADD CONSTRAINT invited_users_pkey PRIMARY KEY (id);


--
-- Name: isp_score_batch_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY isp_score_batch
    ADD CONSTRAINT isp_score_batch_pkey PRIMARY KEY (id);


--
-- Name: jamcompany_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY jamcompany
    ADD CONSTRAINT jamcompany_pkey PRIMARY KEY (coid);


--
-- Name: join_requests_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY join_requests
    ADD CONSTRAINT join_requests_pkey PRIMARY KEY (id);


--
-- Name: likes_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY likes
    ADD CONSTRAINT likes_pkey PRIMARY KEY (id);


--
-- Name: likes_user_uniqkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY likes
    ADD CONSTRAINT likes_user_uniqkey UNIQUE (user_id, likable_id);


--
-- Name: mixes_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY mixes
    ADD CONSTRAINT mixes_pkey PRIMARY KEY (id);


--
-- Name: music_session_perf_data_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY music_session_perf_data
    ADD CONSTRAINT music_session_perf_data_pkey PRIMARY KEY (id);


--
-- Name: music_session_uniqkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY music_sessions
    ADD CONSTRAINT music_session_uniqkey UNIQUE (music_session_id);


--
-- Name: music_sessions_comments_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY music_sessions_comments
    ADD CONSTRAINT music_sessions_comments_pkey PRIMARY KEY (id);


--
-- Name: music_sessions_history_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY music_sessions
    ADD CONSTRAINT music_sessions_history_pkey PRIMARY KEY (id);


--
-- Name: music_sessions_likers_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY music_sessions_likers
    ADD CONSTRAINT music_sessions_likers_pkey PRIMARY KEY (id);


--
-- Name: music_sessions_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY active_music_sessions
    ADD CONSTRAINT music_sessions_pkey PRIMARY KEY (id);


--
-- Name: musician_instrument_uniqkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY musicians_instruments
    ADD CONSTRAINT musician_instrument_uniqkey UNIQUE (user_id, instrument_id);


--
-- Name: musician_recording_uniqkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY claimed_recordings
    ADD CONSTRAINT musician_recording_uniqkey UNIQUE (user_id, recording_id);


--
-- Name: musicians_instruments_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY musicians_instruments
    ADD CONSTRAINT musicians_instruments_pkey PRIMARY KEY (id);


--
-- Name: notifications_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY notifications
    ADD CONSTRAINT notifications_pkey PRIMARY KEY (id);


--
-- Name: playable_plays_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY playable_plays
    ADD CONSTRAINT playable_plays_pkey PRIMARY KEY (id);


--
-- Name: promotionals_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY promotionals
    ADD CONSTRAINT promotionals_pkey PRIMARY KEY (id);


--
-- Name: recording_liker_uniqkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY recordings_likers
    ADD CONSTRAINT recording_liker_uniqkey UNIQUE (recording_id, liker_id);


--
-- Name: recordings_comments_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY recordings_comments
    ADD CONSTRAINT recordings_comments_pkey PRIMARY KEY (id);


--
-- Name: recordings_downloads_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY recordings_downloads
    ADD CONSTRAINT recordings_downloads_pkey PRIMARY KEY (id);


--
-- Name: recordings_likers_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY recordings_likers
    ADD CONSTRAINT recordings_likers_pkey PRIMARY KEY (id);


--
-- Name: recordings_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY recordings
    ADD CONSTRAINT recordings_pkey PRIMARY KEY (id);


--
-- Name: recurring_sessions_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY recurring_sessions
    ADD CONSTRAINT recurring_sessions_pkey PRIMARY KEY (id);


--
-- Name: rsvp_requests_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY rsvp_requests
    ADD CONSTRAINT rsvp_requests_pkey PRIMARY KEY (id);


--
-- Name: rsvp_slots_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY rsvp_slots
    ADD CONSTRAINT rsvp_slots_pkey PRIMARY KEY (id);


--
-- Name: saved_tracks_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY recorded_tracks
    ADD CONSTRAINT saved_tracks_pkey PRIMARY KEY (id);


--
-- Name: server_mount_uniqkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY icecast_server_mounts
    ADD CONSTRAINT server_mount_uniqkey UNIQUE (icecast_mount_id, icecast_server_id);


--
-- Name: server_relay_uniqkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY icecast_server_relays
    ADD CONSTRAINT server_relay_uniqkey UNIQUE (icecast_relay_id, icecast_server_id);


--
-- Name: server_socket_uniqkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY icecast_server_sockets
    ADD CONSTRAINT server_socket_uniqkey UNIQUE (icecast_listen_socket_id, icecast_server_id);


--
-- Name: share_tokens_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY share_tokens
    ADD CONSTRAINT share_tokens_pkey PRIMARY KEY (id);


--
-- Name: template_socket_uniqkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY icecast_template_sockets
    ADD CONSTRAINT template_socket_uniqkey UNIQUE (icecast_listen_socket_id, icecast_template_id);


--
-- Name: token_uniqkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY share_tokens
    ADD CONSTRAINT token_uniqkey UNIQUE (token);


--
-- Name: tracks_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY tracks
    ADD CONSTRAINT tracks_pkey PRIMARY KEY (id);


--
-- Name: user_authorizations_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY user_authorizations
    ADD CONSTRAINT user_authorizations_pkey PRIMARY KEY (id);


--
-- Name: user_authorizations_uniqkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY user_authorizations
    ADD CONSTRAINT user_authorizations_uniqkey UNIQUE (provider, uid);


--
-- Name: user_friend_uniqkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY friendships
    ADD CONSTRAINT user_friend_uniqkey UNIQUE (user_id, friend_id);


--
-- Name: user_music_session_uniqkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY join_requests
    ADD CONSTRAINT user_music_session_uniqkey UNIQUE (user_id, music_session_id);


--
-- Name: users_email_key; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY users
    ADD CONSTRAINT users_email_key UNIQUE (email);


--
-- Name: users_pkey; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY users
    ADD CONSTRAINT users_pkey PRIMARY KEY (id);


--
-- Name: users_remember_token_key; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY users
    ADD CONSTRAINT users_remember_token_key UNIQUE (remember_token);


--
-- Name: users_signup_token_key; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY users
    ADD CONSTRAINT users_signup_token_key UNIQUE (signup_token);


--
-- Name: users_update_email_token_key; Type: CONSTRAINT; Schema: public; Owner: -; Tablespace: 
--

ALTER TABLE ONLY users
    ADD CONSTRAINT users_update_email_token_key UNIQUE (update_email_token);


SET search_path = pgmigrate, pg_catalog;

--
-- Name: pg_migrate_unique_index; Type: INDEX; Schema: pgmigrate; Owner: -; Tablespace: 
--

CREATE INDEX pg_migrate_unique_index ON pg_migrate USING btree (template_version, builder_version, migrator_version, database_version);


SET search_path = public, pg_catalog;

--
-- Name: affiliate_partners_code_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX affiliate_partners_code_idx ON affiliate_partners USING btree (partner_code);


--
-- Name: affiliate_partners_user_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX affiliate_partners_user_idx ON affiliate_partners USING btree (partner_user_id);


--
-- Name: bands_name_tsv_index; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX bands_name_tsv_index ON bands USING gin (name_tsv);


--
-- Name: claimed_recordings_description_tsv_index; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX claimed_recordings_description_tsv_index ON claimed_recordings USING gin (description_tsv);


--
-- Name: claimed_recordings_name_tsv_index; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX claimed_recordings_name_tsv_index ON claimed_recordings USING gin (name_tsv);


--
-- Name: connections_locidispid_ndx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX connections_locidispid_ndx ON connections USING btree (locidispid);


--
-- Name: crash_dumps_client_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX crash_dumps_client_id_idx ON crash_dumps USING btree (client_id);


--
-- Name: crash_dumps_timestamp_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX crash_dumps_timestamp_idx ON crash_dumps USING btree ("timestamp");


--
-- Name: crash_dumps_user_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX crash_dumps_user_id_idx ON crash_dumps USING btree (user_id);


--
-- Name: diagnostics_type_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX diagnostics_type_idx ON diagnostics USING btree (type);


--
-- Name: email_batch_set_fkidx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX email_batch_set_fkidx ON email_batch_sets USING btree (email_batch_id);


--
-- Name: email_batch_sets_progress_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX email_batch_sets_progress_idx ON email_batch_sets USING btree (user_id, sub_type);


--
-- Name: email_error_address_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX email_error_address_idx ON email_errors USING btree (email_address);


--
-- Name: email_error_user_fkidx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX email_error_user_fkidx ON email_errors USING btree (user_id);


--
-- Name: geoipblocks_geom_gix; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX geoipblocks_geom_gix ON geoipblocks USING gist (geom);


--
-- Name: geoipisp_company_ndx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX geoipisp_company_ndx ON geoipisp USING btree (company);


--
-- Name: geoiplocations_geog_gix; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX geoiplocations_geog_gix ON geoiplocations USING gist (geog);


--
-- Name: index_active_admin_comments_on_author_type_and_author_id; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX index_active_admin_comments_on_author_type_and_author_id ON active_admin_comments USING btree (author_type, author_id);


--
-- Name: index_active_admin_comments_on_namespace; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX index_active_admin_comments_on_namespace ON active_admin_comments USING btree (namespace);


--
-- Name: index_admin_comments_on_resource_type_and_resource_id; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX index_admin_comments_on_resource_type_and_resource_id ON active_admin_comments USING btree (resource_type, resource_id);


--
-- Name: index_completed_at; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX index_completed_at ON mixes USING btree (completed_at);


--
-- Name: index_started_at; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX index_started_at ON mixes USING btree (started_at);


--
-- Name: jamcompany_company_ndx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE UNIQUE INDEX jamcompany_company_ndx ON jamcompany USING btree (company);


--
-- Name: jamisp_coid_ndx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX jamisp_coid_ndx ON jamisp USING btree (coid);


--
-- Name: jamisp_geom_gix; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX jamisp_geom_gix ON jamisp USING gist (geom);


--
-- Name: max_mind_isp_ip_bottom_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX max_mind_isp_ip_bottom_idx ON max_mind_isp USING btree (ip_bottom);


--
-- Name: max_mind_isp_ip_top_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX max_mind_isp_ip_top_idx ON max_mind_isp USING btree (ip_top);


--
-- Name: promo_latest_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX promo_latest_idx ON promotionals USING btree (latest_id, latest_type);


--
-- Name: remember_token_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX remember_token_idx ON users USING btree (remember_token);


--
-- Name: scores_alocidispid_blocidispid_score_dt_ndx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX scores_alocidispid_blocidispid_score_dt_ndx ON scores USING btree (alocidispid, blocidispid, score_dt);


--
-- Name: scores_blocidispid_alocidispid_score_dt_ndx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX scores_blocidispid_alocidispid_score_dt_ndx ON scores USING btree (blocidispid, alocidispid, score_dt);


--
-- Name: user_authorizations_user_id_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX user_authorizations_user_id_idx ON user_authorizations USING btree (user_id);


--
-- Name: users_musician_email_idx; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX users_musician_email_idx ON users USING btree (subscribe_email, musician);


--
-- Name: users_name_tsv_index; Type: INDEX; Schema: public; Owner: -; Tablespace: 
--

CREATE INDEX users_name_tsv_index ON users USING gin (name_tsv);


--
-- Name: tsvectorupdate; Type: TRIGGER; Schema: public; Owner: -
--

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


--
-- Name: tsvectorupdate; Type: TRIGGER; Schema: public; Owner: -
--

CREATE TRIGGER tsvectorupdate BEFORE INSERT OR UPDATE ON bands FOR EACH ROW EXECUTE PROCEDURE tsvector_update_trigger('name_tsv', 'public.jamenglish', 'name');


--
-- Name: tsvectorupdate_description; Type: TRIGGER; Schema: public; Owner: -
--

CREATE TRIGGER tsvectorupdate_description BEFORE INSERT OR UPDATE ON claimed_recordings FOR EACH ROW EXECUTE PROCEDURE tsvector_update_trigger('description_tsv', 'public.jamenglish', 'description');


--
-- Name: tsvectorupdate_name; Type: TRIGGER; Schema: public; Owner: -
--

CREATE TRIGGER tsvectorupdate_name BEFORE INSERT OR UPDATE ON claimed_recordings FOR EACH ROW EXECUTE PROCEDURE tsvector_update_trigger('name_tsv', 'public.jamenglish', 'name');


SET search_path = pgmigrate, pg_catalog;

--
-- Name: pg_migrations_pg_migrate_id_fkey; Type: FK CONSTRAINT; Schema: pgmigrate; Owner: -
--

ALTER TABLE ONLY pg_migrations
    ADD CONSTRAINT pg_migrations_pg_migrate_id_fkey FOREIGN KEY (pg_migrate_id) REFERENCES pg_migrate(id);


SET search_path = public, pg_catalog;

--
-- Name: band_invitations_band_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY band_invitations
    ADD CONSTRAINT band_invitations_band_id_fkey FOREIGN KEY (band_id) REFERENCES bands(id) ON DELETE CASCADE;


--
-- Name: band_invitations_creator_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY band_invitations
    ADD CONSTRAINT band_invitations_creator_id_fkey FOREIGN KEY (creator_id) REFERENCES users(id) ON DELETE CASCADE;


--
-- Name: band_invitations_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY band_invitations
    ADD CONSTRAINT band_invitations_user_id_fkey FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE;


--
-- Name: bands_genres_band_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY bands_genres
    ADD CONSTRAINT bands_genres_band_id_fkey FOREIGN KEY (band_id) REFERENCES bands(id) ON DELETE CASCADE;


--
-- Name: bands_genres_genre_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY bands_genres
    ADD CONSTRAINT bands_genres_genre_id_fkey FOREIGN KEY (genre_id) REFERENCES genres(id) ON DELETE CASCADE;


--
-- Name: bands_musicians_band_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY bands_musicians
    ADD CONSTRAINT bands_musicians_band_id_fkey FOREIGN KEY (band_id) REFERENCES bands(id) ON DELETE CASCADE;


--
-- Name: bands_musicians_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY bands_musicians
    ADD CONSTRAINT bands_musicians_user_id_fkey FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE;


--
-- Name: chat_messages_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY chat_messages
    ADD CONSTRAINT chat_messages_user_id_fkey FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE;


--
-- Name: claimed_recordings_genre_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY claimed_recordings
    ADD CONSTRAINT claimed_recordings_genre_id_fkey FOREIGN KEY (genre_id) REFERENCES genres(id);


--
-- Name: connections_music_session_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY connections
    ADD CONSTRAINT connections_music_session_id_fkey FOREIGN KEY (music_session_id) REFERENCES active_music_sessions(id) ON DELETE SET NULL;


--
-- Name: connections_tracks_connection_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY tracks
    ADD CONSTRAINT connections_tracks_connection_id_fkey FOREIGN KEY (connection_id) REFERENCES connections(id) ON DELETE CASCADE;


--
-- Name: crash_dumps_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY crash_dumps
    ADD CONSTRAINT crash_dumps_user_id_fkey FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE SET NULL;


--
-- Name: diagnostics_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY diagnostics
    ADD CONSTRAINT diagnostics_user_id_fkey FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE;


--
-- Name: email_batch_sets_email_batch_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY email_batch_sets
    ADD CONSTRAINT email_batch_sets_email_batch_id_fkey FOREIGN KEY (email_batch_id) REFERENCES email_batches(id) ON DELETE CASCADE;


--
-- Name: email_errors_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY email_errors
    ADD CONSTRAINT email_errors_user_id_fkey FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE;


--
-- Name: event_sessions_band_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY event_sessions
    ADD CONSTRAINT event_sessions_band_id_fkey FOREIGN KEY (band_id) REFERENCES bands(id) ON DELETE SET NULL;


--
-- Name: event_sessions_event_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY event_sessions
    ADD CONSTRAINT event_sessions_event_id_fkey FOREIGN KEY (event_id) REFERENCES events(id) ON DELETE CASCADE;


--
-- Name: event_sessions_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY event_sessions
    ADD CONSTRAINT event_sessions_user_id_fkey FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE SET NULL;


--
-- Name: fan_invitations_music_session_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY fan_invitations
    ADD CONSTRAINT fan_invitations_music_session_id_fkey FOREIGN KEY (music_session_id) REFERENCES music_sessions(id) ON DELETE CASCADE;


--
-- Name: feeds_music_session_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY feeds
    ADD CONSTRAINT feeds_music_session_id_fkey FOREIGN KEY (music_session_id) REFERENCES music_sessions(id) ON DELETE CASCADE;


--
-- Name: feeds_recording_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY feeds
    ADD CONSTRAINT feeds_recording_id_fkey FOREIGN KEY (recording_id) REFERENCES recordings(id) ON DELETE CASCADE;


--
-- Name: follows_user_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY follows
    ADD CONSTRAINT follows_user_fkey FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE;


--
-- Name: friend_requests_friend_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY friend_requests
    ADD CONSTRAINT friend_requests_friend_id_fkey FOREIGN KEY (friend_id) REFERENCES users(id) ON DELETE CASCADE;


--
-- Name: friend_requests_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY friend_requests
    ADD CONSTRAINT friend_requests_user_id_fkey FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE;


--
-- Name: friendships_friend_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY friendships
    ADD CONSTRAINT friendships_friend_id_fkey FOREIGN KEY (friend_id) REFERENCES users(id) ON DELETE CASCADE;


--
-- Name: friendships_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY friendships
    ADD CONSTRAINT friendships_user_id_fkey FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE;


--
-- Name: genres_music_sessions_music_session_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY genres_music_sessions
    ADD CONSTRAINT genres_music_sessions_music_session_id_fkey FOREIGN KEY (music_session_id) REFERENCES active_music_sessions(id) ON DELETE CASCADE;


--
-- Name: icecast_mounts_icecast_mount_template_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY icecast_mounts
    ADD CONSTRAINT icecast_mounts_icecast_mount_template_id_fkey FOREIGN KEY (icecast_mount_template_id) REFERENCES icecast_mount_templates(id) ON DELETE SET NULL;


--
-- Name: icecast_mounts_icecast_server_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY icecast_mounts
    ADD CONSTRAINT icecast_mounts_icecast_server_id_fkey FOREIGN KEY (icecast_server_id) REFERENCES icecast_servers(id) ON DELETE SET NULL;


--
-- Name: icecast_mounts_music_session_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY icecast_mounts
    ADD CONSTRAINT icecast_mounts_music_session_id_fkey FOREIGN KEY (music_session_id) REFERENCES active_music_sessions(id) ON DELETE CASCADE;


--
-- Name: icecast_server_mounts_icecast_server_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY icecast_server_mounts
    ADD CONSTRAINT icecast_server_mounts_icecast_server_id_fkey FOREIGN KEY (icecast_server_id) REFERENCES icecast_servers(id) ON DELETE CASCADE;


--
-- Name: icecast_server_relays_icecast_relay_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY icecast_server_relays
    ADD CONSTRAINT icecast_server_relays_icecast_relay_id_fkey FOREIGN KEY (icecast_relay_id) REFERENCES icecast_relays(id) ON DELETE CASCADE;


--
-- Name: icecast_server_relays_icecast_server_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY icecast_server_relays
    ADD CONSTRAINT icecast_server_relays_icecast_server_id_fkey FOREIGN KEY (icecast_server_id) REFERENCES icecast_servers(id) ON DELETE CASCADE;


--
-- Name: icecast_server_sockets_icecast_listen_socket_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY icecast_server_sockets
    ADD CONSTRAINT icecast_server_sockets_icecast_listen_socket_id_fkey FOREIGN KEY (icecast_listen_socket_id) REFERENCES icecast_listen_sockets(id) ON DELETE CASCADE;


--
-- Name: icecast_server_sockets_icecast_server_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY icecast_server_sockets
    ADD CONSTRAINT icecast_server_sockets_icecast_server_id_fkey FOREIGN KEY (icecast_server_id) REFERENCES icecast_servers(id) ON DELETE CASCADE;


--
-- Name: icecast_servers_admin_auth_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY icecast_servers
    ADD CONSTRAINT icecast_servers_admin_auth_id_fkey FOREIGN KEY (admin_auth_id) REFERENCES icecast_admin_authentications(id) ON DELETE SET NULL;


--
-- Name: icecast_servers_directory_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY icecast_servers
    ADD CONSTRAINT icecast_servers_directory_id_fkey FOREIGN KEY (directory_id) REFERENCES icecast_directories(id) ON DELETE SET NULL;


--
-- Name: icecast_servers_icecast_server_group_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY icecast_servers
    ADD CONSTRAINT icecast_servers_icecast_server_group_id_fkey FOREIGN KEY (icecast_server_group_id) REFERENCES icecast_server_groups(id) ON DELETE SET NULL;


--
-- Name: icecast_servers_limit_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY icecast_servers
    ADD CONSTRAINT icecast_servers_limit_id_fkey FOREIGN KEY (limit_id) REFERENCES icecast_limits(id) ON DELETE SET NULL;


--
-- Name: icecast_servers_logging_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY icecast_servers
    ADD CONSTRAINT icecast_servers_logging_id_fkey FOREIGN KEY (logging_id) REFERENCES icecast_loggings(id) ON DELETE SET NULL;


--
-- Name: icecast_servers_master_relay_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY icecast_servers
    ADD CONSTRAINT icecast_servers_master_relay_id_fkey FOREIGN KEY (master_relay_id) REFERENCES icecast_master_server_relays(id) ON DELETE SET NULL;


--
-- Name: icecast_servers_mount_template_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY icecast_servers
    ADD CONSTRAINT icecast_servers_mount_template_id_fkey FOREIGN KEY (mount_template_id) REFERENCES icecast_mount_templates(id) ON DELETE SET NULL;


--
-- Name: icecast_servers_path_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY icecast_servers
    ADD CONSTRAINT icecast_servers_path_id_fkey FOREIGN KEY (path_id) REFERENCES icecast_paths(id) ON DELETE SET NULL;


--
-- Name: icecast_servers_security_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY icecast_servers
    ADD CONSTRAINT icecast_servers_security_id_fkey FOREIGN KEY (security_id) REFERENCES icecast_securities(id) ON DELETE SET NULL;


--
-- Name: icecast_servers_template_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY icecast_servers
    ADD CONSTRAINT icecast_servers_template_id_fkey FOREIGN KEY (template_id) REFERENCES icecast_templates(id) ON DELETE SET NULL;


--
-- Name: icecast_template_sockets_icecast_listen_socket_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY icecast_template_sockets
    ADD CONSTRAINT icecast_template_sockets_icecast_listen_socket_id_fkey FOREIGN KEY (icecast_listen_socket_id) REFERENCES icecast_listen_sockets(id) ON DELETE CASCADE;


--
-- Name: icecast_template_sockets_icecast_template_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY icecast_template_sockets
    ADD CONSTRAINT icecast_template_sockets_icecast_template_id_fkey FOREIGN KEY (icecast_template_id) REFERENCES icecast_templates(id) ON DELETE CASCADE;


--
-- Name: icecast_templates_admin_auth_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY icecast_templates
    ADD CONSTRAINT icecast_templates_admin_auth_id_fkey FOREIGN KEY (admin_auth_id) REFERENCES icecast_admin_authentications(id) ON DELETE SET NULL;


--
-- Name: icecast_templates_directory_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY icecast_templates
    ADD CONSTRAINT icecast_templates_directory_id_fkey FOREIGN KEY (directory_id) REFERENCES icecast_directories(id) ON DELETE SET NULL;


--
-- Name: icecast_templates_limit_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY icecast_templates
    ADD CONSTRAINT icecast_templates_limit_id_fkey FOREIGN KEY (limit_id) REFERENCES icecast_limits(id) ON DELETE SET NULL;


--
-- Name: icecast_templates_logging_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY icecast_templates
    ADD CONSTRAINT icecast_templates_logging_id_fkey FOREIGN KEY (logging_id) REFERENCES icecast_loggings(id) ON DELETE SET NULL;


--
-- Name: icecast_templates_master_relay_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY icecast_templates
    ADD CONSTRAINT icecast_templates_master_relay_id_fkey FOREIGN KEY (master_relay_id) REFERENCES icecast_master_server_relays(id) ON DELETE SET NULL;


--
-- Name: icecast_templates_path_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY icecast_templates
    ADD CONSTRAINT icecast_templates_path_id_fkey FOREIGN KEY (path_id) REFERENCES icecast_paths(id) ON DELETE SET NULL;


--
-- Name: icecast_templates_security_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY icecast_templates
    ADD CONSTRAINT icecast_templates_security_id_fkey FOREIGN KEY (security_id) REFERENCES icecast_securities(id) ON DELETE SET NULL;


--
-- Name: invitations_join_request_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY invitations
    ADD CONSTRAINT invitations_join_request_id_fkey FOREIGN KEY (join_request_id) REFERENCES join_requests(id) ON DELETE CASCADE;


--
-- Name: invitations_music_session_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY invitations
    ADD CONSTRAINT invitations_music_session_id_fkey FOREIGN KEY (music_session_id) REFERENCES music_sessions(id) ON DELETE CASCADE;


--
-- Name: invited_users_sender_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY invited_users
    ADD CONSTRAINT invited_users_sender_id_fkey FOREIGN KEY (sender_id) REFERENCES users(id) ON DELETE CASCADE;


--
-- Name: join_requests_music_session_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY join_requests
    ADD CONSTRAINT join_requests_music_session_id_fkey FOREIGN KEY (music_session_id) REFERENCES music_sessions(id) ON DELETE CASCADE;


--
-- Name: likes_user_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY likes
    ADD CONSTRAINT likes_user_fkey FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE;


--
-- Name: mixes_recording_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY mixes
    ADD CONSTRAINT mixes_recording_id_fkey FOREIGN KEY (recording_id) REFERENCES recordings(id) ON DELETE CASCADE;


--
-- Name: music_sessions_comments_creator_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY music_sessions_comments
    ADD CONSTRAINT music_sessions_comments_creator_id_fkey FOREIGN KEY (creator_id) REFERENCES users(id) ON DELETE CASCADE;


--
-- Name: music_sessions_comments_music_session_id2_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY music_sessions_comments
    ADD CONSTRAINT music_sessions_comments_music_session_id2_fkey FOREIGN KEY (music_session_id) REFERENCES music_sessions(id) ON DELETE CASCADE;


--
-- Name: music_sessions_history_band_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY music_sessions
    ADD CONSTRAINT music_sessions_history_band_id_fkey FOREIGN KEY (band_id) REFERENCES bands(id) ON DELETE CASCADE;


--
-- Name: music_sessions_history_genre_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY music_sessions
    ADD CONSTRAINT music_sessions_history_genre_id_fkey FOREIGN KEY (genre_id) REFERENCES genres(id);


--
-- Name: music_sessions_history_recurring_session_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY music_sessions
    ADD CONSTRAINT music_sessions_history_recurring_session_id_fkey FOREIGN KEY (recurring_session_id) REFERENCES recurring_sessions(id);


--
-- Name: music_sessions_history_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY music_sessions
    ADD CONSTRAINT music_sessions_history_user_id_fkey FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE;


--
-- Name: music_sessions_likers_liker_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY music_sessions_likers
    ADD CONSTRAINT music_sessions_likers_liker_id_fkey FOREIGN KEY (liker_id) REFERENCES users(id) ON DELETE CASCADE;


--
-- Name: music_sessions_likers_music_session_id2_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY music_sessions_likers
    ADD CONSTRAINT music_sessions_likers_music_session_id2_fkey FOREIGN KEY (music_session_id) REFERENCES music_sessions(id) ON DELETE CASCADE;


--
-- Name: music_sessions_user_history_music_session_id2_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY music_sessions_user_history
    ADD CONSTRAINT music_sessions_user_history_music_session_id2_fkey FOREIGN KEY (music_session_id) REFERENCES music_sessions(id) ON DELETE CASCADE;


--
-- Name: music_sessions_user_history_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY music_sessions_user_history
    ADD CONSTRAINT music_sessions_user_history_user_id_fkey FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE;


--
-- Name: musicians_instruments_instrument_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY musicians_instruments
    ADD CONSTRAINT musicians_instruments_instrument_id_fkey FOREIGN KEY (instrument_id) REFERENCES instruments(id) ON DELETE CASCADE;


--
-- Name: musicians_instruments_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY musicians_instruments
    ADD CONSTRAINT musicians_instruments_user_id_fkey FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE;


--
-- Name: musicians_recordings_recording_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY claimed_recordings
    ADD CONSTRAINT musicians_recordings_recording_id_fkey FOREIGN KEY (recording_id) REFERENCES recordings(id) ON DELETE CASCADE;


--
-- Name: musicians_recordings_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY claimed_recordings
    ADD CONSTRAINT musicians_recordings_user_id_fkey FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE;


--
-- Name: notifications_band_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY notifications
    ADD CONSTRAINT notifications_band_id_fkey FOREIGN KEY (band_id) REFERENCES bands(id) ON DELETE CASCADE;


--
-- Name: notifications_band_invitation_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY notifications
    ADD CONSTRAINT notifications_band_invitation_id_fkey FOREIGN KEY (band_invitation_id) REFERENCES band_invitations(id) ON DELETE CASCADE;


--
-- Name: notifications_friend_request_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY notifications
    ADD CONSTRAINT notifications_friend_request_id_fkey FOREIGN KEY (friend_request_id) REFERENCES friend_requests(id);


--
-- Name: notifications_recording_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY notifications
    ADD CONSTRAINT notifications_recording_id_fkey FOREIGN KEY (recording_id) REFERENCES recordings(id) ON DELETE CASCADE;


--
-- Name: notifications_source_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY notifications
    ADD CONSTRAINT notifications_source_user_id_fkey FOREIGN KEY (source_user_id) REFERENCES users(id) ON DELETE CASCADE;


--
-- Name: notifications_target_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY notifications
    ADD CONSTRAINT notifications_target_user_id_fkey FOREIGN KEY (target_user_id) REFERENCES users(id) ON DELETE CASCADE;


--
-- Name: playable_plays_claimed_recording_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY playable_plays
    ADD CONSTRAINT playable_plays_claimed_recording_id_fkey FOREIGN KEY (claimed_recording_id) REFERENCES claimed_recordings(id) ON DELETE CASCADE;


--
-- Name: playable_plays_player_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY playable_plays
    ADD CONSTRAINT playable_plays_player_id_fkey FOREIGN KEY (player_id) REFERENCES users(id) ON DELETE CASCADE;


--
-- Name: recorded_tracks_recording_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY recorded_tracks
    ADD CONSTRAINT recorded_tracks_recording_id_fkey FOREIGN KEY (recording_id) REFERENCES recordings(id) ON DELETE CASCADE;


--
-- Name: recordings_band_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY recordings
    ADD CONSTRAINT recordings_band_id_fkey FOREIGN KEY (band_id) REFERENCES bands(id);


--
-- Name: recordings_comments_creator_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY recordings_comments
    ADD CONSTRAINT recordings_comments_creator_id_fkey FOREIGN KEY (creator_id) REFERENCES users(id) ON DELETE CASCADE;


--
-- Name: recordings_comments_recording_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY recordings_comments
    ADD CONSTRAINT recordings_comments_recording_id_fkey FOREIGN KEY (recording_id) REFERENCES recordings(id) ON DELETE CASCADE;


--
-- Name: recordings_creator_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY recordings
    ADD CONSTRAINT recordings_creator_id_fkey FOREIGN KEY (owner_id) REFERENCES users(id) ON DELETE CASCADE;


--
-- Name: recordings_downloads_downloader_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY recordings_downloads
    ADD CONSTRAINT recordings_downloads_downloader_id_fkey FOREIGN KEY (downloader_id) REFERENCES users(id) ON DELETE CASCADE;


--
-- Name: recordings_downloads_recording_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY recordings_downloads
    ADD CONSTRAINT recordings_downloads_recording_id_fkey FOREIGN KEY (recording_id) REFERENCES recordings(id) ON DELETE CASCADE;


--
-- Name: recordings_likers_claimed_recording_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY recordings_likers
    ADD CONSTRAINT recordings_likers_claimed_recording_id_fkey FOREIGN KEY (claimed_recording_id) REFERENCES claimed_recordings(id);


--
-- Name: recordings_likers_liker_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY recordings_likers
    ADD CONSTRAINT recordings_likers_liker_id_fkey FOREIGN KEY (liker_id) REFERENCES users(id) ON DELETE CASCADE;


--
-- Name: recordings_likers_recording_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY recordings_likers
    ADD CONSTRAINT recordings_likers_recording_id_fkey FOREIGN KEY (recording_id) REFERENCES recordings(id) ON DELETE CASCADE;


--
-- Name: recurring_sessions_band_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY recurring_sessions
    ADD CONSTRAINT recurring_sessions_band_id_fkey FOREIGN KEY (band_id) REFERENCES bands(id) ON DELETE CASCADE;


--
-- Name: recurring_sessions_genre_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY recurring_sessions
    ADD CONSTRAINT recurring_sessions_genre_id_fkey FOREIGN KEY (genre_id) REFERENCES genres(id);


--
-- Name: recurring_sessions_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY recurring_sessions
    ADD CONSTRAINT recurring_sessions_user_id_fkey FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE;


--
-- Name: rsvp_requests_rsvp_slot_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY rsvp_requests
    ADD CONSTRAINT rsvp_requests_rsvp_slot_id_fkey FOREIGN KEY (rsvp_slot_id) REFERENCES rsvp_slots(id) ON DELETE CASCADE;


--
-- Name: rsvp_requests_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY rsvp_requests
    ADD CONSTRAINT rsvp_requests_user_id_fkey FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE;


--
-- Name: rsvp_slots_instrument_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY rsvp_slots
    ADD CONSTRAINT rsvp_slots_instrument_id_fkey FOREIGN KEY (instrument_id) REFERENCES instruments(id);


--
-- Name: rsvp_slots_music_session_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY rsvp_slots
    ADD CONSTRAINT rsvp_slots_music_session_id_fkey FOREIGN KEY (music_session_id) REFERENCES music_sessions(id) ON DELETE CASCADE;


--
-- Name: saved_tracks_instrument_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY recorded_tracks
    ADD CONSTRAINT saved_tracks_instrument_id_fkey FOREIGN KEY (instrument_id) REFERENCES instruments(id) ON DELETE CASCADE;


--
-- Name: saved_tracks_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY recorded_tracks
    ADD CONSTRAINT saved_tracks_user_id_fkey FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE;


--
-- Name: user_authorizations_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY user_authorizations
    ADD CONSTRAINT user_authorizations_user_id_fkey FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE;


--
-- Name: users_affiliate_referral_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY users
    ADD CONSTRAINT users_affiliate_referral_id_fkey FOREIGN KEY (affiliate_referral_id) REFERENCES affiliate_partners(id);


--
-- Name: users_icecast_server_group_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: -
--

ALTER TABLE ONLY users
    ADD CONSTRAINT users_icecast_server_group_id_fkey FOREIGN KEY (icecast_server_group_id) REFERENCES icecast_server_groups(id);


--
-- PostgreSQL database dump complete
--

SET search_path TO "$user", public, topology;

