diff --git a/src/db/migrations/0000_cold_old_lace.sql b/src/db/migrations/0000_cold_old_lace.sql deleted file mode 100644 index 05cab79b11f6b92db4de66b38ef0d486e81cbd6f..0000000000000000000000000000000000000000 --- a/src/db/migrations/0000_cold_old_lace.sql +++ /dev/null @@ -1,431 +0,0 @@ -CREATE TABLE IF NOT EXISTS "achievement" ( - "id" serial PRIMARY KEY NOT NULL, - "name" varchar(255) NOT NULL, - "description" text, - "reward_experience" numeric, - "reward_points" numeric, - "state" integer DEFAULT 0 NOT NULL, - "repeatable" integer NOT NULL, - "is_resettable" boolean NOT NULL, - "created_at" timestamp DEFAULT now() NOT NULL, - "updated_at" timestamp DEFAULT now() NOT NULL, - CONSTRAINT "achievement_id_unique" UNIQUE("id") -); ---> statement-breakpoint -CREATE TABLE IF NOT EXISTS "collection_likes" ( - "user_id" integer NOT NULL, - "collection" integer NOT NULL -); ---> statement-breakpoint -CREATE TABLE IF NOT EXISTS "collection_resources" ( - "collection_id" integer NOT NULL, - "resource_id" integer NOT NULL -); ---> statement-breakpoint -CREATE TABLE IF NOT EXISTS "collection_stats" ( - "id" serial PRIMARY KEY NOT NULL, - "collection_id" bigint NOT NULL, - "views" bigint DEFAULT 0, - "downloads" bigint DEFAULT 0, - "likes" bigint DEFAULT 0, - "shares" bigint DEFAULT 0, - "score" bigint DEFAULT 0, - "follows" bigint DEFAULT 0, - CONSTRAINT "collection_stats_id_unique" UNIQUE("id") -); ---> statement-breakpoint -CREATE TABLE IF NOT EXISTS "collection" ( - "id" serial PRIMARY KEY NOT NULL, - "name" varchar(255), - "description" text, - "is_private" boolean, - "is_active" boolean DEFAULT true, - "created_at" timestamp DEFAULT now() NOT NULL, - "updated_at" timestamp, - "deleted_at" timestamp, - "thumbnail" varchar(255), - CONSTRAINT "collection_id_unique" UNIQUE("id") -); ---> statement-breakpoint -CREATE TABLE IF NOT EXISTS "complaint" ( - "id" serial PRIMARY KEY NOT NULL, - "state" integer DEFAULT 0 NOT NULL, - "description" text NOT NULL, - "evaluatedUser" integer NOT NULL, - "resource_id" integer, - "collection_id" integer, - "user_id" integer, - "evaluated_at" timestamp, - "created_at" timestamp DEFAULT now() NOT NULL, - "q1" boolean, - "q2" boolean, - "q3" boolean, - "q4" boolean -); ---> statement-breakpoint -CREATE TABLE IF NOT EXISTS "educational_stages" ( - "id" serial PRIMARY KEY NOT NULL, - "name" varchar NOT NULL, - CONSTRAINT "educational_stages_id_unique" UNIQUE("id"), - CONSTRAINT "educational_stages_name_unique" UNIQUE("name") -); ---> statement-breakpoint -CREATE TABLE IF NOT EXISTS "follows" ( - "id" serial PRIMARY KEY NOT NULL, - "user_id" integer NOT NULL, - "follower_id" integer NOT NULL, - CONSTRAINT "follows_id_unique" UNIQUE("id") -); ---> statement-breakpoint -CREATE TABLE IF NOT EXISTS "institution" ( - "id" serial PRIMARY KEY NOT NULL, - "name" varchar(255) NOT NULL, - "uf" varchar(2), - "city" varchar(255), - "cep" varchar(10), - "created_at" timestamp DEFAULT now() NOT NULL, - "updated_at" timestamp DEFAULT now() NOT NULL, - CONSTRAINT "institution_id_unique" UNIQUE("id") -); ---> statement-breakpoint -CREATE TABLE IF NOT EXISTS "language" ( - "id" serial PRIMARY KEY NOT NULL, - "name" varchar NOT NULL, - "code" varchar NOT NULL, - CONSTRAINT "language_id_unique" UNIQUE("id"), - CONSTRAINT "language_name_unique" UNIQUE("name"), - CONSTRAINT "language_code_unique" UNIQUE("code") -); ---> statement-breakpoint -CREATE TABLE IF NOT EXISTS "licenses" ( - "id" serial PRIMARY KEY NOT NULL, - "name" varchar NOT NULL, - "description" varchar NOT NULL, - "url" varchar NOT NULL, - CONSTRAINT "licenses_id_unique" UNIQUE("id"), - CONSTRAINT "licenses_name_unique" UNIQUE("name") -); ---> statement-breakpoint -CREATE TABLE IF NOT EXISTS "object_types" ( - "id" serial PRIMARY KEY NOT NULL, - "name" varchar(255) NOT NULL, - CONSTRAINT "object_types_id_unique" UNIQUE("id") -); ---> statement-breakpoint -CREATE TABLE IF NOT EXISTS "reset_ticket" ( - "id" serial PRIMARY KEY NOT NULL, - "user_id" integer NOT NULL, - "token_hash" varchar(255) NOT NULL, - "expiration_date" timestamp NOT NULL, - "token_used" boolean DEFAULT false NOT NULL, - "valid_token" boolean DEFAULT true NOT NULL, - "created_at" timestamp DEFAULT now() NOT NULL, - "updated_at" timestamp DEFAULT now() NOT NULL, - CONSTRAINT "reset_ticket_id_unique" UNIQUE("id") -); ---> statement-breakpoint -CREATE TABLE IF NOT EXISTS "resource_educational_stages" ( - "resource_id" integer NOT NULL, - "educational_stage_id" integer NOT NULL -); ---> statement-breakpoint -CREATE TABLE IF NOT EXISTS "resource_languages" ( - "resource_id" integer NOT NULL, - "language_id" integer NOT NULL -); ---> statement-breakpoint -CREATE TABLE IF NOT EXISTS "resource_likes" ( - "user_id" integer NOT NULL, - "resource_id" integer NOT NULL -); ---> statement-breakpoint -CREATE TABLE IF NOT EXISTS "resource_subjects" ( - "resource_id" integer NOT NULL, - "subject_id" integer NOT NULL -); ---> statement-breakpoint -CREATE TABLE IF NOT EXISTS "resource" ( - "id" serial PRIMARY KEY NOT NULL, - "name" varchar(256) NOT NULL, - "author" varchar(256) NOT NULL, - "description" varchar(256), - "bucket_key" varchar(256), - "link" varchar(256), - "thumbnail" varchar(256) NOT NULL, - "active" boolean DEFAULT false NOT NULL, - "published_at" timestamp, - "submited_at" timestamp, - "created_at" timestamp DEFAULT now() NOT NULL, - "updated_at" timestamp, - "deleted_at" timestamp, - CONSTRAINT "resource_id_unique" UNIQUE("id"), - CONSTRAINT "resource_bucket_key_unique" UNIQUE("bucket_key") -); ---> statement-breakpoint -CREATE TABLE IF NOT EXISTS "role" ( - "id" serial PRIMARY KEY NOT NULL, - "name" varchar(255) NOT NULL, - "description" text, - "created_at" timestamp DEFAULT now() NOT NULL, - "updated_at" timestamp DEFAULT now() NOT NULL, - CONSTRAINT "role_id_unique" UNIQUE("id"), - CONSTRAINT "role_name_unique" UNIQUE("name") -); ---> statement-breakpoint -CREATE TABLE IF NOT EXISTS "stats_resources" ( - "id" serial PRIMARY KEY NOT NULL, - "resource_id" bigint NOT NULL, - "views" bigint DEFAULT 0 NOT NULL, - "downloads" bigint DEFAULT 0 NOT NULL, - "shares" bigint DEFAULT 0 NOT NULL, - "score" bigint DEFAULT 0 NOT NULL, - CONSTRAINT "stats_resources_id_unique" UNIQUE("id") -); ---> statement-breakpoint -CREATE TABLE IF NOT EXISTS "subjects" ( - "id" serial PRIMARY KEY NOT NULL, - "name" varchar NOT NULL, - CONSTRAINT "subjects_id_unique" UNIQUE("id"), - CONSTRAINT "subjects_name_unique" UNIQUE("name") -); ---> statement-breakpoint -CREATE TABLE IF NOT EXISTS "submission" ( - "id" serial PRIMARY KEY NOT NULL, - "is_accepted" boolean DEFAULT false NOT NULL, - "justification" text, - "resource_id" integer NOT NULL, - "submitter_id" integer NOT NULL, - "curator_id" integer NOT NULL, - "created_at" timestamp DEFAULT now() NOT NULL, - "updated_at" timestamp, - "answered_at" timestamp, - "q1" boolean, - "q2" boolean, - "q3" boolean, - "q4" boolean -); ---> statement-breakpoint -CREATE TABLE IF NOT EXISTS "user_achievements" ( - "user_id" integer NOT NULL, - "achievement_id" integer NOT NULL -); ---> statement-breakpoint -CREATE TABLE IF NOT EXISTS "user_institution" ( - "id" serial PRIMARY KEY NOT NULL, - "user_id" integer NOT NULL, - "institution_id" integer NOT NULL, - CONSTRAINT "user_institution_id_unique" UNIQUE("id") -); ---> statement-breakpoint -CREATE TABLE IF NOT EXISTS "user_role" ( - "id" serial PRIMARY KEY NOT NULL, - "user_id" integer NOT NULL, - "role_id" integer NOT NULL, - CONSTRAINT "user_role_id_unique" UNIQUE("id") -); ---> statement-breakpoint -CREATE TABLE IF NOT EXISTS "user_stats" ( - "id" serial PRIMARY KEY NOT NULL, - "user_id" integer NOT NULL, - "score" integer DEFAULT 0 NOT NULL, - "likes" integer DEFAULT 0 NOT NULL, - "likes_received" integer DEFAULT 0 NOT NULL, - "follows" integer DEFAULT 0 NOT NULL, - "followers" integer DEFAULT 0 NOT NULL, - "collections" integer DEFAULT 0 NOT NULL, - "submitted_resources" integer DEFAULT 0 NOT NULL, - "approved_resources" integer DEFAULT 0 NOT NULL, - "reviewed_resources" integer DEFAULT 0 NOT NULL, - "comments" integer DEFAULT 0 NOT NULL, - CONSTRAINT "user_stats_id_unique" UNIQUE("id") -); ---> statement-breakpoint -CREATE TABLE IF NOT EXISTS "user" ( - "id" serial PRIMARY KEY NOT NULL, - "name" varchar(255) NOT NULL, - "username" varchar(255) NOT NULL, - "password" varchar(255) NOT NULL, - "email" varchar(255) NOT NULL, - "description" text DEFAULT 'sem descrição', - "institution" text DEFAULT 'sem instituição', - "birthday" timestamp NOT NULL, - "cpf" varchar(255) NOT NULL, - "created_at" timestamp DEFAULT now() NOT NULL, - "updated_at" timestamp DEFAULT now() NOT NULL, - "confirmed_at" timestamp, - "confirmation_sent_at" timestamp, - "deleted_at" timestamp, - "reactivated_at" timestamp, - "active" boolean DEFAULT true, - CONSTRAINT "user_id_unique" UNIQUE("id"), - CONSTRAINT "user_username_unique" UNIQUE("username"), - CONSTRAINT "user_email_unique" UNIQUE("email") -); ---> statement-breakpoint -DO $$ BEGIN - ALTER TABLE "collection_likes" ADD CONSTRAINT "collection_likes_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action; -EXCEPTION - WHEN duplicate_object THEN null; -END $$; ---> statement-breakpoint -DO $$ BEGIN - ALTER TABLE "collection_likes" ADD CONSTRAINT "collection_likes_collection_collection_id_fk" FOREIGN KEY ("collection") REFERENCES "public"."collection"("id") ON DELETE cascade ON UPDATE no action; -EXCEPTION - WHEN duplicate_object THEN null; -END $$; ---> statement-breakpoint -DO $$ BEGIN - ALTER TABLE "collection_resources" ADD CONSTRAINT "collection_resources_collection_id_collection_id_fk" FOREIGN KEY ("collection_id") REFERENCES "public"."collection"("id") ON DELETE cascade ON UPDATE no action; -EXCEPTION - WHEN duplicate_object THEN null; -END $$; ---> statement-breakpoint -DO $$ BEGIN - ALTER TABLE "collection_resources" ADD CONSTRAINT "collection_resources_resource_id_resource_id_fk" FOREIGN KEY ("resource_id") REFERENCES "public"."resource"("id") ON DELETE cascade ON UPDATE no action; -EXCEPTION - WHEN duplicate_object THEN null; -END $$; ---> statement-breakpoint -DO $$ BEGIN - ALTER TABLE "collection_stats" ADD CONSTRAINT "collection_stats_collection_id_collection_id_fk" FOREIGN KEY ("collection_id") REFERENCES "public"."collection"("id") ON DELETE cascade ON UPDATE no action; -EXCEPTION - WHEN duplicate_object THEN null; -END $$; ---> statement-breakpoint -DO $$ BEGIN - ALTER TABLE "complaint" ADD CONSTRAINT "complaint_evaluatedUser_user_id_fk" FOREIGN KEY ("evaluatedUser") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action; -EXCEPTION - WHEN duplicate_object THEN null; -END $$; ---> statement-breakpoint -DO $$ BEGIN - ALTER TABLE "follows" ADD CONSTRAINT "follows_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action; -EXCEPTION - WHEN duplicate_object THEN null; -END $$; ---> statement-breakpoint -DO $$ BEGIN - ALTER TABLE "follows" ADD CONSTRAINT "follows_follower_id_user_id_fk" FOREIGN KEY ("follower_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action; -EXCEPTION - WHEN duplicate_object THEN null; -END $$; ---> statement-breakpoint -DO $$ BEGIN - ALTER TABLE "reset_ticket" ADD CONSTRAINT "reset_ticket_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action; -EXCEPTION - WHEN duplicate_object THEN null; -END $$; ---> statement-breakpoint -DO $$ BEGIN - ALTER TABLE "resource_educational_stages" ADD CONSTRAINT "resource_educational_stages_resource_id_resource_id_fk" FOREIGN KEY ("resource_id") REFERENCES "public"."resource"("id") ON DELETE cascade ON UPDATE no action; -EXCEPTION - WHEN duplicate_object THEN null; -END $$; ---> statement-breakpoint -DO $$ BEGIN - ALTER TABLE "resource_educational_stages" ADD CONSTRAINT "resource_educational_stages_educational_stage_id_educational_stages_id_fk" FOREIGN KEY ("educational_stage_id") REFERENCES "public"."educational_stages"("id") ON DELETE cascade ON UPDATE no action; -EXCEPTION - WHEN duplicate_object THEN null; -END $$; ---> statement-breakpoint -DO $$ BEGIN - ALTER TABLE "resource_languages" ADD CONSTRAINT "resource_languages_resource_id_resource_id_fk" FOREIGN KEY ("resource_id") REFERENCES "public"."resource"("id") ON DELETE cascade ON UPDATE no action; -EXCEPTION - WHEN duplicate_object THEN null; -END $$; ---> statement-breakpoint -DO $$ BEGIN - ALTER TABLE "resource_languages" ADD CONSTRAINT "resource_languages_language_id_language_id_fk" FOREIGN KEY ("language_id") REFERENCES "public"."language"("id") ON DELETE cascade ON UPDATE no action; -EXCEPTION - WHEN duplicate_object THEN null; -END $$; ---> statement-breakpoint -DO $$ BEGIN - ALTER TABLE "resource_likes" ADD CONSTRAINT "resource_likes_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action; -EXCEPTION - WHEN duplicate_object THEN null; -END $$; ---> statement-breakpoint -DO $$ BEGIN - ALTER TABLE "resource_likes" ADD CONSTRAINT "resource_likes_resource_id_resource_id_fk" FOREIGN KEY ("resource_id") REFERENCES "public"."resource"("id") ON DELETE cascade ON UPDATE no action; -EXCEPTION - WHEN duplicate_object THEN null; -END $$; ---> statement-breakpoint -DO $$ BEGIN - ALTER TABLE "resource_subjects" ADD CONSTRAINT "resource_subjects_resource_id_resource_id_fk" FOREIGN KEY ("resource_id") REFERENCES "public"."resource"("id") ON DELETE cascade ON UPDATE no action; -EXCEPTION - WHEN duplicate_object THEN null; -END $$; ---> statement-breakpoint -DO $$ BEGIN - ALTER TABLE "resource_subjects" ADD CONSTRAINT "resource_subjects_subject_id_subjects_id_fk" FOREIGN KEY ("subject_id") REFERENCES "public"."subjects"("id") ON DELETE cascade ON UPDATE no action; -EXCEPTION - WHEN duplicate_object THEN null; -END $$; ---> statement-breakpoint -DO $$ BEGIN - ALTER TABLE "stats_resources" ADD CONSTRAINT "stats_resources_resource_id_resource_id_fk" FOREIGN KEY ("resource_id") REFERENCES "public"."resource"("id") ON DELETE cascade ON UPDATE no action; -EXCEPTION - WHEN duplicate_object THEN null; -END $$; ---> statement-breakpoint -DO $$ BEGIN - ALTER TABLE "submission" ADD CONSTRAINT "submission_resource_id_resource_id_fk" FOREIGN KEY ("resource_id") REFERENCES "public"."resource"("id") ON DELETE cascade ON UPDATE no action; -EXCEPTION - WHEN duplicate_object THEN null; -END $$; ---> statement-breakpoint -DO $$ BEGIN - ALTER TABLE "submission" ADD CONSTRAINT "submission_submitter_id_user_id_fk" FOREIGN KEY ("submitter_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action; -EXCEPTION - WHEN duplicate_object THEN null; -END $$; ---> statement-breakpoint -DO $$ BEGIN - ALTER TABLE "submission" ADD CONSTRAINT "submission_curator_id_user_id_fk" FOREIGN KEY ("curator_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action; -EXCEPTION - WHEN duplicate_object THEN null; -END $$; ---> statement-breakpoint -DO $$ BEGIN - ALTER TABLE "user_achievements" ADD CONSTRAINT "user_achievements_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action; -EXCEPTION - WHEN duplicate_object THEN null; -END $$; ---> statement-breakpoint -DO $$ BEGIN - ALTER TABLE "user_achievements" ADD CONSTRAINT "user_achievements_achievement_id_user_id_fk" FOREIGN KEY ("achievement_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action; -EXCEPTION - WHEN duplicate_object THEN null; -END $$; ---> statement-breakpoint -DO $$ BEGIN - ALTER TABLE "user_institution" ADD CONSTRAINT "user_institution_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action; -EXCEPTION - WHEN duplicate_object THEN null; -END $$; ---> statement-breakpoint -DO $$ BEGIN - ALTER TABLE "user_institution" ADD CONSTRAINT "user_institution_institution_id_institution_id_fk" FOREIGN KEY ("institution_id") REFERENCES "public"."institution"("id") ON DELETE cascade ON UPDATE no action; -EXCEPTION - WHEN duplicate_object THEN null; -END $$; ---> statement-breakpoint -DO $$ BEGIN - ALTER TABLE "user_role" ADD CONSTRAINT "user_role_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action; -EXCEPTION - WHEN duplicate_object THEN null; -END $$; ---> statement-breakpoint -DO $$ BEGIN - ALTER TABLE "user_role" ADD CONSTRAINT "user_role_role_id_role_id_fk" FOREIGN KEY ("role_id") REFERENCES "public"."role"("id") ON DELETE cascade ON UPDATE no action; -EXCEPTION - WHEN duplicate_object THEN null; -END $$; ---> statement-breakpoint -DO $$ BEGIN - ALTER TABLE "user_stats" ADD CONSTRAINT "user_stats_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action; -EXCEPTION - WHEN duplicate_object THEN null; -END $$; diff --git a/src/db/migrations/0000_cooing_doorman.sql b/src/db/migrations/0000_cooing_doorman.sql deleted file mode 100644 index 6095e064c65b7d1583bda0b5863206abced62244..0000000000000000000000000000000000000000 --- a/src/db/migrations/0000_cooing_doorman.sql +++ /dev/null @@ -1,434 +0,0 @@ -CREATE TABLE IF NOT EXISTS "achievement" ( - "id" serial PRIMARY KEY NOT NULL, - "name" varchar(255) NOT NULL, - "description" text, - "reward_experience" numeric, - "reward_points" numeric, - "state" integer DEFAULT 0 NOT NULL, - "repeatable" integer NOT NULL, - "is_resettable" boolean NOT NULL, - "created_at" timestamp DEFAULT now() NOT NULL, - "updated_at" timestamp DEFAULT now() NOT NULL, - CONSTRAINT "achievement_id_unique" UNIQUE("id") -); ---> statement-breakpoint -CREATE TABLE IF NOT EXISTS "collection_likes" ( - "user_id" integer NOT NULL, - "collection" integer NOT NULL -); ---> statement-breakpoint -CREATE TABLE IF NOT EXISTS "collection_resources" ( - "collection_id" integer NOT NULL, - "resource_id" integer NOT NULL -); ---> statement-breakpoint -CREATE TABLE IF NOT EXISTS "collection_stats" ( - "id" serial PRIMARY KEY NOT NULL, - "collection_id" bigint NOT NULL, - "views" bigint DEFAULT 0, - "downloads" bigint DEFAULT 0, - "likes" bigint DEFAULT 0, - "shares" bigint DEFAULT 0, - "score" bigint DEFAULT 0, - "follows" bigint DEFAULT 0, - CONSTRAINT "collection_stats_id_unique" UNIQUE("id") -); ---> statement-breakpoint -CREATE TABLE IF NOT EXISTS "collection" ( - "id" serial PRIMARY KEY NOT NULL, - "name" varchar(255), - "description" text, - "is_private" boolean, - "is_active" boolean DEFAULT true, - "created_at" timestamp DEFAULT now() NOT NULL, - "updated_at" timestamp, - "deleted_at" timestamp, - "thumbnail" varchar(255), - CONSTRAINT "collection_id_unique" UNIQUE("id") -); ---> statement-breakpoint -CREATE TABLE IF NOT EXISTS "complaint" ( - "id" serial PRIMARY KEY NOT NULL, - "state" integer DEFAULT 0 NOT NULL, - "description" text NOT NULL, - "evaluatedUser" integer NOT NULL, - "resource_id" integer, - "collection_id" integer, - "user_id" integer, - "evaluated_at" timestamp, - "created_at" timestamp DEFAULT now() NOT NULL, - "q1" boolean, - "q2" boolean, - "q3" boolean, - "q4" boolean -); ---> statement-breakpoint -CREATE TABLE IF NOT EXISTS "educational_stages" ( - "id" serial PRIMARY KEY NOT NULL, - "name" varchar NOT NULL, - CONSTRAINT "educational_stages_id_unique" UNIQUE("id"), - CONSTRAINT "educational_stages_name_unique" UNIQUE("name") -); ---> statement-breakpoint -CREATE TABLE IF NOT EXISTS "follows" ( - "id" serial PRIMARY KEY NOT NULL, - "user_id" integer NOT NULL, - "follower_id" integer NOT NULL, - CONSTRAINT "follows_id_unique" UNIQUE("id") -); ---> statement-breakpoint -CREATE TABLE IF NOT EXISTS "institution" ( - "id" serial PRIMARY KEY NOT NULL, - "name" varchar(255) NOT NULL, - "uf" varchar(2), - "city" varchar(255), - "cep" varchar(10), - "created_at" timestamp DEFAULT now() NOT NULL, - "updated_at" timestamp DEFAULT now() NOT NULL, - CONSTRAINT "institution_id_unique" UNIQUE("id") -); ---> statement-breakpoint -CREATE TABLE IF NOT EXISTS "items" ( - "id" serial PRIMARY KEY NOT NULL, - "name" varchar(256) NOT NULL, - "price" numeric(10, 2), - "discount" numeric(10, 2), - "description" varchar(256), - "is_active" boolean DEFAULT false, - "item_type" varchar(256), - "created_at" timestamp DEFAULT now() NOT NULL, - "updated_at" timestamp NOT NULL, - "achievement_id" integer, - CONSTRAINT "items_id_unique" UNIQUE("id") -); ---> statement-breakpoint -CREATE TABLE IF NOT EXISTS "language" ( - "id" serial PRIMARY KEY NOT NULL, - "name" varchar NOT NULL, - "code" varchar NOT NULL, - CONSTRAINT "language_id_unique" UNIQUE("id"), - CONSTRAINT "language_name_unique" UNIQUE("name"), - CONSTRAINT "language_code_unique" UNIQUE("code") -); ---> statement-breakpoint -CREATE TABLE IF NOT EXISTS "licenses" ( - "id" serial PRIMARY KEY NOT NULL, - "name" varchar NOT NULL, - "description" varchar NOT NULL, - "url" varchar NOT NULL, - CONSTRAINT "licenses_id_unique" UNIQUE("id"), - CONSTRAINT "licenses_name_unique" UNIQUE("name") -); ---> statement-breakpoint -CREATE TABLE IF NOT EXISTS "object_types" ( - "id" serial PRIMARY KEY NOT NULL, - "name" varchar(255) NOT NULL, - CONSTRAINT "object_types_id_unique" UNIQUE("id") -); ---> statement-breakpoint -CREATE TABLE IF NOT EXISTS "reset_ticket" ( - "id" serial PRIMARY KEY NOT NULL, - "user_id" integer NOT NULL, - "token_hash" varchar(255) NOT NULL, - "expiration_date" timestamp NOT NULL, - "token_used" boolean DEFAULT false NOT NULL, - "valid_token" boolean DEFAULT true NOT NULL, - "created_at" timestamp DEFAULT now() NOT NULL, - "updated_at" timestamp DEFAULT now() NOT NULL, - CONSTRAINT "reset_ticket_id_unique" UNIQUE("id") -); ---> statement-breakpoint -CREATE TABLE IF NOT EXISTS "resource_educational_stages" ( - "resource_id" integer NOT NULL, - "educational_stage_id" integer NOT NULL -); ---> statement-breakpoint -CREATE TABLE IF NOT EXISTS "resource_languages" ( - "resource_id" integer NOT NULL, - "language_id" integer NOT NULL -); ---> statement-breakpoint -CREATE TABLE IF NOT EXISTS "resource_likes" ( - "user_id" integer NOT NULL, - "resource_id" integer NOT NULL -); ---> statement-breakpoint -CREATE TABLE IF NOT EXISTS "resource_subjects" ( - "resource_id" integer NOT NULL, - "subject_id" integer NOT NULL -); ---> statement-breakpoint -CREATE TABLE IF NOT EXISTS "resource" ( - "id" serial PRIMARY KEY NOT NULL, - "name" varchar(256) NOT NULL, - "author" varchar(256) NOT NULL, - "description" varchar(256), - "bucket_key" varchar(256), - "link" varchar(256), - "thumbnail" varchar(256) NOT NULL, - "active" boolean DEFAULT false NOT NULL, - "published_at" timestamp, - "submited_at" timestamp, - "created_at" timestamp DEFAULT now() NOT NULL, - "updated_at" timestamp, - "deleted_at" timestamp, - CONSTRAINT "resource_id_unique" UNIQUE("id"), - CONSTRAINT "resource_bucket_key_unique" UNIQUE("bucket_key") -); ---> statement-breakpoint -CREATE TABLE IF NOT EXISTS "role" ( - "id" serial PRIMARY KEY NOT NULL, - "name" varchar(255) NOT NULL, - "description" text, - "created_at" timestamp DEFAULT now() NOT NULL, - "updated_at" timestamp DEFAULT now() NOT NULL, - CONSTRAINT "role_id_unique" UNIQUE("id"), - CONSTRAINT "role_name_unique" UNIQUE("name") -); ---> statement-breakpoint -CREATE TABLE IF NOT EXISTS "stats_resources" ( - "id" serial PRIMARY KEY NOT NULL, - "resource_id" bigint NOT NULL, - "views" bigint DEFAULT 0 NOT NULL, - "downloads" bigint DEFAULT 0 NOT NULL, - "shares" bigint DEFAULT 0 NOT NULL, - "score" bigint DEFAULT 0 NOT NULL, - CONSTRAINT "stats_resources_id_unique" UNIQUE("id") -); ---> statement-breakpoint -CREATE TABLE IF NOT EXISTS "subjects" ( - "id" serial PRIMARY KEY NOT NULL, - "name" varchar NOT NULL, - CONSTRAINT "subjects_id_unique" UNIQUE("id"), - CONSTRAINT "subjects_name_unique" UNIQUE("name") -); ---> statement-breakpoint -CREATE TABLE IF NOT EXISTS "submission" ( - "id" serial PRIMARY KEY NOT NULL, - "is_accepted" boolean DEFAULT false NOT NULL, - "justification" text, - "resource_id" integer NOT NULL, - "submitter_id" integer NOT NULL, - "curator_id" integer NOT NULL, - "created_at" timestamp DEFAULT now() NOT NULL, - "updated_at" timestamp, - "answered_at" timestamp, - "q1" boolean, - "q2" boolean, - "q3" boolean, - "q4" boolean -); ---> statement-breakpoint -CREATE TABLE IF NOT EXISTS "user_institution" ( - "id" serial PRIMARY KEY NOT NULL, - "user_id" integer NOT NULL, - "institution_id" integer NOT NULL, - CONSTRAINT "user_institution_id_unique" UNIQUE("id") -); ---> statement-breakpoint -CREATE TABLE IF NOT EXISTS "user_role" ( - "id" serial PRIMARY KEY NOT NULL, - "user_id" integer NOT NULL, - "role_id" integer NOT NULL, - CONSTRAINT "user_role_id_unique" UNIQUE("id") -); ---> statement-breakpoint -CREATE TABLE IF NOT EXISTS "user_stats" ( - "id" serial PRIMARY KEY NOT NULL, - "user_id" integer NOT NULL, - "score" integer DEFAULT 0 NOT NULL, - "likes" integer DEFAULT 0 NOT NULL, - "likes_received" integer DEFAULT 0 NOT NULL, - "follows" integer DEFAULT 0 NOT NULL, - "followers" integer DEFAULT 0 NOT NULL, - "collections" integer DEFAULT 0 NOT NULL, - "submitted_resources" integer DEFAULT 0 NOT NULL, - "approved_resources" integer DEFAULT 0 NOT NULL, - "reviewed_resources" integer DEFAULT 0 NOT NULL, - "comments" integer DEFAULT 0 NOT NULL, - CONSTRAINT "user_stats_id_unique" UNIQUE("id") -); ---> statement-breakpoint -CREATE TABLE IF NOT EXISTS "user" ( - "id" serial PRIMARY KEY NOT NULL, - "name" varchar(255) NOT NULL, - "username" varchar(255) NOT NULL, - "password" varchar(255) NOT NULL, - "email" varchar(255) NOT NULL, - "description" text DEFAULT 'sem descrição', - "institution" text DEFAULT 'sem instituição', - "birthday" timestamp NOT NULL, - "cpf" varchar(255) NOT NULL, - "created_at" timestamp DEFAULT now() NOT NULL, - "updated_at" timestamp DEFAULT now() NOT NULL, - "confirmed_at" timestamp, - "confirmation_sent_at" timestamp, - "deleted_at" timestamp, - "reactivated_at" timestamp, - "active" boolean DEFAULT true, - CONSTRAINT "user_id_unique" UNIQUE("id"), - CONSTRAINT "user_username_unique" UNIQUE("username"), - CONSTRAINT "user_email_unique" UNIQUE("email") -); ---> statement-breakpoint -DO $$ BEGIN - ALTER TABLE "collection_likes" ADD CONSTRAINT "collection_likes_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action; -EXCEPTION - WHEN duplicate_object THEN null; -END $$; ---> statement-breakpoint -DO $$ BEGIN - ALTER TABLE "collection_likes" ADD CONSTRAINT "collection_likes_collection_collection_id_fk" FOREIGN KEY ("collection") REFERENCES "public"."collection"("id") ON DELETE cascade ON UPDATE no action; -EXCEPTION - WHEN duplicate_object THEN null; -END $$; ---> statement-breakpoint -DO $$ BEGIN - ALTER TABLE "collection_resources" ADD CONSTRAINT "collection_resources_collection_id_collection_id_fk" FOREIGN KEY ("collection_id") REFERENCES "public"."collection"("id") ON DELETE cascade ON UPDATE no action; -EXCEPTION - WHEN duplicate_object THEN null; -END $$; ---> statement-breakpoint -DO $$ BEGIN - ALTER TABLE "collection_resources" ADD CONSTRAINT "collection_resources_resource_id_resource_id_fk" FOREIGN KEY ("resource_id") REFERENCES "public"."resource"("id") ON DELETE cascade ON UPDATE no action; -EXCEPTION - WHEN duplicate_object THEN null; -END $$; ---> statement-breakpoint -DO $$ BEGIN - ALTER TABLE "collection_stats" ADD CONSTRAINT "collection_stats_collection_id_collection_id_fk" FOREIGN KEY ("collection_id") REFERENCES "public"."collection"("id") ON DELETE cascade ON UPDATE no action; -EXCEPTION - WHEN duplicate_object THEN null; -END $$; ---> statement-breakpoint -DO $$ BEGIN - ALTER TABLE "complaint" ADD CONSTRAINT "complaint_evaluatedUser_user_id_fk" FOREIGN KEY ("evaluatedUser") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action; -EXCEPTION - WHEN duplicate_object THEN null; -END $$; ---> statement-breakpoint -DO $$ BEGIN - ALTER TABLE "follows" ADD CONSTRAINT "follows_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action; -EXCEPTION - WHEN duplicate_object THEN null; -END $$; ---> statement-breakpoint -DO $$ BEGIN - ALTER TABLE "follows" ADD CONSTRAINT "follows_follower_id_user_id_fk" FOREIGN KEY ("follower_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action; -EXCEPTION - WHEN duplicate_object THEN null; -END $$; ---> statement-breakpoint -DO $$ BEGIN - ALTER TABLE "items" ADD CONSTRAINT "items_achievement_id_achievement_id_fk" FOREIGN KEY ("achievement_id") REFERENCES "public"."achievement"("id") ON DELETE no action ON UPDATE no action; -EXCEPTION - WHEN duplicate_object THEN null; -END $$; ---> statement-breakpoint -DO $$ BEGIN - ALTER TABLE "reset_ticket" ADD CONSTRAINT "reset_ticket_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action; -EXCEPTION - WHEN duplicate_object THEN null; -END $$; ---> statement-breakpoint -DO $$ BEGIN - ALTER TABLE "resource_educational_stages" ADD CONSTRAINT "resource_educational_stages_resource_id_resource_id_fk" FOREIGN KEY ("resource_id") REFERENCES "public"."resource"("id") ON DELETE cascade ON UPDATE no action; -EXCEPTION - WHEN duplicate_object THEN null; -END $$; ---> statement-breakpoint -DO $$ BEGIN - ALTER TABLE "resource_educational_stages" ADD CONSTRAINT "resource_educational_stages_educational_stage_id_educational_stages_id_fk" FOREIGN KEY ("educational_stage_id") REFERENCES "public"."educational_stages"("id") ON DELETE cascade ON UPDATE no action; -EXCEPTION - WHEN duplicate_object THEN null; -END $$; ---> statement-breakpoint -DO $$ BEGIN - ALTER TABLE "resource_languages" ADD CONSTRAINT "resource_languages_resource_id_resource_id_fk" FOREIGN KEY ("resource_id") REFERENCES "public"."resource"("id") ON DELETE cascade ON UPDATE no action; -EXCEPTION - WHEN duplicate_object THEN null; -END $$; ---> statement-breakpoint -DO $$ BEGIN - ALTER TABLE "resource_languages" ADD CONSTRAINT "resource_languages_language_id_language_id_fk" FOREIGN KEY ("language_id") REFERENCES "public"."language"("id") ON DELETE cascade ON UPDATE no action; -EXCEPTION - WHEN duplicate_object THEN null; -END $$; ---> statement-breakpoint -DO $$ BEGIN - ALTER TABLE "resource_likes" ADD CONSTRAINT "resource_likes_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action; -EXCEPTION - WHEN duplicate_object THEN null; -END $$; ---> statement-breakpoint -DO $$ BEGIN - ALTER TABLE "resource_likes" ADD CONSTRAINT "resource_likes_resource_id_resource_id_fk" FOREIGN KEY ("resource_id") REFERENCES "public"."resource"("id") ON DELETE cascade ON UPDATE no action; -EXCEPTION - WHEN duplicate_object THEN null; -END $$; ---> statement-breakpoint -DO $$ BEGIN - ALTER TABLE "resource_subjects" ADD CONSTRAINT "resource_subjects_resource_id_resource_id_fk" FOREIGN KEY ("resource_id") REFERENCES "public"."resource"("id") ON DELETE cascade ON UPDATE no action; -EXCEPTION - WHEN duplicate_object THEN null; -END $$; ---> statement-breakpoint -DO $$ BEGIN - ALTER TABLE "resource_subjects" ADD CONSTRAINT "resource_subjects_subject_id_subjects_id_fk" FOREIGN KEY ("subject_id") REFERENCES "public"."subjects"("id") ON DELETE cascade ON UPDATE no action; -EXCEPTION - WHEN duplicate_object THEN null; -END $$; ---> statement-breakpoint -DO $$ BEGIN - ALTER TABLE "stats_resources" ADD CONSTRAINT "stats_resources_resource_id_resource_id_fk" FOREIGN KEY ("resource_id") REFERENCES "public"."resource"("id") ON DELETE cascade ON UPDATE no action; -EXCEPTION - WHEN duplicate_object THEN null; -END $$; ---> statement-breakpoint -DO $$ BEGIN - ALTER TABLE "submission" ADD CONSTRAINT "submission_resource_id_resource_id_fk" FOREIGN KEY ("resource_id") REFERENCES "public"."resource"("id") ON DELETE cascade ON UPDATE no action; -EXCEPTION - WHEN duplicate_object THEN null; -END $$; ---> statement-breakpoint -DO $$ BEGIN - ALTER TABLE "submission" ADD CONSTRAINT "submission_submitter_id_user_id_fk" FOREIGN KEY ("submitter_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action; -EXCEPTION - WHEN duplicate_object THEN null; -END $$; ---> statement-breakpoint -DO $$ BEGIN - ALTER TABLE "submission" ADD CONSTRAINT "submission_curator_id_user_id_fk" FOREIGN KEY ("curator_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action; -EXCEPTION - WHEN duplicate_object THEN null; -END $$; ---> statement-breakpoint -DO $$ BEGIN - ALTER TABLE "user_institution" ADD CONSTRAINT "user_institution_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action; -EXCEPTION - WHEN duplicate_object THEN null; -END $$; ---> statement-breakpoint -DO $$ BEGIN - ALTER TABLE "user_institution" ADD CONSTRAINT "user_institution_institution_id_institution_id_fk" FOREIGN KEY ("institution_id") REFERENCES "public"."institution"("id") ON DELETE cascade ON UPDATE no action; -EXCEPTION - WHEN duplicate_object THEN null; -END $$; ---> statement-breakpoint -DO $$ BEGIN - ALTER TABLE "user_role" ADD CONSTRAINT "user_role_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action; -EXCEPTION - WHEN duplicate_object THEN null; -END $$; ---> statement-breakpoint -DO $$ BEGIN - ALTER TABLE "user_role" ADD CONSTRAINT "user_role_role_id_role_id_fk" FOREIGN KEY ("role_id") REFERENCES "public"."role"("id") ON DELETE cascade ON UPDATE no action; -EXCEPTION - WHEN duplicate_object THEN null; -END $$; ---> statement-breakpoint -DO $$ BEGIN - ALTER TABLE "user_stats" ADD CONSTRAINT "user_stats_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action; -EXCEPTION - WHEN duplicate_object THEN null; -END $$; diff --git a/src/db/migrations/meta/0000_snapshot.json b/src/db/migrations/meta/0000_snapshot.json deleted file mode 100644 index 12f80d5ab8dff1866fcd0c002d48191582f94b78..0000000000000000000000000000000000000000 --- a/src/db/migrations/meta/0000_snapshot.json +++ /dev/null @@ -1,1852 +0,0 @@ -{ - "id": "859d43fc-3e36-405b-8a21-e76b61e071e6", - "prevId": "00000000-0000-0000-0000-000000000000", - "version": "7", - "dialect": "postgresql", - "tables": { - "public.achievement": { - "name": "achievement", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "name": { - "name": "name", - "type": "varchar(255)", - "primaryKey": false, - "notNull": true - }, - "description": { - "name": "description", - "type": "text", - "primaryKey": false, - "notNull": false - }, - "reward_experience": { - "name": "reward_experience", - "type": "numeric", - "primaryKey": false, - "notNull": false - }, - "reward_points": { - "name": "reward_points", - "type": "numeric", - "primaryKey": false, - "notNull": false - }, - "state": { - "name": "state", - "type": "integer", - "primaryKey": false, - "notNull": true, - "default": 0 - }, - "repeatable": { - "name": "repeatable", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "is_resettable": { - "name": "is_resettable", - "type": "boolean", - "primaryKey": false, - "notNull": true - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "default": "now()" - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "default": "now()" - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "achievement_id_unique": { - "name": "achievement_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - } - } - }, - "public.collection_likes": { - "name": "collection_likes", - "schema": "", - "columns": { - "user_id": { - "name": "user_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "collection": { - "name": "collection", - "type": "integer", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": { - "collection_likes_user_id_user_id_fk": { - "name": "collection_likes_user_id_user_id_fk", - "tableFrom": "collection_likes", - "tableTo": "user", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "collection_likes_collection_collection_id_fk": { - "name": "collection_likes_collection_collection_id_fk", - "tableFrom": "collection_likes", - "tableTo": "collection", - "columnsFrom": [ - "collection" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "public.collection_resources": { - "name": "collection_resources", - "schema": "", - "columns": { - "collection_id": { - "name": "collection_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "resource_id": { - "name": "resource_id", - "type": "integer", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": { - "collection_resources_collection_id_collection_id_fk": { - "name": "collection_resources_collection_id_collection_id_fk", - "tableFrom": "collection_resources", - "tableTo": "collection", - "columnsFrom": [ - "collection_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "collection_resources_resource_id_resource_id_fk": { - "name": "collection_resources_resource_id_resource_id_fk", - "tableFrom": "collection_resources", - "tableTo": "resource", - "columnsFrom": [ - "resource_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "public.collection_stats": { - "name": "collection_stats", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "collection_id": { - "name": "collection_id", - "type": "bigint", - "primaryKey": false, - "notNull": true - }, - "views": { - "name": "views", - "type": "bigint", - "primaryKey": false, - "notNull": false, - "default": 0 - }, - "downloads": { - "name": "downloads", - "type": "bigint", - "primaryKey": false, - "notNull": false, - "default": 0 - }, - "likes": { - "name": "likes", - "type": "bigint", - "primaryKey": false, - "notNull": false, - "default": 0 - }, - "shares": { - "name": "shares", - "type": "bigint", - "primaryKey": false, - "notNull": false, - "default": 0 - }, - "score": { - "name": "score", - "type": "bigint", - "primaryKey": false, - "notNull": false, - "default": 0 - }, - "follows": { - "name": "follows", - "type": "bigint", - "primaryKey": false, - "notNull": false, - "default": 0 - } - }, - "indexes": {}, - "foreignKeys": { - "collection_stats_collection_id_collection_id_fk": { - "name": "collection_stats_collection_id_collection_id_fk", - "tableFrom": "collection_stats", - "tableTo": "collection", - "columnsFrom": [ - "collection_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "collection_stats_id_unique": { - "name": "collection_stats_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - } - } - }, - "public.collection": { - "name": "collection", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "name": { - "name": "name", - "type": "varchar(255)", - "primaryKey": false, - "notNull": false - }, - "description": { - "name": "description", - "type": "text", - "primaryKey": false, - "notNull": false - }, - "is_private": { - "name": "is_private", - "type": "boolean", - "primaryKey": false, - "notNull": false - }, - "is_active": { - "name": "is_active", - "type": "boolean", - "primaryKey": false, - "notNull": false, - "default": true - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "default": "now()" - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false - }, - "deleted_at": { - "name": "deleted_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false - }, - "thumbnail": { - "name": "thumbnail", - "type": "varchar(255)", - "primaryKey": false, - "notNull": false - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "collection_id_unique": { - "name": "collection_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - } - } - }, - "public.complaint": { - "name": "complaint", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "state": { - "name": "state", - "type": "integer", - "primaryKey": false, - "notNull": true, - "default": 0 - }, - "description": { - "name": "description", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "evaluatedUser": { - "name": "evaluatedUser", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "resource_id": { - "name": "resource_id", - "type": "integer", - "primaryKey": false, - "notNull": false - }, - "collection_id": { - "name": "collection_id", - "type": "integer", - "primaryKey": false, - "notNull": false - }, - "user_id": { - "name": "user_id", - "type": "integer", - "primaryKey": false, - "notNull": false - }, - "evaluated_at": { - "name": "evaluated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "default": "now()" - }, - "q1": { - "name": "q1", - "type": "boolean", - "primaryKey": false, - "notNull": false - }, - "q2": { - "name": "q2", - "type": "boolean", - "primaryKey": false, - "notNull": false - }, - "q3": { - "name": "q3", - "type": "boolean", - "primaryKey": false, - "notNull": false - }, - "q4": { - "name": "q4", - "type": "boolean", - "primaryKey": false, - "notNull": false - } - }, - "indexes": {}, - "foreignKeys": { - "complaint_evaluatedUser_user_id_fk": { - "name": "complaint_evaluatedUser_user_id_fk", - "tableFrom": "complaint", - "tableTo": "user", - "columnsFrom": [ - "evaluatedUser" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "public.educational_stages": { - "name": "educational_stages", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "name": { - "name": "name", - "type": "varchar", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "educational_stages_id_unique": { - "name": "educational_stages_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - }, - "educational_stages_name_unique": { - "name": "educational_stages_name_unique", - "nullsNotDistinct": false, - "columns": [ - "name" - ] - } - } - }, - "public.follows": { - "name": "follows", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "user_id": { - "name": "user_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "follower_id": { - "name": "follower_id", - "type": "integer", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": { - "follows_user_id_user_id_fk": { - "name": "follows_user_id_user_id_fk", - "tableFrom": "follows", - "tableTo": "user", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "follows_follower_id_user_id_fk": { - "name": "follows_follower_id_user_id_fk", - "tableFrom": "follows", - "tableTo": "user", - "columnsFrom": [ - "follower_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "follows_id_unique": { - "name": "follows_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - } - } - }, - "public.institution": { - "name": "institution", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "name": { - "name": "name", - "type": "varchar(255)", - "primaryKey": false, - "notNull": true - }, - "uf": { - "name": "uf", - "type": "varchar(2)", - "primaryKey": false, - "notNull": false - }, - "city": { - "name": "city", - "type": "varchar(255)", - "primaryKey": false, - "notNull": false - }, - "cep": { - "name": "cep", - "type": "varchar(10)", - "primaryKey": false, - "notNull": false - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "default": "now()" - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "default": "now()" - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "institution_id_unique": { - "name": "institution_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - } - } - }, - "public.language": { - "name": "language", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "name": { - "name": "name", - "type": "varchar", - "primaryKey": false, - "notNull": true - }, - "code": { - "name": "code", - "type": "varchar", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "language_id_unique": { - "name": "language_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - }, - "language_name_unique": { - "name": "language_name_unique", - "nullsNotDistinct": false, - "columns": [ - "name" - ] - }, - "language_code_unique": { - "name": "language_code_unique", - "nullsNotDistinct": false, - "columns": [ - "code" - ] - } - } - }, - "public.licenses": { - "name": "licenses", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "name": { - "name": "name", - "type": "varchar", - "primaryKey": false, - "notNull": true - }, - "description": { - "name": "description", - "type": "varchar", - "primaryKey": false, - "notNull": true - }, - "url": { - "name": "url", - "type": "varchar", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "licenses_id_unique": { - "name": "licenses_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - }, - "licenses_name_unique": { - "name": "licenses_name_unique", - "nullsNotDistinct": false, - "columns": [ - "name" - ] - } - } - }, - "public.object_types": { - "name": "object_types", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "name": { - "name": "name", - "type": "varchar(255)", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "object_types_id_unique": { - "name": "object_types_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - } - } - }, - "public.reset_ticket": { - "name": "reset_ticket", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "user_id": { - "name": "user_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "token_hash": { - "name": "token_hash", - "type": "varchar(255)", - "primaryKey": false, - "notNull": true - }, - "expiration_date": { - "name": "expiration_date", - "type": "timestamp", - "primaryKey": false, - "notNull": true - }, - "token_used": { - "name": "token_used", - "type": "boolean", - "primaryKey": false, - "notNull": true, - "default": false - }, - "valid_token": { - "name": "valid_token", - "type": "boolean", - "primaryKey": false, - "notNull": true, - "default": true - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "default": "now()" - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "default": "now()" - } - }, - "indexes": {}, - "foreignKeys": { - "reset_ticket_user_id_user_id_fk": { - "name": "reset_ticket_user_id_user_id_fk", - "tableFrom": "reset_ticket", - "tableTo": "user", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "reset_ticket_id_unique": { - "name": "reset_ticket_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - } - } - }, - "public.resource_educational_stages": { - "name": "resource_educational_stages", - "schema": "", - "columns": { - "resource_id": { - "name": "resource_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "educational_stage_id": { - "name": "educational_stage_id", - "type": "integer", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": { - "resource_educational_stages_resource_id_resource_id_fk": { - "name": "resource_educational_stages_resource_id_resource_id_fk", - "tableFrom": "resource_educational_stages", - "tableTo": "resource", - "columnsFrom": [ - "resource_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "resource_educational_stages_educational_stage_id_educational_stages_id_fk": { - "name": "resource_educational_stages_educational_stage_id_educational_stages_id_fk", - "tableFrom": "resource_educational_stages", - "tableTo": "educational_stages", - "columnsFrom": [ - "educational_stage_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "public.resource_languages": { - "name": "resource_languages", - "schema": "", - "columns": { - "resource_id": { - "name": "resource_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "language_id": { - "name": "language_id", - "type": "integer", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": { - "resource_languages_resource_id_resource_id_fk": { - "name": "resource_languages_resource_id_resource_id_fk", - "tableFrom": "resource_languages", - "tableTo": "resource", - "columnsFrom": [ - "resource_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "resource_languages_language_id_language_id_fk": { - "name": "resource_languages_language_id_language_id_fk", - "tableFrom": "resource_languages", - "tableTo": "language", - "columnsFrom": [ - "language_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "public.resource_likes": { - "name": "resource_likes", - "schema": "", - "columns": { - "user_id": { - "name": "user_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "resource_id": { - "name": "resource_id", - "type": "integer", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": { - "resource_likes_user_id_user_id_fk": { - "name": "resource_likes_user_id_user_id_fk", - "tableFrom": "resource_likes", - "tableTo": "user", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "resource_likes_resource_id_resource_id_fk": { - "name": "resource_likes_resource_id_resource_id_fk", - "tableFrom": "resource_likes", - "tableTo": "resource", - "columnsFrom": [ - "resource_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "public.resource_subjects": { - "name": "resource_subjects", - "schema": "", - "columns": { - "resource_id": { - "name": "resource_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "subject_id": { - "name": "subject_id", - "type": "integer", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": { - "resource_subjects_resource_id_resource_id_fk": { - "name": "resource_subjects_resource_id_resource_id_fk", - "tableFrom": "resource_subjects", - "tableTo": "resource", - "columnsFrom": [ - "resource_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "resource_subjects_subject_id_subjects_id_fk": { - "name": "resource_subjects_subject_id_subjects_id_fk", - "tableFrom": "resource_subjects", - "tableTo": "subjects", - "columnsFrom": [ - "subject_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "public.resource": { - "name": "resource", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "name": { - "name": "name", - "type": "varchar(256)", - "primaryKey": false, - "notNull": true - }, - "author": { - "name": "author", - "type": "varchar(256)", - "primaryKey": false, - "notNull": true - }, - "description": { - "name": "description", - "type": "varchar(256)", - "primaryKey": false, - "notNull": false - }, - "bucket_key": { - "name": "bucket_key", - "type": "varchar(256)", - "primaryKey": false, - "notNull": false - }, - "link": { - "name": "link", - "type": "varchar(256)", - "primaryKey": false, - "notNull": false - }, - "thumbnail": { - "name": "thumbnail", - "type": "varchar(256)", - "primaryKey": false, - "notNull": true - }, - "active": { - "name": "active", - "type": "boolean", - "primaryKey": false, - "notNull": true, - "default": false - }, - "published_at": { - "name": "published_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false - }, - "submited_at": { - "name": "submited_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "default": "now()" - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false - }, - "deleted_at": { - "name": "deleted_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "resource_id_unique": { - "name": "resource_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - }, - "resource_bucket_key_unique": { - "name": "resource_bucket_key_unique", - "nullsNotDistinct": false, - "columns": [ - "bucket_key" - ] - } - } - }, - "public.role": { - "name": "role", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "name": { - "name": "name", - "type": "varchar(255)", - "primaryKey": false, - "notNull": true - }, - "description": { - "name": "description", - "type": "text", - "primaryKey": false, - "notNull": false - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "default": "now()" - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "default": "now()" - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "role_id_unique": { - "name": "role_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - }, - "role_name_unique": { - "name": "role_name_unique", - "nullsNotDistinct": false, - "columns": [ - "name" - ] - } - } - }, - "public.stats_resources": { - "name": "stats_resources", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "resource_id": { - "name": "resource_id", - "type": "bigint", - "primaryKey": false, - "notNull": true - }, - "views": { - "name": "views", - "type": "bigint", - "primaryKey": false, - "notNull": true, - "default": 0 - }, - "downloads": { - "name": "downloads", - "type": "bigint", - "primaryKey": false, - "notNull": true, - "default": 0 - }, - "shares": { - "name": "shares", - "type": "bigint", - "primaryKey": false, - "notNull": true, - "default": 0 - }, - "score": { - "name": "score", - "type": "bigint", - "primaryKey": false, - "notNull": true, - "default": 0 - } - }, - "indexes": {}, - "foreignKeys": { - "stats_resources_resource_id_resource_id_fk": { - "name": "stats_resources_resource_id_resource_id_fk", - "tableFrom": "stats_resources", - "tableTo": "resource", - "columnsFrom": [ - "resource_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "stats_resources_id_unique": { - "name": "stats_resources_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - } - } - }, - "public.subjects": { - "name": "subjects", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "name": { - "name": "name", - "type": "varchar", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "subjects_id_unique": { - "name": "subjects_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - }, - "subjects_name_unique": { - "name": "subjects_name_unique", - "nullsNotDistinct": false, - "columns": [ - "name" - ] - } - } - }, - "public.submission": { - "name": "submission", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "is_accepted": { - "name": "is_accepted", - "type": "boolean", - "primaryKey": false, - "notNull": true, - "default": false - }, - "justification": { - "name": "justification", - "type": "text", - "primaryKey": false, - "notNull": false - }, - "resource_id": { - "name": "resource_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "submitter_id": { - "name": "submitter_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "curator_id": { - "name": "curator_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "default": "now()" - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false - }, - "answered_at": { - "name": "answered_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false - }, - "q1": { - "name": "q1", - "type": "boolean", - "primaryKey": false, - "notNull": false - }, - "q2": { - "name": "q2", - "type": "boolean", - "primaryKey": false, - "notNull": false - }, - "q3": { - "name": "q3", - "type": "boolean", - "primaryKey": false, - "notNull": false - }, - "q4": { - "name": "q4", - "type": "boolean", - "primaryKey": false, - "notNull": false - } - }, - "indexes": {}, - "foreignKeys": { - "submission_resource_id_resource_id_fk": { - "name": "submission_resource_id_resource_id_fk", - "tableFrom": "submission", - "tableTo": "resource", - "columnsFrom": [ - "resource_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "submission_submitter_id_user_id_fk": { - "name": "submission_submitter_id_user_id_fk", - "tableFrom": "submission", - "tableTo": "user", - "columnsFrom": [ - "submitter_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "submission_curator_id_user_id_fk": { - "name": "submission_curator_id_user_id_fk", - "tableFrom": "submission", - "tableTo": "user", - "columnsFrom": [ - "curator_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "public.user_achievements": { - "name": "user_achievements", - "schema": "", - "columns": { - "user_id": { - "name": "user_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "achievement_id": { - "name": "achievement_id", - "type": "integer", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": { - "user_achievements_user_id_user_id_fk": { - "name": "user_achievements_user_id_user_id_fk", - "tableFrom": "user_achievements", - "tableTo": "user", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "user_achievements_achievement_id_user_id_fk": { - "name": "user_achievements_achievement_id_user_id_fk", - "tableFrom": "user_achievements", - "tableTo": "user", - "columnsFrom": [ - "achievement_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": {} - }, - "public.user_institution": { - "name": "user_institution", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "user_id": { - "name": "user_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "institution_id": { - "name": "institution_id", - "type": "integer", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": { - "user_institution_user_id_user_id_fk": { - "name": "user_institution_user_id_user_id_fk", - "tableFrom": "user_institution", - "tableTo": "user", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "user_institution_institution_id_institution_id_fk": { - "name": "user_institution_institution_id_institution_id_fk", - "tableFrom": "user_institution", - "tableTo": "institution", - "columnsFrom": [ - "institution_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "user_institution_id_unique": { - "name": "user_institution_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - } - } - }, - "public.user_role": { - "name": "user_role", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "user_id": { - "name": "user_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "role_id": { - "name": "role_id", - "type": "integer", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": { - "user_role_user_id_user_id_fk": { - "name": "user_role_user_id_user_id_fk", - "tableFrom": "user_role", - "tableTo": "user", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "user_role_role_id_role_id_fk": { - "name": "user_role_role_id_role_id_fk", - "tableFrom": "user_role", - "tableTo": "role", - "columnsFrom": [ - "role_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "user_role_id_unique": { - "name": "user_role_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - } - } - }, - "public.user_stats": { - "name": "user_stats", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "user_id": { - "name": "user_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "score": { - "name": "score", - "type": "integer", - "primaryKey": false, - "notNull": true, - "default": 0 - }, - "likes": { - "name": "likes", - "type": "integer", - "primaryKey": false, - "notNull": true, - "default": 0 - }, - "likes_received": { - "name": "likes_received", - "type": "integer", - "primaryKey": false, - "notNull": true, - "default": 0 - }, - "follows": { - "name": "follows", - "type": "integer", - "primaryKey": false, - "notNull": true, - "default": 0 - }, - "followers": { - "name": "followers", - "type": "integer", - "primaryKey": false, - "notNull": true, - "default": 0 - }, - "collections": { - "name": "collections", - "type": "integer", - "primaryKey": false, - "notNull": true, - "default": 0 - }, - "submitted_resources": { - "name": "submitted_resources", - "type": "integer", - "primaryKey": false, - "notNull": true, - "default": 0 - }, - "approved_resources": { - "name": "approved_resources", - "type": "integer", - "primaryKey": false, - "notNull": true, - "default": 0 - }, - "reviewed_resources": { - "name": "reviewed_resources", - "type": "integer", - "primaryKey": false, - "notNull": true, - "default": 0 - }, - "comments": { - "name": "comments", - "type": "integer", - "primaryKey": false, - "notNull": true, - "default": 0 - } - }, - "indexes": {}, - "foreignKeys": { - "user_stats_user_id_user_id_fk": { - "name": "user_stats_user_id_user_id_fk", - "tableFrom": "user_stats", - "tableTo": "user", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "user_stats_id_unique": { - "name": "user_stats_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - } - } - }, - "public.user": { - "name": "user", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "name": { - "name": "name", - "type": "varchar(255)", - "primaryKey": false, - "notNull": true - }, - "username": { - "name": "username", - "type": "varchar(255)", - "primaryKey": false, - "notNull": true - }, - "password": { - "name": "password", - "type": "varchar(255)", - "primaryKey": false, - "notNull": true - }, - "email": { - "name": "email", - "type": "varchar(255)", - "primaryKey": false, - "notNull": true - }, - "description": { - "name": "description", - "type": "text", - "primaryKey": false, - "notNull": false, - "default": "'sem descrição'" - }, - "institution": { - "name": "institution", - "type": "text", - "primaryKey": false, - "notNull": false, - "default": "'sem instituição'" - }, - "birthday": { - "name": "birthday", - "type": "timestamp", - "primaryKey": false, - "notNull": true - }, - "cpf": { - "name": "cpf", - "type": "varchar(255)", - "primaryKey": false, - "notNull": true - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "default": "now()" - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "default": "now()" - }, - "confirmed_at": { - "name": "confirmed_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false - }, - "confirmation_sent_at": { - "name": "confirmation_sent_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false - }, - "deleted_at": { - "name": "deleted_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false - }, - "reactivated_at": { - "name": "reactivated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false - }, - "active": { - "name": "active", - "type": "boolean", - "primaryKey": false, - "notNull": false, - "default": true - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "user_id_unique": { - "name": "user_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - }, - "user_username_unique": { - "name": "user_username_unique", - "nullsNotDistinct": false, - "columns": [ - "username" - ] - }, - "user_email_unique": { - "name": "user_email_unique", - "nullsNotDistinct": false, - "columns": [ - "email" - ] - } - } - } - }, - "enums": {}, - "schemas": {}, - "_meta": { - "columns": {}, - "schemas": {}, - "tables": {} - } -} \ No newline at end of file diff --git a/src/db/migrations/meta/_journal.json b/src/db/migrations/meta/_journal.json index a7ac2305369ff1a1e4f24733d713d5e9d6b131b7..eaa8fcf3b643329af83679deadefa3c53fdb6305 100644 --- a/src/db/migrations/meta/_journal.json +++ b/src/db/migrations/meta/_journal.json @@ -1,13 +1,5 @@ { "version": "7", "dialect": "postgresql", - "entries": [ - { - "idx": 0, - "version": "7", - "when": 1729690423126, - "tag": "0000_cold_old_lace", - "breakpoints": true - } - ] + "entries": [] } \ No newline at end of file diff --git a/src/db/relations/notification.relation.ts b/src/db/relations/notification.relation.ts new file mode 100644 index 0000000000000000000000000000000000000000..32a605c259a09eab7e873371dd7d7e2a368495da --- /dev/null +++ b/src/db/relations/notification.relation.ts @@ -0,0 +1,55 @@ +import { sql } from "drizzle-orm" +import { integer, pgTable, serial, timestamp } from "drizzle-orm/pg-core" +import { createInsertSchema, createSelectSchema } from "drizzle-zod" +import type { z } from "zod" +import { actionTable, collectionTable, resourceTable, userTable } from "../schema" + +const notificationRelationTable = pgTable('notification', { + id: serial('id').primaryKey() + .unique() + .notNull(), + action_id: integer('action_id') + .references(() => actionTable.id, {onDelete: 'cascade'}) + .notNull(), + actor_user_id: integer('actor_user_id') + .references(() => userTable.id, {onDelete: 'cascade'}) + .notNull(), + target_user_id: integer('target_user_id') + .references(() => userTable.id, {onDelete: 'cascade'}) + .notNull(), + target_resource_id: integer('target_resource_id') + .references(() => resourceTable.id, {onDelete: 'cascade'}) + .notNull(), + target_collection_id: integer('target_collection_id') + .references(() => collectionTable.id, {onDelete: 'cascade'}) + .notNull(), + + createdAt: timestamp('created_at', { mode: 'string' }) + .notNull() + .defaultNow(), + updatedAt: timestamp('updated_at', { mode: 'string' }) + .notNull() + .defaultNow() + .$onUpdate(() => sql`current_timestamp`), +}) + +const notificationModelSchema = createSelectSchema(notificationRelationTable) +const notificationDtoSchema = notificationModelSchema +const notificationInputSchema = createInsertSchema(notificationRelationTable) +const notificationUpdateSchema = notificationInputSchema + .partial() + .required({ id: true }) + +export type NotificationModel = z.infer<typeof notificationModelSchema> +export type NotificationDto = z.infer<typeof notificationDtoSchema> +export type NotificationInput = z.infer<typeof notificationInputSchema> +export type NotificationUpdate = z.infer<typeof notificationUpdateSchema> + +export const notificationSchemas = { + model: notificationModelSchema, + dto: notificationDtoSchema, + input: notificationInputSchema, + update: notificationUpdateSchema +} + +export default notificationRelationTable \ No newline at end of file diff --git a/src/db/repo/notification.repo.ts b/src/db/repo/notification.repo.ts new file mode 100644 index 0000000000000000000000000000000000000000..35b790bb7c97c31fab5b1aab77aad4d641ce5456 --- /dev/null +++ b/src/db/repo/notification.repo.ts @@ -0,0 +1,88 @@ +import { Service } from "typedi"; +import db from ".."; +import { eq } from "drizzle-orm"; +import { z } from "zod"; +import notificationRelationTable, { notificationSchemas, type NotificationInput, type NotificationModel, type NotificationUpdate } from "../relations/notification.relation"; + +@Service() +export class NotificationRepo { + async findMany():Promise<NotificationModel[]>{ + + return z.array(notificationSchemas.model).parse(await db.query.notificationRelationTable.findMany()) + } + async findById(id: NotificationModel['id']): Promise<NotificationModel | null>{ + const notification = await db.query.notificationRelationTable.findFirst({ + where: eq(notificationRelationTable.id, id) + }) + + if(!notification) return null + return notificationSchemas.model.parse(notification) + } + async findByAction(action_id: NotificationModel['action_id']): Promise<NotificationModel | null>{ + const notification = await db.query.notificationRelationTable.findFirst({ + where: eq(notificationRelationTable.action_id, action_id) + }) + + if(!notification) return null + return notificationSchemas.model.parse(notification) + } + async findByActorUser(actor_user_id: NotificationModel['actor_user_id']): Promise<NotificationModel | null>{ + const notification = await db.query.notificationRelationTable.findFirst({ + where: eq(notificationRelationTable.actor_user_id, actor_user_id) + }) + + if(!notification) return null + return notificationSchemas.model.parse(notification) + } + async findByTargetUser(target_user_id: NotificationModel['target_user_id']): Promise<NotificationModel | null>{ + const notification = await db.query.notificationRelationTable.findFirst({ + where: eq(notificationRelationTable.target_user_id, target_user_id) + }) + + if(!notification) return null + return notificationSchemas.model.parse(notification) + } + async findByTargetResource(target_resource_id: NotificationModel['target_resource_id']): Promise<NotificationModel | null>{ + const notification = await db.query.notificationRelationTable.findFirst({ + where: eq(notificationRelationTable.target_resource_id, target_resource_id) + }) + + if(!notification) return null + return notificationSchemas.model.parse(notification) + } + async findByTargetCollection(target_collection_id: NotificationModel['target_collection_id']): Promise<NotificationModel | null>{ + const notification = await db.query.notificationRelationTable.findFirst({ + where: eq(notificationRelationTable.target_collection_id, target_collection_id) + }) + + if(!notification) return null + return notificationSchemas.model.parse(notification) + } + + async create(notification: NotificationInput, tx?: db): Promise<NotificationModel>{ + const repo = tx ?? db + const [ret] = await repo + .insert(notificationRelationTable) + .values(notification) + .returning() + + return notificationSchemas.model.parse(ret) + } + async update(notification: NotificationUpdate): Promise<NotificationModel>{ + const [ret] = await db + .update(notificationRelationTable) + .set(notification) + .where(eq(notificationRelationTable.id, notification.id)) + .returning() + + return notificationSchemas.model.parse(ret) + } + async delete(id: NotificationModel['id']): Promise<NotificationModel>{ + const [ret] = await db + .delete(notificationRelationTable) + .where(eq(notificationRelationTable.id, id)) + .returning() + + return notificationSchemas.model.parse(ret) + } +} \ No newline at end of file diff --git a/src/db/schema/index.ts b/src/db/schema/index.ts index 3c8b2a3abf87271d6661271bca941a38c210acc9..b9f5f89124b76a8ab7b45335a0728acc912c765b 100644 --- a/src/db/schema/index.ts +++ b/src/db/schema/index.ts @@ -30,6 +30,7 @@ import resourceEducationalStagesTable from './resource-educational-stages.schema import itemsTable from './items.schema' import userAchievementsTable from '../relations/user-achievements.relation' import actionTable from './action.schema' +import notificationRelationTable from '../relations/notification.relation' export { userTable, @@ -62,6 +63,7 @@ export { itemsTable, userAchievementsTable, actionTable, + notificationRelationTable, } export const tables = [ @@ -91,4 +93,5 @@ export const tables = [ itemsTable, userAchievementsTable, actionTable, + notificationRelationTable, ] diff --git a/src/db/seed.ts b/src/db/seed.ts index 40fb50e8435effea6558ae31b61a65d70ee8efde..99d3ff9c18013a0ef7decbddce81c65334b29003 100644 --- a/src/db/seed.ts +++ b/src/db/seed.ts @@ -21,8 +21,8 @@ for (const table of schema.tables) { await resetTable(db, table) } -await seeds.userSeed(db) await seeds.userStatsSeed(db) +await seeds.userSeed(db) await seeds.resourceSeed(db) await seeds.statsResourcesSeed(db) await seeds.collectionSeed(db) diff --git a/src/db/seeds/user-stats.seed.ts b/src/db/seeds/user-stats.seed.ts index 8d1a9be05c8093b2658ff6663dda52cdad6d6360..47a6a08b4ed45545cae539d8a22f34347b550305 100644 --- a/src/db/seeds/user-stats.seed.ts +++ b/src/db/seeds/user-stats.seed.ts @@ -8,9 +8,15 @@ export default async function seed(db: db) { const usersStatsData: UserStatsInput[] = [ { - user_id: 1 + }, { - user_id: 2 + + }, + { + + }, + { + } ] diff --git a/src/db/seeds/user.seed.ts b/src/db/seeds/user.seed.ts index e67353b02c7566383c829972a74d719630c05ccf..4bf2f1fceffc5660f9f2fe426e4616e2d0fde380 100644 --- a/src/db/seeds/user.seed.ts +++ b/src/db/seeds/user.seed.ts @@ -13,7 +13,8 @@ const usersData: UserInput[] = [ password: hashPassword('1234mudar'), email: 'admin@admin.com', birthday: '2000-06-06', - cpf: '12346579800' + cpf: '12346579800', + user_stats_id: 1 }, { name: 'Client name', @@ -21,7 +22,8 @@ const usersData: UserInput[] = [ password: hashPassword('1234mudar'), email: 'client@client.com', birthday: '2000-06-06', - cpf: '12346579801' + cpf: '12346579801', + user_stats_id: 2 }, { name: 'Client 2 name', @@ -29,7 +31,8 @@ const usersData: UserInput[] = [ password: hashPassword('1234mudar'), email: 'client3@client.com', birthday: '2000-06-06', - cpf: '12346579802' + cpf: '12346579802', + user_stats_id: 3 }, { name: 'Client 3 name', @@ -37,6 +40,7 @@ const usersData: UserInput[] = [ password: hashPassword('1234mudar'), email: 'cliente@client.com', birthday: '2000-06-06', - cpf: '12346579803' + cpf: '12346579803', + user_stats_id: 4 }, ] diff --git a/src/index.ts b/src/index.ts index 6c4fd6e83a8f990480f034b04129c08da8f0c26b..606dfe5813c296e240ed69864769f08b158c03ea 100644 --- a/src/index.ts +++ b/src/index.ts @@ -37,6 +37,7 @@ import { achievementRouter, publicAchievementRouter } from './routes/achievement import { itemsRouter, publicItemsRouter } from './routes/items.route' import { publicUserAchievementsRoute, userAchievementsRouter } from './routes/user-achievements.route' import { actionRouter } from './routes/action.route' +import { notificationRouter } from './routes/notification.route' const app = new Hono() @@ -126,6 +127,7 @@ app .route('/achievements', achievementRouter) .route('/resourceLikes', resourceLikesRoutes) .route('/userAchievements', userAchievementsRouter) + .route('/notifications', notificationRouter) export default app export type AppType = typeof app diff --git a/src/routes/notification.route.ts b/src/routes/notification.route.ts new file mode 100644 index 0000000000000000000000000000000000000000..b4384c8e4d31cbf81ba63794d2436ceefe9af258 --- /dev/null +++ b/src/routes/notification.route.ts @@ -0,0 +1,154 @@ +import { NotificationService } from "@/services/notification.service" +import Container from "typedi" +import { honoWithJwt } from ".." +import { zValidator } from "@hono/zod-validator" +import { createApexError, HttpStatus } from "@/services/error.service" +import { z } from "zod" +import { notificationSchemas } from "@/db/relations/notification.relation" + +const service = Container.get(NotificationService) + +export const notificationRouter = honoWithJwt() +.post('/create', zValidator('json', notificationSchemas.input), + async (c) => { + try{ + const input = await c.req.valid('json') + + const notification = notificationSchemas.dto.parse( + await service.create(input) + ) + + return c.json(notification) + } catch (e){ + return c.json( + createApexError({ + status: 'error', + message: 'could not create notification', + code: HttpStatus.BAD_REQUEST, + path: c.req.routePath, + suggestion: 'check the input and try again', + }), + HttpStatus.BAD_REQUEST + ) + } +}) +.get('/notifications', + async (c) => { + try { + const notifications = z.array(notificationSchemas.dto).parse(await service.findMany()) + + return c.json({notifications}) + } catch (e) { + return c.notFound() + } +}) +.get('/action/:action_id', + async (c) =>{ + try { + const action_id = +c.req.param('action_id') + + const notification = notificationSchemas.dto.parse(await service.findByAction(action_id)) + + return c.json({ notification }) + } catch (e) { + return c.notFound() + } + } +) +.get('/actor-user/:actor_user_id', + async (c) =>{ + try { + const actor_user_id = +c.req.param('actor_user_id') + + const notification = notificationSchemas.dto.parse(await service.findByActorUser(actor_user_id)) + + return c.json({ notification }) + } catch (e) { + return c.notFound() + } + } +) +.get('/target-user/:target_user_id', + async (c) =>{ + try { + const target_user_id = +c.req.param('target_user_id') + + const notification = notificationSchemas.dto.parse(await service.findByTargetUser(target_user_id)) + + return c.json({ notification }) + } catch (e) { + return c.notFound() + } + } +) +.get('/target-resource/:target_resource_id', + async (c) =>{ + try { + const target_resource_id = +c.req.param('target_resource_id') + + const notification = notificationSchemas.dto.parse(await service.findByTargetResource(target_resource_id)) + + return c.json({ notification }) + } catch (e) { + return c.notFound() + } + } +) +.get('/target-collection/:target_collection_id', + async (c) =>{ + try { + const target_collection_id = +c.req.param('target_collection_id') + + const notification = notificationSchemas.dto.parse(await service.findByTargetCollection(target_collection_id)) + + return c.json({ notification }) + } catch (e) { + return c.notFound() + } + } +) +.post('/update', + zValidator('json', notificationSchemas.update), + async (c) => { + try { + const input = await c.req.valid('json') + const notification = notificationSchemas.dto.parse(await service.update(input)) + + return c.json({ notification }) + } catch (e) { + return c.json( + createApexError({ + status: 'error', + message: 'could not update notification', + code: HttpStatus.BAD_REQUEST, + path: c.req.routePath, + suggestion: 'check the input and try again', + }), + HttpStatus.BAD_REQUEST + ) + } + } +) +.delete('/delete/:id', + async (c) =>{ + try{ + const id: number = +c.req.param('id') + + const notification = notificationSchemas.dto.parse( + await service.delete(id) + ) + + return c.json(notification) + } catch (e){ + return c.json( + createApexError({ + status: 'error', + message: 'could delete notification', + code: HttpStatus.BAD_REQUEST, + path: c.req.routePath, + suggestion: 'check the input and try again', + }), + HttpStatus.BAD_REQUEST + ) + } +}) \ No newline at end of file diff --git a/src/services/notification.service.ts b/src/services/notification.service.ts new file mode 100644 index 0000000000000000000000000000000000000000..e10d5a896f39e136b9d61ed2691c5767bd5e61ee --- /dev/null +++ b/src/services/notification.service.ts @@ -0,0 +1,51 @@ +import type db from "@/db" +import type { NotificationInput, NotificationModel, NotificationUpdate } from "@/db/relations/notification.relation" +import { NotificationRepo } from "@/db/repo/notification.repo" +import { Inject, Service } from "typedi" + +@Service() +export class NotificationService{ + @Inject() + private readonly repo: NotificationRepo + + async findMany():Promise<NotificationModel[]>{ + + return this.repo.findMany() + } + async findById(id: NotificationModel['id']): Promise<NotificationModel | null>{ + + return this.repo.findById(id) + } + async findByAction(action_id: NotificationModel['action_id']): Promise<NotificationModel | null>{ + + return this.repo.findByAction(action_id) + } + async findByActorUser(actor_user_id: NotificationModel['actor_user_id']): Promise<NotificationModel | null>{ + + return this.repo.findByActorUser(actor_user_id) + } + async findByTargetUser(target_user_id: NotificationModel['target_user_id']): Promise<NotificationModel | null>{ + + return this.repo.findByTargetUser(target_user_id) + } + async findByTargetResource(target_resource_id: NotificationModel['target_resource_id']): Promise<NotificationModel | null>{ + + return this.repo.findByTargetResource(target_resource_id) + } + async findByTargetCollection(target_collection_id: NotificationModel['target_collection_id']): Promise<NotificationModel | null>{ + + return this.repo.findByTargetCollection(target_collection_id) + } + async create(notification: NotificationInput, tx?: db): Promise<NotificationModel>{ + + return this.repo.create(notification, tx) + } + async update(notification: NotificationUpdate): Promise<NotificationModel>{ + + return this.repo.update(notification) + } + async delete(id: NotificationModel['id']): Promise<NotificationModel>{ + + return this.repo.delete(id) + } +} \ No newline at end of file