 # --- !Downs
 
 alter table "application_user_settings" drop constraint "application_user_settings_user_fk";
+alter table "courses" drop constraint "courses_organization_fk";
 alter table "courses" drop constraint "courses_owner_fk";
-alter table "courses" drop constraint "courses_organization_fk";
 alter table "courses_2_derivative_quizzes" drop constraint "courses_2_derivative_quizzes_quiz_fk";
 alter table "courses_2_derivative_quizzes" drop constraint "courses_2_derivative_quizzes_course_fk";
 alter table "derivative_answer_times" drop constraint "derivative_answer_times_user_fk";

# --- Created by Slick DDL
# To stop Slick DDL generation, remove this comment and start using Evolutions

# --- !Ups

create table "application_user_settings" ("user_id" BIGINT NOT NULL PRIMARY KEY,"consented" BOOLEAN NOT NULL,"name" VARCHAR NOT NULL,"allow_auto_match" BOOLEAN NOT NULL,"seen_help" BOOLEAN NOT NULL,"email_game_updates" BOOLEAN NOT NULL);
create unique index "application_user_settings_name_index" on "application_user_settings" ("name");
create table "courses" ("id" BIGINT GENERATED BY DEFAULT AS IDENTITY(START WITH 1) NOT NULL PRIMARY KEY,"name" VARCHAR NOT NULL,"organization" BIGINT NOT NULL,"owner" BIGINT NOT NULL,"edit_code" VARCHAR NOT NULL,"view_code" VARCHAR NOT NULL,"creation_Date" TIMESTAMP NOT NULL,"update_date" TIMESTAMP NOT NULL);
create table "courses_2_derivative_quizzes" ("course_id" BIGINT NOT NULL,"quiz_id" BIGINT NOT NULL);
alter table "courses_2_derivative_quizzes" add constraint "courses_2_derivative_quizzes_pk" primary key("course_id","quiz_id");
create table "derivative_answer_times" ("user_id" BIGINT NOT NULL,"question_id" BIGINT NOT NULL,"time" TIMESTAMP NOT NULL);
alter table "derivative_answer_times" add constraint "derivative_answer_times_pk" primary key("user_id","question_id");
create table "derivative_answers" ("id" BIGINT GENERATED BY DEFAULT AS IDENTITY(START WITH 1) NOT NULL PRIMARY KEY,"owner" BIGINT NOT NULL,"question_id" BIGINT NOT NULL,"mathml" VARCHAR NOT NULL,"rawstr" VARCHAR NOT NULL,"correct" BOOLEAN NOT NULL,"creation_date" TIMESTAMP NOT NULL);
create table "derivative_questions" ("id" BIGINT GENERATED BY DEFAULT AS IDENTITY(START WITH 1) NOT NULL PRIMARY KEY,"owner" BIGINT NOT NULL,"mathml" VARCHAR NOT NULL,"rawstr" VARCHAR NOT NULL,"creation_date" TIMESTAMP NOT NULL);
create table "derivative_quizzes" ("id" BIGINT GENERATED BY DEFAULT AS IDENTITY(START WITH 1) NOT NULL PRIMARY KEY,"owner" BIGINT NOT NULL,"name" VARCHAR NOT NULL,"creation_date" TIMESTAMP NOT NULL,"update_date" TIMESTAMP NOT NULL);
create table "derivative_quizzes_2_questions" ("quiz_id" BIGINT NOT NULL,"question_id" BIGINT NOT NULL);
alter table "derivative_quizzes_2_questions" add constraint "derivative_quizzes_2_questions_pk" primary key("question_id","quiz_id");
create table "equations" ("id" BIGINT GENERATED BY DEFAULT AS IDENTITY(START WITH 1) NOT NULL PRIMARY KEY,"equation" VARCHAR NOT NULL);
create table "games" ("id" BIGINT GENERATED BY DEFAULT AS IDENTITY(START WITH 1) NOT NULL PRIMARY KEY,"request_date" TIMESTAMP NOT NULL,"requestor" BIGINT NOT NULL,"requestee" BIGINT NOT NULL,"response" SMALLINT NOT NULL,"course" BIGINT,"requestor_quiz" BIGINT,"requestee_quiz" BIGINT,"requestee_finished" BOOLEAN NOT NULL,"requestor_finished" BOOLEAN NOT NULL,"finished_date" TIMESTAMP);
create table "organizations" ("id" BIGINT GENERATED BY DEFAULT AS IDENTITY(START WITH 1) NOT NULL PRIMARY KEY,"name" VARCHAR NOT NULL,"creation_Date" TIMESTAMP NOT NULL,"update_date" TIMESTAMP NOT NULL);
create table "secure_social_tokens" ("uuid" VARCHAR NOT NULL PRIMARY KEY,"email" VARCHAR NOT NULL,"creation_time" TIMESTAMP NOT NULL,"expiration_time" TIMESTAMP NOT NULL,"is_sign_up" BOOLEAN NOT NULL);
create table "secure_social_users" ("id" BIGINT GENERATED BY DEFAULT AS IDENTITY(START WITH 1) NOT NULL PRIMARY KEY,"user_id" VARCHAR NOT NULL,"provider_id" VARCHAR NOT NULL,"first_name" VARCHAR NOT NULL,"last_name" VARCHAR NOT NULL,"full_name" VARCHAR NOT NULL,"email" VARCHAR,"avatar_url" VARCHAR,"auth_Method" VARCHAR NOT NULL,"token" VARCHAR,"secret" VARCHAR,"access_token" VARCHAR,"token_type" VARCHAR,"expires_in" INTEGER,"refresh_token" VARCHAR,"hasher" VARCHAR,"password" VARCHAR,"salt" VARCHAR,"creation_date" TIMESTAMP NOT NULL,"update_date" TIMESTAMP NOT NULL);
create table "users_2_courses" ("user_id" BIGINT NOT NULL,"course_id" BIGINT NOT NULL,"access" SMALLINT NOT NULL);
alter table "users_2_courses" add constraint "users_2_courses_pk" primary key("user_id","course_id");
create table "users_2_derivative_answers" ("user_id" BIGINT NOT NULL,"answer_id" BIGINT NOT NULL,"access" SMALLINT NOT NULL);

create table "users_2_derivative_quizzes" ("user_id" BIGINT NOT NULL,"quiz_id" BIGINT NOT NULL,"access" SMALLINT NOT NULL);
alter table "users_2_derivative_quizzes" add constraint "users_2_derivative_quizzes_pk" primary key("user_id","quiz_id");
alter table "application_user_settings" add constraint "application_user_settings_user_fk" foreign key("user_id") references "secure_social_users"("id") on update NO ACTION on delete CASCADE;
alter table "courses" add constraint "courses_organization_fk" foreign key("organization") references "organizations"("id") on update NO ACTION on delete CASCADE;
alter table "courses" add constraint "courses_owner_fk" foreign key("owner") references "secure_social_users"("id") on update NO ACTION on delete CASCADE;
alter table "courses_2_derivative_quizzes" add constraint "courses_2_derivative_quizzes_quiz_fk" foreign key("quiz_id") references "derivative_quizzes"("id") on update NO ACTION on delete CASCADE;
alter table "courses_2_derivative_quizzes" add constraint "courses_2_derivative_quizzes_course_fk" foreign key("course_id") references "courses"("id") on update NO ACTION on delete CASCADE;
alter table "derivative_answer_times" add constraint "derivative_answer_times_user_fk" foreign key("user_id") references "secure_social_users"("id") on update NO ACTION on delete CASCADE;
