diff --git a/src/db/migrations/0001_milky_annihilus.sql b/src/db/migrations/0001_milky_annihilus.sql new file mode 100644 index 0000000000000000000000000000000000000000..a36e8c821c821c572780a2a0e6d201d9e2118508 --- /dev/null +++ b/src/db/migrations/0001_milky_annihilus.sql @@ -0,0 +1,38 @@ +ALTER TYPE "resource_state" ADD VALUE 'deleted';--> 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 +ALTER TABLE "achievements" RENAME COLUMN "state" TO "review_state";--> statement-breakpoint +ALTER TABLE "collection_likes" RENAME COLUMN "collection" TO "collection_id";--> statement-breakpoint +ALTER TABLE "users" RENAME COLUMN "active" TO "is_active";--> statement-breakpoint +ALTER TABLE "collection_likes" DROP CONSTRAINT "collection_likes_collection_collections_id_fk"; +--> statement-breakpoint +ALTER TABLE "items" DROP CONSTRAINT "items_achievement_id_achievements_id_fk"; +--> statement-breakpoint +ALTER TABLE "achievements" ALTER COLUMN "review_state" SET DEFAULT 'under_review';--> statement-breakpoint +ALTER TABLE "collections" ALTER COLUMN "name" SET NOT NULL;--> statement-breakpoint +ALTER TABLE "resources" ALTER COLUMN "thumbnail" DROP NOT NULL;--> 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 "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 +ALTER TABLE "items" DROP COLUMN IF EXISTS "achievement_id";--> statement-breakpoint +ALTER TABLE "resources" DROP COLUMN IF EXISTS "active";--> statement-breakpoint +ALTER TABLE "users" DROP COLUMN IF EXISTS "institution"; \ No newline at end of file diff --git a/src/db/migrations/meta/0001_snapshot.json b/src/db/migrations/meta/0001_snapshot.json new file mode 100644 index 0000000000000000000000000000000000000000..f2d6cfc290a5855fe57e8dfb44bda5756a3e2eee --- /dev/null +++ b/src/db/migrations/meta/0001_snapshot.json @@ -0,0 +1,2642 @@ +{ + "id": "fa865788-c6ff-4a5a-8b90-acc4275c1526", + "prevId": "0ad63f02-9e60-4b45-85a0-3b8096d0223d", + "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 + } + }, + "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 + }, + "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": true + }, + "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 + }, + "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_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 + } + }, + "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 bfbd55101e53ff1b2858340cd151ad7bb0932fcb..c7618af73a1771de6f0bde0de1110960f8bd424a 100644 --- a/src/db/migrations/meta/_journal.json +++ b/src/db/migrations/meta/_journal.json @@ -8,6 +8,13 @@ "when": 1744041940840, "tag": "0000_volatile_whirlwind", "breakpoints": true + }, + { + "idx": 1, + "version": "7", + "when": 1743689366285, + "tag": "0001_milky_annihilus", + "breakpoints": true } ] } \ No newline at end of file diff --git a/src/db/repo/collections.repo.ts b/src/db/repo/collections.repo.ts index f7cc1ffcbfd825d3670bf626947179054fb9f4d6..09c3ec873e68d583694498150a4100ed38c2e741 100644 --- a/src/db/repo/collections.repo.ts +++ b/src/db/repo/collections.repo.ts @@ -6,12 +6,8 @@ import type { } from '../schema/collections.schema' import db from ".."; import collectionTable, { collectionSchemas } from "../schema/collections.schema"; -import { and, eq, isNull } from 'drizzle-orm' -import resourceTable, { resourceSchema, type ResourceModel } from "../schema/resource.schema"; -import fs from 'fs'; -import path from 'path'; -import archiver from 'archiver'; -import { PassThrough } from "stream"; +import { and, eq } from 'drizzle-orm' +import resourceTable, { type ResourceModel } from "../schema/resource.schema"; import { collectionResourcesTable } from "../schema"; diff --git a/src/db/repo/comments.repo.ts b/src/db/repo/comments.repo.ts index efb49297b7b9f2773f667f8edaff0b2ce7bb7417..0af80a3dcbbcb86ea2d4e7d08a1899dc3f89ed4b 100644 --- a/src/db/repo/comments.repo.ts +++ b/src/db/repo/comments.repo.ts @@ -61,7 +61,6 @@ export class commentsRepo { .select() .from(commentsTable) .where(isNull(commentsTable.deleted_at)) - return commentsSchema.model.array().parse(comments) } @@ -72,7 +71,7 @@ export class commentsRepo { .from(commentsTable) .where(and(eq(commentsTable.resource_id, id_resource), isNull(commentsTable.deleted_at))) - return commentsSchema.model.array().parse(comments) + return comments ? commentsSchema.model.array().parse(comments) : [] } //retorna todos(ativos e inativos) os comentarios de um recurso @@ -80,9 +79,9 @@ export class commentsRepo { const comments = await db .select() .from(commentsTable) - .where(and(eq(commentsTable.resource_id, id_resource))) + .where((eq(commentsTable.resource_id, id_resource))) - return commentsSchema.model.array().parse(comments) + return comments ? commentsSchema.model.array().parse(comments) : [] } diff --git a/src/db/repo/homologation.repo.ts b/src/db/repo/homologation.repo.ts index d044ffaa396bd5cff0b2898ad9d69fb11374777e..8cfd42f9b980722445db1d5f0183f0f28b805ac8 100644 --- a/src/db/repo/homologation.repo.ts +++ b/src/db/repo/homologation.repo.ts @@ -31,5 +31,4 @@ export class HomologationRepo { return resourceSchema.model.array().parse(resources) } - } diff --git a/src/routes/comments.route.ts b/src/routes/comments.route.ts index d4f385e9ea0a75f6e30d4477538b89408128fecb..7a7cac99bc5eb853e509808341c29e4973e593e5 100644 --- a/src/routes/comments.route.ts +++ b/src/routes/comments.route.ts @@ -7,6 +7,7 @@ import { createApexError, HttpStatus } from "@/services/error.service"; import { Hono } from "hono"; import { UserStatsService } from "@/services/user-stats.service"; import { ResourceStatsService } from "@/services/resource-stats.service"; +import { UserService } from "@/services/user.service"; import { createCommentRoute, @@ -24,6 +25,7 @@ import { const service = Container.get(CommentsService); const serviceUserStats = Container.get(UserStatsService) const serviceStatsResource = Container.get(ResourceStatsService) +const serviceUser = Container.get(UserService) export const commentsRouter = honoWithJwt() @@ -35,6 +37,7 @@ export const commentsRouter = honoWithJwt() try { const input = await c.req.valid('json') const comment = commentsSchema.dto.parse(await service.create(input)) + console.log("nao funcioina") await serviceUserStats.updateComments(input.user_id) await serviceStatsResource.updateComments(input.resource_id) @@ -172,13 +175,26 @@ export const publicCommentsRoute = new Hono() } ) - // get all resource by resource + .get('/findCommentsByResource/:resource_id', findCommentsByResourceRoute, async (c) => { try { const id_resource = +c.req.param('resource_id') - const comments =commentsSchema.dto.array().parse( await service.findCommentsByResource(id_resource)); - - return c.json(comments); + + const comments = await service.findCommentsByResource(id_resource); + + const commentsWithUser = await Promise.all( + + comments.map(async(comment) =>{ + const user = await serviceUser.findById(comment.user_id) + return{ + ...comment, + author_name: user?.name || 'unknown' + }; + }) + ); + + //retornar nome do usuario que comentou + return c.json(commentsWithUser); } catch (e) { return c.json( createApexError({ @@ -193,7 +209,7 @@ export const publicCommentsRoute = new Hono() } }) - // get active resource by resource + .get('/findAllCommentsByResource/:resource_id', findAllCommentsByResourceRoute, async (c) => { try { const id_resource = +c.req.param('resource_id') diff --git a/src/routes/resource.route.ts b/src/routes/resource.route.ts index 72bb60136b7c6da39a9b817473caa220658d25f8..0da397c9e4615614470e8de6c04567025c397334 100644 --- a/src/routes/resource.route.ts +++ b/src/routes/resource.route.ts @@ -12,6 +12,7 @@ import { resourceLanguagesRepo } from "@/db/repo/resource-language.repo"; import { ObjectTypeService } from "@/services/object-type.service"; import { ResourceEducationalStagesService } from "@/services/resource-educational-stages.service"; import { ResourceSubjectsService } from "@/services/resource-subjects.service"; +import { UserService } from "@/services/user.service"; import { createResourceRoute, @@ -33,6 +34,7 @@ const objectTypeService = Container.get(ObjectTypeService); const resourceLanguagesService = Container.get(resourceLanguagesRepo); const resourceEducationalStagesService = Container.get(ResourceEducationalStagesService); const resourceSubjectsService = Container.get(ResourceSubjectsService); +const userService = Container.get(UserService); //define um novo Model type ResourceWithObjectTypeName = ResourceModel & { @@ -319,18 +321,21 @@ export const publicResourceRouter = new Hono() return c.json({ message: "Arquivo não encontrado" }, 404); } - // Buscar todas as linguagens do recurso const languages = await resourceLanguagesService.getLanguagesByResource(id); - const educationalStage = await resourceEducationalStagesService.getEducationalStagesByResource(id); + const educational_stages = await resourceEducationalStagesService.getEducationalStagesByResource(id); const subjects = await resourceSubjectsService.getSubjectsByResource(id); + const stats = await serviceStats.findById(id); + const publisher = await userService.findById(resource.user_id) return c.json({ ...resourceWithObjectTypeName, contentType: response.ContentType || "application/octet-stream", // Adicionando contentType ao JSON languages, - educationalStage, + educational_stages, subjects, + stats, + publisher, }); } catch (e) { diff --git a/src/routes/s3.route.ts b/src/routes/s3.route.ts index a57af7db082998c944bb11da378207360e1e9d68..6cf343977903b06e7295da502a13550417619ea9 100644 --- a/src/routes/s3.route.ts +++ b/src/routes/s3.route.ts @@ -1,7 +1,5 @@ import { deleteObject, getFile, putFile } from "@/services/s3.service"; -import { zValidator } from "@hono/zod-validator"; import { Hono } from "hono"; -import { z } from "zod"; import { uploadResourceRoute, @@ -17,6 +15,8 @@ import { getThumbnailCollectionRoute, getAvatarRoute } from "../documentation/s3Describers" +import { z } from "zod"; +import { zValidator } from "@hono/zod-validator"; const resourceUploadSchema = z.object({ id_resource: z.string().min(1, 'id_resource é obrigatório'), @@ -41,9 +41,9 @@ export const s3Routes = new Hono() .post('/upload/resource', uploadResourceRoute, async (ctx) => { const formData = await ctx.req.formData(); + const fileBlob = formData.get('file'); const id_resource = formData.get('id_resource'); const content_type = formData.get('content_type'); - const fileBlob = formData.get('file'); @@ -63,7 +63,7 @@ export const s3Routes = new Hono() } try { - const result = await putFile(fileBlob, id_resource, content_type, "resource") + const result = await putFile(fileBlob, String(id_resource), String(content_type), "resource") return ctx.json({ message: 'Arquivo enviado com sucesso!', fileId:id_resource, @@ -83,11 +83,10 @@ export const s3Routes = new Hono() // envio de fotos de thumbnail do recurso .post('/upload/thumbnail/resource', uploadThumbnailResourceRoute, zValidator('json',resourceUploadSchema ), async (ctx) => { - const { id_resource, content_type } = ctx.req.valid('json'); - - const formData = await ctx.req.formData(); const fileBlob = formData.get('file'); + const id_resource = formData.get('id_resource'); + const content_type = formData.get('content_type'); if (!fileBlob || !(fileBlob instanceof Blob)) { @@ -107,7 +106,7 @@ export const s3Routes = new Hono() try { - const result = await putFile(fileBlob, id_resource, content_type, "thumbnail/resource") + const result = await putFile(fileBlob, String(id_resource), String(content_type), "thumbnail/resource") return ctx.json({ message: 'Arquivo enviado com sucesso!', fileId: id_resource, content_type, @@ -128,10 +127,12 @@ export const s3Routes = new Hono() // envio de fotos de thumbnail da coleção .post('/upload/thumbnail/collection', uploadThumbnailCollectionRoute, zValidator('json',collectionUploadSchema ), async (ctx) => { - const { id_collection, content_type } = ctx.req.valid('json'); const formData = await ctx.req.formData(); const fileBlob = formData.get('file'); + const id_collection = formData.get('id_collection'); + const content_type = formData.get('content_type'); + if (!fileBlob || !(fileBlob instanceof Blob)) { @@ -151,7 +152,7 @@ export const s3Routes = new Hono() try { - const result = await putFile(fileBlob, id_collection, content_type, "thumbnail/collection") + const result = await putFile(fileBlob, String(id_collection), String(content_type), "thumbnail/collection") return ctx.json({ message: 'Arquivo enviado com sucesso!', fileId: id_collection, @@ -172,11 +173,10 @@ export const s3Routes = new Hono() // envio de fotos de thumbnail da coleção .post('/upload/avatar', uploadAvatarRoute, zValidator('json', userUploadSchema ), async (ctx) => { - const { id_user, content_type } = ctx.req.valid('json'); - - const formData = await ctx.req.formData(); const fileBlob = formData.get('file'); + const id_user = formData.get('id_user'); + const content_type = formData.get('content_type'); if (!fileBlob || !(fileBlob instanceof Blob)) { @@ -194,9 +194,8 @@ export const s3Routes = new Hono() }, 400); } - try { - const result = await putFile(fileBlob, id_user, content_type, "avatar") + const result = await putFile(fileBlob, String(id_user), String(content_type), "avatar") return ctx.json({ message: 'Arquivo enviado com sucesso!', fileId: id_user, diff --git a/src/services/comments.sevice.ts b/src/services/comments.sevice.ts index 07f1d8ce6ba0a14c106ea8e4743f659a5ec6c64b..04e998debb144f8721aec95125d814a7d40770df 100644 --- a/src/services/comments.sevice.ts +++ b/src/services/comments.sevice.ts @@ -39,7 +39,6 @@ export class CommentsService { //retorna os comentarios ativos de um recurso async findCommentsByResource(id_resource: CommentsModel['resource_id']): Promise<CommentsModel[]> { - return this.repo.findCommentsByResource(id_resource) } diff --git a/src/services/user.service.ts b/src/services/user.service.ts index c75d8792211327604149a48ce028eefe866d56a0..7e0262747ca3e8a92e2c06bbedfedde2a6daf367 100644 --- a/src/services/user.service.ts +++ b/src/services/user.service.ts @@ -11,15 +11,15 @@ import { Inject, Service } from 'typedi' import { z } from 'zod' @Service() -export class UserService { +export class UserService { @Inject() private readonly repo: UserRepo getUpdateTime(): string { const deactivated_at = new Date() - deactivated_at.setHours(deactivated_at.getHours() + 1) + deactivated_at.setHours(deactivated_at.getHours() + 1) - return deactivated_at.toLocaleString('pt-br', {timeZone: 'America/Sao_Paulo'}) + return deactivated_at.toLocaleString('pt-br', { timeZone: 'America/Sao_Paulo' }) } async findMany(): Promise<UserModel[]> { @@ -33,14 +33,12 @@ export class UserService { } async findByEmail( - userEmail: UserModel['email'] - ): Promise<UserModel | null>{ + userEmail: UserModel['email'] + ): Promise<UserModel | null> { return await this.repo.findByEmail(userEmail) } - async findById( - userId: UserModel['id'] - ): Promise<UserModel | null>{ + async findById(userId: UserModel['id']): Promise<UserModel | null> { return await this.repo.findById(userId) } @@ -73,18 +71,18 @@ export class UserService { } async update(user: UserUpdate): Promise<UserModel> { - if(user.password) + if (user.password) user.password = hashPassword(user.password) return this.repo.update(user) } async delete(user: UserModel): Promise<UserModel> { - + return this.repo.update(user) } async systemDelete(user: UserModel['id']): Promise<UserModel> { - + return this.repo.delete(user) } }