diff --git a/bun.lockb b/bun.lockb new file mode 100755 index 0000000000000000000000000000000000000000..c6fab67ceda4fd6f25551f4c2a416322ac7ac6ae Binary files /dev/null and b/bun.lockb differ diff --git a/package.json b/package.json index fe9262e491868543cf85292f797cfbf5aa117c18..dc6c791f39f0e0e41553932347c303a78fd7e115 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "hono-backend", "scripts": { - "dev": "bun run --port '4000' --hot --watch src/index.ts", + "dev": "bun run --port '3000' --hot --watch src/index.ts", "db:generate": "drizzle-kit generate", "db:migrate": "cross-env DB_MIGRATING=true bun run src/db/migrate.ts", "db:seed": "cross-env DB_SEEDING=true bun run src/db/seed.ts", diff --git a/src/db/migrations/0000_daffy_sentinel.sql b/src/db/migrations/0000_daffy_sentinel.sql new file mode 100644 index 0000000000000000000000000000000000000000..f19b960224aa3b90eed56ffb4168696c5a8b9268 --- /dev/null +++ b/src/db/migrations/0000_daffy_sentinel.sql @@ -0,0 +1,672 @@ +DO $$ BEGIN + CREATE TYPE "public"."complaints_state" AS ENUM('complained', 'rejected', 'accepted'); +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + CREATE TYPE "public"."resource_state" AS ENUM('draft', 'submitted', 'accepted', 'reported', 'deleted'); +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + CREATE TYPE "public"."review_state" AS ENUM('active', 'inactive', 'under_review'); +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "achievements" ( + "id" serial PRIMARY KEY NOT NULL, + "name" varchar(255) NOT NULL, + "description" text, + "reward_experience" numeric, + "reward_points" numeric, + "review_state" "review_state" DEFAULT 'under_review' 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 "achievements_id_unique" UNIQUE("id") +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "actions" ( + "id" serial PRIMARY KEY NOT NULL, + "name" varchar(255) NOT NULL, + "created_at" timestamp DEFAULT now() NOT NULL, + "updated_at" timestamp DEFAULT now() NOT NULL, + CONSTRAINT "actions_id_unique" UNIQUE("id") +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "collection_likes" ( + "id" serial PRIMARY KEY NOT NULL, + "user_id" integer NOT NULL, + "collection_id" integer NOT NULL, + CONSTRAINT "collection_likes_id_unique" UNIQUE("id") +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "collection_resources" ( + "id" serial PRIMARY KEY NOT NULL, + "collection_id" integer NOT NULL, + "resource_id" integer NOT NULL, + CONSTRAINT "collection_resources_id_unique" UNIQUE("id") +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "collection_stats" ( + "id" serial PRIMARY KEY NOT NULL, + "views" integer DEFAULT 0 NOT NULL, + "downloads" integer DEFAULT 0 NOT NULL, + "likes" integer DEFAULT 0 NOT NULL, + "shares" integer DEFAULT 0 NOT NULL, + "score" numeric DEFAULT '0.0' NOT NULL, + "follows" integer DEFAULT 0 NOT NULL, + CONSTRAINT "collection_stats_id_unique" UNIQUE("id") +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "collections" ( + "id" serial PRIMARY KEY NOT NULL, + "name" varchar(255) NOT NULL, + "description" text, + "is_private" boolean DEFAULT false, + "is_active" boolean, + "created_at" timestamp DEFAULT now() NOT NULL, + "updated_at" timestamp DEFAULT now() NOT NULL, + "deleted_at" timestamp, + "thumbnail" varchar(255), + "user_id" integer NOT NULL, + "collection_stats_id" integer NOT NULL, + CONSTRAINT "collections_id_unique" UNIQUE("id"), + CONSTRAINT "collections_collection_stats_id_unique" UNIQUE("collection_stats_id") +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "commentReply" ( + "id" serial PRIMARY KEY NOT NULL, + "user_id" integer NOT NULL, + "comment_id" integer NOT NULL, + "text" text NOT NULL, + "created_at" timestamp DEFAULT now() NOT NULL, + "deleted_at" timestamp, + "update_at" timestamp DEFAULT now() NOT NULL, + CONSTRAINT "commentReply_id_unique" UNIQUE("id") +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "comments" ( + "id" serial PRIMARY KEY NOT NULL, + "user_id" integer NOT NULL, + "resource_id" integer NOT NULL, + "text" text NOT NULL, + "created_at" timestamp DEFAULT now() NOT NULL, + "deleted_at" timestamp, + "updated_at" timestamp DEFAULT now() NOT NULL, + CONSTRAINT "comments_id_unique" UNIQUE("id") +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "complaints" ( + "id" serial PRIMARY KEY NOT NULL, + "state" "complaints_state" DEFAULT 'complained' NOT NULL, + "description" text NOT NULL, + "denouncer_id" integer NOT NULL, + "resource_id" integer NOT NULL, + "collection_id" integer, + "user_id" integer, + "evaluated_at" timestamp, + "created_at" timestamp DEFAULT now() NOT NULL, + "q1" boolean, + "q2" boolean, + "q3" boolean, + "q4" boolean, + "q5" boolean, + "q6" boolean, + "q7" boolean, + CONSTRAINT "complaints_id_unique" UNIQUE("id") +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "educational_stages" ( + "id" serial PRIMARY KEY NOT NULL, + "name" varchar(255) NOT NULL, + CONSTRAINT "educational_stages_id_unique" UNIQUE("id") +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "followers" ( + "id" serial PRIMARY KEY NOT NULL, + "user_id" integer NOT NULL, + "follower_id" integer NOT NULL, + CONSTRAINT "followers_id_unique" UNIQUE("id") +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "institutions" ( + "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 "institutions_id_unique" UNIQUE("id") +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "item_achievements" ( + "item_id" integer NOT NULL, + "achievement_id" integer NOT NULL, + CONSTRAINT "item_achievements_item_id_achievement_id_pk" PRIMARY KEY("item_id","achievement_id") +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "items" ( + "id" serial PRIMARY KEY NOT NULL, + "name" varchar(255) NOT NULL, + "price" numeric, + "discount" numeric, + "description" text, + "is_active" boolean DEFAULT false, + "created_at" timestamp DEFAULT now() NOT NULL, + "updated_at" timestamp DEFAULT now() NOT NULL, + CONSTRAINT "items_id_unique" UNIQUE("id") +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "languages" ( + "id" serial PRIMARY KEY NOT NULL, + "name" varchar(255) NOT NULL, + "code" varchar(10) NOT NULL, + CONSTRAINT "languages_id_unique" UNIQUE("id"), + CONSTRAINT "languages_code_unique" UNIQUE("code") +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "licenses" ( + "id" serial PRIMARY KEY NOT NULL, + "name" varchar(255) NOT NULL, + "description" text NOT NULL, + "url" varchar(255) NOT NULL, + CONSTRAINT "licenses_id_unique" UNIQUE("id") +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "notifications" ( + "id" serial PRIMARY KEY NOT NULL, + "owner_id" integer NOT NULL, + "action_id" integer NOT NULL, + "actor_user_id" integer NOT NULL, + "target_user_id" integer, + "target_resource_id" integer, + "target_collection_id" integer, + "viewed" boolean DEFAULT false, + "created_at" timestamp DEFAULT now() NOT NULL, + "updated_at" timestamp DEFAULT now() NOT NULL, + CONSTRAINT "notifications_id_unique" UNIQUE("id") +); +--> 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 "resource_educational_stages" ( + "id" serial PRIMARY KEY NOT NULL, + "resource_id" integer NOT NULL, + "educational_stage_id" integer NOT NULL, + CONSTRAINT "resource_educational_stages_id_unique" UNIQUE("id") +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "resource_languages" ( + "id" serial PRIMARY KEY NOT NULL, + "resource_id" integer NOT NULL, + "language_id" integer NOT NULL, + CONSTRAINT "resource_languages_id_unique" UNIQUE("id") +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "resource_likes" ( + "id" serial PRIMARY KEY NOT NULL, + "user_id" integer NOT NULL, + "resource_id" integer NOT NULL, + CONSTRAINT "resource_likes_id_unique" UNIQUE("id") +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "resource_stats" ( + "id" serial PRIMARY KEY NOT NULL, + "views" integer DEFAULT 0 NOT NULL, + "downloads" integer DEFAULT 0 NOT NULL, + "likes" integer DEFAULT 0 NOT NULL, + "shares" integer DEFAULT 0 NOT NULL, + "score" numeric DEFAULT '0.0' NOT NULL, + "follows" integer DEFAULT 0 NOT NULL, + "comments" integer DEFAULT 0 NOT NULL, + CONSTRAINT "resource_stats_id_unique" UNIQUE("id") +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "resource_subjects" ( + "id" serial PRIMARY KEY NOT NULL, + "resource_id" integer NOT NULL, + "subject_id" integer NOT NULL, + CONSTRAINT "resource_subjects_id_unique" UNIQUE("id") +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "resources" ( + "id" serial PRIMARY KEY NOT NULL, + "state" "resource_state" DEFAULT 'draft' NOT NULL, + "name" varchar(255) NOT NULL, + "author" varchar(255) NOT NULL, + "link" varchar(255), + "thumbnail" varchar(255), + "description" text, + "created_at" timestamp DEFAULT now() NOT NULL, + "updated_at" timestamp DEFAULT now() NOT NULL, + "published_at" timestamp, + "submitted_at" timestamp, + "deleted_at" timestamp, + "user_id" integer NOT NULL, + "resource_stats_id" integer NOT NULL, + "object_type_id" integer NOT NULL, + "license_id" integer NOT NULL, + CONSTRAINT "resources_id_unique" UNIQUE("id"), + CONSTRAINT "resources_resource_stats_id_unique" UNIQUE("resource_stats_id") +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "roles" ( + "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 "roles_id_unique" UNIQUE("id"), + CONSTRAINT "roles_name_unique" UNIQUE("name") +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "subjects" ( + "id" serial PRIMARY KEY NOT NULL, + "name" varchar(255) NOT NULL, + CONSTRAINT "subjects_id_unique" UNIQUE("id") +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "submissions" ( + "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, + "created_at" timestamp DEFAULT now() NOT NULL, + "updated_at" timestamp DEFAULT now() NOT NULL, + "answered_at" timestamp, + "q1" boolean, + "q2" boolean, + "q3" boolean, + "q4" boolean, + CONSTRAINT "submissions_id_unique" UNIQUE("id") +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "user_achievements" ( + "id" serial PRIMARY KEY NOT NULL, + "user_id" integer NOT NULL, + "achievement_id" integer NOT NULL, + CONSTRAINT "user_achievements_id_unique" UNIQUE("id") +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "user_collections" ( + "id" serial PRIMARY KEY NOT NULL, + "user_id" integer NOT NULL, + "collection_id" integer NOT NULL, + CONSTRAINT "user_collections_id_unique" UNIQUE("id") +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "user_institutions" ( + "id" serial PRIMARY KEY NOT NULL, + "user_id" integer NOT NULL, + "institution_id" integer NOT NULL, + CONSTRAINT "user_institutions_id_unique" UNIQUE("id") +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "user_items" ( + "id" serial PRIMARY KEY NOT NULL, + "user_id" integer NOT NULL, + "item_id" integer NOT NULL, + CONSTRAINT "user_items_id_unique" UNIQUE("id") +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "user_roles" ( + "id" serial PRIMARY KEY NOT NULL, + "user_id" integer NOT NULL, + "role_id" integer NOT NULL, + CONSTRAINT "user_roles_id_unique" UNIQUE("id") +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "user_stats" ( + "id" serial PRIMARY KEY NOT NULL, + "score" numeric DEFAULT '0.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 "users" ( + "id" serial PRIMARY KEY NOT NULL, + "name" varchar(255) NOT NULL, + "username" varchar(255), + "password" varchar(255), + "email" varchar(255) NOT NULL, + "description" text DEFAULT 'sem descrição', + "birthday" timestamp, + "cpf" varchar(11) 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, + "is_active" boolean DEFAULT true, + "user_stats_id" integer NOT NULL, + "level" integer DEFAULT 1, + "experience" integer DEFAULT 0, + "points" integer DEFAULT 0, + "level_xp" integer DEFAULT 0, + CONSTRAINT "users_id_unique" UNIQUE("id"), + CONSTRAINT "users_username_unique" UNIQUE("username"), + CONSTRAINT "users_email_unique" UNIQUE("email"), + CONSTRAINT "users_cpf_unique" UNIQUE("cpf"), + CONSTRAINT "users_user_stats_id_unique" UNIQUE("user_stats_id") +); +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "collection_likes" ADD CONSTRAINT "collection_likes_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("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_id_collections_id_fk" FOREIGN KEY ("collection_id") REFERENCES "public"."collections"("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_collections_id_fk" FOREIGN KEY ("collection_id") REFERENCES "public"."collections"("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_resources_id_fk" FOREIGN KEY ("resource_id") REFERENCES "public"."resources"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "collections" ADD CONSTRAINT "collections_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "collections" ADD CONSTRAINT "collections_collection_stats_id_collection_stats_id_fk" FOREIGN KEY ("collection_stats_id") REFERENCES "public"."collection_stats"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "commentReply" ADD CONSTRAINT "commentReply_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "commentReply" ADD CONSTRAINT "commentReply_comment_id_comments_id_fk" FOREIGN KEY ("comment_id") REFERENCES "public"."comments"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "comments" ADD CONSTRAINT "comments_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "comments" ADD CONSTRAINT "comments_resource_id_resources_id_fk" FOREIGN KEY ("resource_id") REFERENCES "public"."resources"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "complaints" ADD CONSTRAINT "complaints_denouncer_id_users_id_fk" FOREIGN KEY ("denouncer_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "complaints" ADD CONSTRAINT "complaints_resource_id_resources_id_fk" FOREIGN KEY ("resource_id") REFERENCES "public"."resources"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "complaints" ADD CONSTRAINT "complaints_collection_id_collections_id_fk" FOREIGN KEY ("collection_id") REFERENCES "public"."collections"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "complaints" ADD CONSTRAINT "complaints_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "followers" ADD CONSTRAINT "followers_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "followers" ADD CONSTRAINT "followers_follower_id_users_id_fk" FOREIGN KEY ("follower_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "item_achievements" ADD CONSTRAINT "item_achievements_item_id_items_id_fk" FOREIGN KEY ("item_id") REFERENCES "public"."items"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "item_achievements" ADD CONSTRAINT "item_achievements_achievement_id_achievements_id_fk" FOREIGN KEY ("achievement_id") REFERENCES "public"."achievements"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "notifications" ADD CONSTRAINT "notifications_owner_id_users_id_fk" FOREIGN KEY ("owner_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "notifications" ADD CONSTRAINT "notifications_action_id_actions_id_fk" FOREIGN KEY ("action_id") REFERENCES "public"."actions"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "notifications" ADD CONSTRAINT "notifications_actor_user_id_users_id_fk" FOREIGN KEY ("actor_user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "notifications" ADD CONSTRAINT "notifications_target_user_id_users_id_fk" FOREIGN KEY ("target_user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "notifications" ADD CONSTRAINT "notifications_target_resource_id_resources_id_fk" FOREIGN KEY ("target_resource_id") REFERENCES "public"."resources"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "notifications" ADD CONSTRAINT "notifications_target_collection_id_collections_id_fk" FOREIGN KEY ("target_collection_id") REFERENCES "public"."collections"("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_resources_id_fk" FOREIGN KEY ("resource_id") REFERENCES "public"."resources"("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_resources_id_fk" FOREIGN KEY ("resource_id") REFERENCES "public"."resources"("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_languages_id_fk" FOREIGN KEY ("language_id") REFERENCES "public"."languages"("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_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("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_resources_id_fk" FOREIGN KEY ("resource_id") REFERENCES "public"."resources"("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_resources_id_fk" FOREIGN KEY ("resource_id") REFERENCES "public"."resources"("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 "resources" ADD CONSTRAINT "resources_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "resources" ADD CONSTRAINT "resources_resource_stats_id_resource_stats_id_fk" FOREIGN KEY ("resource_stats_id") REFERENCES "public"."resource_stats"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "resources" ADD CONSTRAINT "resources_object_type_id_object_types_id_fk" FOREIGN KEY ("object_type_id") REFERENCES "public"."object_types"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "resources" ADD CONSTRAINT "resources_license_id_licenses_id_fk" FOREIGN KEY ("license_id") REFERENCES "public"."licenses"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "submissions" ADD CONSTRAINT "submissions_resource_id_resources_id_fk" FOREIGN KEY ("resource_id") REFERENCES "public"."resources"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "submissions" ADD CONSTRAINT "submissions_submitter_id_users_id_fk" FOREIGN KEY ("submitter_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "submissions" ADD CONSTRAINT "submissions_curator_id_users_id_fk" FOREIGN KEY ("curator_id") REFERENCES "public"."users"("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_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("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_users_id_fk" FOREIGN KEY ("achievement_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "user_collections" ADD CONSTRAINT "user_collections_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "user_collections" ADD CONSTRAINT "user_collections_collection_id_collections_id_fk" FOREIGN KEY ("collection_id") REFERENCES "public"."collections"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "user_institutions" ADD CONSTRAINT "user_institutions_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "user_institutions" ADD CONSTRAINT "user_institutions_institution_id_institutions_id_fk" FOREIGN KEY ("institution_id") REFERENCES "public"."institutions"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "user_items" ADD CONSTRAINT "user_items_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "user_items" ADD CONSTRAINT "user_items_item_id_items_id_fk" FOREIGN KEY ("item_id") REFERENCES "public"."items"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "user_roles" ADD CONSTRAINT "user_roles_user_id_users_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "user_roles" ADD CONSTRAINT "user_roles_role_id_roles_id_fk" FOREIGN KEY ("role_id") REFERENCES "public"."roles"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "users" ADD CONSTRAINT "users_user_stats_id_user_stats_id_fk" FOREIGN KEY ("user_stats_id") REFERENCES "public"."user_stats"("id") ON DELETE no action ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; diff --git a/src/db/migrations/0001_bouncy_valkyrie.sql b/src/db/migrations/0001_bouncy_valkyrie.sql deleted file mode 100644 index 9f33f0696818dd1e393f9f56ea7601c752c9fe1e..0000000000000000000000000000000000000000 --- a/src/db/migrations/0001_bouncy_valkyrie.sql +++ /dev/null @@ -1 +0,0 @@ -DROP TABLE "notifications"; \ No newline at end of file diff --git a/src/db/migrations/0002_melodic_baron_strucker.sql b/src/db/migrations/0002_melodic_baron_strucker.sql deleted file mode 100644 index cca2115757e93bd993f7b6cd7f4ce86f4792e1a7..0000000000000000000000000000000000000000 --- a/src/db/migrations/0002_melodic_baron_strucker.sql +++ /dev/null @@ -1,4 +0,0 @@ -ALTER TABLE "resources" RENAME COLUMN "resource_state" TO "state";--> statement-breakpoint -ALTER TABLE "complaints" ADD COLUMN "q5" boolean;--> statement-breakpoint -ALTER TABLE "complaints" ADD COLUMN "q6" boolean;--> statement-breakpoint -ALTER TABLE "complaints" ADD COLUMN "q7" boolean; \ No newline at end of file diff --git a/src/db/migrations/0002_thankful_captain_midlands.sql b/src/db/migrations/0002_thankful_captain_midlands.sql deleted file mode 100644 index 031cfae25cd5de4dd12cf85e54bd474a2c4f9140..0000000000000000000000000000000000000000 --- a/src/db/migrations/0002_thankful_captain_midlands.sql +++ /dev/null @@ -1,49 +0,0 @@ -CREATE TABLE IF NOT EXISTS "notifications" ( - "id" serial PRIMARY KEY NOT NULL, - "owner_id" integer NOT NULL, - "action_id" integer NOT NULL, - "actor_user_id" integer, - "target_user_id" integer, - "target_resource_id" integer, - "target_collection_id" integer, - "viewed" boolean DEFAULT false, - "created_at" timestamp DEFAULT now() NOT NULL, - "updated_at" timestamp DEFAULT now() NOT NULL, - CONSTRAINT "notifications_id_unique" UNIQUE("id") -); ---> statement-breakpoint -DO $$ BEGIN - ALTER TABLE "notifications" ADD CONSTRAINT "notifications_owner_id_users_id_fk" FOREIGN KEY ("owner_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action; -EXCEPTION - WHEN duplicate_object THEN null; -END $$; ---> statement-breakpoint -DO $$ BEGIN - ALTER TABLE "notifications" ADD CONSTRAINT "notifications_action_id_actions_id_fk" FOREIGN KEY ("action_id") REFERENCES "public"."actions"("id") ON DELETE cascade ON UPDATE no action; -EXCEPTION - WHEN duplicate_object THEN null; -END $$; ---> statement-breakpoint -DO $$ BEGIN - ALTER TABLE "notifications" ADD CONSTRAINT "notifications_actor_user_id_users_id_fk" FOREIGN KEY ("actor_user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action; -EXCEPTION - WHEN duplicate_object THEN null; -END $$; ---> statement-breakpoint -DO $$ BEGIN - ALTER TABLE "notifications" ADD CONSTRAINT "notifications_target_user_id_users_id_fk" FOREIGN KEY ("target_user_id") REFERENCES "public"."users"("id") ON DELETE cascade ON UPDATE no action; -EXCEPTION - WHEN duplicate_object THEN null; -END $$; ---> statement-breakpoint -DO $$ BEGIN - ALTER TABLE "notifications" ADD CONSTRAINT "notifications_target_resource_id_resources_id_fk" FOREIGN KEY ("target_resource_id") REFERENCES "public"."resources"("id") ON DELETE cascade ON UPDATE no action; -EXCEPTION - WHEN duplicate_object THEN null; -END $$; ---> statement-breakpoint -DO $$ BEGIN - ALTER TABLE "notifications" ADD CONSTRAINT "notifications_target_collection_id_collections_id_fk" FOREIGN KEY ("target_collection_id") REFERENCES "public"."collections"("id") ON DELETE cascade ON UPDATE no action; -EXCEPTION - WHEN duplicate_object THEN null; -END $$; diff --git a/src/db/migrations/0003_mysterious_the_fallen.sql b/src/db/migrations/0003_mysterious_the_fallen.sql deleted file mode 100644 index 9d889c1c3d593938c9a76d9538699b26591cbe08..0000000000000000000000000000000000000000 --- a/src/db/migrations/0003_mysterious_the_fallen.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE "notifications" ALTER COLUMN "actor_user_id" SET NOT NULL; \ No newline at end of file diff --git a/src/db/migrations/meta/0000_snapshot.json b/src/db/migrations/meta/0000_snapshot.json index 62c7e28a280c927f41ece9f20cf51c2e1a2009ba..614bf452ca708d1b4451b0984cfcbc6ed88c1974 100644 --- a/src/db/migrations/meta/0000_snapshot.json +++ b/src/db/migrations/meta/0000_snapshot.json @@ -1,5 +1,5 @@ { - "id": "69415c6c-8351-4948-b467-c4c262bf063e", + "id": "17e5bf00-dd96-41e3-bf35-afd7c7d13881", "prevId": "00000000-0000-0000-0000-000000000000", "version": "7", "dialect": "postgresql", @@ -1183,7 +1183,7 @@ "name": "actor_user_id", "type": "integer", "primaryKey": false, - "notNull": false + "notNull": true }, "target_user_id": { "name": "target_user_id", @@ -1682,8 +1682,8 @@ "primaryKey": true, "notNull": true }, - "resource_state": { - "name": "resource_state", + "state": { + "name": "state", "type": "resource_state", "typeSchema": "public", "primaryKey": false, @@ -2505,13 +2505,13 @@ "name": "username", "type": "varchar(255)", "primaryKey": false, - "notNull": true + "notNull": false }, "password": { "name": "password", "type": "varchar(255)", "primaryKey": false, - "notNull": true + "notNull": false }, "email": { "name": "email", @@ -2530,7 +2530,7 @@ "name": "birthday", "type": "timestamp", "primaryKey": false, - "notNull": true + "notNull": false }, "cpf": { "name": "cpf", diff --git a/src/db/migrations/meta/0002_snapshot.json b/src/db/migrations/meta/0002_snapshot.json deleted file mode 100644 index a0d9e2db02b8ec311c35c5bd01b45f174a3340a3..0000000000000000000000000000000000000000 --- a/src/db/migrations/meta/0002_snapshot.json +++ /dev/null @@ -1,2714 +0,0 @@ -{ - "id": "9feef775-e14c-4a3d-a342-bb281dd95fa3", - "prevId": "5839f5ff-e09a-433f-9517-b6d374d4521f", - "version": "7", - "dialect": "postgresql", - "tables": { - "public.achievements": { - "name": "achievements", - "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 - }, - "review_state": { - "name": "review_state", - "type": "review_state", - "typeSchema": "public", - "primaryKey": false, - "notNull": true, - "default": "'under_review'" - }, - "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": { - "achievements_id_unique": { - "name": "achievements_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - } - } - }, - "public.actions": { - "name": "actions", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "name": { - "name": "name", - "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()" - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "actions_id_unique": { - "name": "actions_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - } - } - }, - "public.collection_likes": { - "name": "collection_likes", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "user_id": { - "name": "user_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "collection_id": { - "name": "collection_id", - "type": "integer", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": { - "collection_likes_user_id_users_id_fk": { - "name": "collection_likes_user_id_users_id_fk", - "tableFrom": "collection_likes", - "tableTo": "users", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "collection_likes_collection_id_collections_id_fk": { - "name": "collection_likes_collection_id_collections_id_fk", - "tableFrom": "collection_likes", - "tableTo": "collections", - "columnsFrom": [ - "collection_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "collection_likes_id_unique": { - "name": "collection_likes_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - } - } - }, - "public.collection_resources": { - "name": "collection_resources", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "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_collections_id_fk": { - "name": "collection_resources_collection_id_collections_id_fk", - "tableFrom": "collection_resources", - "tableTo": "collections", - "columnsFrom": [ - "collection_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "collection_resources_resource_id_resources_id_fk": { - "name": "collection_resources_resource_id_resources_id_fk", - "tableFrom": "collection_resources", - "tableTo": "resources", - "columnsFrom": [ - "resource_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "collection_resources_id_unique": { - "name": "collection_resources_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - } - } - }, - "public.collection_stats": { - "name": "collection_stats", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "views": { - "name": "views", - "type": "integer", - "primaryKey": false, - "notNull": true, - "default": 0 - }, - "downloads": { - "name": "downloads", - "type": "integer", - "primaryKey": false, - "notNull": true, - "default": 0 - }, - "likes": { - "name": "likes", - "type": "integer", - "primaryKey": false, - "notNull": true, - "default": 0 - }, - "shares": { - "name": "shares", - "type": "integer", - "primaryKey": false, - "notNull": true, - "default": 0 - }, - "score": { - "name": "score", - "type": "numeric", - "primaryKey": false, - "notNull": true, - "default": "'0.0'" - }, - "follows": { - "name": "follows", - "type": "integer", - "primaryKey": false, - "notNull": true, - "default": 0 - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "collection_stats_id_unique": { - "name": "collection_stats_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - } - } - }, - "public.collections": { - "name": "collections", - "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 - }, - "is_private": { - "name": "is_private", - "type": "boolean", - "primaryKey": false, - "notNull": false, - "default": false - }, - "is_active": { - "name": "is_active", - "type": "boolean", - "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()" - }, - "deleted_at": { - "name": "deleted_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false - }, - "thumbnail": { - "name": "thumbnail", - "type": "varchar(255)", - "primaryKey": false, - "notNull": false - }, - "user_id": { - "name": "user_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "collection_stats_id": { - "name": "collection_stats_id", - "type": "integer", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": { - "collections_user_id_users_id_fk": { - "name": "collections_user_id_users_id_fk", - "tableFrom": "collections", - "tableTo": "users", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "collections_collection_stats_id_collection_stats_id_fk": { - "name": "collections_collection_stats_id_collection_stats_id_fk", - "tableFrom": "collections", - "tableTo": "collection_stats", - "columnsFrom": [ - "collection_stats_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "collections_id_unique": { - "name": "collections_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - }, - "collections_collection_stats_id_unique": { - "name": "collections_collection_stats_id_unique", - "nullsNotDistinct": false, - "columns": [ - "collection_stats_id" - ] - } - } - }, - "public.commentReply": { - "name": "commentReply", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "user_id": { - "name": "user_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "comment_id": { - "name": "comment_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "text": { - "name": "text", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "default": "now()" - }, - "deleted_at": { - "name": "deleted_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false - }, - "update_at": { - "name": "update_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "default": "now()" - } - }, - "indexes": {}, - "foreignKeys": { - "commentReply_user_id_users_id_fk": { - "name": "commentReply_user_id_users_id_fk", - "tableFrom": "commentReply", - "tableTo": "users", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "commentReply_comment_id_comments_id_fk": { - "name": "commentReply_comment_id_comments_id_fk", - "tableFrom": "commentReply", - "tableTo": "comments", - "columnsFrom": [ - "comment_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "commentReply_id_unique": { - "name": "commentReply_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - } - } - }, - "public.comments": { - "name": "comments", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "user_id": { - "name": "user_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "resource_id": { - "name": "resource_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "text": { - "name": "text", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "default": "now()" - }, - "deleted_at": { - "name": "deleted_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "default": "now()" - } - }, - "indexes": {}, - "foreignKeys": { - "comments_user_id_users_id_fk": { - "name": "comments_user_id_users_id_fk", - "tableFrom": "comments", - "tableTo": "users", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "comments_resource_id_resources_id_fk": { - "name": "comments_resource_id_resources_id_fk", - "tableFrom": "comments", - "tableTo": "resources", - "columnsFrom": [ - "resource_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "comments_id_unique": { - "name": "comments_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - } - } - }, - "public.complaints": { - "name": "complaints", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "state": { - "name": "state", - "type": "complaints_state", - "typeSchema": "public", - "primaryKey": false, - "notNull": true, - "default": "'complained'" - }, - "description": { - "name": "description", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "denouncer_id": { - "name": "denouncer_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "resource_id": { - "name": "resource_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "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 - }, - "q5": { - "name": "q5", - "type": "boolean", - "primaryKey": false, - "notNull": false - }, - "q6": { - "name": "q6", - "type": "boolean", - "primaryKey": false, - "notNull": false - }, - "q7": { - "name": "q7", - "type": "boolean", - "primaryKey": false, - "notNull": false - } - }, - "indexes": {}, - "foreignKeys": { - "complaints_denouncer_id_users_id_fk": { - "name": "complaints_denouncer_id_users_id_fk", - "tableFrom": "complaints", - "tableTo": "users", - "columnsFrom": [ - "denouncer_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "complaints_resource_id_resources_id_fk": { - "name": "complaints_resource_id_resources_id_fk", - "tableFrom": "complaints", - "tableTo": "resources", - "columnsFrom": [ - "resource_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "complaints_collection_id_collections_id_fk": { - "name": "complaints_collection_id_collections_id_fk", - "tableFrom": "complaints", - "tableTo": "collections", - "columnsFrom": [ - "collection_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "complaints_user_id_users_id_fk": { - "name": "complaints_user_id_users_id_fk", - "tableFrom": "complaints", - "tableTo": "users", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "complaints_id_unique": { - "name": "complaints_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - } - } - }, - "public.educational_stages": { - "name": "educational_stages", - "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": { - "educational_stages_id_unique": { - "name": "educational_stages_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - } - } - }, - "public.followers": { - "name": "followers", - "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": { - "followers_user_id_users_id_fk": { - "name": "followers_user_id_users_id_fk", - "tableFrom": "followers", - "tableTo": "users", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "followers_follower_id_users_id_fk": { - "name": "followers_follower_id_users_id_fk", - "tableFrom": "followers", - "tableTo": "users", - "columnsFrom": [ - "follower_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "followers_id_unique": { - "name": "followers_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - } - } - }, - "public.institutions": { - "name": "institutions", - "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": { - "institutions_id_unique": { - "name": "institutions_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - } - } - }, - "public.item_achievements": { - "name": "item_achievements", - "schema": "", - "columns": { - "item_id": { - "name": "item_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "achievement_id": { - "name": "achievement_id", - "type": "integer", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": { - "item_achievements_item_id_items_id_fk": { - "name": "item_achievements_item_id_items_id_fk", - "tableFrom": "item_achievements", - "tableTo": "items", - "columnsFrom": [ - "item_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "item_achievements_achievement_id_achievements_id_fk": { - "name": "item_achievements_achievement_id_achievements_id_fk", - "tableFrom": "item_achievements", - "tableTo": "achievements", - "columnsFrom": [ - "achievement_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": { - "item_achievements_item_id_achievement_id_pk": { - "name": "item_achievements_item_id_achievement_id_pk", - "columns": [ - "item_id", - "achievement_id" - ] - } - }, - "uniqueConstraints": {} - }, - "public.items": { - "name": "items", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "name": { - "name": "name", - "type": "varchar(255)", - "primaryKey": false, - "notNull": true - }, - "price": { - "name": "price", - "type": "numeric", - "primaryKey": false, - "notNull": false - }, - "discount": { - "name": "discount", - "type": "numeric", - "primaryKey": false, - "notNull": false - }, - "description": { - "name": "description", - "type": "text", - "primaryKey": false, - "notNull": false - }, - "is_active": { - "name": "is_active", - "type": "boolean", - "primaryKey": false, - "notNull": false, - "default": 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": { - "items_id_unique": { - "name": "items_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - } - } - }, - "public.languages": { - "name": "languages", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "name": { - "name": "name", - "type": "varchar(255)", - "primaryKey": false, - "notNull": true - }, - "code": { - "name": "code", - "type": "varchar(10)", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "languages_id_unique": { - "name": "languages_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - }, - "languages_code_unique": { - "name": "languages_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(255)", - "primaryKey": false, - "notNull": true - }, - "description": { - "name": "description", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "url": { - "name": "url", - "type": "varchar(255)", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "licenses_id_unique": { - "name": "licenses_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - } - } - }, - "public.notifications": { - "name": "notifications", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "owner_id": { - "name": "owner_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "action_id": { - "name": "action_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "actor_user_id": { - "name": "actor_user_id", - "type": "integer", - "primaryKey": false, - "notNull": false - }, - "target_user_id": { - "name": "target_user_id", - "type": "integer", - "primaryKey": false, - "notNull": false - }, - "target_resource_id": { - "name": "target_resource_id", - "type": "integer", - "primaryKey": false, - "notNull": false - }, - "target_collection_id": { - "name": "target_collection_id", - "type": "integer", - "primaryKey": false, - "notNull": false - }, - "viewed": { - "name": "viewed", - "type": "boolean", - "primaryKey": false, - "notNull": false, - "default": 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": { - "notifications_owner_id_users_id_fk": { - "name": "notifications_owner_id_users_id_fk", - "tableFrom": "notifications", - "tableTo": "users", - "columnsFrom": [ - "owner_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "notifications_action_id_actions_id_fk": { - "name": "notifications_action_id_actions_id_fk", - "tableFrom": "notifications", - "tableTo": "actions", - "columnsFrom": [ - "action_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "notifications_actor_user_id_users_id_fk": { - "name": "notifications_actor_user_id_users_id_fk", - "tableFrom": "notifications", - "tableTo": "users", - "columnsFrom": [ - "actor_user_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "notifications_target_user_id_users_id_fk": { - "name": "notifications_target_user_id_users_id_fk", - "tableFrom": "notifications", - "tableTo": "users", - "columnsFrom": [ - "target_user_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "notifications_target_resource_id_resources_id_fk": { - "name": "notifications_target_resource_id_resources_id_fk", - "tableFrom": "notifications", - "tableTo": "resources", - "columnsFrom": [ - "target_resource_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "notifications_target_collection_id_collections_id_fk": { - "name": "notifications_target_collection_id_collections_id_fk", - "tableFrom": "notifications", - "tableTo": "collections", - "columnsFrom": [ - "target_collection_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "notifications_id_unique": { - "name": "notifications_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - } - } - }, - "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.resource_educational_stages": { - "name": "resource_educational_stages", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "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_resources_id_fk": { - "name": "resource_educational_stages_resource_id_resources_id_fk", - "tableFrom": "resource_educational_stages", - "tableTo": "resources", - "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": { - "resource_educational_stages_id_unique": { - "name": "resource_educational_stages_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - } - } - }, - "public.resource_languages": { - "name": "resource_languages", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "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_resources_id_fk": { - "name": "resource_languages_resource_id_resources_id_fk", - "tableFrom": "resource_languages", - "tableTo": "resources", - "columnsFrom": [ - "resource_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "resource_languages_language_id_languages_id_fk": { - "name": "resource_languages_language_id_languages_id_fk", - "tableFrom": "resource_languages", - "tableTo": "languages", - "columnsFrom": [ - "language_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "resource_languages_id_unique": { - "name": "resource_languages_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - } - } - }, - "public.resource_likes": { - "name": "resource_likes", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "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_users_id_fk": { - "name": "resource_likes_user_id_users_id_fk", - "tableFrom": "resource_likes", - "tableTo": "users", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "resource_likes_resource_id_resources_id_fk": { - "name": "resource_likes_resource_id_resources_id_fk", - "tableFrom": "resource_likes", - "tableTo": "resources", - "columnsFrom": [ - "resource_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "resource_likes_id_unique": { - "name": "resource_likes_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - } - } - }, - "public.resource_stats": { - "name": "resource_stats", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "views": { - "name": "views", - "type": "integer", - "primaryKey": false, - "notNull": true, - "default": 0 - }, - "downloads": { - "name": "downloads", - "type": "integer", - "primaryKey": false, - "notNull": true, - "default": 0 - }, - "likes": { - "name": "likes", - "type": "integer", - "primaryKey": false, - "notNull": true, - "default": 0 - }, - "shares": { - "name": "shares", - "type": "integer", - "primaryKey": false, - "notNull": true, - "default": 0 - }, - "score": { - "name": "score", - "type": "numeric", - "primaryKey": false, - "notNull": true, - "default": "'0.0'" - }, - "follows": { - "name": "follows", - "type": "integer", - "primaryKey": false, - "notNull": true, - "default": 0 - }, - "comments": { - "name": "comments", - "type": "integer", - "primaryKey": false, - "notNull": true, - "default": 0 - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "resource_stats_id_unique": { - "name": "resource_stats_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - } - } - }, - "public.resource_subjects": { - "name": "resource_subjects", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "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_resources_id_fk": { - "name": "resource_subjects_resource_id_resources_id_fk", - "tableFrom": "resource_subjects", - "tableTo": "resources", - "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": { - "resource_subjects_id_unique": { - "name": "resource_subjects_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - } - } - }, - "public.resources": { - "name": "resources", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "resource_state": { - "name": "resource_state", - "type": "resource_state", - "typeSchema": "public", - "primaryKey": false, - "notNull": true, - "default": "'draft'" - }, - "name": { - "name": "name", - "type": "varchar(255)", - "primaryKey": false, - "notNull": true - }, - "author": { - "name": "author", - "type": "varchar(255)", - "primaryKey": false, - "notNull": true - }, - "link": { - "name": "link", - "type": "varchar(255)", - "primaryKey": false, - "notNull": false - }, - "thumbnail": { - "name": "thumbnail", - "type": "varchar(255)", - "primaryKey": false, - "notNull": false - }, - "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()" - }, - "published_at": { - "name": "published_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false - }, - "submitted_at": { - "name": "submitted_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false - }, - "deleted_at": { - "name": "deleted_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false - }, - "user_id": { - "name": "user_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "resource_stats_id": { - "name": "resource_stats_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "object_type_id": { - "name": "object_type_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "license_id": { - "name": "license_id", - "type": "integer", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": { - "resources_user_id_users_id_fk": { - "name": "resources_user_id_users_id_fk", - "tableFrom": "resources", - "tableTo": "users", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "resources_resource_stats_id_resource_stats_id_fk": { - "name": "resources_resource_stats_id_resource_stats_id_fk", - "tableFrom": "resources", - "tableTo": "resource_stats", - "columnsFrom": [ - "resource_stats_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "resources_object_type_id_object_types_id_fk": { - "name": "resources_object_type_id_object_types_id_fk", - "tableFrom": "resources", - "tableTo": "object_types", - "columnsFrom": [ - "object_type_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "resources_license_id_licenses_id_fk": { - "name": "resources_license_id_licenses_id_fk", - "tableFrom": "resources", - "tableTo": "licenses", - "columnsFrom": [ - "license_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "resources_id_unique": { - "name": "resources_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - }, - "resources_resource_stats_id_unique": { - "name": "resources_resource_stats_id_unique", - "nullsNotDistinct": false, - "columns": [ - "resource_stats_id" - ] - } - } - }, - "public.roles": { - "name": "roles", - "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": { - "roles_id_unique": { - "name": "roles_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - }, - "roles_name_unique": { - "name": "roles_name_unique", - "nullsNotDistinct": false, - "columns": [ - "name" - ] - } - } - }, - "public.subjects": { - "name": "subjects", - "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": { - "subjects_id_unique": { - "name": "subjects_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - } - } - }, - "public.submissions": { - "name": "submissions", - "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": 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()" - }, - "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": { - "submissions_resource_id_resources_id_fk": { - "name": "submissions_resource_id_resources_id_fk", - "tableFrom": "submissions", - "tableTo": "resources", - "columnsFrom": [ - "resource_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "submissions_submitter_id_users_id_fk": { - "name": "submissions_submitter_id_users_id_fk", - "tableFrom": "submissions", - "tableTo": "users", - "columnsFrom": [ - "submitter_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "submissions_curator_id_users_id_fk": { - "name": "submissions_curator_id_users_id_fk", - "tableFrom": "submissions", - "tableTo": "users", - "columnsFrom": [ - "curator_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "submissions_id_unique": { - "name": "submissions_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - } - } - }, - "public.user_achievements": { - "name": "user_achievements", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "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_users_id_fk": { - "name": "user_achievements_user_id_users_id_fk", - "tableFrom": "user_achievements", - "tableTo": "users", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "user_achievements_achievement_id_users_id_fk": { - "name": "user_achievements_achievement_id_users_id_fk", - "tableFrom": "user_achievements", - "tableTo": "users", - "columnsFrom": [ - "achievement_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "user_achievements_id_unique": { - "name": "user_achievements_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - } - } - }, - "public.user_collections": { - "name": "user_collections", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "user_id": { - "name": "user_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "collection_id": { - "name": "collection_id", - "type": "integer", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": { - "user_collections_user_id_users_id_fk": { - "name": "user_collections_user_id_users_id_fk", - "tableFrom": "user_collections", - "tableTo": "users", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "user_collections_collection_id_collections_id_fk": { - "name": "user_collections_collection_id_collections_id_fk", - "tableFrom": "user_collections", - "tableTo": "collections", - "columnsFrom": [ - "collection_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "user_collections_id_unique": { - "name": "user_collections_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - } - } - }, - "public.user_institutions": { - "name": "user_institutions", - "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_institutions_user_id_users_id_fk": { - "name": "user_institutions_user_id_users_id_fk", - "tableFrom": "user_institutions", - "tableTo": "users", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "user_institutions_institution_id_institutions_id_fk": { - "name": "user_institutions_institution_id_institutions_id_fk", - "tableFrom": "user_institutions", - "tableTo": "institutions", - "columnsFrom": [ - "institution_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "user_institutions_id_unique": { - "name": "user_institutions_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - } - } - }, - "public.user_items": { - "name": "user_items", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "user_id": { - "name": "user_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "item_id": { - "name": "item_id", - "type": "integer", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": { - "user_items_user_id_users_id_fk": { - "name": "user_items_user_id_users_id_fk", - "tableFrom": "user_items", - "tableTo": "users", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "user_items_item_id_items_id_fk": { - "name": "user_items_item_id_items_id_fk", - "tableFrom": "user_items", - "tableTo": "items", - "columnsFrom": [ - "item_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "user_items_id_unique": { - "name": "user_items_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - } - } - }, - "public.user_roles": { - "name": "user_roles", - "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_roles_user_id_users_id_fk": { - "name": "user_roles_user_id_users_id_fk", - "tableFrom": "user_roles", - "tableTo": "users", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "user_roles_role_id_roles_id_fk": { - "name": "user_roles_role_id_roles_id_fk", - "tableFrom": "user_roles", - "tableTo": "roles", - "columnsFrom": [ - "role_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "user_roles_id_unique": { - "name": "user_roles_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - } - } - }, - "public.user_stats": { - "name": "user_stats", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "score": { - "name": "score", - "type": "numeric", - "primaryKey": false, - "notNull": true, - "default": "'0.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": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "user_stats_id_unique": { - "name": "user_stats_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - } - } - }, - "public.users": { - "name": "users", - "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'" - }, - "birthday": { - "name": "birthday", - "type": "timestamp", - "primaryKey": false, - "notNull": true - }, - "cpf": { - "name": "cpf", - "type": "varchar(11)", - "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 - }, - "is_active": { - "name": "is_active", - "type": "boolean", - "primaryKey": false, - "notNull": false, - "default": true - }, - "user_stats_id": { - "name": "user_stats_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "level": { - "name": "level", - "type": "integer", - "primaryKey": false, - "notNull": false, - "default": 1 - }, - "experience": { - "name": "experience", - "type": "integer", - "primaryKey": false, - "notNull": false, - "default": 0 - }, - "points": { - "name": "points", - "type": "integer", - "primaryKey": false, - "notNull": false, - "default": 0 - }, - "level_xp": { - "name": "level_xp", - "type": "integer", - "primaryKey": false, - "notNull": false, - "default": 0 - } - }, - "indexes": {}, - "foreignKeys": { - "users_user_stats_id_user_stats_id_fk": { - "name": "users_user_stats_id_user_stats_id_fk", - "tableFrom": "users", - "tableTo": "user_stats", - "columnsFrom": [ - "user_stats_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "users_id_unique": { - "name": "users_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - }, - "users_username_unique": { - "name": "users_username_unique", - "nullsNotDistinct": false, - "columns": [ - "username" - ] - }, - "users_email_unique": { - "name": "users_email_unique", - "nullsNotDistinct": false, - "columns": [ - "email" - ] - }, - "users_cpf_unique": { - "name": "users_cpf_unique", - "nullsNotDistinct": false, - "columns": [ - "cpf" - ] - }, - "users_user_stats_id_unique": { - "name": "users_user_stats_id_unique", - "nullsNotDistinct": false, - "columns": [ - "user_stats_id" - ] - } - } - } - }, - "enums": { - "public.complaints_state": { - "name": "complaints_state", - "schema": "public", - "values": [ - "complained", - "rejected", - "accepted" - ] - }, - "public.resource_state": { - "name": "resource_state", - "schema": "public", - "values": [ - "draft", - "submitted", - "accepted", - "reported", - "deleted" - ] - }, - "public.review_state": { - "name": "review_state", - "schema": "public", - "values": [ - "active", - "inactive", - "under_review" - ] - } - }, - "schemas": {}, - "_meta": { - "columns": {}, - "schemas": {}, - "tables": {} - } -} \ No newline at end of file diff --git a/src/db/migrations/meta/0003_snapshot.json b/src/db/migrations/meta/0003_snapshot.json deleted file mode 100644 index f8eb3db361644930a3209b0ca7e463d927148794..0000000000000000000000000000000000000000 --- a/src/db/migrations/meta/0003_snapshot.json +++ /dev/null @@ -1,2714 +0,0 @@ -{ - "id": "50829ae2-c646-4fc2-aaeb-40af6e5e926c", - "prevId": "9feef775-e14c-4a3d-a342-bb281dd95fa3", - "version": "7", - "dialect": "postgresql", - "tables": { - "public.achievements": { - "name": "achievements", - "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 - }, - "review_state": { - "name": "review_state", - "type": "review_state", - "typeSchema": "public", - "primaryKey": false, - "notNull": true, - "default": "'under_review'" - }, - "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": { - "achievements_id_unique": { - "name": "achievements_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - } - } - }, - "public.actions": { - "name": "actions", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "name": { - "name": "name", - "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()" - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "actions_id_unique": { - "name": "actions_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - } - } - }, - "public.collection_likes": { - "name": "collection_likes", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "user_id": { - "name": "user_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "collection_id": { - "name": "collection_id", - "type": "integer", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": { - "collection_likes_user_id_users_id_fk": { - "name": "collection_likes_user_id_users_id_fk", - "tableFrom": "collection_likes", - "tableTo": "users", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "collection_likes_collection_id_collections_id_fk": { - "name": "collection_likes_collection_id_collections_id_fk", - "tableFrom": "collection_likes", - "tableTo": "collections", - "columnsFrom": [ - "collection_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "collection_likes_id_unique": { - "name": "collection_likes_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - } - } - }, - "public.collection_resources": { - "name": "collection_resources", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "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_collections_id_fk": { - "name": "collection_resources_collection_id_collections_id_fk", - "tableFrom": "collection_resources", - "tableTo": "collections", - "columnsFrom": [ - "collection_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "collection_resources_resource_id_resources_id_fk": { - "name": "collection_resources_resource_id_resources_id_fk", - "tableFrom": "collection_resources", - "tableTo": "resources", - "columnsFrom": [ - "resource_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "collection_resources_id_unique": { - "name": "collection_resources_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - } - } - }, - "public.collection_stats": { - "name": "collection_stats", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "views": { - "name": "views", - "type": "integer", - "primaryKey": false, - "notNull": true, - "default": 0 - }, - "downloads": { - "name": "downloads", - "type": "integer", - "primaryKey": false, - "notNull": true, - "default": 0 - }, - "likes": { - "name": "likes", - "type": "integer", - "primaryKey": false, - "notNull": true, - "default": 0 - }, - "shares": { - "name": "shares", - "type": "integer", - "primaryKey": false, - "notNull": true, - "default": 0 - }, - "score": { - "name": "score", - "type": "numeric", - "primaryKey": false, - "notNull": true, - "default": "'0.0'" - }, - "follows": { - "name": "follows", - "type": "integer", - "primaryKey": false, - "notNull": true, - "default": 0 - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "collection_stats_id_unique": { - "name": "collection_stats_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - } - } - }, - "public.collections": { - "name": "collections", - "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 - }, - "is_private": { - "name": "is_private", - "type": "boolean", - "primaryKey": false, - "notNull": false, - "default": false - }, - "is_active": { - "name": "is_active", - "type": "boolean", - "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()" - }, - "deleted_at": { - "name": "deleted_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false - }, - "thumbnail": { - "name": "thumbnail", - "type": "varchar(255)", - "primaryKey": false, - "notNull": false - }, - "user_id": { - "name": "user_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "collection_stats_id": { - "name": "collection_stats_id", - "type": "integer", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": { - "collections_user_id_users_id_fk": { - "name": "collections_user_id_users_id_fk", - "tableFrom": "collections", - "tableTo": "users", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "collections_collection_stats_id_collection_stats_id_fk": { - "name": "collections_collection_stats_id_collection_stats_id_fk", - "tableFrom": "collections", - "tableTo": "collection_stats", - "columnsFrom": [ - "collection_stats_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "collections_id_unique": { - "name": "collections_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - }, - "collections_collection_stats_id_unique": { - "name": "collections_collection_stats_id_unique", - "nullsNotDistinct": false, - "columns": [ - "collection_stats_id" - ] - } - } - }, - "public.commentReply": { - "name": "commentReply", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "user_id": { - "name": "user_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "comment_id": { - "name": "comment_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "text": { - "name": "text", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "default": "now()" - }, - "deleted_at": { - "name": "deleted_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false - }, - "update_at": { - "name": "update_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "default": "now()" - } - }, - "indexes": {}, - "foreignKeys": { - "commentReply_user_id_users_id_fk": { - "name": "commentReply_user_id_users_id_fk", - "tableFrom": "commentReply", - "tableTo": "users", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "commentReply_comment_id_comments_id_fk": { - "name": "commentReply_comment_id_comments_id_fk", - "tableFrom": "commentReply", - "tableTo": "comments", - "columnsFrom": [ - "comment_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "commentReply_id_unique": { - "name": "commentReply_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - } - } - }, - "public.comments": { - "name": "comments", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "user_id": { - "name": "user_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "resource_id": { - "name": "resource_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "text": { - "name": "text", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "created_at": { - "name": "created_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "default": "now()" - }, - "deleted_at": { - "name": "deleted_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false - }, - "updated_at": { - "name": "updated_at", - "type": "timestamp", - "primaryKey": false, - "notNull": true, - "default": "now()" - } - }, - "indexes": {}, - "foreignKeys": { - "comments_user_id_users_id_fk": { - "name": "comments_user_id_users_id_fk", - "tableFrom": "comments", - "tableTo": "users", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "comments_resource_id_resources_id_fk": { - "name": "comments_resource_id_resources_id_fk", - "tableFrom": "comments", - "tableTo": "resources", - "columnsFrom": [ - "resource_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "comments_id_unique": { - "name": "comments_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - } - } - }, - "public.complaints": { - "name": "complaints", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "state": { - "name": "state", - "type": "complaints_state", - "typeSchema": "public", - "primaryKey": false, - "notNull": true, - "default": "'complained'" - }, - "description": { - "name": "description", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "denouncer_id": { - "name": "denouncer_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "resource_id": { - "name": "resource_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "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 - }, - "q5": { - "name": "q5", - "type": "boolean", - "primaryKey": false, - "notNull": false - }, - "q6": { - "name": "q6", - "type": "boolean", - "primaryKey": false, - "notNull": false - }, - "q7": { - "name": "q7", - "type": "boolean", - "primaryKey": false, - "notNull": false - } - }, - "indexes": {}, - "foreignKeys": { - "complaints_denouncer_id_users_id_fk": { - "name": "complaints_denouncer_id_users_id_fk", - "tableFrom": "complaints", - "tableTo": "users", - "columnsFrom": [ - "denouncer_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "complaints_resource_id_resources_id_fk": { - "name": "complaints_resource_id_resources_id_fk", - "tableFrom": "complaints", - "tableTo": "resources", - "columnsFrom": [ - "resource_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "complaints_collection_id_collections_id_fk": { - "name": "complaints_collection_id_collections_id_fk", - "tableFrom": "complaints", - "tableTo": "collections", - "columnsFrom": [ - "collection_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "complaints_user_id_users_id_fk": { - "name": "complaints_user_id_users_id_fk", - "tableFrom": "complaints", - "tableTo": "users", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "complaints_id_unique": { - "name": "complaints_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - } - } - }, - "public.educational_stages": { - "name": "educational_stages", - "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": { - "educational_stages_id_unique": { - "name": "educational_stages_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - } - } - }, - "public.followers": { - "name": "followers", - "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": { - "followers_user_id_users_id_fk": { - "name": "followers_user_id_users_id_fk", - "tableFrom": "followers", - "tableTo": "users", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "followers_follower_id_users_id_fk": { - "name": "followers_follower_id_users_id_fk", - "tableFrom": "followers", - "tableTo": "users", - "columnsFrom": [ - "follower_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "followers_id_unique": { - "name": "followers_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - } - } - }, - "public.institutions": { - "name": "institutions", - "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": { - "institutions_id_unique": { - "name": "institutions_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - } - } - }, - "public.item_achievements": { - "name": "item_achievements", - "schema": "", - "columns": { - "item_id": { - "name": "item_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "achievement_id": { - "name": "achievement_id", - "type": "integer", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": { - "item_achievements_item_id_items_id_fk": { - "name": "item_achievements_item_id_items_id_fk", - "tableFrom": "item_achievements", - "tableTo": "items", - "columnsFrom": [ - "item_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "item_achievements_achievement_id_achievements_id_fk": { - "name": "item_achievements_achievement_id_achievements_id_fk", - "tableFrom": "item_achievements", - "tableTo": "achievements", - "columnsFrom": [ - "achievement_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": { - "item_achievements_item_id_achievement_id_pk": { - "name": "item_achievements_item_id_achievement_id_pk", - "columns": [ - "item_id", - "achievement_id" - ] - } - }, - "uniqueConstraints": {} - }, - "public.items": { - "name": "items", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "name": { - "name": "name", - "type": "varchar(255)", - "primaryKey": false, - "notNull": true - }, - "price": { - "name": "price", - "type": "numeric", - "primaryKey": false, - "notNull": false - }, - "discount": { - "name": "discount", - "type": "numeric", - "primaryKey": false, - "notNull": false - }, - "description": { - "name": "description", - "type": "text", - "primaryKey": false, - "notNull": false - }, - "is_active": { - "name": "is_active", - "type": "boolean", - "primaryKey": false, - "notNull": false, - "default": 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": { - "items_id_unique": { - "name": "items_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - } - } - }, - "public.languages": { - "name": "languages", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "name": { - "name": "name", - "type": "varchar(255)", - "primaryKey": false, - "notNull": true - }, - "code": { - "name": "code", - "type": "varchar(10)", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "languages_id_unique": { - "name": "languages_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - }, - "languages_code_unique": { - "name": "languages_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(255)", - "primaryKey": false, - "notNull": true - }, - "description": { - "name": "description", - "type": "text", - "primaryKey": false, - "notNull": true - }, - "url": { - "name": "url", - "type": "varchar(255)", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "licenses_id_unique": { - "name": "licenses_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - } - } - }, - "public.notifications": { - "name": "notifications", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "owner_id": { - "name": "owner_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "action_id": { - "name": "action_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "actor_user_id": { - "name": "actor_user_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "target_user_id": { - "name": "target_user_id", - "type": "integer", - "primaryKey": false, - "notNull": false - }, - "target_resource_id": { - "name": "target_resource_id", - "type": "integer", - "primaryKey": false, - "notNull": false - }, - "target_collection_id": { - "name": "target_collection_id", - "type": "integer", - "primaryKey": false, - "notNull": false - }, - "viewed": { - "name": "viewed", - "type": "boolean", - "primaryKey": false, - "notNull": false, - "default": 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": { - "notifications_owner_id_users_id_fk": { - "name": "notifications_owner_id_users_id_fk", - "tableFrom": "notifications", - "tableTo": "users", - "columnsFrom": [ - "owner_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "notifications_action_id_actions_id_fk": { - "name": "notifications_action_id_actions_id_fk", - "tableFrom": "notifications", - "tableTo": "actions", - "columnsFrom": [ - "action_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "notifications_actor_user_id_users_id_fk": { - "name": "notifications_actor_user_id_users_id_fk", - "tableFrom": "notifications", - "tableTo": "users", - "columnsFrom": [ - "actor_user_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "notifications_target_user_id_users_id_fk": { - "name": "notifications_target_user_id_users_id_fk", - "tableFrom": "notifications", - "tableTo": "users", - "columnsFrom": [ - "target_user_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "notifications_target_resource_id_resources_id_fk": { - "name": "notifications_target_resource_id_resources_id_fk", - "tableFrom": "notifications", - "tableTo": "resources", - "columnsFrom": [ - "target_resource_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "notifications_target_collection_id_collections_id_fk": { - "name": "notifications_target_collection_id_collections_id_fk", - "tableFrom": "notifications", - "tableTo": "collections", - "columnsFrom": [ - "target_collection_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "notifications_id_unique": { - "name": "notifications_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - } - } - }, - "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.resource_educational_stages": { - "name": "resource_educational_stages", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "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_resources_id_fk": { - "name": "resource_educational_stages_resource_id_resources_id_fk", - "tableFrom": "resource_educational_stages", - "tableTo": "resources", - "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": { - "resource_educational_stages_id_unique": { - "name": "resource_educational_stages_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - } - } - }, - "public.resource_languages": { - "name": "resource_languages", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "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_resources_id_fk": { - "name": "resource_languages_resource_id_resources_id_fk", - "tableFrom": "resource_languages", - "tableTo": "resources", - "columnsFrom": [ - "resource_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "resource_languages_language_id_languages_id_fk": { - "name": "resource_languages_language_id_languages_id_fk", - "tableFrom": "resource_languages", - "tableTo": "languages", - "columnsFrom": [ - "language_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "resource_languages_id_unique": { - "name": "resource_languages_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - } - } - }, - "public.resource_likes": { - "name": "resource_likes", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "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_users_id_fk": { - "name": "resource_likes_user_id_users_id_fk", - "tableFrom": "resource_likes", - "tableTo": "users", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "resource_likes_resource_id_resources_id_fk": { - "name": "resource_likes_resource_id_resources_id_fk", - "tableFrom": "resource_likes", - "tableTo": "resources", - "columnsFrom": [ - "resource_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "resource_likes_id_unique": { - "name": "resource_likes_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - } - } - }, - "public.resource_stats": { - "name": "resource_stats", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "views": { - "name": "views", - "type": "integer", - "primaryKey": false, - "notNull": true, - "default": 0 - }, - "downloads": { - "name": "downloads", - "type": "integer", - "primaryKey": false, - "notNull": true, - "default": 0 - }, - "likes": { - "name": "likes", - "type": "integer", - "primaryKey": false, - "notNull": true, - "default": 0 - }, - "shares": { - "name": "shares", - "type": "integer", - "primaryKey": false, - "notNull": true, - "default": 0 - }, - "score": { - "name": "score", - "type": "numeric", - "primaryKey": false, - "notNull": true, - "default": "'0.0'" - }, - "follows": { - "name": "follows", - "type": "integer", - "primaryKey": false, - "notNull": true, - "default": 0 - }, - "comments": { - "name": "comments", - "type": "integer", - "primaryKey": false, - "notNull": true, - "default": 0 - } - }, - "indexes": {}, - "foreignKeys": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "resource_stats_id_unique": { - "name": "resource_stats_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - } - } - }, - "public.resource_subjects": { - "name": "resource_subjects", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "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_resources_id_fk": { - "name": "resource_subjects_resource_id_resources_id_fk", - "tableFrom": "resource_subjects", - "tableTo": "resources", - "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": { - "resource_subjects_id_unique": { - "name": "resource_subjects_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - } - } - }, - "public.resources": { - "name": "resources", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "resource_state": { - "name": "resource_state", - "type": "resource_state", - "typeSchema": "public", - "primaryKey": false, - "notNull": true, - "default": "'draft'" - }, - "name": { - "name": "name", - "type": "varchar(255)", - "primaryKey": false, - "notNull": true - }, - "author": { - "name": "author", - "type": "varchar(255)", - "primaryKey": false, - "notNull": true - }, - "link": { - "name": "link", - "type": "varchar(255)", - "primaryKey": false, - "notNull": false - }, - "thumbnail": { - "name": "thumbnail", - "type": "varchar(255)", - "primaryKey": false, - "notNull": false - }, - "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()" - }, - "published_at": { - "name": "published_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false - }, - "submitted_at": { - "name": "submitted_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false - }, - "deleted_at": { - "name": "deleted_at", - "type": "timestamp", - "primaryKey": false, - "notNull": false - }, - "user_id": { - "name": "user_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "resource_stats_id": { - "name": "resource_stats_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "object_type_id": { - "name": "object_type_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "license_id": { - "name": "license_id", - "type": "integer", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": { - "resources_user_id_users_id_fk": { - "name": "resources_user_id_users_id_fk", - "tableFrom": "resources", - "tableTo": "users", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "resources_resource_stats_id_resource_stats_id_fk": { - "name": "resources_resource_stats_id_resource_stats_id_fk", - "tableFrom": "resources", - "tableTo": "resource_stats", - "columnsFrom": [ - "resource_stats_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "resources_object_type_id_object_types_id_fk": { - "name": "resources_object_type_id_object_types_id_fk", - "tableFrom": "resources", - "tableTo": "object_types", - "columnsFrom": [ - "object_type_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "resources_license_id_licenses_id_fk": { - "name": "resources_license_id_licenses_id_fk", - "tableFrom": "resources", - "tableTo": "licenses", - "columnsFrom": [ - "license_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "resources_id_unique": { - "name": "resources_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - }, - "resources_resource_stats_id_unique": { - "name": "resources_resource_stats_id_unique", - "nullsNotDistinct": false, - "columns": [ - "resource_stats_id" - ] - } - } - }, - "public.roles": { - "name": "roles", - "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": { - "roles_id_unique": { - "name": "roles_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - }, - "roles_name_unique": { - "name": "roles_name_unique", - "nullsNotDistinct": false, - "columns": [ - "name" - ] - } - } - }, - "public.subjects": { - "name": "subjects", - "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": { - "subjects_id_unique": { - "name": "subjects_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - } - } - }, - "public.submissions": { - "name": "submissions", - "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": 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()" - }, - "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": { - "submissions_resource_id_resources_id_fk": { - "name": "submissions_resource_id_resources_id_fk", - "tableFrom": "submissions", - "tableTo": "resources", - "columnsFrom": [ - "resource_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "submissions_submitter_id_users_id_fk": { - "name": "submissions_submitter_id_users_id_fk", - "tableFrom": "submissions", - "tableTo": "users", - "columnsFrom": [ - "submitter_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "submissions_curator_id_users_id_fk": { - "name": "submissions_curator_id_users_id_fk", - "tableFrom": "submissions", - "tableTo": "users", - "columnsFrom": [ - "curator_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "submissions_id_unique": { - "name": "submissions_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - } - } - }, - "public.user_achievements": { - "name": "user_achievements", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "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_users_id_fk": { - "name": "user_achievements_user_id_users_id_fk", - "tableFrom": "user_achievements", - "tableTo": "users", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "user_achievements_achievement_id_users_id_fk": { - "name": "user_achievements_achievement_id_users_id_fk", - "tableFrom": "user_achievements", - "tableTo": "users", - "columnsFrom": [ - "achievement_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "user_achievements_id_unique": { - "name": "user_achievements_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - } - } - }, - "public.user_collections": { - "name": "user_collections", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "user_id": { - "name": "user_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "collection_id": { - "name": "collection_id", - "type": "integer", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": { - "user_collections_user_id_users_id_fk": { - "name": "user_collections_user_id_users_id_fk", - "tableFrom": "user_collections", - "tableTo": "users", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "user_collections_collection_id_collections_id_fk": { - "name": "user_collections_collection_id_collections_id_fk", - "tableFrom": "user_collections", - "tableTo": "collections", - "columnsFrom": [ - "collection_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "user_collections_id_unique": { - "name": "user_collections_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - } - } - }, - "public.user_institutions": { - "name": "user_institutions", - "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_institutions_user_id_users_id_fk": { - "name": "user_institutions_user_id_users_id_fk", - "tableFrom": "user_institutions", - "tableTo": "users", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "user_institutions_institution_id_institutions_id_fk": { - "name": "user_institutions_institution_id_institutions_id_fk", - "tableFrom": "user_institutions", - "tableTo": "institutions", - "columnsFrom": [ - "institution_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "user_institutions_id_unique": { - "name": "user_institutions_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - } - } - }, - "public.user_items": { - "name": "user_items", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "user_id": { - "name": "user_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "item_id": { - "name": "item_id", - "type": "integer", - "primaryKey": false, - "notNull": true - } - }, - "indexes": {}, - "foreignKeys": { - "user_items_user_id_users_id_fk": { - "name": "user_items_user_id_users_id_fk", - "tableFrom": "user_items", - "tableTo": "users", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "user_items_item_id_items_id_fk": { - "name": "user_items_item_id_items_id_fk", - "tableFrom": "user_items", - "tableTo": "items", - "columnsFrom": [ - "item_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "user_items_id_unique": { - "name": "user_items_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - } - } - }, - "public.user_roles": { - "name": "user_roles", - "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_roles_user_id_users_id_fk": { - "name": "user_roles_user_id_users_id_fk", - "tableFrom": "user_roles", - "tableTo": "users", - "columnsFrom": [ - "user_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - }, - "user_roles_role_id_roles_id_fk": { - "name": "user_roles_role_id_roles_id_fk", - "tableFrom": "user_roles", - "tableTo": "roles", - "columnsFrom": [ - "role_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "cascade", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "user_roles_id_unique": { - "name": "user_roles_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - } - } - }, - "public.user_stats": { - "name": "user_stats", - "schema": "", - "columns": { - "id": { - "name": "id", - "type": "serial", - "primaryKey": true, - "notNull": true - }, - "score": { - "name": "score", - "type": "numeric", - "primaryKey": false, - "notNull": true, - "default": "'0.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": {}, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "user_stats_id_unique": { - "name": "user_stats_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - } - } - }, - "public.users": { - "name": "users", - "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'" - }, - "birthday": { - "name": "birthday", - "type": "timestamp", - "primaryKey": false, - "notNull": true - }, - "cpf": { - "name": "cpf", - "type": "varchar(11)", - "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 - }, - "is_active": { - "name": "is_active", - "type": "boolean", - "primaryKey": false, - "notNull": false, - "default": true - }, - "user_stats_id": { - "name": "user_stats_id", - "type": "integer", - "primaryKey": false, - "notNull": true - }, - "level": { - "name": "level", - "type": "integer", - "primaryKey": false, - "notNull": false, - "default": 1 - }, - "experience": { - "name": "experience", - "type": "integer", - "primaryKey": false, - "notNull": false, - "default": 0 - }, - "points": { - "name": "points", - "type": "integer", - "primaryKey": false, - "notNull": false, - "default": 0 - }, - "level_xp": { - "name": "level_xp", - "type": "integer", - "primaryKey": false, - "notNull": false, - "default": 0 - } - }, - "indexes": {}, - "foreignKeys": { - "users_user_stats_id_user_stats_id_fk": { - "name": "users_user_stats_id_user_stats_id_fk", - "tableFrom": "users", - "tableTo": "user_stats", - "columnsFrom": [ - "user_stats_id" - ], - "columnsTo": [ - "id" - ], - "onDelete": "no action", - "onUpdate": "no action" - } - }, - "compositePrimaryKeys": {}, - "uniqueConstraints": { - "users_id_unique": { - "name": "users_id_unique", - "nullsNotDistinct": false, - "columns": [ - "id" - ] - }, - "users_username_unique": { - "name": "users_username_unique", - "nullsNotDistinct": false, - "columns": [ - "username" - ] - }, - "users_email_unique": { - "name": "users_email_unique", - "nullsNotDistinct": false, - "columns": [ - "email" - ] - }, - "users_cpf_unique": { - "name": "users_cpf_unique", - "nullsNotDistinct": false, - "columns": [ - "cpf" - ] - }, - "users_user_stats_id_unique": { - "name": "users_user_stats_id_unique", - "nullsNotDistinct": false, - "columns": [ - "user_stats_id" - ] - } - } - } - }, - "enums": { - "public.complaints_state": { - "name": "complaints_state", - "schema": "public", - "values": [ - "complained", - "rejected", - "accepted" - ] - }, - "public.resource_state": { - "name": "resource_state", - "schema": "public", - "values": [ - "draft", - "submitted", - "accepted", - "reported", - "deleted" - ] - }, - "public.review_state": { - "name": "review_state", - "schema": "public", - "values": [ - "active", - "inactive", - "under_review" - ] - } - }, - "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 a7e0211fea0fead86736c8fea9cb47098889ecc9..1487bcc1195974437e8ee194b4ecba9903871676 100644 --- a/src/db/migrations/meta/_journal.json +++ b/src/db/migrations/meta/_journal.json @@ -1,5 +1,13 @@ { "version": "7", "dialect": "postgresql", - "entries": [] -} + "entries": [ + { + "idx": 0, + "version": "7", + "when": 1747659017843, + "tag": "0000_daffy_sentinel", + "breakpoints": true + } + ] +} \ No newline at end of file diff --git a/src/db/repo/resource-educational-stages.repo.ts b/src/db/repo/resource-educational-stages.repo.ts index a1e49ea4e6c1db71dc85068750898d5b2f5f2804..f4de4fedef00e1ed4cf25e686f6c0e452b449222 100644 --- a/src/db/repo/resource-educational-stages.repo.ts +++ b/src/db/repo/resource-educational-stages.repo.ts @@ -154,4 +154,6 @@ export class resourceEducationalStagesRepo { .execute(); } } + + } \ No newline at end of file diff --git a/src/db/repo/resource.repo.ts b/src/db/repo/resource.repo.ts index 8418ce48a008aeb411715d3c4afed127ee501002..5f0077135d8411b0a36464687306a8c7358f6e93 100644 --- a/src/db/repo/resource.repo.ts +++ b/src/db/repo/resource.repo.ts @@ -8,7 +8,6 @@ import { eq, sql, and } from 'drizzle-orm' export class ResourceRepo { async create(resource: ResourceInput ): Promise<ResourceModel> { - console.log("Teste do resource: ", resource) const [ret] = await db .insert(resourceTable) .values(resource) @@ -50,7 +49,19 @@ export class ResourceRepo { return resourceSchema.model.parse(ret) } + async updatePublishedAt(id: ResourceModel['id']): Promise<ResourceModel> { + const [ret] = await db + .update(resourceTable) + .set({ + published_at: sql`NOW()` + }) + .where(eq(resourceTable.id, id)) + .returning() + + return resourceSchema.model.parse(ret) + } + async setResourceState(id: ResourceModel['id']): Promise<ResourceModel> { const [ret] = await db .update(resourceTable) diff --git a/src/db/repo/search.repo.ts b/src/db/repo/search.repo.ts index b8e10480497b5319a805c5abf10829d70cbb99dd..a6e0a840757c3ed292f589ec4c278703d18967b6 100644 --- a/src/db/repo/search.repo.ts +++ b/src/db/repo/search.repo.ts @@ -23,6 +23,7 @@ export class SearchRepo { object_type: sql`ot.name`, state: sql`re.state`, user: sql`us.name`, + user_id: sql`re.user_id`, views: sql`rest.views`, downloads: sql`rest.downloads`, likes: sql`rest.likes`, @@ -31,8 +32,8 @@ export class SearchRepo { comments: sql`rest.comments`, }) .from(sql`resources re`) - .leftJoin(sql`resource_educational_stage res`, sql`res.resource_id = re.id`) - .leftJoin(sql`educational_stages es`, sql`res.educational_stage_id = es.id`) + .leftJoin(sql`resource_educational_stages resed`, sql`resed.resource_id = re.id`) + .leftJoin(sql`educational_stages es`, sql`resed.educational_stage_id = es.id`) .leftJoin(sql`resource_languages rel`, sql`rel.resource_id = re.id`) .leftJoin(sql`languages lg`, sql`rel.language_id = lg.id`) .leftJoin(sql`resource_subjects res`, sql`res.resource_id = re.id`) @@ -50,13 +51,10 @@ export class SearchRepo { sql`re.link`, sql`re.published_at`, sql`re.state`, - sql`re.views_count`, - sql`re.downloads_count`, - sql`re.likes_count`, - sql`re.shares_count`, sql`ot.name`, sql`lc.name`, sql`us.name`, + sql`re.user_id`, sql`rest.views`, sql`rest.downloads`, sql`rest.likes`, @@ -65,9 +63,11 @@ export class SearchRepo { sql`rest.comments` ); - const results = await query.execute(); + let results = await query.execute(); - // Parse and validate each result using Zod schema + // O driver do postgres (pg) usado no drizzle retorna Numeric como uma string por padrão + // para evitar problemas com precisão numérica. Por isso precisamos parsear o score aqui + results = results.map(result => ({ ...result, score: Number(result.score) })); return results.map((result) => resourceIndexSchema.parse(result)); } diff --git a/src/db/schema/search.schema.ts b/src/db/schema/search.schema.ts index 8582ac8cf4f86671e092ed7655feb3a9c3c6e45a..f969933bf68d2ae1c1278295d01ab10dd97d473f 100644 --- a/src/db/schema/search.schema.ts +++ b/src/db/schema/search.schema.ts @@ -6,14 +6,15 @@ export const resourceIndexSchema = z.object({ author: z.string().nullable(), description: z.string().nullable(), link: z.string().nullable(), - created_at: z.string(), + created_at: z.string().optional().nullable(), educational_stages: z.string().nullable(), languages: z.string(), subjects: z.string().nullable(), license: z.string(), object_type: z.string(), - state: z.number(), + state: z.enum(['draft', 'submitted', 'accepted', 'reported', 'deleted']), user: z.string(), + user_id: z.number(), views: z.number(), downloads: z.number(), likes: z.number(), diff --git a/src/db/seeds/object-type.seed.ts b/src/db/seeds/object-type.seed.ts index 4c11de73546c964dd2d51a6446a5dc62137fe1f1..49648f6af4592ccd7be0af400b0f4d7cb3bbe9ed 100644 --- a/src/db/seeds/object-type.seed.ts +++ b/src/db/seeds/object-type.seed.ts @@ -55,49 +55,4 @@ const objectTypeData: ObjectTypeInput[] = [ { name: 'Livro Digital', }, - { - name: 'Imagem', - }, - { - name: 'Mapa', - }, - { - name: 'Software Educacional', - }, - { - name: 'Experimento Prático', - }, - { - name: 'Texto', - }, - { - name: 'Áudio', - }, - { - name: 'Vídeo', - }, - { - name: 'Animação', - }, - { - name: 'Plano de Aula', - }, - { - name: 'Website Externo', - }, - { - name: 'Apresentação', - }, - { - name: 'Infrográfico', - }, - { - name: 'Jogo', - }, - { - name: 'Aplicativo Móvel', - }, - { - name: 'Livro Digital', - } ] \ No newline at end of file diff --git a/src/db/seeds/subjects.seed.ts b/src/db/seeds/subjects.seed.ts index 748f30cbe731119c03bcfb24b48c651ea7a2bacb..06ea728d2ccffc5067aff9f92d7248adba37cb28 100644 --- a/src/db/seeds/subjects.seed.ts +++ b/src/db/seeds/subjects.seed.ts @@ -45,196 +45,6 @@ const subjectsData: SubjectInput[] = [ }, { name: 'Sociologia' - },{ - name: 'Matemática' - }, - { - name: 'Português' - }, - { - name: 'História' - }, - { - name: 'Geografia' - }, - { - name: 'Biologia' - }, - { - name: 'Física' - }, - { - name: 'Química' - }, - { - name: 'Inglês' - }, - { - name: 'Espanhol' - }, - { - name: 'Artes' - }, - { - name: 'Educação Física' - }, - { - name: 'Filosofia' - }, - { - name: 'Sociologia' - },{ - name: 'Matemática' - }, - { - name: 'Português' - }, - { - name: 'História' - }, - { - name: 'Geografia' - }, - { - name: 'Biologia' - }, - { - name: 'Física' - }, - { - name: 'Química' - }, - { - name: 'Inglês' - }, - { - name: 'Espanhol' - }, - { - name: 'Artes' - }, - { - name: 'Educação Física' - }, - { - name: 'Filosofia' - }, - { - name: 'Sociologia' - },{ - name: 'Matemática' - }, - { - name: 'Português' - }, - { - name: 'História' - }, - { - name: 'Geografia' - }, - { - name: 'Biologia' - }, - { - name: 'Física' - }, - { - name: 'Química' - }, - { - name: 'Inglês' - }, - { - name: 'Espanhol' - }, - { - name: 'Artes' - }, - { - name: 'Educação Física' - }, - { - name: 'Filosofia' - }, - { - name: 'Sociologia' - },{ - name: 'Matemática' - }, - { - name: 'Português' - }, - { - name: 'História' - }, - { - name: 'Geografia' - }, - { - name: 'Biologia' - }, - { - name: 'Física' - }, - { - name: 'Química' - }, - { - name: 'Inglês' - }, - { - name: 'Espanhol' - }, - { - name: 'Artes' - }, - { - name: 'Educação Física' - }, - { - name: 'Filosofia' - }, - { - name: 'Sociologia' - },{ - name: 'Matemática' - }, - { - name: 'Português' - }, - { - name: 'História' - }, - { - name: 'Geografia' - }, - { - name: 'Biologia' - }, - { - name: 'Física' - }, - { - name: 'Química' - }, - { - name: 'Inglês' - }, - { - name: 'Espanhol' - }, - { - name: 'Artes' - }, - { - name: 'Educação Física' - }, - { - name: 'Filosofia' - }, - { - name: 'Sociologia' - }, + } ] diff --git a/src/env.ts b/src/env.ts index b998d39250b1ec842c85b069212bfe8ef7fb93ef..272cd12e4c7943c1e3d3e7197d399306c77ba104 100644 --- a/src/env.ts +++ b/src/env.ts @@ -31,7 +31,7 @@ const EnvSchema = z.object({ GOVBR_TOKEN_URL: z.string(), GOVBR_PUBLIC_KEY_URL: z.string(), FRONT_END_RETURN_URL: z.string(), - URL: z.string(), + EMAIL_URL: z.string(), ELASTICSEARCH_USER: z.string(), ELASTICSEARCH_PASSWORD: z.string(), diff --git a/src/routes/homologation.route.ts b/src/routes/homologation.route.ts index 71b7c4af2aa2db8ed4c0dcdbd03be02ee12066fb..e3f45729e97772f74d66bc802606bf5de46de38e 100644 --- a/src/routes/homologation.route.ts +++ b/src/routes/homologation.route.ts @@ -110,6 +110,7 @@ export const homologationRouter = honoWithJwt() if (acceptedSubmissionsCount >= 3) { await serviceResource.setResourceState(validInput.resource_id); await searchService.indexResource(validInput.resource_id); + await serviceResource.updatePublishedAt(validInput.resource_id); } return c.json({ message: "Homologação feita com sucesso!", data: homologation }) diff --git a/src/routes/resource.route.ts b/src/routes/resource.route.ts index 336c04394a1e3deaf99f6f1b9f0f7461e81b788f..012551dec84278cd819614c3cf50b4e3b9dc5464 100644 --- a/src/routes/resource.route.ts +++ b/src/routes/resource.route.ts @@ -28,6 +28,7 @@ import { downloadResourceRoute } from "../documentation/resourceDescriber" import { z } from "zod"; +import { HomologationService } from "@/services/homologation.service"; const service = Container.get(ResourceService); @@ -38,6 +39,7 @@ const resourceEducationalStagesService = Container.get(ResourceEducationalStages const resourceSubjectsService = Container.get(ResourceSubjectsService); const userService = Container.get(UserService); const searchService = Container.get(SearchService); +const serviceHomologation = Container.get(HomologationService); //define um novo Model type ResourceWithObjectTypeName = ResourceModel & { @@ -61,11 +63,12 @@ export const resourceSchemaJson = { educational_stages: z.array(z.number()), user_id: z.number(), link: z.string().optional().nullable(), - thumbnail:z.string().optional().nullable(), + thumbnail: z.string().optional().nullable(), state: z.enum(['draft', 'submitted', 'accepted', 'reported', 'deleted']).optional(), resource_stats_id: z.number().optional(), }), input: z.object({ + name: z.string().min(1).max(100), description: z.string().min(1).max(1500), object_type_id: z.number().int(), @@ -162,6 +165,10 @@ export const resourceRouter = honoWithJwt() const languageIds = languages.map((l) => l.id); const educationalStageIds = educationalStages.map((e) => e.id); + //indexando + await searchService.indexResource(resource.id) + + // 5. Retorna o recurso com os arrays de IDs return c.json({ ...resourceSchema.return.parse(resource), @@ -190,11 +197,21 @@ export const resourceRouter = honoWithJwt() // update a resource .post('/update', updateResourceRoute, zValidator('json', resourceSchemaJson.update), + async (c) => { + const user = c.get('jwtPayload').id; + try { const input = c.req.valid('json') const resource = resourceSchema.dto.parse(await service.update(input)) + //verifica se tem a permissao + const userRoles = await serviceHomologation.findRolesByUserId(user); + // definido que 1: user, 2: admin, 3: contribuidor + if(userRoles.some(role => role === 2 || role === 3)){ + await service.updatePublishedAt(input.id); + } + // Atualiza as associações usando os métodos que você já tem await Promise.all([ @@ -216,6 +233,8 @@ export const resourceRouter = honoWithJwt() const languageIds = languages.map((l) => l.id); const educationalStagesId = educationalStages.map((e) => e.id); //educational stage retorna o objeto inteiro + //indexando + await searchService.indexResource(resource.id) // 5. Retorna o recurso com os arrays de IDs return c.json({ diff --git a/src/routes/search.route.ts b/src/routes/search.route.ts index c0f9a0bcc1eda761776693ba2d8078fbba5eb701..2cf6112e9b25c2b9ef4fa72ffcfd6e1322273d73 100644 --- a/src/routes/search.route.ts +++ b/src/routes/search.route.ts @@ -11,18 +11,31 @@ const searchService = Container.get(SearchService); export const searchRouter = new Hono() .get( '/search', + zValidator( 'query', z.object({ - query: z.string().min(1, 'Query is required'), + query: z.string().optional(), + sortBy: z.enum(['created_at']).optional(), + sortOrder: z.enum(['asc', 'desc']).optional(), + offset: z.coerce.number().int().nonnegative().optional(), + page_size: z.coerce.number().int().positive().optional(), + + // filters + language: z.string().optional(), + objectType: z.string().optional(), + institution: z.string().optional(), }) ), + async (c) => { + try { const { query } = c.req.valid('query'); const results = await searchService.searchIndex(query); + console.log("results", results) return c.json({ results }); } catch (e) { console.log(e) @@ -41,13 +54,13 @@ export const searchRouter = new Hono() ) .post( - '/index/resource/:id', + '/index/resource/:id', async (c) => { try { const id: number = +c.req.param('id') - + await searchService.indexResource(id); - return c.json({ message: `resource indexed successfully`}); + return c.json({ message: `resource indexed successfully` }); } catch (e) { return c.json( createApexError({ @@ -64,13 +77,13 @@ export const searchRouter = new Hono() ) .post( - '/index/collection/:id', + '/index/collection/:id', async (c) => { try { const id: number = +c.req.param('id') - + await searchService.indexCollection(id); - return c.json({ message: `collection indexed successfully`}); + return c.json({ message: `collection indexed successfully` }); } catch (e) { return c.json( createApexError({ @@ -87,14 +100,14 @@ export const searchRouter = new Hono() ) .post( - '/index/user/:id', + '/index/user/:id', async (c) => { try { const id: number = +c.req.param('id') - + await searchService.indexUser(id); - return c.json({ message: `user indexed successfully`}); + return c.json({ message: `user indexed successfully` }); } catch (e) { return c.json( createApexError({ diff --git a/src/routes/subjects.route.ts b/src/routes/subjects.route.ts index 97ff367ba142bab80f1b79d52c9dc9966d4c0287..503d76dd3f620a9763d2750a8ae77e0a80f043ac 100644 --- a/src/routes/subjects.route.ts +++ b/src/routes/subjects.route.ts @@ -94,7 +94,7 @@ export const publicSubjectsRouter = new Hono() async (c) => { try { const subjects = await service.findMany() - return c.json({ subjects }) + return c.json( subjects ) } catch (e) { return c.json( createApexError({ diff --git a/src/services/auth.service.ts b/src/services/auth.service.ts index 8280f2bec11528124c7f24e47e56aecb887a7b1f..4cb3d9bc38752cfacec97335dcbf9f238088fa8c 100644 --- a/src/services/auth.service.ts +++ b/src/services/auth.service.ts @@ -81,7 +81,7 @@ export class AuthService { } async sendConfirmationEmail(receiver: string, subject: string, userName: string, userEmail: string) { - const link: string = `${env.URL}/entrar`; + const link: string = `${env.EMAIL_URL}/entrar`; const text = ` <head> <style> @@ -126,7 +126,7 @@ export class AuthService { <body> <div class="container" > - <a href="${process.env["URL"]}"></a> + <a href="${process.env["EMAIL_URL"]}"></a> <h1 style="color:#00bacc; font-size: 30px; font-weight: 800; margin-top: 5px; margin-bottom: 5px">Recuperação de senha</h1> <br> <p>Olá, ${userName}!</p> @@ -155,7 +155,7 @@ export class AuthService { } async passwordRecoveryEmail(resetTicket: string, receiver: string, subject: string, userEmail: string) { - const token_link: string = `${env.URL}novaSenha?token=${resetTicket}&email=${userEmail}`; + const token_link: string = `${env.EMAIL_URL}novaSenha?token=${resetTicket}&email=${userEmail}`; const text = ` <head> <style> @@ -200,7 +200,7 @@ export class AuthService { <body> <div class="container" > - <a href="${process.env["URL"]}"></a> + <a href="${process.env["EMAIL_URL"]}"></a> <h1 style="color:#00bacc; font-size: 30px; font-weight: 800; margin-top: 5px; margin-bottom: 5px">Recuperação de senha</h1> <br> <p>Este e-mail foi enviado para confirmar que você é o proprietário do endereço de e-mail fornecido no cadastro da MECRED. diff --git a/src/services/contact.service.ts b/src/services/contact.service.ts index 6c7eccd740ca2ee1d925e0c15c3b5f6aff2f0a88..0f6ffe9cdfa7b4dd72c3df1001b91e9406e1cfa3 100644 --- a/src/services/contact.service.ts +++ b/src/services/contact.service.ts @@ -48,7 +48,7 @@ export class ContactService { <body> <div class="container" > - <a href="${process.env["URL"]}"></a> + <a href="${process.env["EMAIL_URL"]}"></a> <h1 style="color:#00bacc; font-size: 30px; font-weight: 800; margin-top: 5px; margin-bottom: 5px">Contato de ${name}</h1> <br> <p>${text}</p> diff --git a/src/services/resource-educational-stages.service.ts b/src/services/resource-educational-stages.service.ts index 437028e07b4e5f379680165a28215811e29a1cee..0c4bdd03357018f45954b8026829abed37302a80 100644 --- a/src/services/resource-educational-stages.service.ts +++ b/src/services/resource-educational-stages.service.ts @@ -30,6 +30,8 @@ export class ResourceEducationalStagesService { async updateResourceEducationalStages(resourceId: ResourceModel['id'], newEducationalStageIds: EducationalStagesModel['id'][]): Promise<void> { await this.repo.updateResourceEducationalStages(resourceId, newEducationalStageIds); - } + } + + } \ No newline at end of file diff --git a/src/services/resource.service.ts b/src/services/resource.service.ts index 196df452617e9f2b353055625c32dbb8c9876dd0..3c6c8316003c951979ebb7e52599ea5831dbe4ae 100644 --- a/src/services/resource.service.ts +++ b/src/services/resource.service.ts @@ -31,6 +31,10 @@ export class ResourceService { return this.repo.setResourceState(id) } + async updatePublishedAt(id: ResourceModel['id']): Promise<ResourceModel> { + return this.repo.updatePublishedAt(id) + } + async allResourceByUser(id_user: ResourceModel['user_id']): Promise <ResourceModel[]>{ return this.repo.allResourceByUser(id_user) } diff --git a/src/services/search.service.ts b/src/services/search.service.ts index 3351cb7039306809ffa41e4ec146091d28b0900f..0504e8dc483bd3fd34c5a3d136cee649957dcbab 100644 --- a/src/services/search.service.ts +++ b/src/services/search.service.ts @@ -56,6 +56,7 @@ export class SearchService { objectType: document.object_type, state: document.state, user: document.user, + user_id: document.user_id, views: document.views, downloads: document.downloads, likes: document.likes, @@ -145,7 +146,7 @@ export class SearchService { // offset: offset da paginação, número da página // page_size: tamanho da página async searchIndex( - query: string, + query: string | undefined, filters: Partial<ExactFilterFields> = {}, sortBy: Partial<SortableFilterFields> = {}, // sortBy?: 'created_at', @@ -177,6 +178,41 @@ export class SearchService { ]; } + const searchQuery = query + ? { + multi_match: { + query, + fuzziness: "AUTO", + fields: [ + 'name', + 'author', + 'description', + 'link', + 'fileFormats', + 'educational_stages', + 'languages', + 'subjects', + 'license', + 'object_type', + 'state', + 'user', + 'roles', + 'institution', + 'city', + 'views', + 'downloads', + 'likes', + 'shares', + 'score', + 'comments', + 'created_at' + ], + }, + } + : { + match_all: {}, + } + const result = await this.esClient.search({ index: index, body: { @@ -184,35 +220,7 @@ export class SearchService { size: page_size, query: { bool: { - must: [ - { - multi_match: { - query, - fuzziness: "AUTO", - fields: ['name', - 'author', - 'description', - 'link', - 'educational_stages', - 'languages', - 'subjects', - 'license', - 'object_type', - 'state', - 'user', - 'roles', - 'institution', - 'city', - // 'views', - // 'downloads', - // 'likes', - 'shares', - 'score', - 'comments', - 'created_at'], - }, - }, - ], + must: [searchQuery], filter: userFilters, }, },