diff --git a/src/db/migrations/0000_cooing_doorman.sql b/src/db/migrations/0000_cooing_doorman.sql new file mode 100644 index 0000000000000000000000000000000000000000..6095e064c65b7d1583bda0b5863206abced62244 --- /dev/null +++ b/src/db/migrations/0000_cooing_doorman.sql @@ -0,0 +1,434 @@ +CREATE TABLE IF NOT EXISTS "achievement" ( + "id" serial PRIMARY KEY NOT NULL, + "name" varchar(255) NOT NULL, + "description" text, + "reward_experience" numeric, + "reward_points" numeric, + "state" integer DEFAULT 0 NOT NULL, + "repeatable" integer NOT NULL, + "is_resettable" boolean NOT NULL, + "created_at" timestamp DEFAULT now() NOT NULL, + "updated_at" timestamp DEFAULT now() NOT NULL, + CONSTRAINT "achievement_id_unique" UNIQUE("id") +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "collection_likes" ( + "user_id" integer NOT NULL, + "collection" integer NOT NULL +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "collection_resources" ( + "collection_id" integer NOT NULL, + "resource_id" integer NOT NULL +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "collection_stats" ( + "id" serial PRIMARY KEY NOT NULL, + "collection_id" bigint NOT NULL, + "views" bigint DEFAULT 0, + "downloads" bigint DEFAULT 0, + "likes" bigint DEFAULT 0, + "shares" bigint DEFAULT 0, + "score" bigint DEFAULT 0, + "follows" bigint DEFAULT 0, + CONSTRAINT "collection_stats_id_unique" UNIQUE("id") +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "collection" ( + "id" serial PRIMARY KEY NOT NULL, + "name" varchar(255), + "description" text, + "is_private" boolean, + "is_active" boolean DEFAULT true, + "created_at" timestamp DEFAULT now() NOT NULL, + "updated_at" timestamp, + "deleted_at" timestamp, + "thumbnail" varchar(255), + CONSTRAINT "collection_id_unique" UNIQUE("id") +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "complaint" ( + "id" serial PRIMARY KEY NOT NULL, + "state" integer DEFAULT 0 NOT NULL, + "description" text NOT NULL, + "evaluatedUser" integer NOT NULL, + "resource_id" integer, + "collection_id" integer, + "user_id" integer, + "evaluated_at" timestamp, + "created_at" timestamp DEFAULT now() NOT NULL, + "q1" boolean, + "q2" boolean, + "q3" boolean, + "q4" boolean +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "educational_stages" ( + "id" serial PRIMARY KEY NOT NULL, + "name" varchar NOT NULL, + CONSTRAINT "educational_stages_id_unique" UNIQUE("id"), + CONSTRAINT "educational_stages_name_unique" UNIQUE("name") +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "follows" ( + "id" serial PRIMARY KEY NOT NULL, + "user_id" integer NOT NULL, + "follower_id" integer NOT NULL, + CONSTRAINT "follows_id_unique" UNIQUE("id") +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "institution" ( + "id" serial PRIMARY KEY NOT NULL, + "name" varchar(255) NOT NULL, + "uf" varchar(2), + "city" varchar(255), + "cep" varchar(10), + "created_at" timestamp DEFAULT now() NOT NULL, + "updated_at" timestamp DEFAULT now() NOT NULL, + CONSTRAINT "institution_id_unique" UNIQUE("id") +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "items" ( + "id" serial PRIMARY KEY NOT NULL, + "name" varchar(256) NOT NULL, + "price" numeric(10, 2), + "discount" numeric(10, 2), + "description" varchar(256), + "is_active" boolean DEFAULT false, + "item_type" varchar(256), + "created_at" timestamp DEFAULT now() NOT NULL, + "updated_at" timestamp NOT NULL, + "achievement_id" integer, + CONSTRAINT "items_id_unique" UNIQUE("id") +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "language" ( + "id" serial PRIMARY KEY NOT NULL, + "name" varchar NOT NULL, + "code" varchar NOT NULL, + CONSTRAINT "language_id_unique" UNIQUE("id"), + CONSTRAINT "language_name_unique" UNIQUE("name"), + CONSTRAINT "language_code_unique" UNIQUE("code") +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "licenses" ( + "id" serial PRIMARY KEY NOT NULL, + "name" varchar NOT NULL, + "description" varchar NOT NULL, + "url" varchar NOT NULL, + CONSTRAINT "licenses_id_unique" UNIQUE("id"), + CONSTRAINT "licenses_name_unique" UNIQUE("name") +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "object_types" ( + "id" serial PRIMARY KEY NOT NULL, + "name" varchar(255) NOT NULL, + CONSTRAINT "object_types_id_unique" UNIQUE("id") +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "reset_ticket" ( + "id" serial PRIMARY KEY NOT NULL, + "user_id" integer NOT NULL, + "token_hash" varchar(255) NOT NULL, + "expiration_date" timestamp NOT NULL, + "token_used" boolean DEFAULT false NOT NULL, + "valid_token" boolean DEFAULT true NOT NULL, + "created_at" timestamp DEFAULT now() NOT NULL, + "updated_at" timestamp DEFAULT now() NOT NULL, + CONSTRAINT "reset_ticket_id_unique" UNIQUE("id") +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "resource_educational_stages" ( + "resource_id" integer NOT NULL, + "educational_stage_id" integer NOT NULL +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "resource_languages" ( + "resource_id" integer NOT NULL, + "language_id" integer NOT NULL +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "resource_likes" ( + "user_id" integer NOT NULL, + "resource_id" integer NOT NULL +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "resource_subjects" ( + "resource_id" integer NOT NULL, + "subject_id" integer NOT NULL +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "resource" ( + "id" serial PRIMARY KEY NOT NULL, + "name" varchar(256) NOT NULL, + "author" varchar(256) NOT NULL, + "description" varchar(256), + "bucket_key" varchar(256), + "link" varchar(256), + "thumbnail" varchar(256) NOT NULL, + "active" boolean DEFAULT false NOT NULL, + "published_at" timestamp, + "submited_at" timestamp, + "created_at" timestamp DEFAULT now() NOT NULL, + "updated_at" timestamp, + "deleted_at" timestamp, + CONSTRAINT "resource_id_unique" UNIQUE("id"), + CONSTRAINT "resource_bucket_key_unique" UNIQUE("bucket_key") +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "role" ( + "id" serial PRIMARY KEY NOT NULL, + "name" varchar(255) NOT NULL, + "description" text, + "created_at" timestamp DEFAULT now() NOT NULL, + "updated_at" timestamp DEFAULT now() NOT NULL, + CONSTRAINT "role_id_unique" UNIQUE("id"), + CONSTRAINT "role_name_unique" UNIQUE("name") +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "stats_resources" ( + "id" serial PRIMARY KEY NOT NULL, + "resource_id" bigint NOT NULL, + "views" bigint DEFAULT 0 NOT NULL, + "downloads" bigint DEFAULT 0 NOT NULL, + "shares" bigint DEFAULT 0 NOT NULL, + "score" bigint DEFAULT 0 NOT NULL, + CONSTRAINT "stats_resources_id_unique" UNIQUE("id") +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "subjects" ( + "id" serial PRIMARY KEY NOT NULL, + "name" varchar NOT NULL, + CONSTRAINT "subjects_id_unique" UNIQUE("id"), + CONSTRAINT "subjects_name_unique" UNIQUE("name") +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "submission" ( + "id" serial PRIMARY KEY NOT NULL, + "is_accepted" boolean DEFAULT false NOT NULL, + "justification" text, + "resource_id" integer NOT NULL, + "submitter_id" integer NOT NULL, + "curator_id" integer NOT NULL, + "created_at" timestamp DEFAULT now() NOT NULL, + "updated_at" timestamp, + "answered_at" timestamp, + "q1" boolean, + "q2" boolean, + "q3" boolean, + "q4" boolean +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "user_institution" ( + "id" serial PRIMARY KEY NOT NULL, + "user_id" integer NOT NULL, + "institution_id" integer NOT NULL, + CONSTRAINT "user_institution_id_unique" UNIQUE("id") +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "user_role" ( + "id" serial PRIMARY KEY NOT NULL, + "user_id" integer NOT NULL, + "role_id" integer NOT NULL, + CONSTRAINT "user_role_id_unique" UNIQUE("id") +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "user_stats" ( + "id" serial PRIMARY KEY NOT NULL, + "user_id" integer NOT NULL, + "score" integer DEFAULT 0 NOT NULL, + "likes" integer DEFAULT 0 NOT NULL, + "likes_received" integer DEFAULT 0 NOT NULL, + "follows" integer DEFAULT 0 NOT NULL, + "followers" integer DEFAULT 0 NOT NULL, + "collections" integer DEFAULT 0 NOT NULL, + "submitted_resources" integer DEFAULT 0 NOT NULL, + "approved_resources" integer DEFAULT 0 NOT NULL, + "reviewed_resources" integer DEFAULT 0 NOT NULL, + "comments" integer DEFAULT 0 NOT NULL, + CONSTRAINT "user_stats_id_unique" UNIQUE("id") +); +--> statement-breakpoint +CREATE TABLE IF NOT EXISTS "user" ( + "id" serial PRIMARY KEY NOT NULL, + "name" varchar(255) NOT NULL, + "username" varchar(255) NOT NULL, + "password" varchar(255) NOT NULL, + "email" varchar(255) NOT NULL, + "description" text DEFAULT 'sem descrição', + "institution" text DEFAULT 'sem instituição', + "birthday" timestamp NOT NULL, + "cpf" varchar(255) NOT NULL, + "created_at" timestamp DEFAULT now() NOT NULL, + "updated_at" timestamp DEFAULT now() NOT NULL, + "confirmed_at" timestamp, + "confirmation_sent_at" timestamp, + "deleted_at" timestamp, + "reactivated_at" timestamp, + "active" boolean DEFAULT true, + CONSTRAINT "user_id_unique" UNIQUE("id"), + CONSTRAINT "user_username_unique" UNIQUE("username"), + CONSTRAINT "user_email_unique" UNIQUE("email") +); +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "collection_likes" ADD CONSTRAINT "collection_likes_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "collection_likes" ADD CONSTRAINT "collection_likes_collection_collection_id_fk" FOREIGN KEY ("collection") REFERENCES "public"."collection"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "collection_resources" ADD CONSTRAINT "collection_resources_collection_id_collection_id_fk" FOREIGN KEY ("collection_id") REFERENCES "public"."collection"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "collection_resources" ADD CONSTRAINT "collection_resources_resource_id_resource_id_fk" FOREIGN KEY ("resource_id") REFERENCES "public"."resource"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "collection_stats" ADD CONSTRAINT "collection_stats_collection_id_collection_id_fk" FOREIGN KEY ("collection_id") REFERENCES "public"."collection"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "complaint" ADD CONSTRAINT "complaint_evaluatedUser_user_id_fk" FOREIGN KEY ("evaluatedUser") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "follows" ADD CONSTRAINT "follows_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "follows" ADD CONSTRAINT "follows_follower_id_user_id_fk" FOREIGN KEY ("follower_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "items" ADD CONSTRAINT "items_achievement_id_achievement_id_fk" FOREIGN KEY ("achievement_id") REFERENCES "public"."achievement"("id") ON DELETE no action ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "reset_ticket" ADD CONSTRAINT "reset_ticket_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "resource_educational_stages" ADD CONSTRAINT "resource_educational_stages_resource_id_resource_id_fk" FOREIGN KEY ("resource_id") REFERENCES "public"."resource"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "resource_educational_stages" ADD CONSTRAINT "resource_educational_stages_educational_stage_id_educational_stages_id_fk" FOREIGN KEY ("educational_stage_id") REFERENCES "public"."educational_stages"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "resource_languages" ADD CONSTRAINT "resource_languages_resource_id_resource_id_fk" FOREIGN KEY ("resource_id") REFERENCES "public"."resource"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "resource_languages" ADD CONSTRAINT "resource_languages_language_id_language_id_fk" FOREIGN KEY ("language_id") REFERENCES "public"."language"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "resource_likes" ADD CONSTRAINT "resource_likes_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "resource_likes" ADD CONSTRAINT "resource_likes_resource_id_resource_id_fk" FOREIGN KEY ("resource_id") REFERENCES "public"."resource"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "resource_subjects" ADD CONSTRAINT "resource_subjects_resource_id_resource_id_fk" FOREIGN KEY ("resource_id") REFERENCES "public"."resource"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "resource_subjects" ADD CONSTRAINT "resource_subjects_subject_id_subjects_id_fk" FOREIGN KEY ("subject_id") REFERENCES "public"."subjects"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "stats_resources" ADD CONSTRAINT "stats_resources_resource_id_resource_id_fk" FOREIGN KEY ("resource_id") REFERENCES "public"."resource"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "submission" ADD CONSTRAINT "submission_resource_id_resource_id_fk" FOREIGN KEY ("resource_id") REFERENCES "public"."resource"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "submission" ADD CONSTRAINT "submission_submitter_id_user_id_fk" FOREIGN KEY ("submitter_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "submission" ADD CONSTRAINT "submission_curator_id_user_id_fk" FOREIGN KEY ("curator_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "user_institution" ADD CONSTRAINT "user_institution_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "user_institution" ADD CONSTRAINT "user_institution_institution_id_institution_id_fk" FOREIGN KEY ("institution_id") REFERENCES "public"."institution"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "user_role" ADD CONSTRAINT "user_role_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "user_role" ADD CONSTRAINT "user_role_role_id_role_id_fk" FOREIGN KEY ("role_id") REFERENCES "public"."role"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; +--> statement-breakpoint +DO $$ BEGIN + ALTER TABLE "user_stats" ADD CONSTRAINT "user_stats_user_id_user_id_fk" FOREIGN KEY ("user_id") REFERENCES "public"."user"("id") ON DELETE cascade ON UPDATE no action; +EXCEPTION + WHEN duplicate_object THEN null; +END $$; diff --git a/src/db/migrations/meta/0000_snapshot.json b/src/db/migrations/meta/0000_snapshot.json new file mode 100644 index 0000000000000000000000000000000000000000..81c96f1dcf05d929245942fe7ce2887527dc4699 --- /dev/null +++ b/src/db/migrations/meta/0000_snapshot.json @@ -0,0 +1,1897 @@ +{ + "id": "a57a8a9a-72a9-43a1-8379-ae187d1f5d05", + "prevId": "00000000-0000-0000-0000-000000000000", + "version": "7", + "dialect": "postgresql", + "tables": { + "public.achievement": { + "name": "achievement", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "reward_experience": { + "name": "reward_experience", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "reward_points": { + "name": "reward_points", + "type": "numeric", + "primaryKey": false, + "notNull": false + }, + "state": { + "name": "state", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "repeatable": { + "name": "repeatable", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "is_resettable": { + "name": "is_resettable", + "type": "boolean", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "achievement_id_unique": { + "name": "achievement_id_unique", + "nullsNotDistinct": false, + "columns": [ + "id" + ] + } + } + }, + "public.collection_likes": { + "name": "collection_likes", + "schema": "", + "columns": { + "user_id": { + "name": "user_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "collection": { + "name": "collection", + "type": "integer", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "collection_likes_user_id_user_id_fk": { + "name": "collection_likes_user_id_user_id_fk", + "tableFrom": "collection_likes", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "collection_likes_collection_collection_id_fk": { + "name": "collection_likes_collection_collection_id_fk", + "tableFrom": "collection_likes", + "tableTo": "collection", + "columnsFrom": [ + "collection" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "public.collection_resources": { + "name": "collection_resources", + "schema": "", + "columns": { + "collection_id": { + "name": "collection_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "resource_id": { + "name": "resource_id", + "type": "integer", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "collection_resources_collection_id_collection_id_fk": { + "name": "collection_resources_collection_id_collection_id_fk", + "tableFrom": "collection_resources", + "tableTo": "collection", + "columnsFrom": [ + "collection_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "collection_resources_resource_id_resource_id_fk": { + "name": "collection_resources_resource_id_resource_id_fk", + "tableFrom": "collection_resources", + "tableTo": "resource", + "columnsFrom": [ + "resource_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "public.collection_stats": { + "name": "collection_stats", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "collection_id": { + "name": "collection_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "views": { + "name": "views", + "type": "bigint", + "primaryKey": false, + "notNull": false, + "default": 0 + }, + "downloads": { + "name": "downloads", + "type": "bigint", + "primaryKey": false, + "notNull": false, + "default": 0 + }, + "likes": { + "name": "likes", + "type": "bigint", + "primaryKey": false, + "notNull": false, + "default": 0 + }, + "shares": { + "name": "shares", + "type": "bigint", + "primaryKey": false, + "notNull": false, + "default": 0 + }, + "score": { + "name": "score", + "type": "bigint", + "primaryKey": false, + "notNull": false, + "default": 0 + }, + "follows": { + "name": "follows", + "type": "bigint", + "primaryKey": false, + "notNull": false, + "default": 0 + } + }, + "indexes": {}, + "foreignKeys": { + "collection_stats_collection_id_collection_id_fk": { + "name": "collection_stats_collection_id_collection_id_fk", + "tableFrom": "collection_stats", + "tableTo": "collection", + "columnsFrom": [ + "collection_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "collection_stats_id_unique": { + "name": "collection_stats_id_unique", + "nullsNotDistinct": false, + "columns": [ + "id" + ] + } + } + }, + "public.collection": { + "name": "collection", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "is_private": { + "name": "is_private", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "is_active": { + "name": "is_active", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "thumbnail": { + "name": "thumbnail", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "collection_id_unique": { + "name": "collection_id_unique", + "nullsNotDistinct": false, + "columns": [ + "id" + ] + } + } + }, + "public.complaint": { + "name": "complaint", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "state": { + "name": "state", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": true + }, + "evaluatedUser": { + "name": "evaluatedUser", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "resource_id": { + "name": "resource_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "collection_id": { + "name": "collection_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "user_id": { + "name": "user_id", + "type": "integer", + "primaryKey": false, + "notNull": false + }, + "evaluated_at": { + "name": "evaluated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "q1": { + "name": "q1", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "q2": { + "name": "q2", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "q3": { + "name": "q3", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "q4": { + "name": "q4", + "type": "boolean", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "complaint_evaluatedUser_user_id_fk": { + "name": "complaint_evaluatedUser_user_id_fk", + "tableFrom": "complaint", + "tableTo": "user", + "columnsFrom": [ + "evaluatedUser" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "public.educational_stages": { + "name": "educational_stages", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "varchar", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "educational_stages_id_unique": { + "name": "educational_stages_id_unique", + "nullsNotDistinct": false, + "columns": [ + "id" + ] + }, + "educational_stages_name_unique": { + "name": "educational_stages_name_unique", + "nullsNotDistinct": false, + "columns": [ + "name" + ] + } + } + }, + "public.follows": { + "name": "follows", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "follower_id": { + "name": "follower_id", + "type": "integer", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "follows_user_id_user_id_fk": { + "name": "follows_user_id_user_id_fk", + "tableFrom": "follows", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "follows_follower_id_user_id_fk": { + "name": "follows_follower_id_user_id_fk", + "tableFrom": "follows", + "tableTo": "user", + "columnsFrom": [ + "follower_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "follows_id_unique": { + "name": "follows_id_unique", + "nullsNotDistinct": false, + "columns": [ + "id" + ] + } + } + }, + "public.institution": { + "name": "institution", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "uf": { + "name": "uf", + "type": "varchar(2)", + "primaryKey": false, + "notNull": false + }, + "city": { + "name": "city", + "type": "varchar(255)", + "primaryKey": false, + "notNull": false + }, + "cep": { + "name": "cep", + "type": "varchar(10)", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "institution_id_unique": { + "name": "institution_id_unique", + "nullsNotDistinct": false, + "columns": [ + "id" + ] + } + } + }, + "public.items": { + "name": "items", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "price": { + "name": "price", + "type": "numeric(10, 2)", + "primaryKey": false, + "notNull": false + }, + "discount": { + "name": "discount", + "type": "numeric(10, 2)", + "primaryKey": false, + "notNull": false + }, + "description": { + "name": "description", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "is_active": { + "name": "is_active", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": false + }, + "item_type": { + "name": "item_type", + "type": "varchar(256)", + "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 + }, + "achievement_id": { + "name": "achievement_id", + "type": "integer", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "items_achievement_id_achievement_id_fk": { + "name": "items_achievement_id_achievement_id_fk", + "tableFrom": "items", + "tableTo": "achievement", + "columnsFrom": [ + "achievement_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "no action", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "items_id_unique": { + "name": "items_id_unique", + "nullsNotDistinct": false, + "columns": [ + "id" + ] + } + } + }, + "public.language": { + "name": "language", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "code": { + "name": "code", + "type": "varchar", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "language_id_unique": { + "name": "language_id_unique", + "nullsNotDistinct": false, + "columns": [ + "id" + ] + }, + "language_name_unique": { + "name": "language_name_unique", + "nullsNotDistinct": false, + "columns": [ + "name" + ] + }, + "language_code_unique": { + "name": "language_code_unique", + "nullsNotDistinct": false, + "columns": [ + "code" + ] + } + } + }, + "public.licenses": { + "name": "licenses", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "varchar", + "primaryKey": false, + "notNull": true + }, + "url": { + "name": "url", + "type": "varchar", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "licenses_id_unique": { + "name": "licenses_id_unique", + "nullsNotDistinct": false, + "columns": [ + "id" + ] + }, + "licenses_name_unique": { + "name": "licenses_name_unique", + "nullsNotDistinct": false, + "columns": [ + "name" + ] + } + } + }, + "public.object_types": { + "name": "object_types", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "object_types_id_unique": { + "name": "object_types_id_unique", + "nullsNotDistinct": false, + "columns": [ + "id" + ] + } + } + }, + "public.reset_ticket": { + "name": "reset_ticket", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "token_hash": { + "name": "token_hash", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "expiration_date": { + "name": "expiration_date", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "token_used": { + "name": "token_used", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "valid_token": { + "name": "valid_token", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": { + "reset_ticket_user_id_user_id_fk": { + "name": "reset_ticket_user_id_user_id_fk", + "tableFrom": "reset_ticket", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "reset_ticket_id_unique": { + "name": "reset_ticket_id_unique", + "nullsNotDistinct": false, + "columns": [ + "id" + ] + } + } + }, + "public.resource_educational_stages": { + "name": "resource_educational_stages", + "schema": "", + "columns": { + "resource_id": { + "name": "resource_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "educational_stage_id": { + "name": "educational_stage_id", + "type": "integer", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "resource_educational_stages_resource_id_resource_id_fk": { + "name": "resource_educational_stages_resource_id_resource_id_fk", + "tableFrom": "resource_educational_stages", + "tableTo": "resource", + "columnsFrom": [ + "resource_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "resource_educational_stages_educational_stage_id_educational_stages_id_fk": { + "name": "resource_educational_stages_educational_stage_id_educational_stages_id_fk", + "tableFrom": "resource_educational_stages", + "tableTo": "educational_stages", + "columnsFrom": [ + "educational_stage_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "public.resource_languages": { + "name": "resource_languages", + "schema": "", + "columns": { + "resource_id": { + "name": "resource_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "language_id": { + "name": "language_id", + "type": "integer", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "resource_languages_resource_id_resource_id_fk": { + "name": "resource_languages_resource_id_resource_id_fk", + "tableFrom": "resource_languages", + "tableTo": "resource", + "columnsFrom": [ + "resource_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "resource_languages_language_id_language_id_fk": { + "name": "resource_languages_language_id_language_id_fk", + "tableFrom": "resource_languages", + "tableTo": "language", + "columnsFrom": [ + "language_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "public.resource_likes": { + "name": "resource_likes", + "schema": "", + "columns": { + "user_id": { + "name": "user_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "resource_id": { + "name": "resource_id", + "type": "integer", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "resource_likes_user_id_user_id_fk": { + "name": "resource_likes_user_id_user_id_fk", + "tableFrom": "resource_likes", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "resource_likes_resource_id_resource_id_fk": { + "name": "resource_likes_resource_id_resource_id_fk", + "tableFrom": "resource_likes", + "tableTo": "resource", + "columnsFrom": [ + "resource_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "public.resource_subjects": { + "name": "resource_subjects", + "schema": "", + "columns": { + "resource_id": { + "name": "resource_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "subject_id": { + "name": "subject_id", + "type": "integer", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "resource_subjects_resource_id_resource_id_fk": { + "name": "resource_subjects_resource_id_resource_id_fk", + "tableFrom": "resource_subjects", + "tableTo": "resource", + "columnsFrom": [ + "resource_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "resource_subjects_subject_id_subjects_id_fk": { + "name": "resource_subjects_subject_id_subjects_id_fk", + "tableFrom": "resource_subjects", + "tableTo": "subjects", + "columnsFrom": [ + "subject_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "public.resource": { + "name": "resource", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "author": { + "name": "author", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "bucket_key": { + "name": "bucket_key", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "link": { + "name": "link", + "type": "varchar(256)", + "primaryKey": false, + "notNull": false + }, + "thumbnail": { + "name": "thumbnail", + "type": "varchar(256)", + "primaryKey": false, + "notNull": true + }, + "active": { + "name": "active", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "published_at": { + "name": "published_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "submited_at": { + "name": "submited_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "resource_id_unique": { + "name": "resource_id_unique", + "nullsNotDistinct": false, + "columns": [ + "id" + ] + }, + "resource_bucket_key_unique": { + "name": "resource_bucket_key_unique", + "nullsNotDistinct": false, + "columns": [ + "bucket_key" + ] + } + } + }, + "public.role": { + "name": "role", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "role_id_unique": { + "name": "role_id_unique", + "nullsNotDistinct": false, + "columns": [ + "id" + ] + }, + "role_name_unique": { + "name": "role_name_unique", + "nullsNotDistinct": false, + "columns": [ + "name" + ] + } + } + }, + "public.stats_resources": { + "name": "stats_resources", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "resource_id": { + "name": "resource_id", + "type": "bigint", + "primaryKey": false, + "notNull": true + }, + "views": { + "name": "views", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "downloads": { + "name": "downloads", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "shares": { + "name": "shares", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "score": { + "name": "score", + "type": "bigint", + "primaryKey": false, + "notNull": true, + "default": 0 + } + }, + "indexes": {}, + "foreignKeys": { + "stats_resources_resource_id_resource_id_fk": { + "name": "stats_resources_resource_id_resource_id_fk", + "tableFrom": "stats_resources", + "tableTo": "resource", + "columnsFrom": [ + "resource_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "stats_resources_id_unique": { + "name": "stats_resources_id_unique", + "nullsNotDistinct": false, + "columns": [ + "id" + ] + } + } + }, + "public.subjects": { + "name": "subjects", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "varchar", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "subjects_id_unique": { + "name": "subjects_id_unique", + "nullsNotDistinct": false, + "columns": [ + "id" + ] + }, + "subjects_name_unique": { + "name": "subjects_name_unique", + "nullsNotDistinct": false, + "columns": [ + "name" + ] + } + } + }, + "public.submission": { + "name": "submission", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "is_accepted": { + "name": "is_accepted", + "type": "boolean", + "primaryKey": false, + "notNull": true, + "default": false + }, + "justification": { + "name": "justification", + "type": "text", + "primaryKey": false, + "notNull": false + }, + "resource_id": { + "name": "resource_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "submitter_id": { + "name": "submitter_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "curator_id": { + "name": "curator_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "answered_at": { + "name": "answered_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "q1": { + "name": "q1", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "q2": { + "name": "q2", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "q3": { + "name": "q3", + "type": "boolean", + "primaryKey": false, + "notNull": false + }, + "q4": { + "name": "q4", + "type": "boolean", + "primaryKey": false, + "notNull": false + } + }, + "indexes": {}, + "foreignKeys": { + "submission_resource_id_resource_id_fk": { + "name": "submission_resource_id_resource_id_fk", + "tableFrom": "submission", + "tableTo": "resource", + "columnsFrom": [ + "resource_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "submission_submitter_id_user_id_fk": { + "name": "submission_submitter_id_user_id_fk", + "tableFrom": "submission", + "tableTo": "user", + "columnsFrom": [ + "submitter_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "submission_curator_id_user_id_fk": { + "name": "submission_curator_id_user_id_fk", + "tableFrom": "submission", + "tableTo": "user", + "columnsFrom": [ + "curator_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": {} + }, + "public.user_institution": { + "name": "user_institution", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "institution_id": { + "name": "institution_id", + "type": "integer", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "user_institution_user_id_user_id_fk": { + "name": "user_institution_user_id_user_id_fk", + "tableFrom": "user_institution", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "user_institution_institution_id_institution_id_fk": { + "name": "user_institution_institution_id_institution_id_fk", + "tableFrom": "user_institution", + "tableTo": "institution", + "columnsFrom": [ + "institution_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "user_institution_id_unique": { + "name": "user_institution_id_unique", + "nullsNotDistinct": false, + "columns": [ + "id" + ] + } + } + }, + "public.user_role": { + "name": "user_role", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "role_id": { + "name": "role_id", + "type": "integer", + "primaryKey": false, + "notNull": true + } + }, + "indexes": {}, + "foreignKeys": { + "user_role_user_id_user_id_fk": { + "name": "user_role_user_id_user_id_fk", + "tableFrom": "user_role", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + }, + "user_role_role_id_role_id_fk": { + "name": "user_role_role_id_role_id_fk", + "tableFrom": "user_role", + "tableTo": "role", + "columnsFrom": [ + "role_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "user_role_id_unique": { + "name": "user_role_id_unique", + "nullsNotDistinct": false, + "columns": [ + "id" + ] + } + } + }, + "public.user_stats": { + "name": "user_stats", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "user_id": { + "name": "user_id", + "type": "integer", + "primaryKey": false, + "notNull": true + }, + "score": { + "name": "score", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "likes": { + "name": "likes", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "likes_received": { + "name": "likes_received", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "follows": { + "name": "follows", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "followers": { + "name": "followers", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "collections": { + "name": "collections", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "submitted_resources": { + "name": "submitted_resources", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "approved_resources": { + "name": "approved_resources", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "reviewed_resources": { + "name": "reviewed_resources", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + }, + "comments": { + "name": "comments", + "type": "integer", + "primaryKey": false, + "notNull": true, + "default": 0 + } + }, + "indexes": {}, + "foreignKeys": { + "user_stats_user_id_user_id_fk": { + "name": "user_stats_user_id_user_id_fk", + "tableFrom": "user_stats", + "tableTo": "user", + "columnsFrom": [ + "user_id" + ], + "columnsTo": [ + "id" + ], + "onDelete": "cascade", + "onUpdate": "no action" + } + }, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "user_stats_id_unique": { + "name": "user_stats_id_unique", + "nullsNotDistinct": false, + "columns": [ + "id" + ] + } + } + }, + "public.user": { + "name": "user", + "schema": "", + "columns": { + "id": { + "name": "id", + "type": "serial", + "primaryKey": true, + "notNull": true + }, + "name": { + "name": "name", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "username": { + "name": "username", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "password": { + "name": "password", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "email": { + "name": "email", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "description": { + "name": "description", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "'sem descrição'" + }, + "institution": { + "name": "institution", + "type": "text", + "primaryKey": false, + "notNull": false, + "default": "'sem instituição'" + }, + "birthday": { + "name": "birthday", + "type": "timestamp", + "primaryKey": false, + "notNull": true + }, + "cpf": { + "name": "cpf", + "type": "varchar(255)", + "primaryKey": false, + "notNull": true + }, + "created_at": { + "name": "created_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "updated_at": { + "name": "updated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": true, + "default": "now()" + }, + "confirmed_at": { + "name": "confirmed_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "confirmation_sent_at": { + "name": "confirmation_sent_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "deleted_at": { + "name": "deleted_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "reactivated_at": { + "name": "reactivated_at", + "type": "timestamp", + "primaryKey": false, + "notNull": false + }, + "active": { + "name": "active", + "type": "boolean", + "primaryKey": false, + "notNull": false, + "default": true + } + }, + "indexes": {}, + "foreignKeys": {}, + "compositePrimaryKeys": {}, + "uniqueConstraints": { + "user_id_unique": { + "name": "user_id_unique", + "nullsNotDistinct": false, + "columns": [ + "id" + ] + }, + "user_username_unique": { + "name": "user_username_unique", + "nullsNotDistinct": false, + "columns": [ + "username" + ] + }, + "user_email_unique": { + "name": "user_email_unique", + "nullsNotDistinct": false, + "columns": [ + "email" + ] + } + } + } + }, + "enums": {}, + "schemas": {}, + "_meta": { + "columns": {}, + "schemas": {}, + "tables": {} + } +} \ No newline at end of file diff --git a/src/db/migrations/meta/_journal.json b/src/db/migrations/meta/_journal.json index 6c380b43155c81440963a530b41839dc9068c2f1..966b5209f2e984b047b6fd6265601ae6a90fa1eb 100644 --- a/src/db/migrations/meta/_journal.json +++ b/src/db/migrations/meta/_journal.json @@ -5,10 +5,9 @@ { "idx": 0, "version": "7", - "when": 1729522512009, - "tag": "0000_narrow_payback", + "when": 1729686694449, + "tag": "0000_cooing_doorman", "breakpoints": true } - ] } \ No newline at end of file diff --git a/src/db/repo/items.repo.ts b/src/db/repo/items.repo.ts new file mode 100644 index 0000000000000000000000000000000000000000..d2b8e4394fef128b8c3e250b13a256017095642b --- /dev/null +++ b/src/db/repo/items.repo.ts @@ -0,0 +1,62 @@ +import { Service } from "typedi"; +import type { ItemsInput, ItemsModel, ItemsUpdate } from "../schema/items.schema"; +import db from ".."; +import itemsTable, { itemsSchema } from "../schema/items.schema"; +import { and, eq } from "drizzle-orm"; + + +@Service() +export class ItemsRepo { + async create(item: ItemsInput): Promise<ItemsModel> { + const [ret] = await db + .insert(itemsTable) + .values(item) + .returning() + + return itemsSchema.model.parse(ret) + } + + async update(item: ItemsUpdate): Promise<ItemsModel> { + const [ret] = await db + .update(itemsTable) + .set(item) + .where(eq(itemsTable.id, item.id)) + .returning() + + return itemsSchema.model.parse(ret) + } + + async delete(id: ItemsModel['id']): Promise<ItemsModel> { + const [ret] = await db + .delete(itemsTable) + .where(eq(itemsTable.id, id)) + .returning() + + return itemsSchema.model.parse(ret) + } + + async active(id: ItemsModel['id']): Promise<ItemsModel> { + const [ret] = await db + .update(itemsTable) + .set({ + is_active: true + }) + .where(eq(itemsTable.id, id)) + .returning() + + return itemsSchema.model.parse(ret) + } + + + async find(id: ItemsModel['id']): Promise<ItemsModel | undefined> { + const item = await db.query.itemsTable.findFirst({ + where: and(eq(itemsTable.id, id), eq(itemsTable.is_active, true)) + }) + + return itemsSchema.model.parse(item) + } + + async findMany(): Promise<ItemsModel[]> { + return itemsSchema.model.array().parse(await db.query.itemsTable.findMany({where: eq(itemsTable.is_active, true)})) + } +} \ No newline at end of file diff --git a/src/db/schema/index.ts b/src/db/schema/index.ts index 8c20b59eb4d364b6f0de2ca3496e11d49f68600d..146861675cbd4ba2f996a42416b0f307e5af9ba2 100644 --- a/src/db/schema/index.ts +++ b/src/db/schema/index.ts @@ -27,6 +27,7 @@ import institutionTable from './institutions.schema' import userInstitutionRelationTable from '../relations/user-institution.relation' import resourceLikesTable from '../relations/resource-likes.relation' import resourceEducationalStagesTable from './resource-educational-stages.schema' +import itemsTable from './items.schema' export { userTable, @@ -56,6 +57,7 @@ export { resourceLikesTable, resourceEducationalStagesTable, achievementTable, + itemsTable, } export const tables = [ @@ -82,4 +84,5 @@ export const tables = [ userInstitutionRelationTable, resourceLikesTable, achievementTable, + itemsTable ] diff --git a/src/db/schema/items.schema.ts b/src/db/schema/items.schema.ts new file mode 100644 index 0000000000000000000000000000000000000000..3694d7a01aa45620fbfd63d85c5cebec0b3d1d9c --- /dev/null +++ b/src/db/schema/items.schema.ts @@ -0,0 +1,42 @@ +import { boolean, serial, timestamp, varchar } from "drizzle-orm/pg-core"; +import { integer, numeric, pgTable } from "drizzle-orm/pg-core"; +import achievementTable from "./achievements.schema"; +import { createInsertSchema, createSelectSchema } from "drizzle-zod"; +import type { z } from "zod"; +import { sql } from "drizzle-orm"; + + + +const itemsTable = pgTable('items', { + id: serial('id').primaryKey().unique().notNull(), + name: varchar('name', { length: 256 }).notNull(), + price: numeric('price', { precision: 10, scale: 2 }), + discount: numeric('discount', { precision: 10, scale: 2 }), + description: varchar('description', { length: 256 }), + is_active: boolean('is_active').default(false), + item_type: varchar('item_type', { length: 256 }), + created_at: timestamp('created_at', { mode: 'string' }).notNull().defaultNow(), + updated_at: timestamp('updated_at', { mode: 'string' }).$onUpdate(() => sql`current_timestamp`).notNull(), + achievement_id: integer('achievement_id').references(() => achievementTable.id) +}) + +const itemsModelSchema = createSelectSchema(itemsTable) +const itemsDtoSchema = itemsModelSchema.omit({}) +const itemsInputSchema = createInsertSchema(itemsTable) +const itemsUpdateSchema = itemsInputSchema + .partial() + .required({ id: true }) + +export type ItemsModel = z.infer<typeof itemsModelSchema> +export type ItemsDto = z.infer<typeof itemsDtoSchema> +export type ItemsInput = z.infer<typeof itemsInputSchema> +export type ItemsUpdate = z.infer<typeof itemsUpdateSchema> + +export const itemsSchema = { + model: itemsModelSchema, + dto: itemsDtoSchema, + input: itemsInputSchema, + update: itemsUpdateSchema, +} + +export default itemsTable diff --git a/src/db/seed.ts b/src/db/seed.ts index 6b050d47fc2abcd5b1cea7482d9c8dd7bf3995b0..e6faaabd8365dd083a9e8ca23ea8d03f8c656fd0 100644 --- a/src/db/seed.ts +++ b/src/db/seed.ts @@ -45,5 +45,6 @@ await seeds.userInstitutionSeed(db) await seeds.resourceLikesSeed(db) await seeds.resourceEducationalStagesSeed(db) await seeds.achievementSeed(db) +await seeds.itemsSeed(db) await connection.end() diff --git a/src/db/seeds/index.ts b/src/db/seeds/index.ts index f3d21f7b29134e4585c87ab0cb577b014a3d8429..ba20da582ac097629ad4a031dc163937d91139b5 100644 --- a/src/db/seeds/index.ts +++ b/src/db/seeds/index.ts @@ -22,3 +22,4 @@ export { default as userInstitutionSeed } from './user-institution.seed' export { default as resourceLikesSeed } from './resource-likes.seed' export { default as resourceEducationalStagesSeed } from './resource-educational-stages.seed' export { default as achievementSeed } from './achievement.seed' +export { default as itemsSeed } from './items.seed' diff --git a/src/db/seeds/items.seed.ts b/src/db/seeds/items.seed.ts new file mode 100644 index 0000000000000000000000000000000000000000..779a0893ccbf6c507c2d353769c2c275975cb0c7 --- /dev/null +++ b/src/db/seeds/items.seed.ts @@ -0,0 +1,31 @@ +import type db from ".."; +import { itemsTable } from "../schema"; +import type { ItemsInput } from "../schema/items.schema"; + + +export default async function seed(db: db) { + await db.insert(itemsTable).values(itemsData) +} + +const itemsData: ItemsInput[] = [ + { + name:'camisa', + description:'camisa de manga larga', + is_active: true + }, + { + name:'pantalon', + description:'pantalon de mezclilla', + is_active: true + }, + { + name:'zapatos', + description:'zapatos de piel', + is_active: true + }, + { + name:'gorra', + description:'gorra de beisbol', + is_active: true + } +] \ No newline at end of file diff --git a/src/index.ts b/src/index.ts index f9b8e17a768f6710386c7649f3aa55d33917ff63..76fac3298b8a25a9922d3f8ec41a84950c79e13b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -34,6 +34,7 @@ import { userInstitutionRouter } from './routes/user-institution.route' import { publicResourceLikesRoutes, resourceLikesRoutes } from './routes/resource-likes.route' import { publicResourceEducationalStagesRouter, resourceEducationalStagesRouter } from './routes/resource-educational-stages.route' import { achievementRouter, publicAchievementRouter } from './routes/achievement.route' +import { itemsRouter, publicItemsRouter } from './routes/items.route' const app = new Hono() @@ -88,7 +89,7 @@ app .route('/collectionResources', publicCollectionResourcesRoutes) .route('/resourceSubjects', publicResourceSubjectsRouter) .route('/resourceEducationalStages', publicResourceEducationalStagesRouter) - + .route('/items', publicItemsRouter) .route('/resourceLikes', publicResourceLikesRoutes) .route('/achievements', publicAchievementRouter) //rotas que precisam de token @@ -117,7 +118,7 @@ app .route('/resourceSubjects', resourceSubjectsRouter) .route('/user-institutions', userInstitutionRouter) .route('/resourceEducationalStages', resourceEducationalStagesRouter) - + .route('/items', itemsRouter) .route('/achievements', achievementRouter) .route('/resourceLikes', resourceLikesRoutes) export default app diff --git a/src/routes/items.route.ts b/src/routes/items.route.ts new file mode 100644 index 0000000000000000000000000000000000000000..1ecf9b3c4733be318ea72ddf0e63495e74c04662 --- /dev/null +++ b/src/routes/items.route.ts @@ -0,0 +1,146 @@ +import { ItemsService } from "@/services/items.service"; +import Container from "typedi"; +import { honoWithJwt } from ".."; +import { zValidator } from "@hono/zod-validator"; +import { itemsSchema } from "@/db/schema/items.schema"; +import { createApexError, HttpStatus } from "@/services/error.service"; +import { Hono } from "hono"; + +const service = Container.get(ItemsService); + +export const itemsRouter = honoWithJwt() + + .post('/create', + zValidator('json', itemsSchema.input), + async (c) => { + try { + const input = await c.req.valid('json') + const item = itemsSchema.dto.parse(await service.create(input)) + + return c.json({ item }) + } catch (e) { + return c.json( + createApexError({ + status: 'error', + message: 'could not create the item', + code: HttpStatus.BAD_REQUEST, + path: c.req.routePath, + suggestion: 'check the json input and try again', + }), + HttpStatus.BAD_REQUEST + ) + } + } + ) + + .post('/update', + zValidator('json', itemsSchema.update), + async (c) => { + try { + const input = await c.req.valid('json') + const item = itemsSchema.dto.parse(await service.update(input)) + + return c.json({ item }) + } catch (e) { + return c.json( + createApexError({ + status: 'error', + message: 'could not update the item', + code: HttpStatus.BAD_REQUEST, + path: c.req.routePath, + suggestion: 'check the json input and try again', + }), + HttpStatus.BAD_REQUEST + ) + } + } + ) + + .post('/delete/:id', + async (c) => { + try { + const id = +c.req.param('id') + const item = itemsSchema.dto.parse(await service.delete(id)) + + return c.json({ item }) + } catch (e) { + return c.json( + createApexError({ + status: 'error', + message: 'could not delete the item', + code: HttpStatus.BAD_REQUEST, + path: c.req.routePath, + suggestion: 'check the id and try again', + }), + HttpStatus.BAD_REQUEST + ) + } + } + ) + + .post('/active/:id', + async (c) => { + try { + const id = +c.req.param('id') + const item = itemsSchema.dto.parse(await service.active(id)) + + return c.json({ item }) + } catch (e) { + return c.json( + createApexError({ + status: 'error', + message: 'could not active the item', + code: HttpStatus.BAD_REQUEST, + path: c.req.routePath, + suggestion: 'check the id and try again', + }), + HttpStatus.BAD_REQUEST + ) + } + } + ) + +export const publicItemsRouter = new Hono() + +.get('/all', + async (c) => { + try { + const items = itemsSchema.dto.array().parse(await service.findMany()) + + return c.json({ items }) + } catch (e) { + return c.json( + createApexError({ + status: 'error', + message: 'could not find the items', + code: HttpStatus.BAD_REQUEST, + path: c.req.routePath, + suggestion: 'are you sure there are items?', + }), + HttpStatus.BAD_REQUEST + ) + } + } +) + +.get('/:id', + async (c) => { + try { + const id = +c.req.param('id') + const item = itemsSchema.dto.parse(await service.find(id)) + + return c.json({ item }) + } catch (e) { + return c.json( + createApexError({ + status: 'error', + message: 'could not find the item', + code: HttpStatus.BAD_REQUEST, + path: c.req.routePath, + suggestion: 'check the id and try again', + }), + HttpStatus.BAD_REQUEST + ) + } + } +) \ No newline at end of file diff --git a/src/services/items.service.ts b/src/services/items.service.ts new file mode 100644 index 0000000000000000000000000000000000000000..d413c53b574f62fa2b2801d647a070ed419c1d2a --- /dev/null +++ b/src/services/items.service.ts @@ -0,0 +1,34 @@ +import { ItemsRepo } from "@/db/repo/items.repo"; +import type { ItemsInput, ItemsModel, ItemsUpdate } from "@/db/schema/items.schema"; +import { Inject, Service } from "typedi"; + + +@Service() +export class ItemsService { + @Inject() + private readonly repo: ItemsRepo + + async create(item: ItemsInput): Promise<ItemsModel> { + return this.repo.create(item) + } + + async update(item: ItemsUpdate): Promise<ItemsModel> { + return this.repo.update(item) + } + + async delete(id: ItemsModel['id']): Promise<ItemsModel> { + return this.repo.delete(id) + } + + async active(id: ItemsModel['id']): Promise<ItemsModel> { + return this.repo.active(id) + } + + async find(id: ItemsModel['id']): Promise<ItemsModel | undefined> { + return this.repo.find(id) + } + + async findMany(): Promise<ItemsModel[]> { + return this.repo.findMany() + } +}