From a91b9db1e2d2cbbe260ee3fa2326a2cdbd86197e Mon Sep 17 00:00:00 2001 From: Lauren Ah-Hot Date: Wed, 25 Mar 2026 15:33:53 -0400 Subject: [PATCH 1/5] Created EventPost model and cron job to process event similarity --- dumps/dev_db_dump_20260226_233628.sql | 1188 +++++++++++++++ dumps/dev_db_dump_20260226_233801.sql | 1302 +++++++++++++++++ jest.config.js | 3 + src/api/controllers/EventController.ts | 39 + src/api/controllers/index.ts | 2 + src/app.ts | 2 + src/cron/eventSimilarityCron.ts | 43 + .../1769700000000-CreateEventPost.ts | 39 + src/models/EventPostModel.ts | 48 + src/models/EventTagModel.ts | 2 +- src/models/index.ts | 2 + src/repositories/EventPostRepository.ts | 140 ++ src/repositories/EventTagRepository.ts | 7 + src/repositories/PostRepository.ts | 50 + src/repositories/index.ts | 7 + src/services/EventPostService.ts | 99 ++ src/services/EventService.ts | 81 + src/services/PostService.ts | 26 +- src/tests/EventTest.test.ts | 485 ++++++ src/tests/controllers/ControllerFactory.ts | 7 + src/tests/data/DatabaseConnection.ts | 1 + src/types/ApiResponses.ts | 17 + 22 files changed, 3585 insertions(+), 5 deletions(-) create mode 100644 dumps/dev_db_dump_20260226_233628.sql create mode 100644 dumps/dev_db_dump_20260226_233801.sql create mode 100644 src/api/controllers/EventController.ts create mode 100644 src/cron/eventSimilarityCron.ts create mode 100644 src/migrations/1769700000000-CreateEventPost.ts create mode 100644 src/models/EventPostModel.ts create mode 100644 src/repositories/EventPostRepository.ts create mode 100644 src/services/EventPostService.ts create mode 100644 src/services/EventService.ts create mode 100644 src/tests/EventTest.test.ts diff --git a/dumps/dev_db_dump_20260226_233628.sql b/dumps/dev_db_dump_20260226_233628.sql new file mode 100644 index 0000000..0ab4ea9 --- /dev/null +++ b/dumps/dev_db_dump_20260226_233628.sql @@ -0,0 +1,1188 @@ +-- +-- PostgreSQL database dump +-- + +\restrict Yn3DWKf7D4yPmect2zcsSffRbqkUHwfacDQkFXAf2KW0gTCv32CIMSM7DnjaIGz + +-- Dumped from database version 18.1 (Homebrew) +-- Dumped by pg_dump version 18.1 (Homebrew) + +SET statement_timeout = 0; +SET lock_timeout = 0; +SET idle_in_transaction_session_timeout = 0; +SET transaction_timeout = 0; +SET client_encoding = 'UTF8'; +SET standard_conforming_strings = on; +SELECT pg_catalog.set_config('search_path', '', false); +SET check_function_bodies = false; +SET xmloption = content; +SET client_min_messages = warning; +SET row_security = off; + +ALTER TABLE IF EXISTS ONLY public."requestMatchesPosts" DROP CONSTRAINT IF EXISTS "FK_fd473bd2ef9b7a23f41a40ebed4"; +ALTER TABLE IF EXISTS ONLY public.searches DROP CONSTRAINT IF EXISTS "FK_fc8760cf4823ab84b0cb28d3dad"; +ALTER TABLE IF EXISTS ONLY public."TransactionReview" DROP CONSTRAINT IF EXISTS "FK_f7cf58b571d5c57ed9da155c628"; +ALTER TABLE IF EXISTS ONLY public."Report" DROP CONSTRAINT IF EXISTS "FK_dd826149b8ac72ddc2d1f4e234e"; +ALTER TABLE IF EXISTS ONLY public."FCMToken" DROP CONSTRAINT IF EXISTS "FK_d215a8d66e472d872409915f7d5"; +ALTER TABLE IF EXISTS ONLY public."Request" DROP CONSTRAINT IF EXISTS "FK_cdaf52464b00ac3016a8f6110fd"; +ALTER TABLE IF EXISTS ONLY public."userBlockingUsers" DROP CONSTRAINT IF EXISTS "FK_bc2ca85580a5c620ccc7f03f5db"; +ALTER TABLE IF EXISTS ONLY public."Transaction" DROP CONSTRAINT IF EXISTS "FK_bba9ded63ef0013ac2ec578f246"; +ALTER TABLE IF EXISTS ONLY public."userSavedPosts" DROP CONSTRAINT IF EXISTS "FK_baa3d7e5e872010a3c23e981532"; +ALTER TABLE IF EXISTS ONLY public."Report" DROP CONSTRAINT IF EXISTS "FK_a050c9cf7f461bc8fc040a48e0a"; +ALTER TABLE IF EXISTS ONLY public."Post" DROP CONSTRAINT IF EXISTS "FK_97e81bcb59530bfb061e48aee6a"; +ALTER TABLE IF EXISTS ONLY public."postCategories" DROP CONSTRAINT IF EXISTS "FK_978f319769e3d7285d6d2e40af8"; +ALTER TABLE IF EXISTS ONLY public.user_following_users DROP CONSTRAINT IF EXISTS "FK_80ef95f34370fd0704c156c13ef"; +ALTER TABLE IF EXISTS ONLY public."userBlockingUsers" DROP CONSTRAINT IF EXISTS "FK_793578cc63c2442a7944e93131a"; +ALTER TABLE IF EXISTS ONLY public."postEventTags" DROP CONSTRAINT IF EXISTS "FK_7532bd6ca893c432ffcfa21f755"; +ALTER TABLE IF EXISTS ONLY public.notifications DROP CONSTRAINT IF EXISTS "FK_692a909ee0fa9383e7859f9b406"; +ALTER TABLE IF EXISTS ONLY public."postEventTags" DROP CONSTRAINT IF EXISTS "FK_61151ebab50db74ea513ff8bd87"; +ALTER TABLE IF EXISTS ONLY public."UserReview" DROP CONSTRAINT IF EXISTS "FK_53a14948aa4e941762a403144ea"; +ALTER TABLE IF EXISTS ONLY public.user_following_users DROP CONSTRAINT IF EXISTS "FK_503e9a09612f9668063099baff1"; +ALTER TABLE IF EXISTS ONLY public."Report" DROP CONSTRAINT IF EXISTS "FK_4bc548745107f37d3512ed688c5"; +ALTER TABLE IF EXISTS ONLY public."Transaction" DROP CONSTRAINT IF EXISTS "FK_4ae4b1f6ff200ae67b40eb5bd8d"; +ALTER TABLE IF EXISTS ONLY public."requestMatchesPosts" DROP CONSTRAINT IF EXISTS "FK_3b2f09095e41d9c82bedaa0d8fe"; +ALTER TABLE IF EXISTS ONLY public."Transaction" DROP CONSTRAINT IF EXISTS "FK_30d551dc74a9537b73d4007592f"; +ALTER TABLE IF EXISTS ONLY public."Feedback" DROP CONSTRAINT IF EXISTS "FK_26bcf6b3c7c6b742e63d9308676"; +ALTER TABLE IF EXISTS ONLY public."postCategories" DROP CONSTRAINT IF EXISTS "FK_1f4b27b2e31fb6263f6fb3a9390"; +ALTER TABLE IF EXISTS ONLY public."Report" DROP CONSTRAINT IF EXISTS "FK_16c178e84273608caf9db34df88"; +ALTER TABLE IF EXISTS ONLY public."UserReview" DROP CONSTRAINT IF EXISTS "FK_14e4fa2651e5c6d6118e2ba18aa"; +ALTER TABLE IF EXISTS ONLY public."userSavedPosts" DROP CONSTRAINT IF EXISTS "FK_0c0a06e6163f7a7315c4ce5fd4c"; +DROP INDEX IF EXISTS public."IDX_fd473bd2ef9b7a23f41a40ebed"; +DROP INDEX IF EXISTS public."IDX_bc2ca85580a5c620ccc7f03f5d"; +DROP INDEX IF EXISTS public."IDX_baa3d7e5e872010a3c23e98153"; +DROP INDEX IF EXISTS public."IDX_978f319769e3d7285d6d2e40af"; +DROP INDEX IF EXISTS public."IDX_80ef95f34370fd0704c156c13e"; +DROP INDEX IF EXISTS public."IDX_793578cc63c2442a7944e93131"; +DROP INDEX IF EXISTS public."IDX_7532bd6ca893c432ffcfa21f75"; +DROP INDEX IF EXISTS public."IDX_61151ebab50db74ea513ff8bd8"; +DROP INDEX IF EXISTS public."IDX_503e9a09612f9668063099baff"; +DROP INDEX IF EXISTS public."IDX_3b2f09095e41d9c82bedaa0d8f"; +DROP INDEX IF EXISTS public."IDX_1f4b27b2e31fb6263f6fb3a939"; +DROP INDEX IF EXISTS public."IDX_0c0a06e6163f7a7315c4ce5fd4"; +ALTER TABLE IF EXISTS ONLY public."User" DROP CONSTRAINT IF EXISTS "User_pkey"; +ALTER TABLE IF EXISTS ONLY public."User" DROP CONSTRAINT IF EXISTS "UQ_ec60b02aab67f0f99f6f88797ed"; +ALTER TABLE IF EXISTS ONLY public."TransactionReview" DROP CONSTRAINT IF EXISTS "UQ_aff62b169ebd519d1f5994e781a"; +ALTER TABLE IF EXISTS ONLY public."User" DROP CONSTRAINT IF EXISTS "UQ_4a257d2c9837248d70640b3e36e"; +ALTER TABLE IF EXISTS ONLY public."User" DROP CONSTRAINT IF EXISTS "UQ_29a05908a0fa0728526d2833657"; +ALTER TABLE IF EXISTS ONLY public."User" DROP CONSTRAINT IF EXISTS "UQ_02dec29f4ca814ab6efa2d4f0c4"; +ALTER TABLE IF EXISTS ONLY public.searches DROP CONSTRAINT IF EXISTS "PK_searches"; +ALTER TABLE IF EXISTS ONLY public."postEventTags" DROP CONSTRAINT IF EXISTS "PK_cc14f1e77d0b18c8ec995937fd0"; +ALTER TABLE IF EXISTS ONLY public."Post" DROP CONSTRAINT IF EXISTS "PK_c4d3b3dcd73db0b0129ea829f9f"; +ALTER TABLE IF EXISTS ONLY public."Category" DROP CONSTRAINT IF EXISTS "PK_c2727780c5b9b0c564c29a4977c"; +ALTER TABLE IF EXISTS ONLY public."TransactionReview" DROP CONSTRAINT IF EXISTS "PK_TransactionReview"; +ALTER TABLE IF EXISTS ONLY public."Transaction" DROP CONSTRAINT IF EXISTS "PK_Transaction"; +ALTER TABLE IF EXISTS ONLY public."FCMToken" DROP CONSTRAINT IF EXISTS "PK_FCMToken"; +ALTER TABLE IF EXISTS ONLY public."Report" DROP CONSTRAINT IF EXISTS "PK_9dbb4c593be9832c28a5793e258"; +ALTER TABLE IF EXISTS ONLY public."EventTag" DROP CONSTRAINT IF EXISTS "PK_929d8d89bf95d848ac3b7546a29"; +ALTER TABLE IF EXISTS ONLY public."UserReview" DROP CONSTRAINT IF EXISTS "PK_91b62f63709469ae812a3519dd1"; +ALTER TABLE IF EXISTS ONLY public."userBlockingUsers" DROP CONSTRAINT IF EXISTS "PK_8db623e58cc4bce5fbcc252c66b"; +ALTER TABLE IF EXISTS ONLY public.migrations DROP CONSTRAINT IF EXISTS "PK_8c82d7f526340ab734260ea46be"; +ALTER TABLE IF EXISTS ONLY public."postCategories" DROP CONSTRAINT IF EXISTS "PK_88340cf0b1b8a00578602f4c80b"; +ALTER TABLE IF EXISTS ONLY public."Feedback" DROP CONSTRAINT IF EXISTS "PK_7ffea537e9c56670b65c2d62316"; +ALTER TABLE IF EXISTS ONLY public."requestMatchesPosts" DROP CONSTRAINT IF EXISTS "PK_7f4c04956dd4e84a3437b2a8018"; +ALTER TABLE IF EXISTS ONLY public."Message" DROP CONSTRAINT IF EXISTS "PK_7dd6398f0d1dcaf73df342fa325"; +ALTER TABLE IF EXISTS ONLY public.notifications DROP CONSTRAINT IF EXISTS "PK_6a72c3c0f683f6462415e653c3a"; +ALTER TABLE IF EXISTS ONLY public."Request" DROP CONSTRAINT IF EXISTS "PK_23de24dc477765bcc099feae8e5"; +ALTER TABLE IF EXISTS ONLY public."userSavedPosts" DROP CONSTRAINT IF EXISTS "PK_11901fe92c42b2d2a71ca74021a"; +ALTER TABLE IF EXISTS ONLY public.user_following_users DROP CONSTRAINT IF EXISTS "PK_01b7a923c26f4be4f7c138cbb88"; +ALTER TABLE IF EXISTS public.migrations ALTER COLUMN id DROP DEFAULT; +DROP TABLE IF EXISTS public.user_following_users; +DROP TABLE IF EXISTS public."userSavedPosts"; +DROP TABLE IF EXISTS public."userBlockingUsers"; +DROP TABLE IF EXISTS public.typeorm_metadata; +DROP TABLE IF EXISTS public.searches; +DROP TABLE IF EXISTS public."requestMatchesPosts"; +DROP TABLE IF EXISTS public."postEventTags"; +DROP TABLE IF EXISTS public."postCategories"; +DROP TABLE IF EXISTS public.notifications; +DROP SEQUENCE IF EXISTS public.migrations_id_seq; +DROP TABLE IF EXISTS public.migrations; +DROP TABLE IF EXISTS public."UserReview"; +DROP TABLE IF EXISTS public."User"; +DROP TABLE IF EXISTS public."TransactionReview"; +DROP TABLE IF EXISTS public."Transaction"; +DROP TABLE IF EXISTS public."Request"; +DROP TABLE IF EXISTS public."Report"; +DROP TABLE IF EXISTS public."Post"; +DROP TABLE IF EXISTS public."Message"; +DROP TABLE IF EXISTS public."Feedback"; +DROP TABLE IF EXISTS public."FCMToken"; +DROP TABLE IF EXISTS public."EventTag"; +DROP TABLE IF EXISTS public."Category"; +DROP EXTENSION IF EXISTS vector; +DROP EXTENSION IF EXISTS "uuid-ossp"; +-- +-- Name: uuid-ossp; Type: EXTENSION; Schema: -; Owner: - +-- + +CREATE EXTENSION IF NOT EXISTS "uuid-ossp" WITH SCHEMA public; + + +-- +-- Name: EXTENSION "uuid-ossp"; Type: COMMENT; Schema: -; Owner: - +-- + +COMMENT ON EXTENSION "uuid-ossp" IS 'generate universally unique identifiers (UUIDs)'; + + +-- +-- Name: vector; Type: EXTENSION; Schema: -; Owner: - +-- + +CREATE EXTENSION IF NOT EXISTS vector WITH SCHEMA public; + + +-- +-- Name: EXTENSION vector; Type: COMMENT; Schema: -; Owner: - +-- + +COMMENT ON EXTENSION vector IS 'vector data type and ivfflat and hnsw access methods'; + + +SET default_tablespace = ''; + +SET default_table_access_method = heap; + +-- +-- Name: Category; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public."Category" ( + id uuid DEFAULT public.uuid_generate_v4() NOT NULL, + name character varying NOT NULL +); + + +-- +-- Name: EventTag; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public."EventTag" ( + id uuid DEFAULT public.uuid_generate_v4() NOT NULL, + name character varying NOT NULL +); + + +-- +-- Name: FCMToken; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public."FCMToken" ( + id uuid DEFAULT public.uuid_generate_v4() NOT NULL, + "fcmToken" character varying NOT NULL, + "notificationsEnabled" boolean NOT NULL, + "timestamp" timestamp without time zone NOT NULL, + "userId" character varying +); + + +-- +-- Name: Feedback; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public."Feedback" ( + id uuid DEFAULT public.uuid_generate_v4() NOT NULL, + description character varying NOT NULL, + images text[] NOT NULL, + "userId" character varying +); + + +-- +-- Name: Message; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public."Message" ( + id uuid NOT NULL +); + + +-- +-- Name: Post; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public."Post" ( + id uuid DEFAULT public.uuid_generate_v4() NOT NULL, + title character varying NOT NULL, + description character varying NOT NULL, + "originalPrice" numeric CONSTRAINT "Post_original_price_not_null" NOT NULL, + "alteredPrice" numeric DEFAULT '-1'::numeric CONSTRAINT "Post_altered_price_not_null" NOT NULL, + images text[] NOT NULL, + created timestamp with time zone DEFAULT now() NOT NULL, + location character varying, + archive boolean DEFAULT false NOT NULL, + condition character varying NOT NULL, + sold boolean DEFAULT false NOT NULL, + embedding double precision[], + "userId" character varying +); + + +-- +-- Name: Report; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public."Report" ( + id uuid DEFAULT public.uuid_generate_v4() NOT NULL, + reason character varying NOT NULL, + type character varying NOT NULL, + resolved boolean NOT NULL, + created timestamp with time zone DEFAULT now() NOT NULL, + "reporterFirebaseUid" character varying, + "reportedFirebaseUid" character varying, + "postId" uuid, + "messageId" uuid +); + + +-- +-- Name: Request; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public."Request" ( + id uuid DEFAULT public.uuid_generate_v4() NOT NULL, + title character varying NOT NULL, + description character varying NOT NULL, + archive boolean DEFAULT false NOT NULL, + embedding double precision[], + "userId" character varying +); + + +-- +-- Name: Transaction; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public."Transaction" ( + id uuid DEFAULT public.uuid_generate_v4() NOT NULL, + location character varying NOT NULL, + amount numeric NOT NULL, + completed boolean DEFAULT false NOT NULL, + "postId" uuid, + "buyerId" character varying, + "sellerId" character varying, + "transactionDate" timestamp with time zone, + "createdAt" timestamp with time zone DEFAULT now() NOT NULL, + "confirmationSent" boolean DEFAULT false NOT NULL +); + + +-- +-- Name: TransactionReview; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public."TransactionReview" ( + id uuid DEFAULT public.uuid_generate_v4() NOT NULL, + stars integer NOT NULL, + "transactionId" uuid, + "hadIssues" boolean DEFAULT false NOT NULL, + "issueCategory" text, + "issueDetails" text, + "createdAt" timestamp with time zone DEFAULT now() NOT NULL, + comments text +); + + +-- +-- Name: User; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public."User" ( + username character varying NOT NULL, + netid character varying, + admin boolean NOT NULL, + stars numeric DEFAULT '0'::numeric NOT NULL, + email character varying NOT NULL, + bio text DEFAULT ''::text NOT NULL, + "isActive" boolean DEFAULT true NOT NULL, + "firebaseUid" character varying NOT NULL, + "givenName" character varying, + "familyName" character varying, + "numReviews" integer DEFAULT 0 NOT NULL, + "photoUrl" character varying, + "venmoHandle" character varying, + "googleId" character varying, + "soldPosts" integer DEFAULT 0 NOT NULL, + "availabilityId" character varying +); + + +-- +-- Name: UserReview; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public."UserReview" ( + id uuid DEFAULT public.uuid_generate_v4() NOT NULL, + fulfilled boolean NOT NULL, + stars integer NOT NULL, + comments character varying NOT NULL, + date timestamp with time zone DEFAULT now() NOT NULL, + "buyerId" character varying, + "sellerId" character varying +); + + +-- +-- Name: migrations; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.migrations ( + id integer NOT NULL, + "timestamp" bigint NOT NULL, + name character varying NOT NULL +); + + +-- +-- Name: migrations_id_seq; Type: SEQUENCE; Schema: public; Owner: - +-- + +CREATE SEQUENCE public.migrations_id_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: migrations_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - +-- + +ALTER SEQUENCE public.migrations_id_seq OWNED BY public.migrations.id; + + +-- +-- Name: notifications; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.notifications ( + id uuid DEFAULT public.uuid_generate_v4() NOT NULL, + title character varying NOT NULL, + body character varying NOT NULL, + data jsonb, + read boolean DEFAULT false NOT NULL, + "userId" character varying NOT NULL, + "createdAt" timestamp without time zone DEFAULT now() NOT NULL, + "updatedAt" timestamp without time zone DEFAULT now() NOT NULL +); + + +-- +-- Name: postCategories; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public."postCategories" ( + posts uuid CONSTRAINT post_categories_posts_not_null NOT NULL, + categories uuid CONSTRAINT post_categories_categories_not_null NOT NULL +); + + +-- +-- Name: postEventTags; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public."postEventTags" ( + posts uuid CONSTRAINT post_event_tags_posts_not_null NOT NULL, + "eventTags" uuid CONSTRAINT post_event_tags_event_tags_not_null NOT NULL +); + + +-- +-- Name: requestMatchesPosts; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public."requestMatchesPosts" ( + matches uuid CONSTRAINT request_matches_posts_matches_not_null NOT NULL, + matched uuid CONSTRAINT request_matches_posts_matched_not_null NOT NULL +); + + +-- +-- Name: searches; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.searches ( + id uuid DEFAULT public.uuid_generate_v4() NOT NULL, + "searchText" character varying NOT NULL, + "firebaseUid" character varying NOT NULL, + "createdAt" timestamp without time zone DEFAULT now() NOT NULL, + "searchVector" character varying NOT NULL +); + + +-- +-- Name: typeorm_metadata; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.typeorm_metadata ( + type character varying NOT NULL, + database character varying, + schema character varying, + "table" character varying, + name character varying, + value text +); + + +-- +-- Name: userBlockingUsers; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public."userBlockingUsers" ( + blockers character varying CONSTRAINT user_blocking_users_blockers_not_null NOT NULL, + blocking character varying CONSTRAINT user_blocking_users_blocking_not_null NOT NULL +); + + +-- +-- Name: userSavedPosts; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public."userSavedPosts" ( + saved uuid CONSTRAINT user_saved_posts_saved_not_null NOT NULL, + savers character varying CONSTRAINT user_saved_posts_savers_not_null NOT NULL +); + + +-- +-- Name: user_following_users; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.user_following_users ( + follower_id character varying NOT NULL, + following_id character varying NOT NULL +); + + +-- +-- Name: migrations id; Type: DEFAULT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.migrations ALTER COLUMN id SET DEFAULT nextval('public.migrations_id_seq'::regclass); + + +-- +-- Data for Name: Category; Type: TABLE DATA; Schema: public; Owner: - +-- + +COPY public."Category" (id, name) FROM stdin; +\. + + +-- +-- Data for Name: EventTag; Type: TABLE DATA; Schema: public; Owner: - +-- + +COPY public."EventTag" (id, name) FROM stdin; +\. + + +-- +-- Data for Name: FCMToken; Type: TABLE DATA; Schema: public; Owner: - +-- + +COPY public."FCMToken" (id, "fcmToken", "notificationsEnabled", "timestamp", "userId") FROM stdin; +\. + + +-- +-- Data for Name: Feedback; Type: TABLE DATA; Schema: public; Owner: - +-- + +COPY public."Feedback" (id, description, images, "userId") FROM stdin; +\. + + +-- +-- Data for Name: Message; Type: TABLE DATA; Schema: public; Owner: - +-- + +COPY public."Message" (id) FROM stdin; +\. + + +-- +-- Data for Name: Post; Type: TABLE DATA; Schema: public; Owner: - +-- + +COPY public."Post" (id, title, description, "originalPrice", "alteredPrice", images, created, location, archive, condition, sold, embedding, "userId") FROM stdin; +\. + + +-- +-- Data for Name: Report; Type: TABLE DATA; Schema: public; Owner: - +-- + +COPY public."Report" (id, reason, type, resolved, created, "reporterFirebaseUid", "reportedFirebaseUid", "postId", "messageId") FROM stdin; +\. + + +-- +-- Data for Name: Request; Type: TABLE DATA; Schema: public; Owner: - +-- + +COPY public."Request" (id, title, description, archive, embedding, "userId") FROM stdin; +\. + + +-- +-- Data for Name: Transaction; Type: TABLE DATA; Schema: public; Owner: - +-- + +COPY public."Transaction" (id, location, amount, completed, "postId", "buyerId", "sellerId", "transactionDate", "createdAt", "confirmationSent") FROM stdin; +\. + + +-- +-- Data for Name: TransactionReview; Type: TABLE DATA; Schema: public; Owner: - +-- + +COPY public."TransactionReview" (id, stars, "transactionId", "hadIssues", "issueCategory", "issueDetails", "createdAt", comments) FROM stdin; +\. + + +-- +-- Data for Name: User; Type: TABLE DATA; Schema: public; Owner: - +-- + +COPY public."User" (username, netid, admin, stars, email, bio, "isActive", "firebaseUid", "givenName", "familyName", "numReviews", "photoUrl", "venmoHandle", "googleId", "soldPosts", "availabilityId") FROM stdin; +\. + + +-- +-- Data for Name: UserReview; Type: TABLE DATA; Schema: public; Owner: - +-- + +COPY public."UserReview" (id, fulfilled, stars, comments, date, "buyerId", "sellerId") FROM stdin; +\. + + +-- +-- Data for Name: migrations; Type: TABLE DATA; Schema: public; Owner: - +-- + +COPY public.migrations (id, "timestamp", name) FROM stdin; +1 1709163288115 init1709163288115 +2 1713139721037 softdelete1713139721037 +3 1713218553306 makenetidnullable1713218553306 +4 1713308449994 addreports1713308449994 +5 1713320015776 UpdateMessageModel1713320015776 +6 1731186421123 AddArchiveToRequest1731186421123 +7 1731271779741 updatecategories1731271779741 +8 1732146942548 addconditiontoposts1732146942548 +9 1732906578369 AddTransactionTable1732906578369 +10 1732924592033 AddSoldColumnToPost1732924592033 +11 1732975238671 AddTransactionReviewTable1732975238671 +12 1739899394694 Notifications1739899394694 +13 1740007049335 ConvertEmbeddingToVector1631740007049335 +14 1740628691583 AuthorizationRefactor1740628691583 +15 1743028223060 AddCategoryTable1743028223060 +16 1743566564676 CreateSearchesTable1743566564676 +17 1761697414368 AddEventTagTable1761697414368 +18 1765000000000 RenameSnakeToCamelResellTest1765000000000 +\. + + +-- +-- Data for Name: notifications; Type: TABLE DATA; Schema: public; Owner: - +-- + +COPY public.notifications (id, title, body, data, read, "userId", "createdAt", "updatedAt") FROM stdin; +\. + + +-- +-- Data for Name: postCategories; Type: TABLE DATA; Schema: public; Owner: - +-- + +COPY public."postCategories" (posts, categories) FROM stdin; +\. + + +-- +-- Data for Name: postEventTags; Type: TABLE DATA; Schema: public; Owner: - +-- + +COPY public."postEventTags" (posts, "eventTags") FROM stdin; +\. + + +-- +-- Data for Name: requestMatchesPosts; Type: TABLE DATA; Schema: public; Owner: - +-- + +COPY public."requestMatchesPosts" (matches, matched) FROM stdin; +\. + + +-- +-- Data for Name: searches; Type: TABLE DATA; Schema: public; Owner: - +-- + +COPY public.searches (id, "searchText", "firebaseUid", "createdAt", "searchVector") FROM stdin; +\. + + +-- +-- Data for Name: typeorm_metadata; Type: TABLE DATA; Schema: public; Owner: - +-- + +COPY public.typeorm_metadata (type, database, schema, "table", name, value) FROM stdin; +\. + + +-- +-- Data for Name: userBlockingUsers; Type: TABLE DATA; Schema: public; Owner: - +-- + +COPY public."userBlockingUsers" (blockers, blocking) FROM stdin; +\. + + +-- +-- Data for Name: userSavedPosts; Type: TABLE DATA; Schema: public; Owner: - +-- + +COPY public."userSavedPosts" (saved, savers) FROM stdin; +\. + + +-- +-- Data for Name: user_following_users; Type: TABLE DATA; Schema: public; Owner: - +-- + +COPY public.user_following_users (follower_id, following_id) FROM stdin; +\. + + +-- +-- Name: migrations_id_seq; Type: SEQUENCE SET; Schema: public; Owner: - +-- + +SELECT pg_catalog.setval('public.migrations_id_seq', 18, true); + + +-- +-- Name: user_following_users PK_01b7a923c26f4be4f7c138cbb88; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.user_following_users + ADD CONSTRAINT "PK_01b7a923c26f4be4f7c138cbb88" PRIMARY KEY (follower_id, following_id); + + +-- +-- Name: userSavedPosts PK_11901fe92c42b2d2a71ca74021a; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."userSavedPosts" + ADD CONSTRAINT "PK_11901fe92c42b2d2a71ca74021a" PRIMARY KEY (saved, savers); + + +-- +-- Name: Request PK_23de24dc477765bcc099feae8e5; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."Request" + ADD CONSTRAINT "PK_23de24dc477765bcc099feae8e5" PRIMARY KEY (id); + + +-- +-- Name: notifications PK_6a72c3c0f683f6462415e653c3a; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.notifications + ADD CONSTRAINT "PK_6a72c3c0f683f6462415e653c3a" PRIMARY KEY (id); + + +-- +-- Name: Message PK_7dd6398f0d1dcaf73df342fa325; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."Message" + ADD CONSTRAINT "PK_7dd6398f0d1dcaf73df342fa325" PRIMARY KEY (id); + + +-- +-- Name: requestMatchesPosts PK_7f4c04956dd4e84a3437b2a8018; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."requestMatchesPosts" + ADD CONSTRAINT "PK_7f4c04956dd4e84a3437b2a8018" PRIMARY KEY (matches, matched); + + +-- +-- Name: Feedback PK_7ffea537e9c56670b65c2d62316; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."Feedback" + ADD CONSTRAINT "PK_7ffea537e9c56670b65c2d62316" PRIMARY KEY (id); + + +-- +-- Name: postCategories PK_88340cf0b1b8a00578602f4c80b; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."postCategories" + ADD CONSTRAINT "PK_88340cf0b1b8a00578602f4c80b" PRIMARY KEY (posts, categories); + + +-- +-- Name: migrations PK_8c82d7f526340ab734260ea46be; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.migrations + ADD CONSTRAINT "PK_8c82d7f526340ab734260ea46be" PRIMARY KEY (id); + + +-- +-- Name: userBlockingUsers PK_8db623e58cc4bce5fbcc252c66b; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."userBlockingUsers" + ADD CONSTRAINT "PK_8db623e58cc4bce5fbcc252c66b" PRIMARY KEY (blockers, blocking); + + +-- +-- Name: UserReview PK_91b62f63709469ae812a3519dd1; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."UserReview" + ADD CONSTRAINT "PK_91b62f63709469ae812a3519dd1" PRIMARY KEY (id); + + +-- +-- Name: EventTag PK_929d8d89bf95d848ac3b7546a29; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."EventTag" + ADD CONSTRAINT "PK_929d8d89bf95d848ac3b7546a29" PRIMARY KEY (id); + + +-- +-- Name: Report PK_9dbb4c593be9832c28a5793e258; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."Report" + ADD CONSTRAINT "PK_9dbb4c593be9832c28a5793e258" PRIMARY KEY (id); + + +-- +-- Name: FCMToken PK_FCMToken; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."FCMToken" + ADD CONSTRAINT "PK_FCMToken" PRIMARY KEY (id); + + +-- +-- Name: Transaction PK_Transaction; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."Transaction" + ADD CONSTRAINT "PK_Transaction" PRIMARY KEY (id); + + +-- +-- Name: TransactionReview PK_TransactionReview; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."TransactionReview" + ADD CONSTRAINT "PK_TransactionReview" PRIMARY KEY (id); + + +-- +-- Name: Category PK_c2727780c5b9b0c564c29a4977c; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."Category" + ADD CONSTRAINT "PK_c2727780c5b9b0c564c29a4977c" PRIMARY KEY (id); + + +-- +-- Name: Post PK_c4d3b3dcd73db0b0129ea829f9f; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."Post" + ADD CONSTRAINT "PK_c4d3b3dcd73db0b0129ea829f9f" PRIMARY KEY (id); + + +-- +-- Name: postEventTags PK_cc14f1e77d0b18c8ec995937fd0; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."postEventTags" + ADD CONSTRAINT "PK_cc14f1e77d0b18c8ec995937fd0" PRIMARY KEY (posts, "eventTags"); + + +-- +-- Name: searches PK_searches; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.searches + ADD CONSTRAINT "PK_searches" PRIMARY KEY (id); + + +-- +-- Name: User UQ_02dec29f4ca814ab6efa2d4f0c4; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."User" + ADD CONSTRAINT "UQ_02dec29f4ca814ab6efa2d4f0c4" UNIQUE ("googleId"); + + +-- +-- Name: User UQ_29a05908a0fa0728526d2833657; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."User" + ADD CONSTRAINT "UQ_29a05908a0fa0728526d2833657" UNIQUE (username); + + +-- +-- Name: User UQ_4a257d2c9837248d70640b3e36e; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."User" + ADD CONSTRAINT "UQ_4a257d2c9837248d70640b3e36e" UNIQUE (email); + + +-- +-- Name: TransactionReview UQ_aff62b169ebd519d1f5994e781a; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."TransactionReview" + ADD CONSTRAINT "UQ_aff62b169ebd519d1f5994e781a" UNIQUE ("transactionId"); + + +-- +-- Name: User UQ_ec60b02aab67f0f99f6f88797ed; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."User" + ADD CONSTRAINT "UQ_ec60b02aab67f0f99f6f88797ed" UNIQUE (netid); + + +-- +-- Name: User User_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."User" + ADD CONSTRAINT "User_pkey" PRIMARY KEY ("firebaseUid"); + + +-- +-- Name: IDX_0c0a06e6163f7a7315c4ce5fd4; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX "IDX_0c0a06e6163f7a7315c4ce5fd4" ON public."userSavedPosts" USING btree (savers); + + +-- +-- Name: IDX_1f4b27b2e31fb6263f6fb3a939; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX "IDX_1f4b27b2e31fb6263f6fb3a939" ON public."postCategories" USING btree (categories); + + +-- +-- Name: IDX_3b2f09095e41d9c82bedaa0d8f; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX "IDX_3b2f09095e41d9c82bedaa0d8f" ON public."requestMatchesPosts" USING btree (matched); + + +-- +-- Name: IDX_503e9a09612f9668063099baff; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX "IDX_503e9a09612f9668063099baff" ON public.user_following_users USING btree (following_id); + + +-- +-- Name: IDX_61151ebab50db74ea513ff8bd8; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX "IDX_61151ebab50db74ea513ff8bd8" ON public."postEventTags" USING btree (posts); + + +-- +-- Name: IDX_7532bd6ca893c432ffcfa21f75; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX "IDX_7532bd6ca893c432ffcfa21f75" ON public."postEventTags" USING btree ("eventTags"); + + +-- +-- Name: IDX_793578cc63c2442a7944e93131; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX "IDX_793578cc63c2442a7944e93131" ON public."userBlockingUsers" USING btree (blockers); + + +-- +-- Name: IDX_80ef95f34370fd0704c156c13e; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX "IDX_80ef95f34370fd0704c156c13e" ON public.user_following_users USING btree (follower_id); + + +-- +-- Name: IDX_978f319769e3d7285d6d2e40af; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX "IDX_978f319769e3d7285d6d2e40af" ON public."postCategories" USING btree (posts); + + +-- +-- Name: IDX_baa3d7e5e872010a3c23e98153; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX "IDX_baa3d7e5e872010a3c23e98153" ON public."userSavedPosts" USING btree (saved); + + +-- +-- Name: IDX_bc2ca85580a5c620ccc7f03f5d; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX "IDX_bc2ca85580a5c620ccc7f03f5d" ON public."userBlockingUsers" USING btree (blocking); + + +-- +-- Name: IDX_fd473bd2ef9b7a23f41a40ebed; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX "IDX_fd473bd2ef9b7a23f41a40ebed" ON public."requestMatchesPosts" USING btree (matches); + + +-- +-- Name: userSavedPosts FK_0c0a06e6163f7a7315c4ce5fd4c; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."userSavedPosts" + ADD CONSTRAINT "FK_0c0a06e6163f7a7315c4ce5fd4c" FOREIGN KEY (savers) REFERENCES public."User"("firebaseUid"); + + +-- +-- Name: UserReview FK_14e4fa2651e5c6d6118e2ba18aa; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."UserReview" + ADD CONSTRAINT "FK_14e4fa2651e5c6d6118e2ba18aa" FOREIGN KEY ("sellerId") REFERENCES public."User"("firebaseUid"); + + +-- +-- Name: Report FK_16c178e84273608caf9db34df88; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."Report" + ADD CONSTRAINT "FK_16c178e84273608caf9db34df88" FOREIGN KEY ("reportedFirebaseUid") REFERENCES public."User"("firebaseUid"); + + +-- +-- Name: postCategories FK_1f4b27b2e31fb6263f6fb3a9390; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."postCategories" + ADD CONSTRAINT "FK_1f4b27b2e31fb6263f6fb3a9390" FOREIGN KEY (categories) REFERENCES public."Category"(id); + + +-- +-- Name: Feedback FK_26bcf6b3c7c6b742e63d9308676; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."Feedback" + ADD CONSTRAINT "FK_26bcf6b3c7c6b742e63d9308676" FOREIGN KEY ("userId") REFERENCES public."User"("firebaseUid") ON DELETE CASCADE; + + +-- +-- Name: Transaction FK_30d551dc74a9537b73d4007592f; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."Transaction" + ADD CONSTRAINT "FK_30d551dc74a9537b73d4007592f" FOREIGN KEY ("sellerId") REFERENCES public."User"("firebaseUid"); + + +-- +-- Name: requestMatchesPosts FK_3b2f09095e41d9c82bedaa0d8fe; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."requestMatchesPosts" + ADD CONSTRAINT "FK_3b2f09095e41d9c82bedaa0d8fe" FOREIGN KEY (matched) REFERENCES public."Request"(id); + + +-- +-- Name: Transaction FK_4ae4b1f6ff200ae67b40eb5bd8d; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."Transaction" + ADD CONSTRAINT "FK_4ae4b1f6ff200ae67b40eb5bd8d" FOREIGN KEY ("buyerId") REFERENCES public."User"("firebaseUid"); + + +-- +-- Name: Report FK_4bc548745107f37d3512ed688c5; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."Report" + ADD CONSTRAINT "FK_4bc548745107f37d3512ed688c5" FOREIGN KEY ("postId") REFERENCES public."Post"(id); + + +-- +-- Name: user_following_users FK_503e9a09612f9668063099baff1; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.user_following_users + ADD CONSTRAINT "FK_503e9a09612f9668063099baff1" FOREIGN KEY (following_id) REFERENCES public."User"("firebaseUid"); + + +-- +-- Name: UserReview FK_53a14948aa4e941762a403144ea; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."UserReview" + ADD CONSTRAINT "FK_53a14948aa4e941762a403144ea" FOREIGN KEY ("buyerId") REFERENCES public."User"("firebaseUid"); + + +-- +-- Name: postEventTags FK_61151ebab50db74ea513ff8bd87; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."postEventTags" + ADD CONSTRAINT "FK_61151ebab50db74ea513ff8bd87" FOREIGN KEY (posts) REFERENCES public."Post"(id) ON UPDATE CASCADE ON DELETE CASCADE; + + +-- +-- Name: notifications FK_692a909ee0fa9383e7859f9b406; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.notifications + ADD CONSTRAINT "FK_692a909ee0fa9383e7859f9b406" FOREIGN KEY ("userId") REFERENCES public."User"("firebaseUid"); + + +-- +-- Name: postEventTags FK_7532bd6ca893c432ffcfa21f755; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."postEventTags" + ADD CONSTRAINT "FK_7532bd6ca893c432ffcfa21f755" FOREIGN KEY ("eventTags") REFERENCES public."EventTag"(id); + + +-- +-- Name: userBlockingUsers FK_793578cc63c2442a7944e93131a; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."userBlockingUsers" + ADD CONSTRAINT "FK_793578cc63c2442a7944e93131a" FOREIGN KEY (blockers) REFERENCES public."User"("firebaseUid") ON UPDATE CASCADE ON DELETE CASCADE; + + +-- +-- Name: user_following_users FK_80ef95f34370fd0704c156c13ef; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.user_following_users + ADD CONSTRAINT "FK_80ef95f34370fd0704c156c13ef" FOREIGN KEY (follower_id) REFERENCES public."User"("firebaseUid") ON UPDATE CASCADE ON DELETE CASCADE; + + +-- +-- Name: postCategories FK_978f319769e3d7285d6d2e40af8; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."postCategories" + ADD CONSTRAINT "FK_978f319769e3d7285d6d2e40af8" FOREIGN KEY (posts) REFERENCES public."Post"(id) ON UPDATE CASCADE ON DELETE CASCADE; + + +-- +-- Name: Post FK_97e81bcb59530bfb061e48aee6a; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."Post" + ADD CONSTRAINT "FK_97e81bcb59530bfb061e48aee6a" FOREIGN KEY ("userId") REFERENCES public."User"("firebaseUid") ON DELETE CASCADE; + + +-- +-- Name: Report FK_a050c9cf7f461bc8fc040a48e0a; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."Report" + ADD CONSTRAINT "FK_a050c9cf7f461bc8fc040a48e0a" FOREIGN KEY ("reporterFirebaseUid") REFERENCES public."User"("firebaseUid"); + + +-- +-- Name: userSavedPosts FK_baa3d7e5e872010a3c23e981532; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."userSavedPosts" + ADD CONSTRAINT "FK_baa3d7e5e872010a3c23e981532" FOREIGN KEY (saved) REFERENCES public."Post"(id) ON UPDATE CASCADE ON DELETE CASCADE; + + +-- +-- Name: Transaction FK_bba9ded63ef0013ac2ec578f246; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."Transaction" + ADD CONSTRAINT "FK_bba9ded63ef0013ac2ec578f246" FOREIGN KEY ("postId") REFERENCES public."Post"(id); + + +-- +-- Name: userBlockingUsers FK_bc2ca85580a5c620ccc7f03f5db; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."userBlockingUsers" + ADD CONSTRAINT "FK_bc2ca85580a5c620ccc7f03f5db" FOREIGN KEY (blocking) REFERENCES public."User"("firebaseUid"); + + +-- +-- Name: Request FK_cdaf52464b00ac3016a8f6110fd; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."Request" + ADD CONSTRAINT "FK_cdaf52464b00ac3016a8f6110fd" FOREIGN KEY ("userId") REFERENCES public."User"("firebaseUid") ON DELETE CASCADE; + + +-- +-- Name: FCMToken FK_d215a8d66e472d872409915f7d5; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."FCMToken" + ADD CONSTRAINT "FK_d215a8d66e472d872409915f7d5" FOREIGN KEY ("userId") REFERENCES public."User"("firebaseUid"); + + +-- +-- Name: Report FK_dd826149b8ac72ddc2d1f4e234e; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."Report" + ADD CONSTRAINT "FK_dd826149b8ac72ddc2d1f4e234e" FOREIGN KEY ("messageId") REFERENCES public."Message"(id); + + +-- +-- Name: TransactionReview FK_f7cf58b571d5c57ed9da155c628; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."TransactionReview" + ADD CONSTRAINT "FK_f7cf58b571d5c57ed9da155c628" FOREIGN KEY ("transactionId") REFERENCES public."Transaction"(id); + + +-- +-- Name: searches FK_fc8760cf4823ab84b0cb28d3dad; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.searches + ADD CONSTRAINT "FK_fc8760cf4823ab84b0cb28d3dad" FOREIGN KEY ("firebaseUid") REFERENCES public."User"("firebaseUid") ON DELETE CASCADE; + + +-- +-- Name: requestMatchesPosts FK_fd473bd2ef9b7a23f41a40ebed4; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."requestMatchesPosts" + ADD CONSTRAINT "FK_fd473bd2ef9b7a23f41a40ebed4" FOREIGN KEY (matches) REFERENCES public."Post"(id) ON UPDATE CASCADE ON DELETE CASCADE; + + +-- +-- PostgreSQL database dump complete +-- + +\unrestrict Yn3DWKf7D4yPmect2zcsSffRbqkUHwfacDQkFXAf2KW0gTCv32CIMSM7DnjaIGz + diff --git a/dumps/dev_db_dump_20260226_233801.sql b/dumps/dev_db_dump_20260226_233801.sql new file mode 100644 index 0000000..876d794 --- /dev/null +++ b/dumps/dev_db_dump_20260226_233801.sql @@ -0,0 +1,1302 @@ +-- +-- PostgreSQL database dump +-- + +\restrict j0zS1YybO7IPtcJxy9ONeBKIaXJBXaXxzwxKQnVNLQIIVc1bKUCxYazgBD8jnUr + +-- Dumped from database version 18.1 (Homebrew) +-- Dumped by pg_dump version 18.1 (Homebrew) + +SET statement_timeout = 0; +SET lock_timeout = 0; +SET idle_in_transaction_session_timeout = 0; +SET transaction_timeout = 0; +SET client_encoding = 'UTF8'; +SET standard_conforming_strings = on; +SELECT pg_catalog.set_config('search_path', '', false); +SET check_function_bodies = false; +SET xmloption = content; +SET client_min_messages = warning; +SET row_security = off; + +ALTER TABLE IF EXISTS ONLY public.user_following_users DROP CONSTRAINT IF EXISTS "FK_user_following_users_following_id"; +ALTER TABLE IF EXISTS ONLY public.user_following_users DROP CONSTRAINT IF EXISTS "FK_user_following_users_follower_id"; +ALTER TABLE IF EXISTS ONLY public."requestMatchesPosts" DROP CONSTRAINT IF EXISTS "FK_fd473bd2ef9b7a23f41a40ebed4"; +ALTER TABLE IF EXISTS ONLY public.searches DROP CONSTRAINT IF EXISTS "FK_fc8760cf4823ab84b0cb28d3dad"; +ALTER TABLE IF EXISTS ONLY public."TransactionReview" DROP CONSTRAINT IF EXISTS "FK_f7cf58b571d5c57ed9da155c628"; +ALTER TABLE IF EXISTS ONLY public."eventPostRelationships" DROP CONSTRAINT IF EXISTS "FK_eventPost_postId"; +ALTER TABLE IF EXISTS ONLY public."eventPostRelationships" DROP CONSTRAINT IF EXISTS "FK_eventPost_eventTagId"; +ALTER TABLE IF EXISTS ONLY public."Report" DROP CONSTRAINT IF EXISTS "FK_dd826149b8ac72ddc2d1f4e234e"; +ALTER TABLE IF EXISTS ONLY public."FCMToken" DROP CONSTRAINT IF EXISTS "FK_d215a8d66e472d872409915f7d5"; +ALTER TABLE IF EXISTS ONLY public."Request" DROP CONSTRAINT IF EXISTS "FK_cdaf52464b00ac3016a8f6110fd"; +ALTER TABLE IF EXISTS ONLY public."userBlockingUsers" DROP CONSTRAINT IF EXISTS "FK_bc2ca85580a5c620ccc7f03f5db"; +ALTER TABLE IF EXISTS ONLY public."Transaction" DROP CONSTRAINT IF EXISTS "FK_bba9ded63ef0013ac2ec578f246"; +ALTER TABLE IF EXISTS ONLY public."userSavedPosts" DROP CONSTRAINT IF EXISTS "FK_baa3d7e5e872010a3c23e981532"; +ALTER TABLE IF EXISTS ONLY public."Report" DROP CONSTRAINT IF EXISTS "FK_a050c9cf7f461bc8fc040a48e0a"; +ALTER TABLE IF EXISTS ONLY public."Post" DROP CONSTRAINT IF EXISTS "FK_97e81bcb59530bfb061e48aee6a"; +ALTER TABLE IF EXISTS ONLY public."postCategories" DROP CONSTRAINT IF EXISTS "FK_978f319769e3d7285d6d2e40af8"; +ALTER TABLE IF EXISTS ONLY public.user_following_users DROP CONSTRAINT IF EXISTS "FK_80ef95f34370fd0704c156c13ef"; +ALTER TABLE IF EXISTS ONLY public."userBlockingUsers" DROP CONSTRAINT IF EXISTS "FK_793578cc63c2442a7944e93131a"; +ALTER TABLE IF EXISTS ONLY public."postEventTags" DROP CONSTRAINT IF EXISTS "FK_7532bd6ca893c432ffcfa21f755"; +ALTER TABLE IF EXISTS ONLY public.notifications DROP CONSTRAINT IF EXISTS "FK_692a909ee0fa9383e7859f9b406"; +ALTER TABLE IF EXISTS ONLY public."postEventTags" DROP CONSTRAINT IF EXISTS "FK_61151ebab50db74ea513ff8bd87"; +ALTER TABLE IF EXISTS ONLY public."UserReview" DROP CONSTRAINT IF EXISTS "FK_53a14948aa4e941762a403144ea"; +ALTER TABLE IF EXISTS ONLY public.user_following_users DROP CONSTRAINT IF EXISTS "FK_503e9a09612f9668063099baff1"; +ALTER TABLE IF EXISTS ONLY public."Report" DROP CONSTRAINT IF EXISTS "FK_4bc548745107f37d3512ed688c5"; +ALTER TABLE IF EXISTS ONLY public."Transaction" DROP CONSTRAINT IF EXISTS "FK_4ae4b1f6ff200ae67b40eb5bd8d"; +ALTER TABLE IF EXISTS ONLY public."requestMatchesPosts" DROP CONSTRAINT IF EXISTS "FK_3b2f09095e41d9c82bedaa0d8fe"; +ALTER TABLE IF EXISTS ONLY public."Transaction" DROP CONSTRAINT IF EXISTS "FK_30d551dc74a9537b73d4007592f"; +ALTER TABLE IF EXISTS ONLY public."Feedback" DROP CONSTRAINT IF EXISTS "FK_26bcf6b3c7c6b742e63d9308676"; +ALTER TABLE IF EXISTS ONLY public."postCategories" DROP CONSTRAINT IF EXISTS "FK_1f4b27b2e31fb6263f6fb3a9390"; +ALTER TABLE IF EXISTS ONLY public."Report" DROP CONSTRAINT IF EXISTS "FK_16c178e84273608caf9db34df88"; +ALTER TABLE IF EXISTS ONLY public."UserReview" DROP CONSTRAINT IF EXISTS "FK_14e4fa2651e5c6d6118e2ba18aa"; +ALTER TABLE IF EXISTS ONLY public."userSavedPosts" DROP CONSTRAINT IF EXISTS "FK_0c0a06e6163f7a7315c4ce5fd4c"; +DROP INDEX IF EXISTS public."IDX_user_following_users_following_id"; +DROP INDEX IF EXISTS public."IDX_user_following_users_follower_id"; +DROP INDEX IF EXISTS public."IDX_fd473bd2ef9b7a23f41a40ebed"; +DROP INDEX IF EXISTS public."IDX_eventPost_postId"; +DROP INDEX IF EXISTS public."IDX_eventPost_eventTagId"; +DROP INDEX IF EXISTS public."IDX_bc2ca85580a5c620ccc7f03f5d"; +DROP INDEX IF EXISTS public."IDX_baa3d7e5e872010a3c23e98153"; +DROP INDEX IF EXISTS public."IDX_978f319769e3d7285d6d2e40af"; +DROP INDEX IF EXISTS public."IDX_80ef95f34370fd0704c156c13e"; +DROP INDEX IF EXISTS public."IDX_793578cc63c2442a7944e93131"; +DROP INDEX IF EXISTS public."IDX_7532bd6ca893c432ffcfa21f75"; +DROP INDEX IF EXISTS public."IDX_61151ebab50db74ea513ff8bd8"; +DROP INDEX IF EXISTS public."IDX_503e9a09612f9668063099baff"; +DROP INDEX IF EXISTS public."IDX_3b2f09095e41d9c82bedaa0d8f"; +DROP INDEX IF EXISTS public."IDX_1f4b27b2e31fb6263f6fb3a939"; +DROP INDEX IF EXISTS public."IDX_0c0a06e6163f7a7315c4ce5fd4"; +ALTER TABLE IF EXISTS ONLY public."User" DROP CONSTRAINT IF EXISTS "User_pkey"; +ALTER TABLE IF EXISTS ONLY public."eventPostRelationships" DROP CONSTRAINT IF EXISTS "UQ_eventPost_postId_eventTagId"; +ALTER TABLE IF EXISTS ONLY public."User" DROP CONSTRAINT IF EXISTS "UQ_ec60b02aab67f0f99f6f88797ed"; +ALTER TABLE IF EXISTS ONLY public."TransactionReview" DROP CONSTRAINT IF EXISTS "UQ_aff62b169ebd519d1f5994e781a"; +ALTER TABLE IF EXISTS ONLY public."User" DROP CONSTRAINT IF EXISTS "UQ_4a257d2c9837248d70640b3e36e"; +ALTER TABLE IF EXISTS ONLY public."User" DROP CONSTRAINT IF EXISTS "UQ_29a05908a0fa0728526d2833657"; +ALTER TABLE IF EXISTS ONLY public."User" DROP CONSTRAINT IF EXISTS "UQ_02dec29f4ca814ab6efa2d4f0c4"; +ALTER TABLE IF EXISTS ONLY public.searches DROP CONSTRAINT IF EXISTS "PK_searches"; +ALTER TABLE IF EXISTS ONLY public."eventPostRelationships" DROP CONSTRAINT IF EXISTS "PK_eventPostRelationships"; +ALTER TABLE IF EXISTS ONLY public."postEventTags" DROP CONSTRAINT IF EXISTS "PK_cc14f1e77d0b18c8ec995937fd0"; +ALTER TABLE IF EXISTS ONLY public."Post" DROP CONSTRAINT IF EXISTS "PK_c4d3b3dcd73db0b0129ea829f9f"; +ALTER TABLE IF EXISTS ONLY public."Category" DROP CONSTRAINT IF EXISTS "PK_c2727780c5b9b0c564c29a4977c"; +ALTER TABLE IF EXISTS ONLY public."TransactionReview" DROP CONSTRAINT IF EXISTS "PK_TransactionReview"; +ALTER TABLE IF EXISTS ONLY public."Transaction" DROP CONSTRAINT IF EXISTS "PK_Transaction"; +ALTER TABLE IF EXISTS ONLY public."FCMToken" DROP CONSTRAINT IF EXISTS "PK_FCMToken"; +ALTER TABLE IF EXISTS ONLY public."Report" DROP CONSTRAINT IF EXISTS "PK_9dbb4c593be9832c28a5793e258"; +ALTER TABLE IF EXISTS ONLY public."EventTag" DROP CONSTRAINT IF EXISTS "PK_929d8d89bf95d848ac3b7546a29"; +ALTER TABLE IF EXISTS ONLY public."UserReview" DROP CONSTRAINT IF EXISTS "PK_91b62f63709469ae812a3519dd1"; +ALTER TABLE IF EXISTS ONLY public."userBlockingUsers" DROP CONSTRAINT IF EXISTS "PK_8db623e58cc4bce5fbcc252c66b"; +ALTER TABLE IF EXISTS ONLY public.migrations DROP CONSTRAINT IF EXISTS "PK_8c82d7f526340ab734260ea46be"; +ALTER TABLE IF EXISTS ONLY public."postCategories" DROP CONSTRAINT IF EXISTS "PK_88340cf0b1b8a00578602f4c80b"; +ALTER TABLE IF EXISTS ONLY public."Feedback" DROP CONSTRAINT IF EXISTS "PK_7ffea537e9c56670b65c2d62316"; +ALTER TABLE IF EXISTS ONLY public."requestMatchesPosts" DROP CONSTRAINT IF EXISTS "PK_7f4c04956dd4e84a3437b2a8018"; +ALTER TABLE IF EXISTS ONLY public."Message" DROP CONSTRAINT IF EXISTS "PK_7dd6398f0d1dcaf73df342fa325"; +ALTER TABLE IF EXISTS ONLY public.notifications DROP CONSTRAINT IF EXISTS "PK_6a72c3c0f683f6462415e653c3a"; +ALTER TABLE IF EXISTS ONLY public."Request" DROP CONSTRAINT IF EXISTS "PK_23de24dc477765bcc099feae8e5"; +ALTER TABLE IF EXISTS ONLY public."userSavedPosts" DROP CONSTRAINT IF EXISTS "PK_11901fe92c42b2d2a71ca74021a"; +ALTER TABLE IF EXISTS ONLY public.user_following_users DROP CONSTRAINT IF EXISTS "PK_01b7a923c26f4be4f7c138cbb88"; +ALTER TABLE IF EXISTS public.migrations ALTER COLUMN id DROP DEFAULT; +DROP TABLE IF EXISTS public.user_following_users; +DROP TABLE IF EXISTS public."userSavedPosts"; +DROP TABLE IF EXISTS public."userBlockingUsers"; +DROP TABLE IF EXISTS public.typeorm_metadata; +DROP TABLE IF EXISTS public.searches; +DROP TABLE IF EXISTS public."requestMatchesPosts"; +DROP TABLE IF EXISTS public."postEventTags"; +DROP TABLE IF EXISTS public."postCategories"; +DROP TABLE IF EXISTS public.notifications; +DROP SEQUENCE IF EXISTS public.migrations_id_seq; +DROP TABLE IF EXISTS public.migrations; +DROP TABLE IF EXISTS public."eventPostRelationships"; +DROP TABLE IF EXISTS public."UserReview"; +DROP TABLE IF EXISTS public."User"; +DROP TABLE IF EXISTS public."TransactionReview"; +DROP TABLE IF EXISTS public."Transaction"; +DROP TABLE IF EXISTS public."Request"; +DROP TABLE IF EXISTS public."Report"; +DROP TABLE IF EXISTS public."Post"; +DROP TABLE IF EXISTS public."Message"; +DROP TABLE IF EXISTS public."Feedback"; +DROP TABLE IF EXISTS public."FCMToken"; +DROP TABLE IF EXISTS public."EventTag"; +DROP TABLE IF EXISTS public."Category"; +DROP EXTENSION IF EXISTS vector; +DROP EXTENSION IF EXISTS "uuid-ossp"; +-- +-- Name: uuid-ossp; Type: EXTENSION; Schema: -; Owner: - +-- + +CREATE EXTENSION IF NOT EXISTS "uuid-ossp" WITH SCHEMA public; + + +-- +-- Name: EXTENSION "uuid-ossp"; Type: COMMENT; Schema: -; Owner: - +-- + +COMMENT ON EXTENSION "uuid-ossp" IS 'generate universally unique identifiers (UUIDs)'; + + +-- +-- Name: vector; Type: EXTENSION; Schema: -; Owner: - +-- + +CREATE EXTENSION IF NOT EXISTS vector WITH SCHEMA public; + + +-- +-- Name: EXTENSION vector; Type: COMMENT; Schema: -; Owner: - +-- + +COMMENT ON EXTENSION vector IS 'vector data type and ivfflat and hnsw access methods'; + + +SET default_tablespace = ''; + +SET default_table_access_method = heap; + +-- +-- Name: Category; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public."Category" ( + id uuid DEFAULT public.uuid_generate_v4() NOT NULL, + name character varying NOT NULL +); + + +-- +-- Name: EventTag; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public."EventTag" ( + id uuid DEFAULT public.uuid_generate_v4() NOT NULL, + name character varying NOT NULL +); + + +-- +-- Name: FCMToken; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public."FCMToken" ( + id uuid DEFAULT public.uuid_generate_v4() NOT NULL, + "fcmToken" character varying NOT NULL, + "notificationsEnabled" boolean NOT NULL, + "timestamp" timestamp without time zone NOT NULL, + "userId" character varying +); + + +-- +-- Name: Feedback; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public."Feedback" ( + id uuid DEFAULT public.uuid_generate_v4() NOT NULL, + description character varying NOT NULL, + images text[] NOT NULL, + "userId" character varying +); + + +-- +-- Name: Message; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public."Message" ( + id uuid NOT NULL +); + + +-- +-- Name: Post; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public."Post" ( + id uuid DEFAULT public.uuid_generate_v4() NOT NULL, + title character varying NOT NULL, + description character varying NOT NULL, + "originalPrice" numeric CONSTRAINT "Post_original_price_not_null" NOT NULL, + "alteredPrice" numeric DEFAULT '-1'::numeric CONSTRAINT "Post_altered_price_not_null" NOT NULL, + images text[] NOT NULL, + created timestamp with time zone DEFAULT now() NOT NULL, + location character varying, + archive boolean DEFAULT false NOT NULL, + condition character varying NOT NULL, + sold boolean DEFAULT false NOT NULL, + embedding double precision[], + "userId" character varying +); + + +-- +-- Name: Report; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public."Report" ( + id uuid DEFAULT public.uuid_generate_v4() NOT NULL, + reason character varying NOT NULL, + type character varying NOT NULL, + resolved boolean NOT NULL, + created timestamp with time zone DEFAULT now() NOT NULL, + "reporterFirebaseUid" character varying, + "reportedFirebaseUid" character varying, + "postId" uuid, + "messageId" uuid +); + + +-- +-- Name: Request; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public."Request" ( + id uuid DEFAULT public.uuid_generate_v4() NOT NULL, + title character varying NOT NULL, + description character varying NOT NULL, + archive boolean DEFAULT false NOT NULL, + embedding double precision[], + "userId" character varying +); + + +-- +-- Name: Transaction; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public."Transaction" ( + id uuid DEFAULT public.uuid_generate_v4() NOT NULL, + location character varying NOT NULL, + amount numeric NOT NULL, + completed boolean DEFAULT false NOT NULL, + "postId" uuid, + "buyerId" character varying, + "sellerId" character varying, + "transactionDate" timestamp with time zone, + "createdAt" timestamp with time zone DEFAULT now() NOT NULL, + "confirmationSent" boolean DEFAULT false NOT NULL +); + + +-- +-- Name: TransactionReview; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public."TransactionReview" ( + id uuid DEFAULT public.uuid_generate_v4() NOT NULL, + stars integer NOT NULL, + "transactionId" uuid, + "hadIssues" boolean DEFAULT false NOT NULL, + "issueCategory" text, + "issueDetails" text, + "createdAt" timestamp with time zone DEFAULT now() NOT NULL, + comments text +); + + +-- +-- Name: User; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public."User" ( + username character varying NOT NULL, + netid character varying, + admin boolean NOT NULL, + stars numeric DEFAULT '0'::numeric NOT NULL, + email character varying NOT NULL, + bio text DEFAULT ''::text NOT NULL, + "isActive" boolean DEFAULT true NOT NULL, + "firebaseUid" character varying NOT NULL, + "givenName" character varying, + "familyName" character varying, + "numReviews" integer DEFAULT 0 NOT NULL, + "photoUrl" character varying, + "venmoHandle" character varying, + "googleId" character varying, + "soldPosts" integer DEFAULT 0 NOT NULL, + "availabilityId" character varying +); + + +-- +-- Name: UserReview; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public."UserReview" ( + id uuid DEFAULT public.uuid_generate_v4() NOT NULL, + fulfilled boolean NOT NULL, + stars integer NOT NULL, + comments character varying NOT NULL, + date timestamp with time zone DEFAULT now() NOT NULL, + "buyerId" character varying, + "sellerId" character varying +); + + +-- +-- Name: eventPostRelationships; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public."eventPostRelationships" ( + id uuid DEFAULT public.uuid_generate_v4() NOT NULL, + "postId" uuid NOT NULL, + "eventTagId" uuid NOT NULL, + source character varying(20) NOT NULL, + "relevanceScore" double precision, + "createdAt" timestamp with time zone DEFAULT now() NOT NULL, + "updatedAt" timestamp with time zone DEFAULT now() NOT NULL +); + + +-- +-- Name: migrations; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.migrations ( + id integer NOT NULL, + "timestamp" bigint NOT NULL, + name character varying NOT NULL +); + + +-- +-- Name: migrations_id_seq; Type: SEQUENCE; Schema: public; Owner: - +-- + +CREATE SEQUENCE public.migrations_id_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + +-- +-- Name: migrations_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - +-- + +ALTER SEQUENCE public.migrations_id_seq OWNED BY public.migrations.id; + + +-- +-- Name: notifications; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.notifications ( + id uuid DEFAULT public.uuid_generate_v4() NOT NULL, + title character varying NOT NULL, + body character varying NOT NULL, + data jsonb, + read boolean DEFAULT false NOT NULL, + "userId" character varying NOT NULL, + "createdAt" timestamp without time zone DEFAULT now() NOT NULL, + "updatedAt" timestamp without time zone DEFAULT now() NOT NULL +); + + +-- +-- Name: postCategories; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public."postCategories" ( + posts uuid CONSTRAINT post_categories_posts_not_null NOT NULL, + categories uuid CONSTRAINT post_categories_categories_not_null NOT NULL +); + + +-- +-- Name: postEventTags; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public."postEventTags" ( + posts uuid CONSTRAINT post_event_tags_posts_not_null NOT NULL, + "eventTags" uuid CONSTRAINT post_event_tags_event_tags_not_null NOT NULL +); + + +-- +-- Name: requestMatchesPosts; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public."requestMatchesPosts" ( + matches uuid CONSTRAINT request_matches_posts_matches_not_null NOT NULL, + matched uuid CONSTRAINT request_matches_posts_matched_not_null NOT NULL +); + + +-- +-- Name: searches; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.searches ( + id uuid DEFAULT public.uuid_generate_v4() NOT NULL, + "searchText" character varying NOT NULL, + "firebaseUid" character varying NOT NULL, + "createdAt" timestamp without time zone DEFAULT now() NOT NULL, + "searchVector" character varying NOT NULL +); + + +-- +-- Name: typeorm_metadata; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.typeorm_metadata ( + type character varying NOT NULL, + database character varying, + schema character varying, + "table" character varying, + name character varying, + value text +); + + +-- +-- Name: userBlockingUsers; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public."userBlockingUsers" ( + blockers character varying CONSTRAINT user_blocking_users_blockers_not_null NOT NULL, + blocking character varying CONSTRAINT user_blocking_users_blocking_not_null NOT NULL +); + + +-- +-- Name: userSavedPosts; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public."userSavedPosts" ( + saved uuid CONSTRAINT user_saved_posts_saved_not_null NOT NULL, + savers character varying CONSTRAINT user_saved_posts_savers_not_null NOT NULL +); + + +-- +-- Name: user_following_users; Type: TABLE; Schema: public; Owner: - +-- + +CREATE TABLE public.user_following_users ( + follower_id character varying NOT NULL, + following_id character varying NOT NULL +); + + +-- +-- Name: migrations id; Type: DEFAULT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.migrations ALTER COLUMN id SET DEFAULT nextval('public.migrations_id_seq'::regclass); + + +-- +-- Data for Name: Category; Type: TABLE DATA; Schema: public; Owner: - +-- + +COPY public."Category" (id, name) FROM stdin; +\. + + +-- +-- Data for Name: EventTag; Type: TABLE DATA; Schema: public; Owner: - +-- + +COPY public."EventTag" (id, name) FROM stdin; +\. + + +-- +-- Data for Name: FCMToken; Type: TABLE DATA; Schema: public; Owner: - +-- + +COPY public."FCMToken" (id, "fcmToken", "notificationsEnabled", "timestamp", "userId") FROM stdin; +\. + + +-- +-- Data for Name: Feedback; Type: TABLE DATA; Schema: public; Owner: - +-- + +COPY public."Feedback" (id, description, images, "userId") FROM stdin; +\. + + +-- +-- Data for Name: Message; Type: TABLE DATA; Schema: public; Owner: - +-- + +COPY public."Message" (id) FROM stdin; +\. + + +-- +-- Data for Name: Post; Type: TABLE DATA; Schema: public; Owner: - +-- + +COPY public."Post" (id, title, description, "originalPrice", "alteredPrice", images, created, location, archive, condition, sold, embedding, "userId") FROM stdin; +\. + + +-- +-- Data for Name: Report; Type: TABLE DATA; Schema: public; Owner: - +-- + +COPY public."Report" (id, reason, type, resolved, created, "reporterFirebaseUid", "reportedFirebaseUid", "postId", "messageId") FROM stdin; +\. + + +-- +-- Data for Name: Request; Type: TABLE DATA; Schema: public; Owner: - +-- + +COPY public."Request" (id, title, description, archive, embedding, "userId") FROM stdin; +\. + + +-- +-- Data for Name: Transaction; Type: TABLE DATA; Schema: public; Owner: - +-- + +COPY public."Transaction" (id, location, amount, completed, "postId", "buyerId", "sellerId", "transactionDate", "createdAt", "confirmationSent") FROM stdin; +\. + + +-- +-- Data for Name: TransactionReview; Type: TABLE DATA; Schema: public; Owner: - +-- + +COPY public."TransactionReview" (id, stars, "transactionId", "hadIssues", "issueCategory", "issueDetails", "createdAt", comments) FROM stdin; +\. + + +-- +-- Data for Name: User; Type: TABLE DATA; Schema: public; Owner: - +-- + +COPY public."User" (username, netid, admin, stars, email, bio, "isActive", "firebaseUid", "givenName", "familyName", "numReviews", "photoUrl", "venmoHandle", "googleId", "soldPosts", "availabilityId") FROM stdin; +\. + + +-- +-- Data for Name: UserReview; Type: TABLE DATA; Schema: public; Owner: - +-- + +COPY public."UserReview" (id, fulfilled, stars, comments, date, "buyerId", "sellerId") FROM stdin; +\. + + +-- +-- Data for Name: eventPostRelationships; Type: TABLE DATA; Schema: public; Owner: - +-- + +COPY public."eventPostRelationships" (id, "postId", "eventTagId", source, "relevanceScore", "createdAt", "updatedAt") FROM stdin; +\. + + +-- +-- Data for Name: migrations; Type: TABLE DATA; Schema: public; Owner: - +-- + +COPY public.migrations (id, "timestamp", name) FROM stdin; +1 1709163288115 init1709163288115 +2 1713139721037 softdelete1713139721037 +3 1713218553306 makenetidnullable1713218553306 +4 1713308449994 addreports1713308449994 +5 1713320015776 UpdateMessageModel1713320015776 +6 1731186421123 AddArchiveToRequest1731186421123 +7 1731271779741 updatecategories1731271779741 +8 1732146942548 addconditiontoposts1732146942548 +9 1732906578369 AddTransactionTable1732906578369 +10 1732924592033 AddSoldColumnToPost1732924592033 +11 1732975238671 AddTransactionReviewTable1732975238671 +12 1739899394694 Notifications1739899394694 +13 1740007049335 ConvertEmbeddingToVector1631740007049335 +14 1740628691583 AuthorizationRefactor1740628691583 +15 1743028223060 AddCategoryTable1743028223060 +16 1743566564676 CreateSearchesTable1743566564676 +17 1761697414368 AddEventTagTable1761697414368 +18 1765000000000 RenameSnakeToCamelResellTest1765000000000 +19 1767386999887 AddUserStats1767386999887 +20 1769385600000 AddAvailabilityToUser1769385600000 +21 1769500000000 AddConfirmationSentToTransaction1769500000000 +22 1769700000000 CreateEventPostRelationships1769700000000 +\. + + +-- +-- Data for Name: notifications; Type: TABLE DATA; Schema: public; Owner: - +-- + +COPY public.notifications (id, title, body, data, read, "userId", "createdAt", "updatedAt") FROM stdin; +\. + + +-- +-- Data for Name: postCategories; Type: TABLE DATA; Schema: public; Owner: - +-- + +COPY public."postCategories" (posts, categories) FROM stdin; +\. + + +-- +-- Data for Name: postEventTags; Type: TABLE DATA; Schema: public; Owner: - +-- + +COPY public."postEventTags" (posts, "eventTags") FROM stdin; +\. + + +-- +-- Data for Name: requestMatchesPosts; Type: TABLE DATA; Schema: public; Owner: - +-- + +COPY public."requestMatchesPosts" (matches, matched) FROM stdin; +\. + + +-- +-- Data for Name: searches; Type: TABLE DATA; Schema: public; Owner: - +-- + +COPY public.searches (id, "searchText", "firebaseUid", "createdAt", "searchVector") FROM stdin; +\. + + +-- +-- Data for Name: typeorm_metadata; Type: TABLE DATA; Schema: public; Owner: - +-- + +COPY public.typeorm_metadata (type, database, schema, "table", name, value) FROM stdin; +\. + + +-- +-- Data for Name: userBlockingUsers; Type: TABLE DATA; Schema: public; Owner: - +-- + +COPY public."userBlockingUsers" (blockers, blocking) FROM stdin; +\. + + +-- +-- Data for Name: userSavedPosts; Type: TABLE DATA; Schema: public; Owner: - +-- + +COPY public."userSavedPosts" (saved, savers) FROM stdin; +\. + + +-- +-- Data for Name: user_following_users; Type: TABLE DATA; Schema: public; Owner: - +-- + +COPY public.user_following_users (follower_id, following_id) FROM stdin; +\. + + +-- +-- Name: migrations_id_seq; Type: SEQUENCE SET; Schema: public; Owner: - +-- + +SELECT pg_catalog.setval('public.migrations_id_seq', 22, true); + + +-- +-- Name: user_following_users PK_01b7a923c26f4be4f7c138cbb88; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.user_following_users + ADD CONSTRAINT "PK_01b7a923c26f4be4f7c138cbb88" PRIMARY KEY (follower_id, following_id); + + +-- +-- Name: userSavedPosts PK_11901fe92c42b2d2a71ca74021a; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."userSavedPosts" + ADD CONSTRAINT "PK_11901fe92c42b2d2a71ca74021a" PRIMARY KEY (saved, savers); + + +-- +-- Name: Request PK_23de24dc477765bcc099feae8e5; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."Request" + ADD CONSTRAINT "PK_23de24dc477765bcc099feae8e5" PRIMARY KEY (id); + + +-- +-- Name: notifications PK_6a72c3c0f683f6462415e653c3a; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.notifications + ADD CONSTRAINT "PK_6a72c3c0f683f6462415e653c3a" PRIMARY KEY (id); + + +-- +-- Name: Message PK_7dd6398f0d1dcaf73df342fa325; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."Message" + ADD CONSTRAINT "PK_7dd6398f0d1dcaf73df342fa325" PRIMARY KEY (id); + + +-- +-- Name: requestMatchesPosts PK_7f4c04956dd4e84a3437b2a8018; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."requestMatchesPosts" + ADD CONSTRAINT "PK_7f4c04956dd4e84a3437b2a8018" PRIMARY KEY (matches, matched); + + +-- +-- Name: Feedback PK_7ffea537e9c56670b65c2d62316; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."Feedback" + ADD CONSTRAINT "PK_7ffea537e9c56670b65c2d62316" PRIMARY KEY (id); + + +-- +-- Name: postCategories PK_88340cf0b1b8a00578602f4c80b; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."postCategories" + ADD CONSTRAINT "PK_88340cf0b1b8a00578602f4c80b" PRIMARY KEY (posts, categories); + + +-- +-- Name: migrations PK_8c82d7f526340ab734260ea46be; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.migrations + ADD CONSTRAINT "PK_8c82d7f526340ab734260ea46be" PRIMARY KEY (id); + + +-- +-- Name: userBlockingUsers PK_8db623e58cc4bce5fbcc252c66b; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."userBlockingUsers" + ADD CONSTRAINT "PK_8db623e58cc4bce5fbcc252c66b" PRIMARY KEY (blockers, blocking); + + +-- +-- Name: UserReview PK_91b62f63709469ae812a3519dd1; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."UserReview" + ADD CONSTRAINT "PK_91b62f63709469ae812a3519dd1" PRIMARY KEY (id); + + +-- +-- Name: EventTag PK_929d8d89bf95d848ac3b7546a29; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."EventTag" + ADD CONSTRAINT "PK_929d8d89bf95d848ac3b7546a29" PRIMARY KEY (id); + + +-- +-- Name: Report PK_9dbb4c593be9832c28a5793e258; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."Report" + ADD CONSTRAINT "PK_9dbb4c593be9832c28a5793e258" PRIMARY KEY (id); + + +-- +-- Name: FCMToken PK_FCMToken; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."FCMToken" + ADD CONSTRAINT "PK_FCMToken" PRIMARY KEY (id); + + +-- +-- Name: Transaction PK_Transaction; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."Transaction" + ADD CONSTRAINT "PK_Transaction" PRIMARY KEY (id); + + +-- +-- Name: TransactionReview PK_TransactionReview; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."TransactionReview" + ADD CONSTRAINT "PK_TransactionReview" PRIMARY KEY (id); + + +-- +-- Name: Category PK_c2727780c5b9b0c564c29a4977c; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."Category" + ADD CONSTRAINT "PK_c2727780c5b9b0c564c29a4977c" PRIMARY KEY (id); + + +-- +-- Name: Post PK_c4d3b3dcd73db0b0129ea829f9f; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."Post" + ADD CONSTRAINT "PK_c4d3b3dcd73db0b0129ea829f9f" PRIMARY KEY (id); + + +-- +-- Name: postEventTags PK_cc14f1e77d0b18c8ec995937fd0; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."postEventTags" + ADD CONSTRAINT "PK_cc14f1e77d0b18c8ec995937fd0" PRIMARY KEY (posts, "eventTags"); + + +-- +-- Name: eventPostRelationships PK_eventPostRelationships; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."eventPostRelationships" + ADD CONSTRAINT "PK_eventPostRelationships" PRIMARY KEY (id); + + +-- +-- Name: searches PK_searches; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.searches + ADD CONSTRAINT "PK_searches" PRIMARY KEY (id); + + +-- +-- Name: User UQ_02dec29f4ca814ab6efa2d4f0c4; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."User" + ADD CONSTRAINT "UQ_02dec29f4ca814ab6efa2d4f0c4" UNIQUE ("googleId"); + + +-- +-- Name: User UQ_29a05908a0fa0728526d2833657; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."User" + ADD CONSTRAINT "UQ_29a05908a0fa0728526d2833657" UNIQUE (username); + + +-- +-- Name: User UQ_4a257d2c9837248d70640b3e36e; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."User" + ADD CONSTRAINT "UQ_4a257d2c9837248d70640b3e36e" UNIQUE (email); + + +-- +-- Name: TransactionReview UQ_aff62b169ebd519d1f5994e781a; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."TransactionReview" + ADD CONSTRAINT "UQ_aff62b169ebd519d1f5994e781a" UNIQUE ("transactionId"); + + +-- +-- Name: User UQ_ec60b02aab67f0f99f6f88797ed; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."User" + ADD CONSTRAINT "UQ_ec60b02aab67f0f99f6f88797ed" UNIQUE (netid); + + +-- +-- Name: eventPostRelationships UQ_eventPost_postId_eventTagId; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."eventPostRelationships" + ADD CONSTRAINT "UQ_eventPost_postId_eventTagId" UNIQUE ("postId", "eventTagId"); + + +-- +-- Name: User User_pkey; Type: CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."User" + ADD CONSTRAINT "User_pkey" PRIMARY KEY ("firebaseUid"); + + +-- +-- Name: IDX_0c0a06e6163f7a7315c4ce5fd4; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX "IDX_0c0a06e6163f7a7315c4ce5fd4" ON public."userSavedPosts" USING btree (savers); + + +-- +-- Name: IDX_1f4b27b2e31fb6263f6fb3a939; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX "IDX_1f4b27b2e31fb6263f6fb3a939" ON public."postCategories" USING btree (categories); + + +-- +-- Name: IDX_3b2f09095e41d9c82bedaa0d8f; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX "IDX_3b2f09095e41d9c82bedaa0d8f" ON public."requestMatchesPosts" USING btree (matched); + + +-- +-- Name: IDX_503e9a09612f9668063099baff; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX "IDX_503e9a09612f9668063099baff" ON public.user_following_users USING btree (following_id); + + +-- +-- Name: IDX_61151ebab50db74ea513ff8bd8; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX "IDX_61151ebab50db74ea513ff8bd8" ON public."postEventTags" USING btree (posts); + + +-- +-- Name: IDX_7532bd6ca893c432ffcfa21f75; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX "IDX_7532bd6ca893c432ffcfa21f75" ON public."postEventTags" USING btree ("eventTags"); + + +-- +-- Name: IDX_793578cc63c2442a7944e93131; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX "IDX_793578cc63c2442a7944e93131" ON public."userBlockingUsers" USING btree (blockers); + + +-- +-- Name: IDX_80ef95f34370fd0704c156c13e; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX "IDX_80ef95f34370fd0704c156c13e" ON public.user_following_users USING btree (follower_id); + + +-- +-- Name: IDX_978f319769e3d7285d6d2e40af; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX "IDX_978f319769e3d7285d6d2e40af" ON public."postCategories" USING btree (posts); + + +-- +-- Name: IDX_baa3d7e5e872010a3c23e98153; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX "IDX_baa3d7e5e872010a3c23e98153" ON public."userSavedPosts" USING btree (saved); + + +-- +-- Name: IDX_bc2ca85580a5c620ccc7f03f5d; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX "IDX_bc2ca85580a5c620ccc7f03f5d" ON public."userBlockingUsers" USING btree (blocking); + + +-- +-- Name: IDX_eventPost_eventTagId; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX "IDX_eventPost_eventTagId" ON public."eventPostRelationships" USING btree ("eventTagId"); + + +-- +-- Name: IDX_eventPost_postId; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX "IDX_eventPost_postId" ON public."eventPostRelationships" USING btree ("postId"); + + +-- +-- Name: IDX_fd473bd2ef9b7a23f41a40ebed; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX "IDX_fd473bd2ef9b7a23f41a40ebed" ON public."requestMatchesPosts" USING btree (matches); + + +-- +-- Name: IDX_user_following_users_follower_id; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX "IDX_user_following_users_follower_id" ON public.user_following_users USING btree (follower_id); + + +-- +-- Name: IDX_user_following_users_following_id; Type: INDEX; Schema: public; Owner: - +-- + +CREATE INDEX "IDX_user_following_users_following_id" ON public.user_following_users USING btree (following_id); + + +-- +-- Name: userSavedPosts FK_0c0a06e6163f7a7315c4ce5fd4c; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."userSavedPosts" + ADD CONSTRAINT "FK_0c0a06e6163f7a7315c4ce5fd4c" FOREIGN KEY (savers) REFERENCES public."User"("firebaseUid"); + + +-- +-- Name: UserReview FK_14e4fa2651e5c6d6118e2ba18aa; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."UserReview" + ADD CONSTRAINT "FK_14e4fa2651e5c6d6118e2ba18aa" FOREIGN KEY ("sellerId") REFERENCES public."User"("firebaseUid"); + + +-- +-- Name: Report FK_16c178e84273608caf9db34df88; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."Report" + ADD CONSTRAINT "FK_16c178e84273608caf9db34df88" FOREIGN KEY ("reportedFirebaseUid") REFERENCES public."User"("firebaseUid"); + + +-- +-- Name: postCategories FK_1f4b27b2e31fb6263f6fb3a9390; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."postCategories" + ADD CONSTRAINT "FK_1f4b27b2e31fb6263f6fb3a9390" FOREIGN KEY (categories) REFERENCES public."Category"(id); + + +-- +-- Name: Feedback FK_26bcf6b3c7c6b742e63d9308676; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."Feedback" + ADD CONSTRAINT "FK_26bcf6b3c7c6b742e63d9308676" FOREIGN KEY ("userId") REFERENCES public."User"("firebaseUid") ON DELETE CASCADE; + + +-- +-- Name: Transaction FK_30d551dc74a9537b73d4007592f; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."Transaction" + ADD CONSTRAINT "FK_30d551dc74a9537b73d4007592f" FOREIGN KEY ("sellerId") REFERENCES public."User"("firebaseUid"); + + +-- +-- Name: requestMatchesPosts FK_3b2f09095e41d9c82bedaa0d8fe; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."requestMatchesPosts" + ADD CONSTRAINT "FK_3b2f09095e41d9c82bedaa0d8fe" FOREIGN KEY (matched) REFERENCES public."Request"(id); + + +-- +-- Name: Transaction FK_4ae4b1f6ff200ae67b40eb5bd8d; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."Transaction" + ADD CONSTRAINT "FK_4ae4b1f6ff200ae67b40eb5bd8d" FOREIGN KEY ("buyerId") REFERENCES public."User"("firebaseUid"); + + +-- +-- Name: Report FK_4bc548745107f37d3512ed688c5; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."Report" + ADD CONSTRAINT "FK_4bc548745107f37d3512ed688c5" FOREIGN KEY ("postId") REFERENCES public."Post"(id); + + +-- +-- Name: user_following_users FK_503e9a09612f9668063099baff1; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.user_following_users + ADD CONSTRAINT "FK_503e9a09612f9668063099baff1" FOREIGN KEY (following_id) REFERENCES public."User"("firebaseUid"); + + +-- +-- Name: UserReview FK_53a14948aa4e941762a403144ea; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."UserReview" + ADD CONSTRAINT "FK_53a14948aa4e941762a403144ea" FOREIGN KEY ("buyerId") REFERENCES public."User"("firebaseUid"); + + +-- +-- Name: postEventTags FK_61151ebab50db74ea513ff8bd87; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."postEventTags" + ADD CONSTRAINT "FK_61151ebab50db74ea513ff8bd87" FOREIGN KEY (posts) REFERENCES public."Post"(id) ON UPDATE CASCADE ON DELETE CASCADE; + + +-- +-- Name: notifications FK_692a909ee0fa9383e7859f9b406; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.notifications + ADD CONSTRAINT "FK_692a909ee0fa9383e7859f9b406" FOREIGN KEY ("userId") REFERENCES public."User"("firebaseUid"); + + +-- +-- Name: postEventTags FK_7532bd6ca893c432ffcfa21f755; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."postEventTags" + ADD CONSTRAINT "FK_7532bd6ca893c432ffcfa21f755" FOREIGN KEY ("eventTags") REFERENCES public."EventTag"(id); + + +-- +-- Name: userBlockingUsers FK_793578cc63c2442a7944e93131a; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."userBlockingUsers" + ADD CONSTRAINT "FK_793578cc63c2442a7944e93131a" FOREIGN KEY (blockers) REFERENCES public."User"("firebaseUid") ON UPDATE CASCADE ON DELETE CASCADE; + + +-- +-- Name: user_following_users FK_80ef95f34370fd0704c156c13ef; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.user_following_users + ADD CONSTRAINT "FK_80ef95f34370fd0704c156c13ef" FOREIGN KEY (follower_id) REFERENCES public."User"("firebaseUid") ON UPDATE CASCADE ON DELETE CASCADE; + + +-- +-- Name: postCategories FK_978f319769e3d7285d6d2e40af8; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."postCategories" + ADD CONSTRAINT "FK_978f319769e3d7285d6d2e40af8" FOREIGN KEY (posts) REFERENCES public."Post"(id) ON UPDATE CASCADE ON DELETE CASCADE; + + +-- +-- Name: Post FK_97e81bcb59530bfb061e48aee6a; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."Post" + ADD CONSTRAINT "FK_97e81bcb59530bfb061e48aee6a" FOREIGN KEY ("userId") REFERENCES public."User"("firebaseUid") ON DELETE CASCADE; + + +-- +-- Name: Report FK_a050c9cf7f461bc8fc040a48e0a; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."Report" + ADD CONSTRAINT "FK_a050c9cf7f461bc8fc040a48e0a" FOREIGN KEY ("reporterFirebaseUid") REFERENCES public."User"("firebaseUid"); + + +-- +-- Name: userSavedPosts FK_baa3d7e5e872010a3c23e981532; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."userSavedPosts" + ADD CONSTRAINT "FK_baa3d7e5e872010a3c23e981532" FOREIGN KEY (saved) REFERENCES public."Post"(id) ON UPDATE CASCADE ON DELETE CASCADE; + + +-- +-- Name: Transaction FK_bba9ded63ef0013ac2ec578f246; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."Transaction" + ADD CONSTRAINT "FK_bba9ded63ef0013ac2ec578f246" FOREIGN KEY ("postId") REFERENCES public."Post"(id); + + +-- +-- Name: userBlockingUsers FK_bc2ca85580a5c620ccc7f03f5db; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."userBlockingUsers" + ADD CONSTRAINT "FK_bc2ca85580a5c620ccc7f03f5db" FOREIGN KEY (blocking) REFERENCES public."User"("firebaseUid"); + + +-- +-- Name: Request FK_cdaf52464b00ac3016a8f6110fd; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."Request" + ADD CONSTRAINT "FK_cdaf52464b00ac3016a8f6110fd" FOREIGN KEY ("userId") REFERENCES public."User"("firebaseUid") ON DELETE CASCADE; + + +-- +-- Name: FCMToken FK_d215a8d66e472d872409915f7d5; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."FCMToken" + ADD CONSTRAINT "FK_d215a8d66e472d872409915f7d5" FOREIGN KEY ("userId") REFERENCES public."User"("firebaseUid"); + + +-- +-- Name: Report FK_dd826149b8ac72ddc2d1f4e234e; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."Report" + ADD CONSTRAINT "FK_dd826149b8ac72ddc2d1f4e234e" FOREIGN KEY ("messageId") REFERENCES public."Message"(id); + + +-- +-- Name: eventPostRelationships FK_eventPost_eventTagId; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."eventPostRelationships" + ADD CONSTRAINT "FK_eventPost_eventTagId" FOREIGN KEY ("eventTagId") REFERENCES public."EventTag"(id) ON DELETE CASCADE; + + +-- +-- Name: eventPostRelationships FK_eventPost_postId; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."eventPostRelationships" + ADD CONSTRAINT "FK_eventPost_postId" FOREIGN KEY ("postId") REFERENCES public."Post"(id) ON DELETE CASCADE; + + +-- +-- Name: TransactionReview FK_f7cf58b571d5c57ed9da155c628; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."TransactionReview" + ADD CONSTRAINT "FK_f7cf58b571d5c57ed9da155c628" FOREIGN KEY ("transactionId") REFERENCES public."Transaction"(id); + + +-- +-- Name: searches FK_fc8760cf4823ab84b0cb28d3dad; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.searches + ADD CONSTRAINT "FK_fc8760cf4823ab84b0cb28d3dad" FOREIGN KEY ("firebaseUid") REFERENCES public."User"("firebaseUid") ON DELETE CASCADE; + + +-- +-- Name: requestMatchesPosts FK_fd473bd2ef9b7a23f41a40ebed4; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public."requestMatchesPosts" + ADD CONSTRAINT "FK_fd473bd2ef9b7a23f41a40ebed4" FOREIGN KEY (matches) REFERENCES public."Post"(id) ON UPDATE CASCADE ON DELETE CASCADE; + + +-- +-- Name: user_following_users FK_user_following_users_follower_id; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.user_following_users + ADD CONSTRAINT "FK_user_following_users_follower_id" FOREIGN KEY (follower_id) REFERENCES public."User"("firebaseUid") ON UPDATE CASCADE ON DELETE CASCADE; + + +-- +-- Name: user_following_users FK_user_following_users_following_id; Type: FK CONSTRAINT; Schema: public; Owner: - +-- + +ALTER TABLE ONLY public.user_following_users + ADD CONSTRAINT "FK_user_following_users_following_id" FOREIGN KEY (following_id) REFERENCES public."User"("firebaseUid") ON UPDATE CASCADE ON DELETE CASCADE; + + +-- +-- PostgreSQL database dump complete +-- + +\unrestrict j0zS1YybO7IPtcJxy9ONeBKIaXJBXaXxzwxKQnVNLQIIVc1bKUCxYazgBD8jnUr + diff --git a/jest.config.js b/jest.config.js index 6eff78f..832b34b 100644 --- a/jest.config.js +++ b/jest.config.js @@ -4,4 +4,7 @@ module.exports = { roots: ["src"], maxWorkers: 1, verbose: true, + moduleNameMapper: { + "^firebase-admin/(.*)$": "/node_modules/firebase-admin/lib/$1/index.js", + }, }; diff --git a/src/api/controllers/EventController.ts b/src/api/controllers/EventController.ts new file mode 100644 index 0000000..bfbddd6 --- /dev/null +++ b/src/api/controllers/EventController.ts @@ -0,0 +1,39 @@ +import { + CurrentUser, + Get, + JsonController, + Param, + QueryParam, +} from "routing-controllers"; + +import { UserModel } from "../../models/UserModel"; +import { EventTagModel } from "../../models/EventTagModel"; +import { EventService } from "../../services/EventService"; +import { EventPostSource, GetEventPostsResponse } from "../../types"; + +@JsonController("event/") +export class EventController { + private eventService: EventService; + + constructor(eventService: EventService) { + this.eventService = eventService; + } + + @Get("available-for-tagging/") + async getAvailableEventTags( + @CurrentUser() user: UserModel, + ): Promise { + return this.eventService.getAvailableEventTags(); + } + + @Get(":eventTagId/posts/") + async getEventPosts( + @CurrentUser() user: UserModel, + @Param("eventTagId") eventTagId: string, + @QueryParam("page", { required: false }) page: number = 1, + @QueryParam("limit", { required: false }) limit: number = 10, + @QueryParam("source", { required: false }) source?: EventPostSource, + ): Promise { + return this.eventService.getEventPosts(user, eventTagId, page, limit, source); + } +} diff --git a/src/api/controllers/index.ts b/src/api/controllers/index.ts index 405e0e8..bacb9db 100644 --- a/src/api/controllers/index.ts +++ b/src/api/controllers/index.ts @@ -1,5 +1,6 @@ import { AuthController } from './AuthController'; import { AvailabilityController } from './AvailabilityController'; +import { EventController } from './EventController'; import { FeedbackController } from './FeedbackController'; import { ImageController } from './ImageController'; import { PostController } from './PostController'; @@ -19,6 +20,7 @@ export const controllers = [ AuthTokenController, AvailabilityController, ChatController, + EventController, FeedbackController, ImageController, NotifController, diff --git a/src/app.ts b/src/app.ts index 8f2d2e3..8e89ac2 100644 --- a/src/app.ts +++ b/src/app.ts @@ -26,6 +26,7 @@ import resellConnection from './utils/DB'; import { ReportService } from './services/ReportService'; import { reportToString } from './utils/Requests'; import { startTransactionConfirmationCron } from './cron/transactionCron'; +import { startEventSimilarityCron } from './cron/eventSimilarityCron'; // Setup dependency injection containers routingUseContainer(Container); @@ -199,6 +200,7 @@ async function main() { console.log(`Resell backend bartering on http://localhost:${port}`); startTransactionConfirmationCron(); + startEventSimilarityCron(); }); } diff --git a/src/cron/eventSimilarityCron.ts b/src/cron/eventSimilarityCron.ts new file mode 100644 index 0000000..e7e5456 --- /dev/null +++ b/src/cron/eventSimilarityCron.ts @@ -0,0 +1,43 @@ +import cron from 'node-cron'; +import { getManager } from 'typeorm'; +import { EventPostService } from '../services/EventPostService'; +import { EventTagRepository } from '../repositories/EventTagRepository'; + +/** + * Hourly cron that reprocesses similarity for every event tag. + * For each tag it computes a centroid from user-tagged post embeddings + * and upserts similar posts into the eventPosts table. + */ +export function startEventSimilarityCron() { + cron.schedule('0 * * * *', async () => { + console.log('[CRON] Starting event similarity processing...'); + + try { + const entityManager = getManager(); + const eventTagRepo = entityManager.getCustomRepository(EventTagRepository); + const eventTags = await eventTagRepo.getAllEventTags(); + + if (eventTags.length === 0) { + console.log('[CRON] No event tags found, skipping similarity processing.'); + return; + } + + const eventPostService = new EventPostService(entityManager); + + for (const tag of eventTags) { + try { + await eventPostService.processEventSimilarity(tag.id); + console.log(`[CRON] Similarity processed for event "${tag.name}" (${tag.id})`); + } catch (err) { + console.error(`[CRON] Error processing similarity for event "${tag.name}" (${tag.id}):`, err); + } + } + + console.log(`[CRON] Event similarity processing complete for ${eventTags.length} event(s).`); + } catch (error) { + console.error('[CRON] Fatal error in event similarity cron:', error); + } + }); + + console.log('[CRON] Event similarity cron job started (runs every hour at :00)'); +} diff --git a/src/migrations/1769700000000-CreateEventPost.ts b/src/migrations/1769700000000-CreateEventPost.ts new file mode 100644 index 0000000..d614984 --- /dev/null +++ b/src/migrations/1769700000000-CreateEventPost.ts @@ -0,0 +1,39 @@ +import { MigrationInterface, QueryRunner } from "typeorm"; + +export class CreateEventPost1769700000000 implements MigrationInterface { + name = "CreateEventPost1769700000000"; + + public async up(queryRunner: QueryRunner): Promise { + await queryRunner.query(` + CREATE TABLE IF NOT EXISTS "eventPosts" ( + "id" uuid NOT NULL DEFAULT uuid_generate_v4(), + "postId" uuid NOT NULL, + "eventTagId" uuid NOT NULL, + "source" character varying(20) NOT NULL, + "relevanceScore" float DEFAULT NULL, + "createdAt" TIMESTAMPTZ NOT NULL DEFAULT now(), + "updatedAt" TIMESTAMPTZ NOT NULL DEFAULT now(), + CONSTRAINT "PK_eventPosts" PRIMARY KEY ("id"), + CONSTRAINT "UQ_eventPost_postId_eventTagId" UNIQUE ("postId", "eventTagId"), + CONSTRAINT "FK_eventPost_postId" FOREIGN KEY ("postId") + REFERENCES "Post"("id") ON DELETE CASCADE, + CONSTRAINT "FK_eventPost_eventTagId" FOREIGN KEY ("eventTagId") + REFERENCES "EventTag"("id") ON DELETE CASCADE + ) + `); + + await queryRunner.query(` + CREATE INDEX "IDX_eventPost_eventTagId" ON "eventPosts" ("eventTagId") + `); + + await queryRunner.query(` + CREATE INDEX "IDX_eventPost_postId" ON "eventPosts" ("postId") + `); + } + + public async down(queryRunner: QueryRunner): Promise { + await queryRunner.query(`DROP INDEX IF EXISTS "IDX_eventPost_postId"`); + await queryRunner.query(`DROP INDEX IF EXISTS "IDX_eventPost_eventTagId"`); + await queryRunner.query(`DROP TABLE IF EXISTS "eventPosts"`); + } +} diff --git a/src/models/EventPostModel.ts b/src/models/EventPostModel.ts new file mode 100644 index 0000000..035243c --- /dev/null +++ b/src/models/EventPostModel.ts @@ -0,0 +1,48 @@ +import { + Column, + CreateDateColumn, + Entity, + JoinColumn, + ManyToOne, + PrimaryGeneratedColumn, + Unique, + UpdateDateColumn, +} from "typeorm"; +import { Uuid } from "../types"; +import { PostModel } from "./PostModel"; +import { EventTagModel } from "./EventTagModel"; + +export type EventPostSource = "user" | "similarity" | "nlp_context"; + +@Entity("eventPosts") +@Unique(["postId", "eventTagId"]) // Enforces one row per post per event, so ML layer can't insert another row if event already user-tagged +export class EventPostModel { + @PrimaryGeneratedColumn("uuid") + id: Uuid; + + @Column() + postId: Uuid; + + @ManyToOne(() => PostModel, { onDelete: "CASCADE" }) + @JoinColumn({ name: "postId" }) + post: PostModel; + + @Column() + eventTagId: Uuid; + + @ManyToOne(() => EventTagModel, { onDelete: "CASCADE" }) + @JoinColumn({ name: "eventTagId" }) + eventTag: EventTagModel; + + @Column({ type: "varchar", length: 20 }) + source: EventPostSource; + + @Column({ type: "float", nullable: true, default: null }) + relevanceScore: number | null; + + @CreateDateColumn({ type: "timestamptz" }) + createdAt: Date; + + @UpdateDateColumn({ type: "timestamptz" }) + updatedAt: Date; +} diff --git a/src/models/EventTagModel.ts b/src/models/EventTagModel.ts index 7ae938e..06b5f30 100644 --- a/src/models/EventTagModel.ts +++ b/src/models/EventTagModel.ts @@ -14,7 +14,7 @@ export class EventTagModel { @Column() name: string; - + @ManyToMany(() => PostModel, (post) => post.eventTags) posts: PostModel[]; diff --git a/src/models/index.ts b/src/models/index.ts index 9c5c598..a114af3 100644 --- a/src/models/index.ts +++ b/src/models/index.ts @@ -12,6 +12,7 @@ import { FcmTokenModel } from "./FcmTokenModel"; import { CategoryModel } from "./CategoryModel"; import { SearchModel } from "./SearchModel"; import { EventTagModel } from "./EventTagModel"; +import { EventPostModel } from "./EventPostModel"; export const models = [ FeedbackModel, @@ -28,4 +29,5 @@ export const models = [ CategoryModel, SearchModel, EventTagModel, + EventPostModel, ]; diff --git a/src/repositories/EventPostRepository.ts b/src/repositories/EventPostRepository.ts new file mode 100644 index 0000000..780bc85 --- /dev/null +++ b/src/repositories/EventPostRepository.ts @@ -0,0 +1,140 @@ +import { AbstractRepository, EntityRepository } from 'typeorm'; + +import { EventPostModel, EventPostSource } from '../models/EventPostModel'; + +@EntityRepository(EventPostModel) +export class EventPostRepository extends AbstractRepository { + + /** + * Create or update a post-event relationship. + */ + public async upsertRelationship( + postId: string, + eventTagId: string, + source: EventPostSource, + relevanceScore: number | null, + ): Promise { + const existing = await this.repository + .createQueryBuilder("epr") + .where("epr.postId = :postId", { postId }) + .andWhere("epr.eventTagId = :eventTagId", { eventTagId }) + .getOne(); + + // User source takes priority (an existing user tag is never overwritten by an ML source) + if (existing) { + if (existing.source === 'user' && source !== 'user') { + return existing; + } + existing.source = source; + existing.relevanceScore = relevanceScore; + return await this.repository.save(existing); + } + + const relationship = this.repository.create({ postId, eventTagId, source, relevanceScore }); + return await this.repository.save(relationship); + } + + /** + * Get all user-tagged relationships for an event, with the post (including embedding) loaded. + * Used as anchor points for similarity processing. + */ + public async getUserTaggedPostsForEvent(eventTagId: string): Promise { + return await this.repository + .createQueryBuilder("epr") + .leftJoinAndSelect("epr.post", "post") + .where("epr.eventTagId = :eventTagId", { eventTagId }) + .andWhere("epr.source = 'user'") + .getMany(); + } + + /** + * Delete all relationships for an event matching a given source. + * Called before reprocessing to clear stale ML results. + */ + public async deleteRelationshipsBySourceForEvent( + eventTagId: string, + source: EventPostSource, + ): Promise { + await this.repository.delete({ eventTagId, source }); + } + + /** + * Delete a specific post-event relationship. + * Called when a user removes an event tag from their post. + */ + public async deleteRelationship(postId: string, eventTagId: string): Promise { + await this.repository.delete({ postId, eventTagId }); + } + + /** + * Get paginated posts for an event, optionally filtered by source. + * Ordered by layer priority: user-tagged (by post recency) first, + * then similarity (by relevance score). + */ + public async getPostsForEvent( + eventTagId: string, + source?: EventPostSource, + skip: number = 0, + limit: number = 10, + ): Promise { + // get ordered relationship IDs with pagination + const qb = this.repository + .createQueryBuilder("epr") + .select("epr.id") + .innerJoin("epr.post", "post") + .where("epr.eventTagId = :eventTagId", { eventTagId }); + + if (source) { + qb.andWhere("epr.source = :source", { source }); + } + + qb + .orderBy(`CASE epr.source WHEN 'user' THEN 0 WHEN 'similarity' THEN 1 ELSE 2 END`, "ASC") + .addOrderBy( + `CASE WHEN epr.source = 'user' THEN EXTRACT(EPOCH FROM post.created) ELSE epr."relevanceScore" END`, + "DESC", + "NULLS LAST", + ) + .skip(skip) + .take(limit); + + const eprIds = await qb.getMany(); + const ids = eprIds.map((e) => e.id); + if (ids.length === 0) return []; + + // fetch full objects with all post relations + return await this.repository + .createQueryBuilder("epr") + .leftJoinAndSelect("epr.post", "post") + .leftJoinAndSelect("post.user", "user") + .leftJoinAndSelect("post.categories", "categories") + .leftJoinAndSelect("post.eventTags", "eventTags") + .where("epr.id IN (:...ids)", { ids }) + .orderBy(`CASE epr.source WHEN 'user' THEN 0 WHEN 'similarity' THEN 1 ELSE 2 END`, "ASC") + .addOrderBy( + `CASE WHEN epr.source = 'user' THEN EXTRACT(EPOCH FROM post.created) ELSE epr."relevanceScore" END`, + "DESC", + "NULLS LAST", + ) + .getMany(); + } + + /** + * Count posts for an event, optionally filtered by source. + * Used for pagination totals. + */ + public async getPostCountForEvent( + eventTagId: string, + source?: EventPostSource, + ): Promise { + const qb = this.repository + .createQueryBuilder("epr") + .where("epr.eventTagId = :eventTagId", { eventTagId }); + + if (source) { + qb.andWhere("epr.source = :source", { source }); + } + + return await qb.getCount(); + } +} diff --git a/src/repositories/EventTagRepository.ts b/src/repositories/EventTagRepository.ts index c7495fc..d8797ff 100644 --- a/src/repositories/EventTagRepository.ts +++ b/src/repositories/EventTagRepository.ts @@ -36,4 +36,11 @@ export class EventTagRepository extends AbstractRepository { const eventTag = this.repository.create({ name }); return await this.repository.save(eventTag); } + + public async getAllEventTags(): Promise { + return await this.repository + .createQueryBuilder("eventTag") + .orderBy("eventTag.name", "ASC") + .getMany(); + } } diff --git a/src/repositories/PostRepository.ts b/src/repositories/PostRepository.ts index 4ad5d53..650d469 100644 --- a/src/repositories/PostRepository.ts +++ b/src/repositories/PostRepository.ts @@ -548,6 +548,56 @@ export class PostRepository extends AbstractRepository { .getMany(); } + /* + This method is for finding posts similar to a centroid embedding for an event. + Returns posts with their similarity score, ordered by score descending. + */ + public async findSimilarPostsForEvent( + centroidEmbedding: number[], + excludePostIds: string[], + threshold: number, + limit: number = 100, + ): Promise<{ post: PostModel; score: number }[]> { + const lit = `[${centroidEmbedding.join(",")}]`; + const scoreExpr = `(1 - (post.embedding::vector <=> CAST('${lit}' AS vector(512))))`; + + // get IDs and scores with threshold filter + pagination + const qb = this.repository + .createQueryBuilder("post") + .select("post.id", "id") + .addSelect(scoreExpr, "score") + .where("post.embedding IS NOT NULL") + .andWhere("post.archive = false") + .andWhere("post.sold = false") + .andWhere(`${scoreExpr} >= :threshold`, { threshold }); + + if (excludePostIds.length > 0) { + qb.andWhere("post.id NOT IN (:...excludePostIds)", { excludePostIds }); + } + + qb.orderBy("score", "DESC").limit(limit); + + const rawResults: { id: string; score: string }[] = await qb.getRawMany(); + if (rawResults.length === 0) return []; + + const ids = rawResults.map((r) => r.id); + const scoreMap = new Map(rawResults.map((r) => [r.id, Number(r.score)])); + + // fetch full posts with all relations + const posts = await this.repository + .createQueryBuilder("post") + .leftJoinAndSelect("post.user", "user") + .leftJoinAndSelect("post.categories", "categories") + .leftJoinAndSelect("post.eventTags", "eventTags") + .where("post.id IN (:...ids)", { ids }) + .getMany(); + + // reattach scores and restore score ordering + return posts + .map((post) => ({ post, score: scoreMap.get(post.id) ?? 0 })) + .sort((a, b) => b.score - a.score); + } + public async getSuggestedPosts( userId: string, limit = 10, diff --git a/src/repositories/index.ts b/src/repositories/index.ts index a2360cf..c3b3e20 100644 --- a/src/repositories/index.ts +++ b/src/repositories/index.ts @@ -12,6 +12,7 @@ import { NotifRepository } from "./NotifRepository"; import { FcmTokenRepository } from "./FcmTokenRepository"; import { CategoryRepository } from "./CategoryRepository" import { EventTagRepository } from "./EventTagRepository"; +import { EventPostRepository } from "./EventPostRepository"; import { SearchRepository } from "./SearchRepository"; export default class Repositories { @@ -91,6 +92,12 @@ export default class Repositories { return transactionalEntityManager.getCustomRepository(FcmTokenRepository); } + public static eventPost( + transactionalEntityManager: EntityManager, + ): EventPostRepository { + return transactionalEntityManager.getCustomRepository(EventPostRepository); + } + public static search( transactionalEntityManager: EntityManager, ): SearchRepository { diff --git a/src/services/EventPostService.ts b/src/services/EventPostService.ts new file mode 100644 index 0000000..5ae67f7 --- /dev/null +++ b/src/services/EventPostService.ts @@ -0,0 +1,99 @@ +import { Service } from "typedi"; +import { EntityManager } from "typeorm"; +import { InjectManager } from "typeorm-typedi-extensions"; + +import Repositories, { TransactionsManager } from "../repositories"; + +@Service() +export class EventPostService { + readonly SIMILARITY_THRESHOLD = 0.7; + readonly MAX_RESULTS = 100; + + private transactions: TransactionsManager; + + constructor(@InjectManager() entityManager: EntityManager) { + this.transactions = new TransactionsManager(entityManager); + } + + /** + * Finds posts similar to the user-tagged posts for an event and saves them + * as similarity relationships. Clears stale similarity rows before reprocessing. + * + * Returns early if no user-tagged posts exist or none have embeddings. + */ + public async processEventSimilarity(eventTagId: string): Promise { + if (process.env.NODE_ENV === "test") return; + + await this.transactions.readWrite(async (transactionalEntityManager) => { + const eventPostRepo = Repositories.eventPost(transactionalEntityManager); + const postRepo = Repositories.post(transactionalEntityManager); + + // Get all user-tagged posts for the event (with post + embedding loaded) + const userTaggedRelationships = + await eventPostRepo.getUserTaggedPostsForEvent(eventTagId); + + // Return early if no user-tagged posts + if (userTaggedRelationships.length === 0) return; + + // Filter to posts that have embeddings + const postsWithEmbeddings = userTaggedRelationships + .filter( + (r) => + r.post?.embedding != null && + Array.isArray(r.post.embedding) && + r.post.embedding.length > 0, + ) + .map((r) => r.post.embedding as number[]); + + // Return early if no embeddings available + if (postsWithEmbeddings.length === 0) return; + + // Compute centroid embedding + const centroid = this.computeCentroid(postsWithEmbeddings); + + const userTaggedPostIds = userTaggedRelationships.map((r) => r.postId); + + // Find similar posts via pgvector cosine distance + const similarPosts = await postRepo.findSimilarPostsForEvent( + centroid, + userTaggedPostIds, + this.SIMILARITY_THRESHOLD, + this.MAX_RESULTS, + ); + + // Clear stale similarity rows before saving new results + await eventPostRepo.deleteRelationshipsBySourceForEvent( + eventTagId, + "similarity", + ); + + // Save new similarity relationships + for (const { post, score } of similarPosts) { + await eventPostRepo.upsertRelationship( + post.id, + eventTagId, + "similarity", + score, + ); + } + }); + } + + /** + * Computes the element-wise mean of a list of embeddings. + * The resulting centroid represents the average semantic direction + * of all user-tagged posts for an event. + */ + private computeCentroid(embeddings: number[][]): number[] { + const dim = embeddings[0].length; + const centroid = new Array(dim).fill(0); + + for (const embedding of embeddings) { + for (let i = 0; i < dim; i++) { + centroid[i] += embedding[i]; + } + } + + return centroid.map((v) => v / embeddings.length); + } +} diff --git a/src/services/EventService.ts b/src/services/EventService.ts new file mode 100644 index 0000000..74f93a3 --- /dev/null +++ b/src/services/EventService.ts @@ -0,0 +1,81 @@ +import { NotFoundError } from "routing-controllers"; +import { Service } from "typedi"; +import { EntityManager } from "typeorm"; +import { InjectManager } from "typeorm-typedi-extensions"; + +import { UserModel } from "../models/UserModel"; +import { EventTagModel } from "../models/EventTagModel"; +import { EventPostSource } from "../models/EventPostModel"; +import Repositories, { TransactionsManager } from "../repositories"; +import { GetEventPostsResponse, PostWithSource } from "../types"; + +@Service() +export class EventService { + private transactions: TransactionsManager; + + constructor(@InjectManager() entityManager: EntityManager) { + this.transactions = new TransactionsManager(entityManager); + } + + /** + * Returns paginated posts for an event, combining user-tagged and similarity layers. + * Ordering: user-tagged (by recency) first, then similarity (by relevance score). + * Optionally filtered to a single source layer. + */ + public async getEventPosts( + user: UserModel, + eventTagId: string, + page: number = 1, + limit: number = 10, + source?: EventPostSource, + ): Promise { + return this.transactions.readOnly(async (transactionalEntityManager) => { + const eventTagRepo = Repositories.eventTag(transactionalEntityManager); + const eventPostRepo = Repositories.eventPost(transactionalEntityManager); + const userRepo = Repositories.user(transactionalEntityManager); + + // Validate event tag exists + const matches = await eventTagRepo.findByIds([eventTagId]); + if (matches.length === 0) throw new NotFoundError('Event not found!'); + + const skip = (page - 1) * limit; + + // Fetch paginated relationships and total count in parallel + const [relationships, total] = await Promise.all([ + eventPostRepo.getPostsForEvent(eventTagId, source, skip, limit), + eventPostRepo.getPostCountForEvent(eventTagId, source), + ]); + + // Filter inactive and blocked users + const userWithBlockedInfo = await userRepo.getUserWithBlockedInfo(user.firebaseUid); + const blockedUids = new Set( + userWithBlockedInfo?.blocking?.map(u => u.firebaseUid) ?? [], + ); + + const filtered = relationships.filter(r => + r.post?.user?.isActive && + !blockedUids.has(r.post.user.firebaseUid), + ); + + // Attach source + relevanceScore to each post + const posts: PostWithSource[] = filtered.map(r => + Object.assign(r.post, { + source: r.source, + relevanceScore: r.relevanceScore, + }), + ); + + return { posts, total, page, limit }; + }); + } + + /** + * Returns all event tags available for user tagging. + * Future: filter by isActive or displayStartDate once activation logic is added. + */ + public async getAvailableEventTags(): Promise { + return this.transactions.readOnly(async (transactionalEntityManager) => { + return Repositories.eventTag(transactionalEntityManager).getAllEventTags(); + }); + } +} diff --git a/src/services/PostService.ts b/src/services/PostService.ts index bf2df6a..f34790b 100644 --- a/src/services/PostService.ts +++ b/src/services/PostService.ts @@ -115,6 +115,14 @@ export class PostService { embedding = null; } const freshPost = await postRepository.createPost(post.title, post.description, categories, eventTags, post.condition, post.originalPrice, images, user, (embedding ?? []) as number[]); + + if (eventTags.length > 0) { + const eventPostRepository = Repositories.eventPost(transactionalEntityManager); + for (const tag of eventTags) { + await eventPostRepository.upsertRelationship(freshPost.id, tag.id, 'user', null); + } + } + if (embedding && Array.isArray(embedding) && embedding.length > 0) { const requestRepository = Repositories.request( transactionalEntityManager, @@ -522,11 +530,15 @@ export class PostService { const eventTagRepository = Repositories.eventTag(transactionalEntityManager); const eventTags = await eventTagRepository.findOrCreateByNames(addEventTagsRequest.eventTags); - // Add new event tags to existing ones const existingEventTagIds = new Set(post.eventTags?.map(tag => tag.id) || []); const newEventTags = eventTags.filter(tag => !existingEventTagIds.has(tag.id)); - post.eventTags = [...(post.eventTags || []), ...newEventTags]; + const eventPostRepository = Repositories.eventPost(transactionalEntityManager); + for (const tag of newEventTags) { + await eventPostRepository.upsertRelationship(post.id, tag.id, 'user', null); + } + + post.eventTags = [...(post.eventTags || []), ...newEventTags]; return await postRepository.savePost(post); }); } @@ -538,9 +550,15 @@ export class PostService { if (!post) throw new NotFoundError('Post not found!'); if (user.firebaseUid !== post.user?.firebaseUid) throw new ForbiddenError('User is not the post owner!'); - const tagsToRemove = new Set(removeEventTagsRequest.eventTags); - post.eventTags = post.eventTags?.filter(tag => !tagsToRemove.has(tag.name)) || []; + const tagsToRemoveNames = new Set(removeEventTagsRequest.eventTags); + const removedTags = post.eventTags?.filter(tag => tagsToRemoveNames.has(tag.name)) || []; + + const eventPostRepository = Repositories.eventPost(transactionalEntityManager); + for (const tag of removedTags) { + await eventPostRepository.deleteRelationship(post.id, tag.id); + } + post.eventTags = post.eventTags?.filter(tag => !tagsToRemoveNames.has(tag.name)) || []; return await postRepository.savePost(post); }); } diff --git a/src/tests/EventTest.test.ts b/src/tests/EventTest.test.ts new file mode 100644 index 0000000..93b300c --- /dev/null +++ b/src/tests/EventTest.test.ts @@ -0,0 +1,485 @@ +import { Connection } from "typeorm"; + +import { EventController } from "src/api/controllers/EventController"; +import { PostController } from "src/api/controllers/PostController"; +import { EventTagModel } from "../models/EventTagModel"; +import { EventPostModel } from "../models/EventPostModel"; +import { EventPostService } from "../services/EventPostService"; +import { ControllerFactory } from "./controllers"; +import { DatabaseConnection, DataFactory, PostFactory, UserFactory } from "./data"; + +let conn: Connection; +let eventController: EventController; +let postController: PostController; + +beforeAll(async () => { + await DatabaseConnection.connect(); +}); + +beforeEach(async () => { + await DatabaseConnection.clear(); + conn = await DatabaseConnection.connect(); + eventController = ControllerFactory.event(conn); + postController = ControllerFactory.post(conn); +}); + +afterAll(async () => { + await DatabaseConnection.close(); +}); + +describe("getAvailableEventTags", () => { + test("returns empty array when no event tags exist", async () => { + const user = UserFactory.fakeTemplate(); + const result = await eventController.getAvailableEventTags(user); + expect(result).toEqual([]); + }); + + test("returns all event tags ordered alphabetically", async () => { + const tag1 = new EventTagModel(); + tag1.name = "SPRING_FAIR"; + + const tag2 = new EventTagModel(); + tag2.name = "CLEARANCE"; + + const tag3 = new EventTagModel(); + tag3.name = "HOLIDAY_SALE"; + + await conn.manager.save([tag1, tag2, tag3]); + + const user = UserFactory.fakeTemplate(); + const result = await eventController.getAvailableEventTags(user); + + expect(result).toHaveLength(3); + expect(result[0].name).toBe("CLEARANCE"); + expect(result[1].name).toBe("HOLIDAY_SALE"); + expect(result[2].name).toBe("SPRING_FAIR"); + }); +}); + +describe("getEventPosts", () => { + test("throws NotFoundError when event tag does not exist", async () => { + const user = UserFactory.fakeTemplate(); + await new DataFactory().createUsers(user).write(); + + await expect( + eventController.getEventPosts( + user, + "00000000-0000-0000-0000-000000000000", + ), + ).rejects.toThrow("Event not found!"); + }); + + test("returns empty posts when no relationships exist", async () => { + const user = UserFactory.fakeTemplate(); + await new DataFactory().createUsers(user).write(); + + const tag = new EventTagModel(); + tag.name = "SPRING_FAIR"; + await conn.manager.save(tag); + + const result = await eventController.getEventPosts(user, tag.id); + + expect(result.posts).toHaveLength(0); + expect(result.total).toBe(0); + expect(result.page).toBe(1); + expect(result.limit).toBe(10); + }); + + test("returns user-tagged posts for an event", async () => { + const user = UserFactory.fakeTemplate(); + const post = PostFactory.fakeTemplate(); + post.user = user; + + await new DataFactory().createUsers(user).createPosts(post).write(); + + const tag = new EventTagModel(); + tag.name = "SPRING_FAIR"; + await conn.manager.save(tag); + + const relationship = new EventPostModel(); + relationship.postId = post.id; + relationship.eventTagId = tag.id; + relationship.source = "user"; + relationship.relevanceScore = null; + await conn.manager.save(relationship); + + const result = await eventController.getEventPosts(user, tag.id); + + expect(result.posts).toHaveLength(1); + expect(result.total).toBe(1); + expect(result.posts[0].id).toBe(post.id); + expect(result.posts[0].source).toBe("user"); + }); + + test("filters out posts from inactive users", async () => { + const activeUser = UserFactory.fakeTemplate(); + + const inactiveUser = UserFactory.fakeTemplate2(); + inactiveUser.isActive = false; + + const activePost = PostFactory.fakeTemplate(); + activePost.user = activeUser; + + const inactivePost = PostFactory.fake(); + inactivePost.user = inactiveUser; + + await new DataFactory() + .createUsers(activeUser, inactiveUser) + .createPosts(activePost, inactivePost) + .write(); + + const tag = new EventTagModel(); + tag.name = "SPRING_FAIR"; + await conn.manager.save(tag); + + const rel1 = new EventPostModel(); + rel1.postId = activePost.id; + rel1.eventTagId = tag.id; + rel1.source = "user"; + rel1.relevanceScore = null; + + const rel2 = new EventPostModel(); + rel2.postId = inactivePost.id; + rel2.eventTagId = tag.id; + rel2.source = "user"; + rel2.relevanceScore = null; + + await conn.manager.save([rel1, rel2]); + + const result = await eventController.getEventPosts(activeUser, tag.id); + + expect(result.posts).toHaveLength(1); + expect(result.posts[0].id).toBe(activePost.id); + }); + + test("filters out posts from blocked users", async () => { + const currentUser = UserFactory.fakeTemplate(); + + const blockedUser = UserFactory.fakeTemplate2(); + currentUser.blocking = [blockedUser]; + + const normalPost = PostFactory.fakeTemplate(); + normalPost.user = currentUser; + + const blockedPost = PostFactory.fake(); + blockedPost.user = blockedUser; + + await new DataFactory() + .createUsers(currentUser, blockedUser) + .createPosts(normalPost, blockedPost) + .write(); + + const tag = new EventTagModel(); + tag.name = "SPRING_FAIR"; + await conn.manager.save(tag); + + const rel1 = new EventPostModel(); + rel1.postId = normalPost.id; + rel1.eventTagId = tag.id; + rel1.source = "user"; + rel1.relevanceScore = null; + + const rel2 = new EventPostModel(); + rel2.postId = blockedPost.id; + rel2.eventTagId = tag.id; + rel2.source = "user"; + rel2.relevanceScore = null; + + await conn.manager.save([rel1, rel2]); + + const result = await eventController.getEventPosts(currentUser, tag.id); + + expect(result.posts).toHaveLength(1); + expect(result.posts[0].id).toBe(normalPost.id); + }); + + test("paginates results correctly", async () => { + const user = UserFactory.fakeTemplate(); + await new DataFactory().createUsers(user).write(); + + const tag = new EventTagModel(); + tag.name = "SPRING_FAIR"; + await conn.manager.save(tag); + + // Create 3 posts and relationships + const posts = PostFactory.create(3); + for (const post of posts) { + post.user = user; + } + await conn.manager.save(posts); + + const relationships = posts.map((post) => { + const rel = new EventPostModel(); + rel.postId = post.id; + rel.eventTagId = tag.id; + rel.source = "user"; + rel.relevanceScore = null; + return rel; + }); + await conn.manager.save(relationships); + + const page1 = await eventController.getEventPosts(user, tag.id, 1, 2); + expect(page1.posts).toHaveLength(2); + expect(page1.total).toBe(3); + expect(page1.page).toBe(1); + expect(page1.limit).toBe(2); + + const page2 = await eventController.getEventPosts(user, tag.id, 2, 2); + expect(page2.posts).toHaveLength(1); + expect(page2.total).toBe(3); + expect(page2.page).toBe(2); + }); + + test("filters by source when provided", async () => { + const user = UserFactory.fakeTemplate(); + const post1 = PostFactory.fakeTemplate(); + post1.user = user; + const post2 = PostFactory.fake(); + post2.user = user; + + await new DataFactory().createUsers(user).createPosts(post1, post2).write(); + + const tag = new EventTagModel(); + tag.name = "SPRING_FAIR"; + await conn.manager.save(tag); + + const userRel = new EventPostModel(); + userRel.postId = post1.id; + userRel.eventTagId = tag.id; + userRel.source = "user"; + userRel.relevanceScore = null; + + const simRel = new EventPostModel(); + simRel.postId = post2.id; + simRel.eventTagId = tag.id; + simRel.source = "similarity"; + simRel.relevanceScore = 0.85; + + await conn.manager.save([userRel, simRel]); + + const userOnly = await eventController.getEventPosts(user, tag.id, 1, 10, "user"); + expect(userOnly.posts).toHaveLength(1); + expect(userOnly.posts[0].source).toBe("user"); + + const simOnly = await eventController.getEventPosts(user, tag.id, 1, 10, "similarity"); + expect(simOnly.posts).toHaveLength(1); + expect(simOnly.posts[0].source).toBe("similarity"); + expect(simOnly.posts[0].relevanceScore).toBeCloseTo(0.85); + + const all = await eventController.getEventPosts(user, tag.id); + expect(all.posts).toHaveLength(2); + }); +}); + +describe("eventPosts integration (user tagging → event feed)", () => { + test("createPost with event tags populates event feed", async () => { + const user = UserFactory.fakeTemplate(); + await new DataFactory().createUsers(user).write(); + + const tag = new EventTagModel(); + tag.name = "SPRING_FAIR"; + await conn.manager.save(tag); + + const createResp = await postController.createPost(user, { + title: "Spring Item", + description: "For the spring fair", + categories: [], + eventTags: ["SPRING_FAIR"], + condition: "NEW", + originalPrice: 25.0, + imagesBase64: [], + userId: user.firebaseUid, + }); + + const result = await eventController.getEventPosts(user, tag.id); + + expect(result.posts).toHaveLength(1); + expect(result.posts[0].id).toBe(createResp.post.id); + expect(result.posts[0].source).toBe("user"); + expect(result.posts[0].relevanceScore).toBeNull(); + }); + + test("addEventTagsToPost populates event feed", async () => { + const user = UserFactory.fakeTemplate(); + const post = PostFactory.fakeTemplate(); + post.user = user; + + await new DataFactory().createUsers(user).createPosts(post).write(); + + const tag = new EventTagModel(); + tag.name = "SPRING_FAIR"; + await conn.manager.save(tag); + + await postController.addEventTagsToPost( + user, + { id: post.id } as any, + { eventTags: ["SPRING_FAIR"] }, + ); + + const result = await eventController.getEventPosts(user, tag.id); + + expect(result.posts).toHaveLength(1); + expect(result.posts[0].id).toBe(post.id); + expect(result.posts[0].source).toBe("user"); + expect(result.posts[0].relevanceScore).toBeNull(); + }); + + test("removeEventTagsFromPost removes post from event feed", async () => { + const user = UserFactory.fakeTemplate(); + const post = PostFactory.fakeTemplate(); + post.user = user; + + await new DataFactory().createUsers(user).createPosts(post).write(); + + const tag = new EventTagModel(); + tag.name = "SPRING_FAIR"; + await conn.manager.save(tag); + + await postController.addEventTagsToPost( + user, + { id: post.id } as any, + { eventTags: ["SPRING_FAIR"] }, + ); + + await postController.removeEventTagsFromPost( + user, + { id: post.id } as any, + { eventTags: ["SPRING_FAIR"] }, + ); + + const result = await eventController.getEventPosts(user, tag.id); + + expect(result.posts).toHaveLength(0); + expect(result.total).toBe(0); + }); +}); + +describe("processEventSimilarity", () => { + function withEnvOverride(fn: () => Promise): Promise { + const orig = process.env.NODE_ENV; + process.env.NODE_ENV = "integration"; + return fn().finally(() => { process.env.NODE_ENV = orig; }); + } + + test("creates similarity rows for matching posts and skips dissimilar ones", async () => { + const user1 = UserFactory.fakeTemplate(); + const user2 = UserFactory.fake(); + + // Anchor: first 256 dims active + const anchorPost = PostFactory.fakeTemplate(); + anchorPost.user = user1; + anchorPost.embedding = new Array(512).fill(0); + for (let i = 0; i < 256; i++) anchorPost.embedding[i] = 0.8; + + // Similar to anchor: same direction, different magnitude → cosine ≈ 1.0 + const similarPost = PostFactory.fake(); + similarPost.user = user2; + similarPost.embedding = new Array(512).fill(0); + for (let i = 0; i < 256; i++) similarPost.embedding[i] = 0.75; + + // Orthogonal to anchor: last 256 dims active → cosine = 0 + const differentPost = PostFactory.fake(); + differentPost.user = user2; + differentPost.embedding = new Array(512).fill(0); + for (let i = 256; i < 512; i++) differentPost.embedding[i] = 0.8; + + await new DataFactory() + .createUsers(user1, user2) + .createPosts(anchorPost, similarPost, differentPost) + .write(); + + const tag = new EventTagModel(); + tag.name = "SPRING_FAIR"; + await conn.manager.save(tag); + + const userRel = new EventPostModel(); + userRel.postId = anchorPost.id; + userRel.eventTagId = tag.id; + userRel.source = "user"; + userRel.relevanceScore = null; + await conn.manager.save(userRel); + + await withEnvOverride(async () => { + const svc = new EventPostService(conn.manager); + await svc.processEventSimilarity(tag.id); + }); + + const rows = await conn.manager.find(EventPostModel, { + where: { eventTagId: tag.id }, + }); + + // Anchor should still be user-tagged + const anchorRow = rows.find(r => r.postId === anchorPost.id); + expect(anchorRow).toBeDefined(); + expect(anchorRow!.source).toBe("user"); + + // Similar post should have a similarity row with high score + const simRow = rows.find(r => r.postId === similarPost.id); + expect(simRow).toBeDefined(); + expect(simRow!.source).toBe("similarity"); + expect(simRow!.relevanceScore).toBeGreaterThan(0.7); + + // Orthogonal post should have no row (score ≈ 0, below threshold) + const diffRow = rows.find(r => r.postId === differentPost.id); + expect(diffRow).toBeUndefined(); + }); + + test("does nothing when no user-tagged posts exist", async () => { + const tag = new EventTagModel(); + tag.name = "SPRING_FAIR"; + await conn.manager.save(tag); + + await withEnvOverride(async () => { + const svc = new EventPostService(conn.manager); + await svc.processEventSimilarity(tag.id); + }); + + const count = await conn.manager.count(EventPostModel, { + where: { eventTagId: tag.id }, + }); + expect(count).toBe(0); + }); + + test("is idempotent — re-running does not duplicate similarity rows", async () => { + const user1 = UserFactory.fakeTemplate(); + const user2 = UserFactory.fake(); + + const anchorPost = PostFactory.fakeTemplate(); + anchorPost.user = user1; + anchorPost.embedding = new Array(512).fill(0); + for (let i = 0; i < 256; i++) anchorPost.embedding[i] = 0.8; + + const similarPost = PostFactory.fake(); + similarPost.user = user2; + similarPost.embedding = new Array(512).fill(0); + for (let i = 0; i < 256; i++) similarPost.embedding[i] = 0.75; + + await new DataFactory() + .createUsers(user1, user2) + .createPosts(anchorPost, similarPost) + .write(); + + const tag = new EventTagModel(); + tag.name = "SPRING_FAIR"; + await conn.manager.save(tag); + + const userRel = new EventPostModel(); + userRel.postId = anchorPost.id; + userRel.eventTagId = tag.id; + userRel.source = "user"; + userRel.relevanceScore = null; + await conn.manager.save(userRel); + + await withEnvOverride(async () => { + const svc = new EventPostService(conn.manager); + await svc.processEventSimilarity(tag.id); + await svc.processEventSimilarity(tag.id); + }); + + const simRows = await conn.manager.find(EventPostModel, { + where: { eventTagId: tag.id, source: "similarity" as any }, + }); + expect(simRows).toHaveLength(1); + expect(simRows[0].postId).toBe(similarPost.id); + }); +}); diff --git a/src/tests/controllers/ControllerFactory.ts b/src/tests/controllers/ControllerFactory.ts index 53f6b1f..bdd214d 100644 --- a/src/tests/controllers/ControllerFactory.ts +++ b/src/tests/controllers/ControllerFactory.ts @@ -1,6 +1,7 @@ import { Connection } from "typeorm"; import { AuthController } from "../../api/controllers/AuthController"; +import { EventController } from "../../api/controllers/EventController"; import { PostController } from "../../api/controllers/PostController"; import { RequestController } from "../../api/controllers/RequestController"; import { UserController } from "../../api/controllers/UserController"; @@ -16,6 +17,7 @@ import { TransactionReviewController } from "../../api/controllers/TransactionRe import { TransactionReviewService } from "../../services/TransactionReviewService"; import { NotifService } from "../../services/NotifService"; import { NotifController } from "../../api/controllers/NotifController"; +import { EventService } from "../../services/EventService"; export class ControllerFactory { public static user(conn: Connection): UserController { @@ -59,4 +61,9 @@ export class ControllerFactory { const notifService = new NotifService(conn.manager); return new NotifController(notifService); } + + public static event(conn: Connection): EventController { + const eventService = new EventService(conn.manager); + return new EventController(eventService); + } } diff --git a/src/tests/data/DatabaseConnection.ts b/src/tests/data/DatabaseConnection.ts index 2e66703..5c22bbc 100644 --- a/src/tests/data/DatabaseConnection.ts +++ b/src/tests/data/DatabaseConnection.ts @@ -36,6 +36,7 @@ export class DatabaseConnection { "Report", "postCategories", "postEventTags", + "eventPosts", "Post", "Category", "EventTag", diff --git a/src/types/ApiResponses.ts b/src/types/ApiResponses.ts index fd60551..a279c4f 100644 --- a/src/types/ApiResponses.ts +++ b/src/types/ApiResponses.ts @@ -5,6 +5,7 @@ import { PostModel } from "../models/PostModel"; import { UserModel } from "../models/UserModel"; import { ReportModel } from "../models/ReportModel"; import { MessageModel } from "../models/MessageModel"; +import { EventPostSource } from "../models/EventPostModel"; // RESPONSE TYPES @@ -74,6 +75,22 @@ export interface EventTag { posts: PostModel[]; } +// EVENT FEED + +export type { EventPostSource }; + +export type PostWithSource = PostModel & { + source: EventPostSource; + relevanceScore: number | null; +}; + +export interface GetEventPostsResponse { + posts: PostWithSource[]; + total: number; + page: number; + limit: number; +} + // POST export interface Post { From 1e186b4e98e126724e88ebf50dc82b4825aef5ab Mon Sep 17 00:00:00 2001 From: Lauren Ah-Hot Date: Wed, 25 Mar 2026 16:02:28 -0400 Subject: [PATCH 2/5] added further testing --- src/repositories/EventPostRepository.ts | 27 ++++++++++++------------- src/tests/EventTest.test.ts | 2 +- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/repositories/EventPostRepository.ts b/src/repositories/EventPostRepository.ts index 780bc85..94c888a 100644 --- a/src/repositories/EventPostRepository.ts +++ b/src/repositories/EventPostRepository.ts @@ -71,16 +71,22 @@ export class EventPostRepository extends AbstractRepository { * Ordered by layer priority: user-tagged (by post recency) first, * then similarity (by relevance score). */ + private static readonly SOURCE_PRIORITY_EXPR = + `CASE "epr"."source" WHEN 'user' THEN 0 WHEN 'similarity' THEN 1 ELSE 2 END`; + private static readonly SCORE_OR_RECENCY_EXPR = + `CASE WHEN "epr"."source" = 'user' THEN EXTRACT(EPOCH FROM "post"."created") ELSE "epr"."relevanceScore" END`; + public async getPostsForEvent( eventTagId: string, source?: EventPostSource, skip: number = 0, limit: number = 10, ): Promise { - // get ordered relationship IDs with pagination const qb = this.repository .createQueryBuilder("epr") .select("epr.id") + .addSelect(EventPostRepository.SOURCE_PRIORITY_EXPR, "source_priority") + .addSelect(EventPostRepository.SCORE_OR_RECENCY_EXPR, "score_or_recency") .innerJoin("epr.post", "post") .where("epr.eventTagId = :eventTagId", { eventTagId }); @@ -89,12 +95,8 @@ export class EventPostRepository extends AbstractRepository { } qb - .orderBy(`CASE epr.source WHEN 'user' THEN 0 WHEN 'similarity' THEN 1 ELSE 2 END`, "ASC") - .addOrderBy( - `CASE WHEN epr.source = 'user' THEN EXTRACT(EPOCH FROM post.created) ELSE epr."relevanceScore" END`, - "DESC", - "NULLS LAST", - ) + .orderBy("source_priority", "ASC") + .addOrderBy("score_or_recency", "DESC", "NULLS LAST") .skip(skip) .take(limit); @@ -102,20 +104,17 @@ export class EventPostRepository extends AbstractRepository { const ids = eprIds.map((e) => e.id); if (ids.length === 0) return []; - // fetch full objects with all post relations return await this.repository .createQueryBuilder("epr") .leftJoinAndSelect("epr.post", "post") .leftJoinAndSelect("post.user", "user") .leftJoinAndSelect("post.categories", "categories") .leftJoinAndSelect("post.eventTags", "eventTags") + .addSelect(EventPostRepository.SOURCE_PRIORITY_EXPR, "source_priority") + .addSelect(EventPostRepository.SCORE_OR_RECENCY_EXPR, "score_or_recency") .where("epr.id IN (:...ids)", { ids }) - .orderBy(`CASE epr.source WHEN 'user' THEN 0 WHEN 'similarity' THEN 1 ELSE 2 END`, "ASC") - .addOrderBy( - `CASE WHEN epr.source = 'user' THEN EXTRACT(EPOCH FROM post.created) ELSE epr."relevanceScore" END`, - "DESC", - "NULLS LAST", - ) + .orderBy("source_priority", "ASC") + .addOrderBy("score_or_recency", "DESC", "NULLS LAST") .getMany(); } diff --git a/src/tests/EventTest.test.ts b/src/tests/EventTest.test.ts index 93b300c..0d2783f 100644 --- a/src/tests/EventTest.test.ts +++ b/src/tests/EventTest.test.ts @@ -271,7 +271,7 @@ describe("getEventPosts", () => { }); }); -describe("eventPosts integration (user tagging → event feed)", () => { +describe("eventPosts integration", () => { test("createPost with event tags populates event feed", async () => { const user = UserFactory.fakeTemplate(); await new DataFactory().createUsers(user).write(); From 3f6e8936f01a7db893842865d16100bf059e999c Mon Sep 17 00:00:00 2001 From: Lauren Ah-Hot Date: Wed, 25 Mar 2026 16:12:02 -0400 Subject: [PATCH 3/5] remove db dumps --- .gitignore | 1 + dumps/dev_db_dump_20260226_233628.sql | 1188 ---------------------- dumps/dev_db_dump_20260226_233801.sql | 1302 ------------------------- 3 files changed, 1 insertion(+), 2490 deletions(-) delete mode 100644 dumps/dev_db_dump_20260226_233628.sql delete mode 100644 dumps/dev_db_dump_20260226_233801.sql diff --git a/.gitignore b/.gitignore index c40cc4d..997da86 100644 --- a/.gitignore +++ b/.gitignore @@ -7,5 +7,6 @@ yarn.lock *.DS_Store *.pem firebase-admin-service-account.json +dumps/ # Firebase secrets secrets/ diff --git a/dumps/dev_db_dump_20260226_233628.sql b/dumps/dev_db_dump_20260226_233628.sql deleted file mode 100644 index 0ab4ea9..0000000 --- a/dumps/dev_db_dump_20260226_233628.sql +++ /dev/null @@ -1,1188 +0,0 @@ --- --- PostgreSQL database dump --- - -\restrict Yn3DWKf7D4yPmect2zcsSffRbqkUHwfacDQkFXAf2KW0gTCv32CIMSM7DnjaIGz - --- Dumped from database version 18.1 (Homebrew) --- Dumped by pg_dump version 18.1 (Homebrew) - -SET statement_timeout = 0; -SET lock_timeout = 0; -SET idle_in_transaction_session_timeout = 0; -SET transaction_timeout = 0; -SET client_encoding = 'UTF8'; -SET standard_conforming_strings = on; -SELECT pg_catalog.set_config('search_path', '', false); -SET check_function_bodies = false; -SET xmloption = content; -SET client_min_messages = warning; -SET row_security = off; - -ALTER TABLE IF EXISTS ONLY public."requestMatchesPosts" DROP CONSTRAINT IF EXISTS "FK_fd473bd2ef9b7a23f41a40ebed4"; -ALTER TABLE IF EXISTS ONLY public.searches DROP CONSTRAINT IF EXISTS "FK_fc8760cf4823ab84b0cb28d3dad"; -ALTER TABLE IF EXISTS ONLY public."TransactionReview" DROP CONSTRAINT IF EXISTS "FK_f7cf58b571d5c57ed9da155c628"; -ALTER TABLE IF EXISTS ONLY public."Report" DROP CONSTRAINT IF EXISTS "FK_dd826149b8ac72ddc2d1f4e234e"; -ALTER TABLE IF EXISTS ONLY public."FCMToken" DROP CONSTRAINT IF EXISTS "FK_d215a8d66e472d872409915f7d5"; -ALTER TABLE IF EXISTS ONLY public."Request" DROP CONSTRAINT IF EXISTS "FK_cdaf52464b00ac3016a8f6110fd"; -ALTER TABLE IF EXISTS ONLY public."userBlockingUsers" DROP CONSTRAINT IF EXISTS "FK_bc2ca85580a5c620ccc7f03f5db"; -ALTER TABLE IF EXISTS ONLY public."Transaction" DROP CONSTRAINT IF EXISTS "FK_bba9ded63ef0013ac2ec578f246"; -ALTER TABLE IF EXISTS ONLY public."userSavedPosts" DROP CONSTRAINT IF EXISTS "FK_baa3d7e5e872010a3c23e981532"; -ALTER TABLE IF EXISTS ONLY public."Report" DROP CONSTRAINT IF EXISTS "FK_a050c9cf7f461bc8fc040a48e0a"; -ALTER TABLE IF EXISTS ONLY public."Post" DROP CONSTRAINT IF EXISTS "FK_97e81bcb59530bfb061e48aee6a"; -ALTER TABLE IF EXISTS ONLY public."postCategories" DROP CONSTRAINT IF EXISTS "FK_978f319769e3d7285d6d2e40af8"; -ALTER TABLE IF EXISTS ONLY public.user_following_users DROP CONSTRAINT IF EXISTS "FK_80ef95f34370fd0704c156c13ef"; -ALTER TABLE IF EXISTS ONLY public."userBlockingUsers" DROP CONSTRAINT IF EXISTS "FK_793578cc63c2442a7944e93131a"; -ALTER TABLE IF EXISTS ONLY public."postEventTags" DROP CONSTRAINT IF EXISTS "FK_7532bd6ca893c432ffcfa21f755"; -ALTER TABLE IF EXISTS ONLY public.notifications DROP CONSTRAINT IF EXISTS "FK_692a909ee0fa9383e7859f9b406"; -ALTER TABLE IF EXISTS ONLY public."postEventTags" DROP CONSTRAINT IF EXISTS "FK_61151ebab50db74ea513ff8bd87"; -ALTER TABLE IF EXISTS ONLY public."UserReview" DROP CONSTRAINT IF EXISTS "FK_53a14948aa4e941762a403144ea"; -ALTER TABLE IF EXISTS ONLY public.user_following_users DROP CONSTRAINT IF EXISTS "FK_503e9a09612f9668063099baff1"; -ALTER TABLE IF EXISTS ONLY public."Report" DROP CONSTRAINT IF EXISTS "FK_4bc548745107f37d3512ed688c5"; -ALTER TABLE IF EXISTS ONLY public."Transaction" DROP CONSTRAINT IF EXISTS "FK_4ae4b1f6ff200ae67b40eb5bd8d"; -ALTER TABLE IF EXISTS ONLY public."requestMatchesPosts" DROP CONSTRAINT IF EXISTS "FK_3b2f09095e41d9c82bedaa0d8fe"; -ALTER TABLE IF EXISTS ONLY public."Transaction" DROP CONSTRAINT IF EXISTS "FK_30d551dc74a9537b73d4007592f"; -ALTER TABLE IF EXISTS ONLY public."Feedback" DROP CONSTRAINT IF EXISTS "FK_26bcf6b3c7c6b742e63d9308676"; -ALTER TABLE IF EXISTS ONLY public."postCategories" DROP CONSTRAINT IF EXISTS "FK_1f4b27b2e31fb6263f6fb3a9390"; -ALTER TABLE IF EXISTS ONLY public."Report" DROP CONSTRAINT IF EXISTS "FK_16c178e84273608caf9db34df88"; -ALTER TABLE IF EXISTS ONLY public."UserReview" DROP CONSTRAINT IF EXISTS "FK_14e4fa2651e5c6d6118e2ba18aa"; -ALTER TABLE IF EXISTS ONLY public."userSavedPosts" DROP CONSTRAINT IF EXISTS "FK_0c0a06e6163f7a7315c4ce5fd4c"; -DROP INDEX IF EXISTS public."IDX_fd473bd2ef9b7a23f41a40ebed"; -DROP INDEX IF EXISTS public."IDX_bc2ca85580a5c620ccc7f03f5d"; -DROP INDEX IF EXISTS public."IDX_baa3d7e5e872010a3c23e98153"; -DROP INDEX IF EXISTS public."IDX_978f319769e3d7285d6d2e40af"; -DROP INDEX IF EXISTS public."IDX_80ef95f34370fd0704c156c13e"; -DROP INDEX IF EXISTS public."IDX_793578cc63c2442a7944e93131"; -DROP INDEX IF EXISTS public."IDX_7532bd6ca893c432ffcfa21f75"; -DROP INDEX IF EXISTS public."IDX_61151ebab50db74ea513ff8bd8"; -DROP INDEX IF EXISTS public."IDX_503e9a09612f9668063099baff"; -DROP INDEX IF EXISTS public."IDX_3b2f09095e41d9c82bedaa0d8f"; -DROP INDEX IF EXISTS public."IDX_1f4b27b2e31fb6263f6fb3a939"; -DROP INDEX IF EXISTS public."IDX_0c0a06e6163f7a7315c4ce5fd4"; -ALTER TABLE IF EXISTS ONLY public."User" DROP CONSTRAINT IF EXISTS "User_pkey"; -ALTER TABLE IF EXISTS ONLY public."User" DROP CONSTRAINT IF EXISTS "UQ_ec60b02aab67f0f99f6f88797ed"; -ALTER TABLE IF EXISTS ONLY public."TransactionReview" DROP CONSTRAINT IF EXISTS "UQ_aff62b169ebd519d1f5994e781a"; -ALTER TABLE IF EXISTS ONLY public."User" DROP CONSTRAINT IF EXISTS "UQ_4a257d2c9837248d70640b3e36e"; -ALTER TABLE IF EXISTS ONLY public."User" DROP CONSTRAINT IF EXISTS "UQ_29a05908a0fa0728526d2833657"; -ALTER TABLE IF EXISTS ONLY public."User" DROP CONSTRAINT IF EXISTS "UQ_02dec29f4ca814ab6efa2d4f0c4"; -ALTER TABLE IF EXISTS ONLY public.searches DROP CONSTRAINT IF EXISTS "PK_searches"; -ALTER TABLE IF EXISTS ONLY public."postEventTags" DROP CONSTRAINT IF EXISTS "PK_cc14f1e77d0b18c8ec995937fd0"; -ALTER TABLE IF EXISTS ONLY public."Post" DROP CONSTRAINT IF EXISTS "PK_c4d3b3dcd73db0b0129ea829f9f"; -ALTER TABLE IF EXISTS ONLY public."Category" DROP CONSTRAINT IF EXISTS "PK_c2727780c5b9b0c564c29a4977c"; -ALTER TABLE IF EXISTS ONLY public."TransactionReview" DROP CONSTRAINT IF EXISTS "PK_TransactionReview"; -ALTER TABLE IF EXISTS ONLY public."Transaction" DROP CONSTRAINT IF EXISTS "PK_Transaction"; -ALTER TABLE IF EXISTS ONLY public."FCMToken" DROP CONSTRAINT IF EXISTS "PK_FCMToken"; -ALTER TABLE IF EXISTS ONLY public."Report" DROP CONSTRAINT IF EXISTS "PK_9dbb4c593be9832c28a5793e258"; -ALTER TABLE IF EXISTS ONLY public."EventTag" DROP CONSTRAINT IF EXISTS "PK_929d8d89bf95d848ac3b7546a29"; -ALTER TABLE IF EXISTS ONLY public."UserReview" DROP CONSTRAINT IF EXISTS "PK_91b62f63709469ae812a3519dd1"; -ALTER TABLE IF EXISTS ONLY public."userBlockingUsers" DROP CONSTRAINT IF EXISTS "PK_8db623e58cc4bce5fbcc252c66b"; -ALTER TABLE IF EXISTS ONLY public.migrations DROP CONSTRAINT IF EXISTS "PK_8c82d7f526340ab734260ea46be"; -ALTER TABLE IF EXISTS ONLY public."postCategories" DROP CONSTRAINT IF EXISTS "PK_88340cf0b1b8a00578602f4c80b"; -ALTER TABLE IF EXISTS ONLY public."Feedback" DROP CONSTRAINT IF EXISTS "PK_7ffea537e9c56670b65c2d62316"; -ALTER TABLE IF EXISTS ONLY public."requestMatchesPosts" DROP CONSTRAINT IF EXISTS "PK_7f4c04956dd4e84a3437b2a8018"; -ALTER TABLE IF EXISTS ONLY public."Message" DROP CONSTRAINT IF EXISTS "PK_7dd6398f0d1dcaf73df342fa325"; -ALTER TABLE IF EXISTS ONLY public.notifications DROP CONSTRAINT IF EXISTS "PK_6a72c3c0f683f6462415e653c3a"; -ALTER TABLE IF EXISTS ONLY public."Request" DROP CONSTRAINT IF EXISTS "PK_23de24dc477765bcc099feae8e5"; -ALTER TABLE IF EXISTS ONLY public."userSavedPosts" DROP CONSTRAINT IF EXISTS "PK_11901fe92c42b2d2a71ca74021a"; -ALTER TABLE IF EXISTS ONLY public.user_following_users DROP CONSTRAINT IF EXISTS "PK_01b7a923c26f4be4f7c138cbb88"; -ALTER TABLE IF EXISTS public.migrations ALTER COLUMN id DROP DEFAULT; -DROP TABLE IF EXISTS public.user_following_users; -DROP TABLE IF EXISTS public."userSavedPosts"; -DROP TABLE IF EXISTS public."userBlockingUsers"; -DROP TABLE IF EXISTS public.typeorm_metadata; -DROP TABLE IF EXISTS public.searches; -DROP TABLE IF EXISTS public."requestMatchesPosts"; -DROP TABLE IF EXISTS public."postEventTags"; -DROP TABLE IF EXISTS public."postCategories"; -DROP TABLE IF EXISTS public.notifications; -DROP SEQUENCE IF EXISTS public.migrations_id_seq; -DROP TABLE IF EXISTS public.migrations; -DROP TABLE IF EXISTS public."UserReview"; -DROP TABLE IF EXISTS public."User"; -DROP TABLE IF EXISTS public."TransactionReview"; -DROP TABLE IF EXISTS public."Transaction"; -DROP TABLE IF EXISTS public."Request"; -DROP TABLE IF EXISTS public."Report"; -DROP TABLE IF EXISTS public."Post"; -DROP TABLE IF EXISTS public."Message"; -DROP TABLE IF EXISTS public."Feedback"; -DROP TABLE IF EXISTS public."FCMToken"; -DROP TABLE IF EXISTS public."EventTag"; -DROP TABLE IF EXISTS public."Category"; -DROP EXTENSION IF EXISTS vector; -DROP EXTENSION IF EXISTS "uuid-ossp"; --- --- Name: uuid-ossp; Type: EXTENSION; Schema: -; Owner: - --- - -CREATE EXTENSION IF NOT EXISTS "uuid-ossp" WITH SCHEMA public; - - --- --- Name: EXTENSION "uuid-ossp"; Type: COMMENT; Schema: -; Owner: - --- - -COMMENT ON EXTENSION "uuid-ossp" IS 'generate universally unique identifiers (UUIDs)'; - - --- --- Name: vector; Type: EXTENSION; Schema: -; Owner: - --- - -CREATE EXTENSION IF NOT EXISTS vector WITH SCHEMA public; - - --- --- Name: EXTENSION vector; Type: COMMENT; Schema: -; Owner: - --- - -COMMENT ON EXTENSION vector IS 'vector data type and ivfflat and hnsw access methods'; - - -SET default_tablespace = ''; - -SET default_table_access_method = heap; - --- --- Name: Category; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public."Category" ( - id uuid DEFAULT public.uuid_generate_v4() NOT NULL, - name character varying NOT NULL -); - - --- --- Name: EventTag; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public."EventTag" ( - id uuid DEFAULT public.uuid_generate_v4() NOT NULL, - name character varying NOT NULL -); - - --- --- Name: FCMToken; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public."FCMToken" ( - id uuid DEFAULT public.uuid_generate_v4() NOT NULL, - "fcmToken" character varying NOT NULL, - "notificationsEnabled" boolean NOT NULL, - "timestamp" timestamp without time zone NOT NULL, - "userId" character varying -); - - --- --- Name: Feedback; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public."Feedback" ( - id uuid DEFAULT public.uuid_generate_v4() NOT NULL, - description character varying NOT NULL, - images text[] NOT NULL, - "userId" character varying -); - - --- --- Name: Message; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public."Message" ( - id uuid NOT NULL -); - - --- --- Name: Post; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public."Post" ( - id uuid DEFAULT public.uuid_generate_v4() NOT NULL, - title character varying NOT NULL, - description character varying NOT NULL, - "originalPrice" numeric CONSTRAINT "Post_original_price_not_null" NOT NULL, - "alteredPrice" numeric DEFAULT '-1'::numeric CONSTRAINT "Post_altered_price_not_null" NOT NULL, - images text[] NOT NULL, - created timestamp with time zone DEFAULT now() NOT NULL, - location character varying, - archive boolean DEFAULT false NOT NULL, - condition character varying NOT NULL, - sold boolean DEFAULT false NOT NULL, - embedding double precision[], - "userId" character varying -); - - --- --- Name: Report; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public."Report" ( - id uuid DEFAULT public.uuid_generate_v4() NOT NULL, - reason character varying NOT NULL, - type character varying NOT NULL, - resolved boolean NOT NULL, - created timestamp with time zone DEFAULT now() NOT NULL, - "reporterFirebaseUid" character varying, - "reportedFirebaseUid" character varying, - "postId" uuid, - "messageId" uuid -); - - --- --- Name: Request; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public."Request" ( - id uuid DEFAULT public.uuid_generate_v4() NOT NULL, - title character varying NOT NULL, - description character varying NOT NULL, - archive boolean DEFAULT false NOT NULL, - embedding double precision[], - "userId" character varying -); - - --- --- Name: Transaction; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public."Transaction" ( - id uuid DEFAULT public.uuid_generate_v4() NOT NULL, - location character varying NOT NULL, - amount numeric NOT NULL, - completed boolean DEFAULT false NOT NULL, - "postId" uuid, - "buyerId" character varying, - "sellerId" character varying, - "transactionDate" timestamp with time zone, - "createdAt" timestamp with time zone DEFAULT now() NOT NULL, - "confirmationSent" boolean DEFAULT false NOT NULL -); - - --- --- Name: TransactionReview; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public."TransactionReview" ( - id uuid DEFAULT public.uuid_generate_v4() NOT NULL, - stars integer NOT NULL, - "transactionId" uuid, - "hadIssues" boolean DEFAULT false NOT NULL, - "issueCategory" text, - "issueDetails" text, - "createdAt" timestamp with time zone DEFAULT now() NOT NULL, - comments text -); - - --- --- Name: User; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public."User" ( - username character varying NOT NULL, - netid character varying, - admin boolean NOT NULL, - stars numeric DEFAULT '0'::numeric NOT NULL, - email character varying NOT NULL, - bio text DEFAULT ''::text NOT NULL, - "isActive" boolean DEFAULT true NOT NULL, - "firebaseUid" character varying NOT NULL, - "givenName" character varying, - "familyName" character varying, - "numReviews" integer DEFAULT 0 NOT NULL, - "photoUrl" character varying, - "venmoHandle" character varying, - "googleId" character varying, - "soldPosts" integer DEFAULT 0 NOT NULL, - "availabilityId" character varying -); - - --- --- Name: UserReview; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public."UserReview" ( - id uuid DEFAULT public.uuid_generate_v4() NOT NULL, - fulfilled boolean NOT NULL, - stars integer NOT NULL, - comments character varying NOT NULL, - date timestamp with time zone DEFAULT now() NOT NULL, - "buyerId" character varying, - "sellerId" character varying -); - - --- --- Name: migrations; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public.migrations ( - id integer NOT NULL, - "timestamp" bigint NOT NULL, - name character varying NOT NULL -); - - --- --- Name: migrations_id_seq; Type: SEQUENCE; Schema: public; Owner: - --- - -CREATE SEQUENCE public.migrations_id_seq - AS integer - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- Name: migrations_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - --- - -ALTER SEQUENCE public.migrations_id_seq OWNED BY public.migrations.id; - - --- --- Name: notifications; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public.notifications ( - id uuid DEFAULT public.uuid_generate_v4() NOT NULL, - title character varying NOT NULL, - body character varying NOT NULL, - data jsonb, - read boolean DEFAULT false NOT NULL, - "userId" character varying NOT NULL, - "createdAt" timestamp without time zone DEFAULT now() NOT NULL, - "updatedAt" timestamp without time zone DEFAULT now() NOT NULL -); - - --- --- Name: postCategories; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public."postCategories" ( - posts uuid CONSTRAINT post_categories_posts_not_null NOT NULL, - categories uuid CONSTRAINT post_categories_categories_not_null NOT NULL -); - - --- --- Name: postEventTags; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public."postEventTags" ( - posts uuid CONSTRAINT post_event_tags_posts_not_null NOT NULL, - "eventTags" uuid CONSTRAINT post_event_tags_event_tags_not_null NOT NULL -); - - --- --- Name: requestMatchesPosts; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public."requestMatchesPosts" ( - matches uuid CONSTRAINT request_matches_posts_matches_not_null NOT NULL, - matched uuid CONSTRAINT request_matches_posts_matched_not_null NOT NULL -); - - --- --- Name: searches; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public.searches ( - id uuid DEFAULT public.uuid_generate_v4() NOT NULL, - "searchText" character varying NOT NULL, - "firebaseUid" character varying NOT NULL, - "createdAt" timestamp without time zone DEFAULT now() NOT NULL, - "searchVector" character varying NOT NULL -); - - --- --- Name: typeorm_metadata; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public.typeorm_metadata ( - type character varying NOT NULL, - database character varying, - schema character varying, - "table" character varying, - name character varying, - value text -); - - --- --- Name: userBlockingUsers; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public."userBlockingUsers" ( - blockers character varying CONSTRAINT user_blocking_users_blockers_not_null NOT NULL, - blocking character varying CONSTRAINT user_blocking_users_blocking_not_null NOT NULL -); - - --- --- Name: userSavedPosts; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public."userSavedPosts" ( - saved uuid CONSTRAINT user_saved_posts_saved_not_null NOT NULL, - savers character varying CONSTRAINT user_saved_posts_savers_not_null NOT NULL -); - - --- --- Name: user_following_users; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public.user_following_users ( - follower_id character varying NOT NULL, - following_id character varying NOT NULL -); - - --- --- Name: migrations id; Type: DEFAULT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.migrations ALTER COLUMN id SET DEFAULT nextval('public.migrations_id_seq'::regclass); - - --- --- Data for Name: Category; Type: TABLE DATA; Schema: public; Owner: - --- - -COPY public."Category" (id, name) FROM stdin; -\. - - --- --- Data for Name: EventTag; Type: TABLE DATA; Schema: public; Owner: - --- - -COPY public."EventTag" (id, name) FROM stdin; -\. - - --- --- Data for Name: FCMToken; Type: TABLE DATA; Schema: public; Owner: - --- - -COPY public."FCMToken" (id, "fcmToken", "notificationsEnabled", "timestamp", "userId") FROM stdin; -\. - - --- --- Data for Name: Feedback; Type: TABLE DATA; Schema: public; Owner: - --- - -COPY public."Feedback" (id, description, images, "userId") FROM stdin; -\. - - --- --- Data for Name: Message; Type: TABLE DATA; Schema: public; Owner: - --- - -COPY public."Message" (id) FROM stdin; -\. - - --- --- Data for Name: Post; Type: TABLE DATA; Schema: public; Owner: - --- - -COPY public."Post" (id, title, description, "originalPrice", "alteredPrice", images, created, location, archive, condition, sold, embedding, "userId") FROM stdin; -\. - - --- --- Data for Name: Report; Type: TABLE DATA; Schema: public; Owner: - --- - -COPY public."Report" (id, reason, type, resolved, created, "reporterFirebaseUid", "reportedFirebaseUid", "postId", "messageId") FROM stdin; -\. - - --- --- Data for Name: Request; Type: TABLE DATA; Schema: public; Owner: - --- - -COPY public."Request" (id, title, description, archive, embedding, "userId") FROM stdin; -\. - - --- --- Data for Name: Transaction; Type: TABLE DATA; Schema: public; Owner: - --- - -COPY public."Transaction" (id, location, amount, completed, "postId", "buyerId", "sellerId", "transactionDate", "createdAt", "confirmationSent") FROM stdin; -\. - - --- --- Data for Name: TransactionReview; Type: TABLE DATA; Schema: public; Owner: - --- - -COPY public."TransactionReview" (id, stars, "transactionId", "hadIssues", "issueCategory", "issueDetails", "createdAt", comments) FROM stdin; -\. - - --- --- Data for Name: User; Type: TABLE DATA; Schema: public; Owner: - --- - -COPY public."User" (username, netid, admin, stars, email, bio, "isActive", "firebaseUid", "givenName", "familyName", "numReviews", "photoUrl", "venmoHandle", "googleId", "soldPosts", "availabilityId") FROM stdin; -\. - - --- --- Data for Name: UserReview; Type: TABLE DATA; Schema: public; Owner: - --- - -COPY public."UserReview" (id, fulfilled, stars, comments, date, "buyerId", "sellerId") FROM stdin; -\. - - --- --- Data for Name: migrations; Type: TABLE DATA; Schema: public; Owner: - --- - -COPY public.migrations (id, "timestamp", name) FROM stdin; -1 1709163288115 init1709163288115 -2 1713139721037 softdelete1713139721037 -3 1713218553306 makenetidnullable1713218553306 -4 1713308449994 addreports1713308449994 -5 1713320015776 UpdateMessageModel1713320015776 -6 1731186421123 AddArchiveToRequest1731186421123 -7 1731271779741 updatecategories1731271779741 -8 1732146942548 addconditiontoposts1732146942548 -9 1732906578369 AddTransactionTable1732906578369 -10 1732924592033 AddSoldColumnToPost1732924592033 -11 1732975238671 AddTransactionReviewTable1732975238671 -12 1739899394694 Notifications1739899394694 -13 1740007049335 ConvertEmbeddingToVector1631740007049335 -14 1740628691583 AuthorizationRefactor1740628691583 -15 1743028223060 AddCategoryTable1743028223060 -16 1743566564676 CreateSearchesTable1743566564676 -17 1761697414368 AddEventTagTable1761697414368 -18 1765000000000 RenameSnakeToCamelResellTest1765000000000 -\. - - --- --- Data for Name: notifications; Type: TABLE DATA; Schema: public; Owner: - --- - -COPY public.notifications (id, title, body, data, read, "userId", "createdAt", "updatedAt") FROM stdin; -\. - - --- --- Data for Name: postCategories; Type: TABLE DATA; Schema: public; Owner: - --- - -COPY public."postCategories" (posts, categories) FROM stdin; -\. - - --- --- Data for Name: postEventTags; Type: TABLE DATA; Schema: public; Owner: - --- - -COPY public."postEventTags" (posts, "eventTags") FROM stdin; -\. - - --- --- Data for Name: requestMatchesPosts; Type: TABLE DATA; Schema: public; Owner: - --- - -COPY public."requestMatchesPosts" (matches, matched) FROM stdin; -\. - - --- --- Data for Name: searches; Type: TABLE DATA; Schema: public; Owner: - --- - -COPY public.searches (id, "searchText", "firebaseUid", "createdAt", "searchVector") FROM stdin; -\. - - --- --- Data for Name: typeorm_metadata; Type: TABLE DATA; Schema: public; Owner: - --- - -COPY public.typeorm_metadata (type, database, schema, "table", name, value) FROM stdin; -\. - - --- --- Data for Name: userBlockingUsers; Type: TABLE DATA; Schema: public; Owner: - --- - -COPY public."userBlockingUsers" (blockers, blocking) FROM stdin; -\. - - --- --- Data for Name: userSavedPosts; Type: TABLE DATA; Schema: public; Owner: - --- - -COPY public."userSavedPosts" (saved, savers) FROM stdin; -\. - - --- --- Data for Name: user_following_users; Type: TABLE DATA; Schema: public; Owner: - --- - -COPY public.user_following_users (follower_id, following_id) FROM stdin; -\. - - --- --- Name: migrations_id_seq; Type: SEQUENCE SET; Schema: public; Owner: - --- - -SELECT pg_catalog.setval('public.migrations_id_seq', 18, true); - - --- --- Name: user_following_users PK_01b7a923c26f4be4f7c138cbb88; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.user_following_users - ADD CONSTRAINT "PK_01b7a923c26f4be4f7c138cbb88" PRIMARY KEY (follower_id, following_id); - - --- --- Name: userSavedPosts PK_11901fe92c42b2d2a71ca74021a; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."userSavedPosts" - ADD CONSTRAINT "PK_11901fe92c42b2d2a71ca74021a" PRIMARY KEY (saved, savers); - - --- --- Name: Request PK_23de24dc477765bcc099feae8e5; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."Request" - ADD CONSTRAINT "PK_23de24dc477765bcc099feae8e5" PRIMARY KEY (id); - - --- --- Name: notifications PK_6a72c3c0f683f6462415e653c3a; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.notifications - ADD CONSTRAINT "PK_6a72c3c0f683f6462415e653c3a" PRIMARY KEY (id); - - --- --- Name: Message PK_7dd6398f0d1dcaf73df342fa325; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."Message" - ADD CONSTRAINT "PK_7dd6398f0d1dcaf73df342fa325" PRIMARY KEY (id); - - --- --- Name: requestMatchesPosts PK_7f4c04956dd4e84a3437b2a8018; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."requestMatchesPosts" - ADD CONSTRAINT "PK_7f4c04956dd4e84a3437b2a8018" PRIMARY KEY (matches, matched); - - --- --- Name: Feedback PK_7ffea537e9c56670b65c2d62316; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."Feedback" - ADD CONSTRAINT "PK_7ffea537e9c56670b65c2d62316" PRIMARY KEY (id); - - --- --- Name: postCategories PK_88340cf0b1b8a00578602f4c80b; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."postCategories" - ADD CONSTRAINT "PK_88340cf0b1b8a00578602f4c80b" PRIMARY KEY (posts, categories); - - --- --- Name: migrations PK_8c82d7f526340ab734260ea46be; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.migrations - ADD CONSTRAINT "PK_8c82d7f526340ab734260ea46be" PRIMARY KEY (id); - - --- --- Name: userBlockingUsers PK_8db623e58cc4bce5fbcc252c66b; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."userBlockingUsers" - ADD CONSTRAINT "PK_8db623e58cc4bce5fbcc252c66b" PRIMARY KEY (blockers, blocking); - - --- --- Name: UserReview PK_91b62f63709469ae812a3519dd1; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."UserReview" - ADD CONSTRAINT "PK_91b62f63709469ae812a3519dd1" PRIMARY KEY (id); - - --- --- Name: EventTag PK_929d8d89bf95d848ac3b7546a29; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."EventTag" - ADD CONSTRAINT "PK_929d8d89bf95d848ac3b7546a29" PRIMARY KEY (id); - - --- --- Name: Report PK_9dbb4c593be9832c28a5793e258; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."Report" - ADD CONSTRAINT "PK_9dbb4c593be9832c28a5793e258" PRIMARY KEY (id); - - --- --- Name: FCMToken PK_FCMToken; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."FCMToken" - ADD CONSTRAINT "PK_FCMToken" PRIMARY KEY (id); - - --- --- Name: Transaction PK_Transaction; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."Transaction" - ADD CONSTRAINT "PK_Transaction" PRIMARY KEY (id); - - --- --- Name: TransactionReview PK_TransactionReview; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."TransactionReview" - ADD CONSTRAINT "PK_TransactionReview" PRIMARY KEY (id); - - --- --- Name: Category PK_c2727780c5b9b0c564c29a4977c; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."Category" - ADD CONSTRAINT "PK_c2727780c5b9b0c564c29a4977c" PRIMARY KEY (id); - - --- --- Name: Post PK_c4d3b3dcd73db0b0129ea829f9f; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."Post" - ADD CONSTRAINT "PK_c4d3b3dcd73db0b0129ea829f9f" PRIMARY KEY (id); - - --- --- Name: postEventTags PK_cc14f1e77d0b18c8ec995937fd0; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."postEventTags" - ADD CONSTRAINT "PK_cc14f1e77d0b18c8ec995937fd0" PRIMARY KEY (posts, "eventTags"); - - --- --- Name: searches PK_searches; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.searches - ADD CONSTRAINT "PK_searches" PRIMARY KEY (id); - - --- --- Name: User UQ_02dec29f4ca814ab6efa2d4f0c4; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."User" - ADD CONSTRAINT "UQ_02dec29f4ca814ab6efa2d4f0c4" UNIQUE ("googleId"); - - --- --- Name: User UQ_29a05908a0fa0728526d2833657; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."User" - ADD CONSTRAINT "UQ_29a05908a0fa0728526d2833657" UNIQUE (username); - - --- --- Name: User UQ_4a257d2c9837248d70640b3e36e; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."User" - ADD CONSTRAINT "UQ_4a257d2c9837248d70640b3e36e" UNIQUE (email); - - --- --- Name: TransactionReview UQ_aff62b169ebd519d1f5994e781a; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."TransactionReview" - ADD CONSTRAINT "UQ_aff62b169ebd519d1f5994e781a" UNIQUE ("transactionId"); - - --- --- Name: User UQ_ec60b02aab67f0f99f6f88797ed; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."User" - ADD CONSTRAINT "UQ_ec60b02aab67f0f99f6f88797ed" UNIQUE (netid); - - --- --- Name: User User_pkey; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."User" - ADD CONSTRAINT "User_pkey" PRIMARY KEY ("firebaseUid"); - - --- --- Name: IDX_0c0a06e6163f7a7315c4ce5fd4; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX "IDX_0c0a06e6163f7a7315c4ce5fd4" ON public."userSavedPosts" USING btree (savers); - - --- --- Name: IDX_1f4b27b2e31fb6263f6fb3a939; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX "IDX_1f4b27b2e31fb6263f6fb3a939" ON public."postCategories" USING btree (categories); - - --- --- Name: IDX_3b2f09095e41d9c82bedaa0d8f; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX "IDX_3b2f09095e41d9c82bedaa0d8f" ON public."requestMatchesPosts" USING btree (matched); - - --- --- Name: IDX_503e9a09612f9668063099baff; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX "IDX_503e9a09612f9668063099baff" ON public.user_following_users USING btree (following_id); - - --- --- Name: IDX_61151ebab50db74ea513ff8bd8; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX "IDX_61151ebab50db74ea513ff8bd8" ON public."postEventTags" USING btree (posts); - - --- --- Name: IDX_7532bd6ca893c432ffcfa21f75; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX "IDX_7532bd6ca893c432ffcfa21f75" ON public."postEventTags" USING btree ("eventTags"); - - --- --- Name: IDX_793578cc63c2442a7944e93131; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX "IDX_793578cc63c2442a7944e93131" ON public."userBlockingUsers" USING btree (blockers); - - --- --- Name: IDX_80ef95f34370fd0704c156c13e; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX "IDX_80ef95f34370fd0704c156c13e" ON public.user_following_users USING btree (follower_id); - - --- --- Name: IDX_978f319769e3d7285d6d2e40af; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX "IDX_978f319769e3d7285d6d2e40af" ON public."postCategories" USING btree (posts); - - --- --- Name: IDX_baa3d7e5e872010a3c23e98153; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX "IDX_baa3d7e5e872010a3c23e98153" ON public."userSavedPosts" USING btree (saved); - - --- --- Name: IDX_bc2ca85580a5c620ccc7f03f5d; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX "IDX_bc2ca85580a5c620ccc7f03f5d" ON public."userBlockingUsers" USING btree (blocking); - - --- --- Name: IDX_fd473bd2ef9b7a23f41a40ebed; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX "IDX_fd473bd2ef9b7a23f41a40ebed" ON public."requestMatchesPosts" USING btree (matches); - - --- --- Name: userSavedPosts FK_0c0a06e6163f7a7315c4ce5fd4c; Type: FK CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."userSavedPosts" - ADD CONSTRAINT "FK_0c0a06e6163f7a7315c4ce5fd4c" FOREIGN KEY (savers) REFERENCES public."User"("firebaseUid"); - - --- --- Name: UserReview FK_14e4fa2651e5c6d6118e2ba18aa; Type: FK CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."UserReview" - ADD CONSTRAINT "FK_14e4fa2651e5c6d6118e2ba18aa" FOREIGN KEY ("sellerId") REFERENCES public."User"("firebaseUid"); - - --- --- Name: Report FK_16c178e84273608caf9db34df88; Type: FK CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."Report" - ADD CONSTRAINT "FK_16c178e84273608caf9db34df88" FOREIGN KEY ("reportedFirebaseUid") REFERENCES public."User"("firebaseUid"); - - --- --- Name: postCategories FK_1f4b27b2e31fb6263f6fb3a9390; Type: FK CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."postCategories" - ADD CONSTRAINT "FK_1f4b27b2e31fb6263f6fb3a9390" FOREIGN KEY (categories) REFERENCES public."Category"(id); - - --- --- Name: Feedback FK_26bcf6b3c7c6b742e63d9308676; Type: FK CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."Feedback" - ADD CONSTRAINT "FK_26bcf6b3c7c6b742e63d9308676" FOREIGN KEY ("userId") REFERENCES public."User"("firebaseUid") ON DELETE CASCADE; - - --- --- Name: Transaction FK_30d551dc74a9537b73d4007592f; Type: FK CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."Transaction" - ADD CONSTRAINT "FK_30d551dc74a9537b73d4007592f" FOREIGN KEY ("sellerId") REFERENCES public."User"("firebaseUid"); - - --- --- Name: requestMatchesPosts FK_3b2f09095e41d9c82bedaa0d8fe; Type: FK CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."requestMatchesPosts" - ADD CONSTRAINT "FK_3b2f09095e41d9c82bedaa0d8fe" FOREIGN KEY (matched) REFERENCES public."Request"(id); - - --- --- Name: Transaction FK_4ae4b1f6ff200ae67b40eb5bd8d; Type: FK CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."Transaction" - ADD CONSTRAINT "FK_4ae4b1f6ff200ae67b40eb5bd8d" FOREIGN KEY ("buyerId") REFERENCES public."User"("firebaseUid"); - - --- --- Name: Report FK_4bc548745107f37d3512ed688c5; Type: FK CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."Report" - ADD CONSTRAINT "FK_4bc548745107f37d3512ed688c5" FOREIGN KEY ("postId") REFERENCES public."Post"(id); - - --- --- Name: user_following_users FK_503e9a09612f9668063099baff1; Type: FK CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.user_following_users - ADD CONSTRAINT "FK_503e9a09612f9668063099baff1" FOREIGN KEY (following_id) REFERENCES public."User"("firebaseUid"); - - --- --- Name: UserReview FK_53a14948aa4e941762a403144ea; Type: FK CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."UserReview" - ADD CONSTRAINT "FK_53a14948aa4e941762a403144ea" FOREIGN KEY ("buyerId") REFERENCES public."User"("firebaseUid"); - - --- --- Name: postEventTags FK_61151ebab50db74ea513ff8bd87; Type: FK CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."postEventTags" - ADD CONSTRAINT "FK_61151ebab50db74ea513ff8bd87" FOREIGN KEY (posts) REFERENCES public."Post"(id) ON UPDATE CASCADE ON DELETE CASCADE; - - --- --- Name: notifications FK_692a909ee0fa9383e7859f9b406; Type: FK CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.notifications - ADD CONSTRAINT "FK_692a909ee0fa9383e7859f9b406" FOREIGN KEY ("userId") REFERENCES public."User"("firebaseUid"); - - --- --- Name: postEventTags FK_7532bd6ca893c432ffcfa21f755; Type: FK CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."postEventTags" - ADD CONSTRAINT "FK_7532bd6ca893c432ffcfa21f755" FOREIGN KEY ("eventTags") REFERENCES public."EventTag"(id); - - --- --- Name: userBlockingUsers FK_793578cc63c2442a7944e93131a; Type: FK CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."userBlockingUsers" - ADD CONSTRAINT "FK_793578cc63c2442a7944e93131a" FOREIGN KEY (blockers) REFERENCES public."User"("firebaseUid") ON UPDATE CASCADE ON DELETE CASCADE; - - --- --- Name: user_following_users FK_80ef95f34370fd0704c156c13ef; Type: FK CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.user_following_users - ADD CONSTRAINT "FK_80ef95f34370fd0704c156c13ef" FOREIGN KEY (follower_id) REFERENCES public."User"("firebaseUid") ON UPDATE CASCADE ON DELETE CASCADE; - - --- --- Name: postCategories FK_978f319769e3d7285d6d2e40af8; Type: FK CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."postCategories" - ADD CONSTRAINT "FK_978f319769e3d7285d6d2e40af8" FOREIGN KEY (posts) REFERENCES public."Post"(id) ON UPDATE CASCADE ON DELETE CASCADE; - - --- --- Name: Post FK_97e81bcb59530bfb061e48aee6a; Type: FK CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."Post" - ADD CONSTRAINT "FK_97e81bcb59530bfb061e48aee6a" FOREIGN KEY ("userId") REFERENCES public."User"("firebaseUid") ON DELETE CASCADE; - - --- --- Name: Report FK_a050c9cf7f461bc8fc040a48e0a; Type: FK CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."Report" - ADD CONSTRAINT "FK_a050c9cf7f461bc8fc040a48e0a" FOREIGN KEY ("reporterFirebaseUid") REFERENCES public."User"("firebaseUid"); - - --- --- Name: userSavedPosts FK_baa3d7e5e872010a3c23e981532; Type: FK CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."userSavedPosts" - ADD CONSTRAINT "FK_baa3d7e5e872010a3c23e981532" FOREIGN KEY (saved) REFERENCES public."Post"(id) ON UPDATE CASCADE ON DELETE CASCADE; - - --- --- Name: Transaction FK_bba9ded63ef0013ac2ec578f246; Type: FK CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."Transaction" - ADD CONSTRAINT "FK_bba9ded63ef0013ac2ec578f246" FOREIGN KEY ("postId") REFERENCES public."Post"(id); - - --- --- Name: userBlockingUsers FK_bc2ca85580a5c620ccc7f03f5db; Type: FK CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."userBlockingUsers" - ADD CONSTRAINT "FK_bc2ca85580a5c620ccc7f03f5db" FOREIGN KEY (blocking) REFERENCES public."User"("firebaseUid"); - - --- --- Name: Request FK_cdaf52464b00ac3016a8f6110fd; Type: FK CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."Request" - ADD CONSTRAINT "FK_cdaf52464b00ac3016a8f6110fd" FOREIGN KEY ("userId") REFERENCES public."User"("firebaseUid") ON DELETE CASCADE; - - --- --- Name: FCMToken FK_d215a8d66e472d872409915f7d5; Type: FK CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."FCMToken" - ADD CONSTRAINT "FK_d215a8d66e472d872409915f7d5" FOREIGN KEY ("userId") REFERENCES public."User"("firebaseUid"); - - --- --- Name: Report FK_dd826149b8ac72ddc2d1f4e234e; Type: FK CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."Report" - ADD CONSTRAINT "FK_dd826149b8ac72ddc2d1f4e234e" FOREIGN KEY ("messageId") REFERENCES public."Message"(id); - - --- --- Name: TransactionReview FK_f7cf58b571d5c57ed9da155c628; Type: FK CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."TransactionReview" - ADD CONSTRAINT "FK_f7cf58b571d5c57ed9da155c628" FOREIGN KEY ("transactionId") REFERENCES public."Transaction"(id); - - --- --- Name: searches FK_fc8760cf4823ab84b0cb28d3dad; Type: FK CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.searches - ADD CONSTRAINT "FK_fc8760cf4823ab84b0cb28d3dad" FOREIGN KEY ("firebaseUid") REFERENCES public."User"("firebaseUid") ON DELETE CASCADE; - - --- --- Name: requestMatchesPosts FK_fd473bd2ef9b7a23f41a40ebed4; Type: FK CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."requestMatchesPosts" - ADD CONSTRAINT "FK_fd473bd2ef9b7a23f41a40ebed4" FOREIGN KEY (matches) REFERENCES public."Post"(id) ON UPDATE CASCADE ON DELETE CASCADE; - - --- --- PostgreSQL database dump complete --- - -\unrestrict Yn3DWKf7D4yPmect2zcsSffRbqkUHwfacDQkFXAf2KW0gTCv32CIMSM7DnjaIGz - diff --git a/dumps/dev_db_dump_20260226_233801.sql b/dumps/dev_db_dump_20260226_233801.sql deleted file mode 100644 index 876d794..0000000 --- a/dumps/dev_db_dump_20260226_233801.sql +++ /dev/null @@ -1,1302 +0,0 @@ --- --- PostgreSQL database dump --- - -\restrict j0zS1YybO7IPtcJxy9ONeBKIaXJBXaXxzwxKQnVNLQIIVc1bKUCxYazgBD8jnUr - --- Dumped from database version 18.1 (Homebrew) --- Dumped by pg_dump version 18.1 (Homebrew) - -SET statement_timeout = 0; -SET lock_timeout = 0; -SET idle_in_transaction_session_timeout = 0; -SET transaction_timeout = 0; -SET client_encoding = 'UTF8'; -SET standard_conforming_strings = on; -SELECT pg_catalog.set_config('search_path', '', false); -SET check_function_bodies = false; -SET xmloption = content; -SET client_min_messages = warning; -SET row_security = off; - -ALTER TABLE IF EXISTS ONLY public.user_following_users DROP CONSTRAINT IF EXISTS "FK_user_following_users_following_id"; -ALTER TABLE IF EXISTS ONLY public.user_following_users DROP CONSTRAINT IF EXISTS "FK_user_following_users_follower_id"; -ALTER TABLE IF EXISTS ONLY public."requestMatchesPosts" DROP CONSTRAINT IF EXISTS "FK_fd473bd2ef9b7a23f41a40ebed4"; -ALTER TABLE IF EXISTS ONLY public.searches DROP CONSTRAINT IF EXISTS "FK_fc8760cf4823ab84b0cb28d3dad"; -ALTER TABLE IF EXISTS ONLY public."TransactionReview" DROP CONSTRAINT IF EXISTS "FK_f7cf58b571d5c57ed9da155c628"; -ALTER TABLE IF EXISTS ONLY public."eventPostRelationships" DROP CONSTRAINT IF EXISTS "FK_eventPost_postId"; -ALTER TABLE IF EXISTS ONLY public."eventPostRelationships" DROP CONSTRAINT IF EXISTS "FK_eventPost_eventTagId"; -ALTER TABLE IF EXISTS ONLY public."Report" DROP CONSTRAINT IF EXISTS "FK_dd826149b8ac72ddc2d1f4e234e"; -ALTER TABLE IF EXISTS ONLY public."FCMToken" DROP CONSTRAINT IF EXISTS "FK_d215a8d66e472d872409915f7d5"; -ALTER TABLE IF EXISTS ONLY public."Request" DROP CONSTRAINT IF EXISTS "FK_cdaf52464b00ac3016a8f6110fd"; -ALTER TABLE IF EXISTS ONLY public."userBlockingUsers" DROP CONSTRAINT IF EXISTS "FK_bc2ca85580a5c620ccc7f03f5db"; -ALTER TABLE IF EXISTS ONLY public."Transaction" DROP CONSTRAINT IF EXISTS "FK_bba9ded63ef0013ac2ec578f246"; -ALTER TABLE IF EXISTS ONLY public."userSavedPosts" DROP CONSTRAINT IF EXISTS "FK_baa3d7e5e872010a3c23e981532"; -ALTER TABLE IF EXISTS ONLY public."Report" DROP CONSTRAINT IF EXISTS "FK_a050c9cf7f461bc8fc040a48e0a"; -ALTER TABLE IF EXISTS ONLY public."Post" DROP CONSTRAINT IF EXISTS "FK_97e81bcb59530bfb061e48aee6a"; -ALTER TABLE IF EXISTS ONLY public."postCategories" DROP CONSTRAINT IF EXISTS "FK_978f319769e3d7285d6d2e40af8"; -ALTER TABLE IF EXISTS ONLY public.user_following_users DROP CONSTRAINT IF EXISTS "FK_80ef95f34370fd0704c156c13ef"; -ALTER TABLE IF EXISTS ONLY public."userBlockingUsers" DROP CONSTRAINT IF EXISTS "FK_793578cc63c2442a7944e93131a"; -ALTER TABLE IF EXISTS ONLY public."postEventTags" DROP CONSTRAINT IF EXISTS "FK_7532bd6ca893c432ffcfa21f755"; -ALTER TABLE IF EXISTS ONLY public.notifications DROP CONSTRAINT IF EXISTS "FK_692a909ee0fa9383e7859f9b406"; -ALTER TABLE IF EXISTS ONLY public."postEventTags" DROP CONSTRAINT IF EXISTS "FK_61151ebab50db74ea513ff8bd87"; -ALTER TABLE IF EXISTS ONLY public."UserReview" DROP CONSTRAINT IF EXISTS "FK_53a14948aa4e941762a403144ea"; -ALTER TABLE IF EXISTS ONLY public.user_following_users DROP CONSTRAINT IF EXISTS "FK_503e9a09612f9668063099baff1"; -ALTER TABLE IF EXISTS ONLY public."Report" DROP CONSTRAINT IF EXISTS "FK_4bc548745107f37d3512ed688c5"; -ALTER TABLE IF EXISTS ONLY public."Transaction" DROP CONSTRAINT IF EXISTS "FK_4ae4b1f6ff200ae67b40eb5bd8d"; -ALTER TABLE IF EXISTS ONLY public."requestMatchesPosts" DROP CONSTRAINT IF EXISTS "FK_3b2f09095e41d9c82bedaa0d8fe"; -ALTER TABLE IF EXISTS ONLY public."Transaction" DROP CONSTRAINT IF EXISTS "FK_30d551dc74a9537b73d4007592f"; -ALTER TABLE IF EXISTS ONLY public."Feedback" DROP CONSTRAINT IF EXISTS "FK_26bcf6b3c7c6b742e63d9308676"; -ALTER TABLE IF EXISTS ONLY public."postCategories" DROP CONSTRAINT IF EXISTS "FK_1f4b27b2e31fb6263f6fb3a9390"; -ALTER TABLE IF EXISTS ONLY public."Report" DROP CONSTRAINT IF EXISTS "FK_16c178e84273608caf9db34df88"; -ALTER TABLE IF EXISTS ONLY public."UserReview" DROP CONSTRAINT IF EXISTS "FK_14e4fa2651e5c6d6118e2ba18aa"; -ALTER TABLE IF EXISTS ONLY public."userSavedPosts" DROP CONSTRAINT IF EXISTS "FK_0c0a06e6163f7a7315c4ce5fd4c"; -DROP INDEX IF EXISTS public."IDX_user_following_users_following_id"; -DROP INDEX IF EXISTS public."IDX_user_following_users_follower_id"; -DROP INDEX IF EXISTS public."IDX_fd473bd2ef9b7a23f41a40ebed"; -DROP INDEX IF EXISTS public."IDX_eventPost_postId"; -DROP INDEX IF EXISTS public."IDX_eventPost_eventTagId"; -DROP INDEX IF EXISTS public."IDX_bc2ca85580a5c620ccc7f03f5d"; -DROP INDEX IF EXISTS public."IDX_baa3d7e5e872010a3c23e98153"; -DROP INDEX IF EXISTS public."IDX_978f319769e3d7285d6d2e40af"; -DROP INDEX IF EXISTS public."IDX_80ef95f34370fd0704c156c13e"; -DROP INDEX IF EXISTS public."IDX_793578cc63c2442a7944e93131"; -DROP INDEX IF EXISTS public."IDX_7532bd6ca893c432ffcfa21f75"; -DROP INDEX IF EXISTS public."IDX_61151ebab50db74ea513ff8bd8"; -DROP INDEX IF EXISTS public."IDX_503e9a09612f9668063099baff"; -DROP INDEX IF EXISTS public."IDX_3b2f09095e41d9c82bedaa0d8f"; -DROP INDEX IF EXISTS public."IDX_1f4b27b2e31fb6263f6fb3a939"; -DROP INDEX IF EXISTS public."IDX_0c0a06e6163f7a7315c4ce5fd4"; -ALTER TABLE IF EXISTS ONLY public."User" DROP CONSTRAINT IF EXISTS "User_pkey"; -ALTER TABLE IF EXISTS ONLY public."eventPostRelationships" DROP CONSTRAINT IF EXISTS "UQ_eventPost_postId_eventTagId"; -ALTER TABLE IF EXISTS ONLY public."User" DROP CONSTRAINT IF EXISTS "UQ_ec60b02aab67f0f99f6f88797ed"; -ALTER TABLE IF EXISTS ONLY public."TransactionReview" DROP CONSTRAINT IF EXISTS "UQ_aff62b169ebd519d1f5994e781a"; -ALTER TABLE IF EXISTS ONLY public."User" DROP CONSTRAINT IF EXISTS "UQ_4a257d2c9837248d70640b3e36e"; -ALTER TABLE IF EXISTS ONLY public."User" DROP CONSTRAINT IF EXISTS "UQ_29a05908a0fa0728526d2833657"; -ALTER TABLE IF EXISTS ONLY public."User" DROP CONSTRAINT IF EXISTS "UQ_02dec29f4ca814ab6efa2d4f0c4"; -ALTER TABLE IF EXISTS ONLY public.searches DROP CONSTRAINT IF EXISTS "PK_searches"; -ALTER TABLE IF EXISTS ONLY public."eventPostRelationships" DROP CONSTRAINT IF EXISTS "PK_eventPostRelationships"; -ALTER TABLE IF EXISTS ONLY public."postEventTags" DROP CONSTRAINT IF EXISTS "PK_cc14f1e77d0b18c8ec995937fd0"; -ALTER TABLE IF EXISTS ONLY public."Post" DROP CONSTRAINT IF EXISTS "PK_c4d3b3dcd73db0b0129ea829f9f"; -ALTER TABLE IF EXISTS ONLY public."Category" DROP CONSTRAINT IF EXISTS "PK_c2727780c5b9b0c564c29a4977c"; -ALTER TABLE IF EXISTS ONLY public."TransactionReview" DROP CONSTRAINT IF EXISTS "PK_TransactionReview"; -ALTER TABLE IF EXISTS ONLY public."Transaction" DROP CONSTRAINT IF EXISTS "PK_Transaction"; -ALTER TABLE IF EXISTS ONLY public."FCMToken" DROP CONSTRAINT IF EXISTS "PK_FCMToken"; -ALTER TABLE IF EXISTS ONLY public."Report" DROP CONSTRAINT IF EXISTS "PK_9dbb4c593be9832c28a5793e258"; -ALTER TABLE IF EXISTS ONLY public."EventTag" DROP CONSTRAINT IF EXISTS "PK_929d8d89bf95d848ac3b7546a29"; -ALTER TABLE IF EXISTS ONLY public."UserReview" DROP CONSTRAINT IF EXISTS "PK_91b62f63709469ae812a3519dd1"; -ALTER TABLE IF EXISTS ONLY public."userBlockingUsers" DROP CONSTRAINT IF EXISTS "PK_8db623e58cc4bce5fbcc252c66b"; -ALTER TABLE IF EXISTS ONLY public.migrations DROP CONSTRAINT IF EXISTS "PK_8c82d7f526340ab734260ea46be"; -ALTER TABLE IF EXISTS ONLY public."postCategories" DROP CONSTRAINT IF EXISTS "PK_88340cf0b1b8a00578602f4c80b"; -ALTER TABLE IF EXISTS ONLY public."Feedback" DROP CONSTRAINT IF EXISTS "PK_7ffea537e9c56670b65c2d62316"; -ALTER TABLE IF EXISTS ONLY public."requestMatchesPosts" DROP CONSTRAINT IF EXISTS "PK_7f4c04956dd4e84a3437b2a8018"; -ALTER TABLE IF EXISTS ONLY public."Message" DROP CONSTRAINT IF EXISTS "PK_7dd6398f0d1dcaf73df342fa325"; -ALTER TABLE IF EXISTS ONLY public.notifications DROP CONSTRAINT IF EXISTS "PK_6a72c3c0f683f6462415e653c3a"; -ALTER TABLE IF EXISTS ONLY public."Request" DROP CONSTRAINT IF EXISTS "PK_23de24dc477765bcc099feae8e5"; -ALTER TABLE IF EXISTS ONLY public."userSavedPosts" DROP CONSTRAINT IF EXISTS "PK_11901fe92c42b2d2a71ca74021a"; -ALTER TABLE IF EXISTS ONLY public.user_following_users DROP CONSTRAINT IF EXISTS "PK_01b7a923c26f4be4f7c138cbb88"; -ALTER TABLE IF EXISTS public.migrations ALTER COLUMN id DROP DEFAULT; -DROP TABLE IF EXISTS public.user_following_users; -DROP TABLE IF EXISTS public."userSavedPosts"; -DROP TABLE IF EXISTS public."userBlockingUsers"; -DROP TABLE IF EXISTS public.typeorm_metadata; -DROP TABLE IF EXISTS public.searches; -DROP TABLE IF EXISTS public."requestMatchesPosts"; -DROP TABLE IF EXISTS public."postEventTags"; -DROP TABLE IF EXISTS public."postCategories"; -DROP TABLE IF EXISTS public.notifications; -DROP SEQUENCE IF EXISTS public.migrations_id_seq; -DROP TABLE IF EXISTS public.migrations; -DROP TABLE IF EXISTS public."eventPostRelationships"; -DROP TABLE IF EXISTS public."UserReview"; -DROP TABLE IF EXISTS public."User"; -DROP TABLE IF EXISTS public."TransactionReview"; -DROP TABLE IF EXISTS public."Transaction"; -DROP TABLE IF EXISTS public."Request"; -DROP TABLE IF EXISTS public."Report"; -DROP TABLE IF EXISTS public."Post"; -DROP TABLE IF EXISTS public."Message"; -DROP TABLE IF EXISTS public."Feedback"; -DROP TABLE IF EXISTS public."FCMToken"; -DROP TABLE IF EXISTS public."EventTag"; -DROP TABLE IF EXISTS public."Category"; -DROP EXTENSION IF EXISTS vector; -DROP EXTENSION IF EXISTS "uuid-ossp"; --- --- Name: uuid-ossp; Type: EXTENSION; Schema: -; Owner: - --- - -CREATE EXTENSION IF NOT EXISTS "uuid-ossp" WITH SCHEMA public; - - --- --- Name: EXTENSION "uuid-ossp"; Type: COMMENT; Schema: -; Owner: - --- - -COMMENT ON EXTENSION "uuid-ossp" IS 'generate universally unique identifiers (UUIDs)'; - - --- --- Name: vector; Type: EXTENSION; Schema: -; Owner: - --- - -CREATE EXTENSION IF NOT EXISTS vector WITH SCHEMA public; - - --- --- Name: EXTENSION vector; Type: COMMENT; Schema: -; Owner: - --- - -COMMENT ON EXTENSION vector IS 'vector data type and ivfflat and hnsw access methods'; - - -SET default_tablespace = ''; - -SET default_table_access_method = heap; - --- --- Name: Category; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public."Category" ( - id uuid DEFAULT public.uuid_generate_v4() NOT NULL, - name character varying NOT NULL -); - - --- --- Name: EventTag; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public."EventTag" ( - id uuid DEFAULT public.uuid_generate_v4() NOT NULL, - name character varying NOT NULL -); - - --- --- Name: FCMToken; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public."FCMToken" ( - id uuid DEFAULT public.uuid_generate_v4() NOT NULL, - "fcmToken" character varying NOT NULL, - "notificationsEnabled" boolean NOT NULL, - "timestamp" timestamp without time zone NOT NULL, - "userId" character varying -); - - --- --- Name: Feedback; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public."Feedback" ( - id uuid DEFAULT public.uuid_generate_v4() NOT NULL, - description character varying NOT NULL, - images text[] NOT NULL, - "userId" character varying -); - - --- --- Name: Message; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public."Message" ( - id uuid NOT NULL -); - - --- --- Name: Post; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public."Post" ( - id uuid DEFAULT public.uuid_generate_v4() NOT NULL, - title character varying NOT NULL, - description character varying NOT NULL, - "originalPrice" numeric CONSTRAINT "Post_original_price_not_null" NOT NULL, - "alteredPrice" numeric DEFAULT '-1'::numeric CONSTRAINT "Post_altered_price_not_null" NOT NULL, - images text[] NOT NULL, - created timestamp with time zone DEFAULT now() NOT NULL, - location character varying, - archive boolean DEFAULT false NOT NULL, - condition character varying NOT NULL, - sold boolean DEFAULT false NOT NULL, - embedding double precision[], - "userId" character varying -); - - --- --- Name: Report; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public."Report" ( - id uuid DEFAULT public.uuid_generate_v4() NOT NULL, - reason character varying NOT NULL, - type character varying NOT NULL, - resolved boolean NOT NULL, - created timestamp with time zone DEFAULT now() NOT NULL, - "reporterFirebaseUid" character varying, - "reportedFirebaseUid" character varying, - "postId" uuid, - "messageId" uuid -); - - --- --- Name: Request; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public."Request" ( - id uuid DEFAULT public.uuid_generate_v4() NOT NULL, - title character varying NOT NULL, - description character varying NOT NULL, - archive boolean DEFAULT false NOT NULL, - embedding double precision[], - "userId" character varying -); - - --- --- Name: Transaction; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public."Transaction" ( - id uuid DEFAULT public.uuid_generate_v4() NOT NULL, - location character varying NOT NULL, - amount numeric NOT NULL, - completed boolean DEFAULT false NOT NULL, - "postId" uuid, - "buyerId" character varying, - "sellerId" character varying, - "transactionDate" timestamp with time zone, - "createdAt" timestamp with time zone DEFAULT now() NOT NULL, - "confirmationSent" boolean DEFAULT false NOT NULL -); - - --- --- Name: TransactionReview; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public."TransactionReview" ( - id uuid DEFAULT public.uuid_generate_v4() NOT NULL, - stars integer NOT NULL, - "transactionId" uuid, - "hadIssues" boolean DEFAULT false NOT NULL, - "issueCategory" text, - "issueDetails" text, - "createdAt" timestamp with time zone DEFAULT now() NOT NULL, - comments text -); - - --- --- Name: User; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public."User" ( - username character varying NOT NULL, - netid character varying, - admin boolean NOT NULL, - stars numeric DEFAULT '0'::numeric NOT NULL, - email character varying NOT NULL, - bio text DEFAULT ''::text NOT NULL, - "isActive" boolean DEFAULT true NOT NULL, - "firebaseUid" character varying NOT NULL, - "givenName" character varying, - "familyName" character varying, - "numReviews" integer DEFAULT 0 NOT NULL, - "photoUrl" character varying, - "venmoHandle" character varying, - "googleId" character varying, - "soldPosts" integer DEFAULT 0 NOT NULL, - "availabilityId" character varying -); - - --- --- Name: UserReview; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public."UserReview" ( - id uuid DEFAULT public.uuid_generate_v4() NOT NULL, - fulfilled boolean NOT NULL, - stars integer NOT NULL, - comments character varying NOT NULL, - date timestamp with time zone DEFAULT now() NOT NULL, - "buyerId" character varying, - "sellerId" character varying -); - - --- --- Name: eventPostRelationships; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public."eventPostRelationships" ( - id uuid DEFAULT public.uuid_generate_v4() NOT NULL, - "postId" uuid NOT NULL, - "eventTagId" uuid NOT NULL, - source character varying(20) NOT NULL, - "relevanceScore" double precision, - "createdAt" timestamp with time zone DEFAULT now() NOT NULL, - "updatedAt" timestamp with time zone DEFAULT now() NOT NULL -); - - --- --- Name: migrations; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public.migrations ( - id integer NOT NULL, - "timestamp" bigint NOT NULL, - name character varying NOT NULL -); - - --- --- Name: migrations_id_seq; Type: SEQUENCE; Schema: public; Owner: - --- - -CREATE SEQUENCE public.migrations_id_seq - AS integer - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - --- --- Name: migrations_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: - --- - -ALTER SEQUENCE public.migrations_id_seq OWNED BY public.migrations.id; - - --- --- Name: notifications; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public.notifications ( - id uuid DEFAULT public.uuid_generate_v4() NOT NULL, - title character varying NOT NULL, - body character varying NOT NULL, - data jsonb, - read boolean DEFAULT false NOT NULL, - "userId" character varying NOT NULL, - "createdAt" timestamp without time zone DEFAULT now() NOT NULL, - "updatedAt" timestamp without time zone DEFAULT now() NOT NULL -); - - --- --- Name: postCategories; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public."postCategories" ( - posts uuid CONSTRAINT post_categories_posts_not_null NOT NULL, - categories uuid CONSTRAINT post_categories_categories_not_null NOT NULL -); - - --- --- Name: postEventTags; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public."postEventTags" ( - posts uuid CONSTRAINT post_event_tags_posts_not_null NOT NULL, - "eventTags" uuid CONSTRAINT post_event_tags_event_tags_not_null NOT NULL -); - - --- --- Name: requestMatchesPosts; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public."requestMatchesPosts" ( - matches uuid CONSTRAINT request_matches_posts_matches_not_null NOT NULL, - matched uuid CONSTRAINT request_matches_posts_matched_not_null NOT NULL -); - - --- --- Name: searches; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public.searches ( - id uuid DEFAULT public.uuid_generate_v4() NOT NULL, - "searchText" character varying NOT NULL, - "firebaseUid" character varying NOT NULL, - "createdAt" timestamp without time zone DEFAULT now() NOT NULL, - "searchVector" character varying NOT NULL -); - - --- --- Name: typeorm_metadata; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public.typeorm_metadata ( - type character varying NOT NULL, - database character varying, - schema character varying, - "table" character varying, - name character varying, - value text -); - - --- --- Name: userBlockingUsers; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public."userBlockingUsers" ( - blockers character varying CONSTRAINT user_blocking_users_blockers_not_null NOT NULL, - blocking character varying CONSTRAINT user_blocking_users_blocking_not_null NOT NULL -); - - --- --- Name: userSavedPosts; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public."userSavedPosts" ( - saved uuid CONSTRAINT user_saved_posts_saved_not_null NOT NULL, - savers character varying CONSTRAINT user_saved_posts_savers_not_null NOT NULL -); - - --- --- Name: user_following_users; Type: TABLE; Schema: public; Owner: - --- - -CREATE TABLE public.user_following_users ( - follower_id character varying NOT NULL, - following_id character varying NOT NULL -); - - --- --- Name: migrations id; Type: DEFAULT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.migrations ALTER COLUMN id SET DEFAULT nextval('public.migrations_id_seq'::regclass); - - --- --- Data for Name: Category; Type: TABLE DATA; Schema: public; Owner: - --- - -COPY public."Category" (id, name) FROM stdin; -\. - - --- --- Data for Name: EventTag; Type: TABLE DATA; Schema: public; Owner: - --- - -COPY public."EventTag" (id, name) FROM stdin; -\. - - --- --- Data for Name: FCMToken; Type: TABLE DATA; Schema: public; Owner: - --- - -COPY public."FCMToken" (id, "fcmToken", "notificationsEnabled", "timestamp", "userId") FROM stdin; -\. - - --- --- Data for Name: Feedback; Type: TABLE DATA; Schema: public; Owner: - --- - -COPY public."Feedback" (id, description, images, "userId") FROM stdin; -\. - - --- --- Data for Name: Message; Type: TABLE DATA; Schema: public; Owner: - --- - -COPY public."Message" (id) FROM stdin; -\. - - --- --- Data for Name: Post; Type: TABLE DATA; Schema: public; Owner: - --- - -COPY public."Post" (id, title, description, "originalPrice", "alteredPrice", images, created, location, archive, condition, sold, embedding, "userId") FROM stdin; -\. - - --- --- Data for Name: Report; Type: TABLE DATA; Schema: public; Owner: - --- - -COPY public."Report" (id, reason, type, resolved, created, "reporterFirebaseUid", "reportedFirebaseUid", "postId", "messageId") FROM stdin; -\. - - --- --- Data for Name: Request; Type: TABLE DATA; Schema: public; Owner: - --- - -COPY public."Request" (id, title, description, archive, embedding, "userId") FROM stdin; -\. - - --- --- Data for Name: Transaction; Type: TABLE DATA; Schema: public; Owner: - --- - -COPY public."Transaction" (id, location, amount, completed, "postId", "buyerId", "sellerId", "transactionDate", "createdAt", "confirmationSent") FROM stdin; -\. - - --- --- Data for Name: TransactionReview; Type: TABLE DATA; Schema: public; Owner: - --- - -COPY public."TransactionReview" (id, stars, "transactionId", "hadIssues", "issueCategory", "issueDetails", "createdAt", comments) FROM stdin; -\. - - --- --- Data for Name: User; Type: TABLE DATA; Schema: public; Owner: - --- - -COPY public."User" (username, netid, admin, stars, email, bio, "isActive", "firebaseUid", "givenName", "familyName", "numReviews", "photoUrl", "venmoHandle", "googleId", "soldPosts", "availabilityId") FROM stdin; -\. - - --- --- Data for Name: UserReview; Type: TABLE DATA; Schema: public; Owner: - --- - -COPY public."UserReview" (id, fulfilled, stars, comments, date, "buyerId", "sellerId") FROM stdin; -\. - - --- --- Data for Name: eventPostRelationships; Type: TABLE DATA; Schema: public; Owner: - --- - -COPY public."eventPostRelationships" (id, "postId", "eventTagId", source, "relevanceScore", "createdAt", "updatedAt") FROM stdin; -\. - - --- --- Data for Name: migrations; Type: TABLE DATA; Schema: public; Owner: - --- - -COPY public.migrations (id, "timestamp", name) FROM stdin; -1 1709163288115 init1709163288115 -2 1713139721037 softdelete1713139721037 -3 1713218553306 makenetidnullable1713218553306 -4 1713308449994 addreports1713308449994 -5 1713320015776 UpdateMessageModel1713320015776 -6 1731186421123 AddArchiveToRequest1731186421123 -7 1731271779741 updatecategories1731271779741 -8 1732146942548 addconditiontoposts1732146942548 -9 1732906578369 AddTransactionTable1732906578369 -10 1732924592033 AddSoldColumnToPost1732924592033 -11 1732975238671 AddTransactionReviewTable1732975238671 -12 1739899394694 Notifications1739899394694 -13 1740007049335 ConvertEmbeddingToVector1631740007049335 -14 1740628691583 AuthorizationRefactor1740628691583 -15 1743028223060 AddCategoryTable1743028223060 -16 1743566564676 CreateSearchesTable1743566564676 -17 1761697414368 AddEventTagTable1761697414368 -18 1765000000000 RenameSnakeToCamelResellTest1765000000000 -19 1767386999887 AddUserStats1767386999887 -20 1769385600000 AddAvailabilityToUser1769385600000 -21 1769500000000 AddConfirmationSentToTransaction1769500000000 -22 1769700000000 CreateEventPostRelationships1769700000000 -\. - - --- --- Data for Name: notifications; Type: TABLE DATA; Schema: public; Owner: - --- - -COPY public.notifications (id, title, body, data, read, "userId", "createdAt", "updatedAt") FROM stdin; -\. - - --- --- Data for Name: postCategories; Type: TABLE DATA; Schema: public; Owner: - --- - -COPY public."postCategories" (posts, categories) FROM stdin; -\. - - --- --- Data for Name: postEventTags; Type: TABLE DATA; Schema: public; Owner: - --- - -COPY public."postEventTags" (posts, "eventTags") FROM stdin; -\. - - --- --- Data for Name: requestMatchesPosts; Type: TABLE DATA; Schema: public; Owner: - --- - -COPY public."requestMatchesPosts" (matches, matched) FROM stdin; -\. - - --- --- Data for Name: searches; Type: TABLE DATA; Schema: public; Owner: - --- - -COPY public.searches (id, "searchText", "firebaseUid", "createdAt", "searchVector") FROM stdin; -\. - - --- --- Data for Name: typeorm_metadata; Type: TABLE DATA; Schema: public; Owner: - --- - -COPY public.typeorm_metadata (type, database, schema, "table", name, value) FROM stdin; -\. - - --- --- Data for Name: userBlockingUsers; Type: TABLE DATA; Schema: public; Owner: - --- - -COPY public."userBlockingUsers" (blockers, blocking) FROM stdin; -\. - - --- --- Data for Name: userSavedPosts; Type: TABLE DATA; Schema: public; Owner: - --- - -COPY public."userSavedPosts" (saved, savers) FROM stdin; -\. - - --- --- Data for Name: user_following_users; Type: TABLE DATA; Schema: public; Owner: - --- - -COPY public.user_following_users (follower_id, following_id) FROM stdin; -\. - - --- --- Name: migrations_id_seq; Type: SEQUENCE SET; Schema: public; Owner: - --- - -SELECT pg_catalog.setval('public.migrations_id_seq', 22, true); - - --- --- Name: user_following_users PK_01b7a923c26f4be4f7c138cbb88; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.user_following_users - ADD CONSTRAINT "PK_01b7a923c26f4be4f7c138cbb88" PRIMARY KEY (follower_id, following_id); - - --- --- Name: userSavedPosts PK_11901fe92c42b2d2a71ca74021a; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."userSavedPosts" - ADD CONSTRAINT "PK_11901fe92c42b2d2a71ca74021a" PRIMARY KEY (saved, savers); - - --- --- Name: Request PK_23de24dc477765bcc099feae8e5; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."Request" - ADD CONSTRAINT "PK_23de24dc477765bcc099feae8e5" PRIMARY KEY (id); - - --- --- Name: notifications PK_6a72c3c0f683f6462415e653c3a; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.notifications - ADD CONSTRAINT "PK_6a72c3c0f683f6462415e653c3a" PRIMARY KEY (id); - - --- --- Name: Message PK_7dd6398f0d1dcaf73df342fa325; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."Message" - ADD CONSTRAINT "PK_7dd6398f0d1dcaf73df342fa325" PRIMARY KEY (id); - - --- --- Name: requestMatchesPosts PK_7f4c04956dd4e84a3437b2a8018; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."requestMatchesPosts" - ADD CONSTRAINT "PK_7f4c04956dd4e84a3437b2a8018" PRIMARY KEY (matches, matched); - - --- --- Name: Feedback PK_7ffea537e9c56670b65c2d62316; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."Feedback" - ADD CONSTRAINT "PK_7ffea537e9c56670b65c2d62316" PRIMARY KEY (id); - - --- --- Name: postCategories PK_88340cf0b1b8a00578602f4c80b; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."postCategories" - ADD CONSTRAINT "PK_88340cf0b1b8a00578602f4c80b" PRIMARY KEY (posts, categories); - - --- --- Name: migrations PK_8c82d7f526340ab734260ea46be; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.migrations - ADD CONSTRAINT "PK_8c82d7f526340ab734260ea46be" PRIMARY KEY (id); - - --- --- Name: userBlockingUsers PK_8db623e58cc4bce5fbcc252c66b; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."userBlockingUsers" - ADD CONSTRAINT "PK_8db623e58cc4bce5fbcc252c66b" PRIMARY KEY (blockers, blocking); - - --- --- Name: UserReview PK_91b62f63709469ae812a3519dd1; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."UserReview" - ADD CONSTRAINT "PK_91b62f63709469ae812a3519dd1" PRIMARY KEY (id); - - --- --- Name: EventTag PK_929d8d89bf95d848ac3b7546a29; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."EventTag" - ADD CONSTRAINT "PK_929d8d89bf95d848ac3b7546a29" PRIMARY KEY (id); - - --- --- Name: Report PK_9dbb4c593be9832c28a5793e258; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."Report" - ADD CONSTRAINT "PK_9dbb4c593be9832c28a5793e258" PRIMARY KEY (id); - - --- --- Name: FCMToken PK_FCMToken; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."FCMToken" - ADD CONSTRAINT "PK_FCMToken" PRIMARY KEY (id); - - --- --- Name: Transaction PK_Transaction; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."Transaction" - ADD CONSTRAINT "PK_Transaction" PRIMARY KEY (id); - - --- --- Name: TransactionReview PK_TransactionReview; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."TransactionReview" - ADD CONSTRAINT "PK_TransactionReview" PRIMARY KEY (id); - - --- --- Name: Category PK_c2727780c5b9b0c564c29a4977c; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."Category" - ADD CONSTRAINT "PK_c2727780c5b9b0c564c29a4977c" PRIMARY KEY (id); - - --- --- Name: Post PK_c4d3b3dcd73db0b0129ea829f9f; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."Post" - ADD CONSTRAINT "PK_c4d3b3dcd73db0b0129ea829f9f" PRIMARY KEY (id); - - --- --- Name: postEventTags PK_cc14f1e77d0b18c8ec995937fd0; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."postEventTags" - ADD CONSTRAINT "PK_cc14f1e77d0b18c8ec995937fd0" PRIMARY KEY (posts, "eventTags"); - - --- --- Name: eventPostRelationships PK_eventPostRelationships; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."eventPostRelationships" - ADD CONSTRAINT "PK_eventPostRelationships" PRIMARY KEY (id); - - --- --- Name: searches PK_searches; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.searches - ADD CONSTRAINT "PK_searches" PRIMARY KEY (id); - - --- --- Name: User UQ_02dec29f4ca814ab6efa2d4f0c4; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."User" - ADD CONSTRAINT "UQ_02dec29f4ca814ab6efa2d4f0c4" UNIQUE ("googleId"); - - --- --- Name: User UQ_29a05908a0fa0728526d2833657; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."User" - ADD CONSTRAINT "UQ_29a05908a0fa0728526d2833657" UNIQUE (username); - - --- --- Name: User UQ_4a257d2c9837248d70640b3e36e; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."User" - ADD CONSTRAINT "UQ_4a257d2c9837248d70640b3e36e" UNIQUE (email); - - --- --- Name: TransactionReview UQ_aff62b169ebd519d1f5994e781a; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."TransactionReview" - ADD CONSTRAINT "UQ_aff62b169ebd519d1f5994e781a" UNIQUE ("transactionId"); - - --- --- Name: User UQ_ec60b02aab67f0f99f6f88797ed; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."User" - ADD CONSTRAINT "UQ_ec60b02aab67f0f99f6f88797ed" UNIQUE (netid); - - --- --- Name: eventPostRelationships UQ_eventPost_postId_eventTagId; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."eventPostRelationships" - ADD CONSTRAINT "UQ_eventPost_postId_eventTagId" UNIQUE ("postId", "eventTagId"); - - --- --- Name: User User_pkey; Type: CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."User" - ADD CONSTRAINT "User_pkey" PRIMARY KEY ("firebaseUid"); - - --- --- Name: IDX_0c0a06e6163f7a7315c4ce5fd4; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX "IDX_0c0a06e6163f7a7315c4ce5fd4" ON public."userSavedPosts" USING btree (savers); - - --- --- Name: IDX_1f4b27b2e31fb6263f6fb3a939; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX "IDX_1f4b27b2e31fb6263f6fb3a939" ON public."postCategories" USING btree (categories); - - --- --- Name: IDX_3b2f09095e41d9c82bedaa0d8f; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX "IDX_3b2f09095e41d9c82bedaa0d8f" ON public."requestMatchesPosts" USING btree (matched); - - --- --- Name: IDX_503e9a09612f9668063099baff; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX "IDX_503e9a09612f9668063099baff" ON public.user_following_users USING btree (following_id); - - --- --- Name: IDX_61151ebab50db74ea513ff8bd8; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX "IDX_61151ebab50db74ea513ff8bd8" ON public."postEventTags" USING btree (posts); - - --- --- Name: IDX_7532bd6ca893c432ffcfa21f75; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX "IDX_7532bd6ca893c432ffcfa21f75" ON public."postEventTags" USING btree ("eventTags"); - - --- --- Name: IDX_793578cc63c2442a7944e93131; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX "IDX_793578cc63c2442a7944e93131" ON public."userBlockingUsers" USING btree (blockers); - - --- --- Name: IDX_80ef95f34370fd0704c156c13e; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX "IDX_80ef95f34370fd0704c156c13e" ON public.user_following_users USING btree (follower_id); - - --- --- Name: IDX_978f319769e3d7285d6d2e40af; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX "IDX_978f319769e3d7285d6d2e40af" ON public."postCategories" USING btree (posts); - - --- --- Name: IDX_baa3d7e5e872010a3c23e98153; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX "IDX_baa3d7e5e872010a3c23e98153" ON public."userSavedPosts" USING btree (saved); - - --- --- Name: IDX_bc2ca85580a5c620ccc7f03f5d; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX "IDX_bc2ca85580a5c620ccc7f03f5d" ON public."userBlockingUsers" USING btree (blocking); - - --- --- Name: IDX_eventPost_eventTagId; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX "IDX_eventPost_eventTagId" ON public."eventPostRelationships" USING btree ("eventTagId"); - - --- --- Name: IDX_eventPost_postId; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX "IDX_eventPost_postId" ON public."eventPostRelationships" USING btree ("postId"); - - --- --- Name: IDX_fd473bd2ef9b7a23f41a40ebed; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX "IDX_fd473bd2ef9b7a23f41a40ebed" ON public."requestMatchesPosts" USING btree (matches); - - --- --- Name: IDX_user_following_users_follower_id; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX "IDX_user_following_users_follower_id" ON public.user_following_users USING btree (follower_id); - - --- --- Name: IDX_user_following_users_following_id; Type: INDEX; Schema: public; Owner: - --- - -CREATE INDEX "IDX_user_following_users_following_id" ON public.user_following_users USING btree (following_id); - - --- --- Name: userSavedPosts FK_0c0a06e6163f7a7315c4ce5fd4c; Type: FK CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."userSavedPosts" - ADD CONSTRAINT "FK_0c0a06e6163f7a7315c4ce5fd4c" FOREIGN KEY (savers) REFERENCES public."User"("firebaseUid"); - - --- --- Name: UserReview FK_14e4fa2651e5c6d6118e2ba18aa; Type: FK CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."UserReview" - ADD CONSTRAINT "FK_14e4fa2651e5c6d6118e2ba18aa" FOREIGN KEY ("sellerId") REFERENCES public."User"("firebaseUid"); - - --- --- Name: Report FK_16c178e84273608caf9db34df88; Type: FK CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."Report" - ADD CONSTRAINT "FK_16c178e84273608caf9db34df88" FOREIGN KEY ("reportedFirebaseUid") REFERENCES public."User"("firebaseUid"); - - --- --- Name: postCategories FK_1f4b27b2e31fb6263f6fb3a9390; Type: FK CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."postCategories" - ADD CONSTRAINT "FK_1f4b27b2e31fb6263f6fb3a9390" FOREIGN KEY (categories) REFERENCES public."Category"(id); - - --- --- Name: Feedback FK_26bcf6b3c7c6b742e63d9308676; Type: FK CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."Feedback" - ADD CONSTRAINT "FK_26bcf6b3c7c6b742e63d9308676" FOREIGN KEY ("userId") REFERENCES public."User"("firebaseUid") ON DELETE CASCADE; - - --- --- Name: Transaction FK_30d551dc74a9537b73d4007592f; Type: FK CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."Transaction" - ADD CONSTRAINT "FK_30d551dc74a9537b73d4007592f" FOREIGN KEY ("sellerId") REFERENCES public."User"("firebaseUid"); - - --- --- Name: requestMatchesPosts FK_3b2f09095e41d9c82bedaa0d8fe; Type: FK CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."requestMatchesPosts" - ADD CONSTRAINT "FK_3b2f09095e41d9c82bedaa0d8fe" FOREIGN KEY (matched) REFERENCES public."Request"(id); - - --- --- Name: Transaction FK_4ae4b1f6ff200ae67b40eb5bd8d; Type: FK CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."Transaction" - ADD CONSTRAINT "FK_4ae4b1f6ff200ae67b40eb5bd8d" FOREIGN KEY ("buyerId") REFERENCES public."User"("firebaseUid"); - - --- --- Name: Report FK_4bc548745107f37d3512ed688c5; Type: FK CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."Report" - ADD CONSTRAINT "FK_4bc548745107f37d3512ed688c5" FOREIGN KEY ("postId") REFERENCES public."Post"(id); - - --- --- Name: user_following_users FK_503e9a09612f9668063099baff1; Type: FK CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.user_following_users - ADD CONSTRAINT "FK_503e9a09612f9668063099baff1" FOREIGN KEY (following_id) REFERENCES public."User"("firebaseUid"); - - --- --- Name: UserReview FK_53a14948aa4e941762a403144ea; Type: FK CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."UserReview" - ADD CONSTRAINT "FK_53a14948aa4e941762a403144ea" FOREIGN KEY ("buyerId") REFERENCES public."User"("firebaseUid"); - - --- --- Name: postEventTags FK_61151ebab50db74ea513ff8bd87; Type: FK CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."postEventTags" - ADD CONSTRAINT "FK_61151ebab50db74ea513ff8bd87" FOREIGN KEY (posts) REFERENCES public."Post"(id) ON UPDATE CASCADE ON DELETE CASCADE; - - --- --- Name: notifications FK_692a909ee0fa9383e7859f9b406; Type: FK CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.notifications - ADD CONSTRAINT "FK_692a909ee0fa9383e7859f9b406" FOREIGN KEY ("userId") REFERENCES public."User"("firebaseUid"); - - --- --- Name: postEventTags FK_7532bd6ca893c432ffcfa21f755; Type: FK CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."postEventTags" - ADD CONSTRAINT "FK_7532bd6ca893c432ffcfa21f755" FOREIGN KEY ("eventTags") REFERENCES public."EventTag"(id); - - --- --- Name: userBlockingUsers FK_793578cc63c2442a7944e93131a; Type: FK CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."userBlockingUsers" - ADD CONSTRAINT "FK_793578cc63c2442a7944e93131a" FOREIGN KEY (blockers) REFERENCES public."User"("firebaseUid") ON UPDATE CASCADE ON DELETE CASCADE; - - --- --- Name: user_following_users FK_80ef95f34370fd0704c156c13ef; Type: FK CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.user_following_users - ADD CONSTRAINT "FK_80ef95f34370fd0704c156c13ef" FOREIGN KEY (follower_id) REFERENCES public."User"("firebaseUid") ON UPDATE CASCADE ON DELETE CASCADE; - - --- --- Name: postCategories FK_978f319769e3d7285d6d2e40af8; Type: FK CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."postCategories" - ADD CONSTRAINT "FK_978f319769e3d7285d6d2e40af8" FOREIGN KEY (posts) REFERENCES public."Post"(id) ON UPDATE CASCADE ON DELETE CASCADE; - - --- --- Name: Post FK_97e81bcb59530bfb061e48aee6a; Type: FK CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."Post" - ADD CONSTRAINT "FK_97e81bcb59530bfb061e48aee6a" FOREIGN KEY ("userId") REFERENCES public."User"("firebaseUid") ON DELETE CASCADE; - - --- --- Name: Report FK_a050c9cf7f461bc8fc040a48e0a; Type: FK CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."Report" - ADD CONSTRAINT "FK_a050c9cf7f461bc8fc040a48e0a" FOREIGN KEY ("reporterFirebaseUid") REFERENCES public."User"("firebaseUid"); - - --- --- Name: userSavedPosts FK_baa3d7e5e872010a3c23e981532; Type: FK CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."userSavedPosts" - ADD CONSTRAINT "FK_baa3d7e5e872010a3c23e981532" FOREIGN KEY (saved) REFERENCES public."Post"(id) ON UPDATE CASCADE ON DELETE CASCADE; - - --- --- Name: Transaction FK_bba9ded63ef0013ac2ec578f246; Type: FK CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."Transaction" - ADD CONSTRAINT "FK_bba9ded63ef0013ac2ec578f246" FOREIGN KEY ("postId") REFERENCES public."Post"(id); - - --- --- Name: userBlockingUsers FK_bc2ca85580a5c620ccc7f03f5db; Type: FK CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."userBlockingUsers" - ADD CONSTRAINT "FK_bc2ca85580a5c620ccc7f03f5db" FOREIGN KEY (blocking) REFERENCES public."User"("firebaseUid"); - - --- --- Name: Request FK_cdaf52464b00ac3016a8f6110fd; Type: FK CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."Request" - ADD CONSTRAINT "FK_cdaf52464b00ac3016a8f6110fd" FOREIGN KEY ("userId") REFERENCES public."User"("firebaseUid") ON DELETE CASCADE; - - --- --- Name: FCMToken FK_d215a8d66e472d872409915f7d5; Type: FK CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."FCMToken" - ADD CONSTRAINT "FK_d215a8d66e472d872409915f7d5" FOREIGN KEY ("userId") REFERENCES public."User"("firebaseUid"); - - --- --- Name: Report FK_dd826149b8ac72ddc2d1f4e234e; Type: FK CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."Report" - ADD CONSTRAINT "FK_dd826149b8ac72ddc2d1f4e234e" FOREIGN KEY ("messageId") REFERENCES public."Message"(id); - - --- --- Name: eventPostRelationships FK_eventPost_eventTagId; Type: FK CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."eventPostRelationships" - ADD CONSTRAINT "FK_eventPost_eventTagId" FOREIGN KEY ("eventTagId") REFERENCES public."EventTag"(id) ON DELETE CASCADE; - - --- --- Name: eventPostRelationships FK_eventPost_postId; Type: FK CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."eventPostRelationships" - ADD CONSTRAINT "FK_eventPost_postId" FOREIGN KEY ("postId") REFERENCES public."Post"(id) ON DELETE CASCADE; - - --- --- Name: TransactionReview FK_f7cf58b571d5c57ed9da155c628; Type: FK CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."TransactionReview" - ADD CONSTRAINT "FK_f7cf58b571d5c57ed9da155c628" FOREIGN KEY ("transactionId") REFERENCES public."Transaction"(id); - - --- --- Name: searches FK_fc8760cf4823ab84b0cb28d3dad; Type: FK CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.searches - ADD CONSTRAINT "FK_fc8760cf4823ab84b0cb28d3dad" FOREIGN KEY ("firebaseUid") REFERENCES public."User"("firebaseUid") ON DELETE CASCADE; - - --- --- Name: requestMatchesPosts FK_fd473bd2ef9b7a23f41a40ebed4; Type: FK CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public."requestMatchesPosts" - ADD CONSTRAINT "FK_fd473bd2ef9b7a23f41a40ebed4" FOREIGN KEY (matches) REFERENCES public."Post"(id) ON UPDATE CASCADE ON DELETE CASCADE; - - --- --- Name: user_following_users FK_user_following_users_follower_id; Type: FK CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.user_following_users - ADD CONSTRAINT "FK_user_following_users_follower_id" FOREIGN KEY (follower_id) REFERENCES public."User"("firebaseUid") ON UPDATE CASCADE ON DELETE CASCADE; - - --- --- Name: user_following_users FK_user_following_users_following_id; Type: FK CONSTRAINT; Schema: public; Owner: - --- - -ALTER TABLE ONLY public.user_following_users - ADD CONSTRAINT "FK_user_following_users_following_id" FOREIGN KEY (following_id) REFERENCES public."User"("firebaseUid") ON UPDATE CASCADE ON DELETE CASCADE; - - --- --- PostgreSQL database dump complete --- - -\unrestrict j0zS1YybO7IPtcJxy9ONeBKIaXJBXaXxzwxKQnVNLQIIVc1bKUCxYazgBD8jnUr - From b22aa9c13c8a656fdb34cbe8c1e1c7e8d717aff9 Mon Sep 17 00:00:00 2001 From: Lauren Ah-Hot Date: Wed, 25 Mar 2026 16:20:41 -0400 Subject: [PATCH 4/5] updated swagger --- swagger.json | 141 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 141 insertions(+) diff --git a/swagger.json b/swagger.json index 1b88a22..bd320b7 100644 --- a/swagger.json +++ b/swagger.json @@ -59,6 +59,10 @@ { "name": "UserReview", "description": "User review management endpoints" + }, + { + "name": "Event", + "description": "Event tagging and feed endpoints" } ], "paths": { @@ -3115,6 +3119,85 @@ } } } + }, + "/event/available-for-tagging/": { + "get": { + "tags": ["Event"], + "summary": "Get events available for tagging", + "description": "Returns all event tags that are currently available for users to tag their posts with.", + "security": [{ "bearerAuth": [] }], + "responses": { + "200": { + "description": "List of available event tags", + "content": { + "application/json": { + "schema": { + "type": "array", + "items": { + "$ref": "#/components/schemas/EventTag" + } + } + } + } + } + } + } + }, + "/event/{eventTagId}/posts/": { + "get": { + "tags": ["Event"], + "summary": "Get posts for an event feed", + "description": "Returns a paginated list of posts associated with an event, combining user-tagged, similarity, and NLP-sourced posts. Posts are ordered by layer priority (user → similarity → NLP) and then by relevance score or recency within each layer.", + "security": [{ "bearerAuth": [] }], + "parameters": [ + { + "name": "eventTagId", + "in": "path", + "required": true, + "schema": { "type": "string", "format": "uuid" }, + "description": "The UUID of the event tag" + }, + { + "name": "page", + "in": "query", + "required": false, + "schema": { "type": "integer", "default": 1 }, + "description": "Page number for pagination" + }, + { + "name": "limit", + "in": "query", + "required": false, + "schema": { "type": "integer", "default": 10 }, + "description": "Number of posts per page" + }, + { + "name": "source", + "in": "query", + "required": false, + "schema": { + "type": "string", + "enum": ["user", "similarity", "nlp_context"] + }, + "description": "Filter posts by source layer" + } + ], + "responses": { + "200": { + "description": "Paginated event feed", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/GetEventPostsResponse" + } + } + } + }, + "404": { + "description": "Event not found" + } + } + } } }, "components": { @@ -4188,6 +4271,64 @@ } } } + }, + "EventTag": { + "type": "object", + "required": ["id", "name"], + "properties": { + "id": { + "type": "string", + "format": "uuid", + "description": "Unique identifier for the event tag" + }, + "name": { + "type": "string", + "description": "Name of the event tag (e.g. SPRING_FAIR, CLEARANCE)" + } + } + }, + "PostWithSource": { + "allOf": [ + { "$ref": "#/components/schemas/Post" }, + { + "type": "object", + "required": ["source", "relevanceScore"], + "properties": { + "source": { + "type": "string", + "enum": ["user", "similarity", "nlp_context"], + "description": "Which layer added this post to the event feed" + }, + "relevanceScore": { + "type": "number", + "nullable": true, + "description": "Similarity or NLP relevance score (null for user-tagged posts)" + } + } + } + ] + }, + "GetEventPostsResponse": { + "type": "object", + "required": ["posts", "total", "page", "limit"], + "properties": { + "posts": { + "type": "array", + "items": { "$ref": "#/components/schemas/PostWithSource" } + }, + "total": { + "type": "integer", + "description": "Total number of posts matching the query" + }, + "page": { + "type": "integer", + "description": "Current page number" + }, + "limit": { + "type": "integer", + "description": "Number of posts per page" + } + } } } } From 0fea8e773c9c4f15cc092327addd996bb300c500 Mon Sep 17 00:00:00 2001 From: Lauren Ah-Hot Date: Tue, 14 Apr 2026 13:44:06 -0400 Subject: [PATCH 5/5] fixed coderabbitai comments --- src/models/EventPostModel.ts | 3 ++- src/repositories/EventPostRepository.ts | 19 +++++++++++++++++-- src/repositories/PostRepository.ts | 5 +++++ src/repositories/RequestRepository.ts | 1 + src/services/EventService.ts | 20 +++----------------- src/services/PostService.ts | 5 +++++ 6 files changed, 33 insertions(+), 20 deletions(-) diff --git a/src/models/EventPostModel.ts b/src/models/EventPostModel.ts index 035243c..343a93a 100644 --- a/src/models/EventPostModel.ts +++ b/src/models/EventPostModel.ts @@ -15,7 +15,8 @@ import { EventTagModel } from "./EventTagModel"; export type EventPostSource = "user" | "similarity" | "nlp_context"; @Entity("eventPosts") -@Unique(["postId", "eventTagId"]) // Enforces one row per post per event, so ML layer can't insert another row if event already user-tagged +// Enforces one row per post per event, so ML layer can't insert another row if event already user-tagged +@Unique(["postId", "eventTagId"]) export class EventPostModel { @PrimaryGeneratedColumn("uuid") id: Uuid; diff --git a/src/repositories/EventPostRepository.ts b/src/repositories/EventPostRepository.ts index 94c888a..ca3e4ea 100644 --- a/src/repositories/EventPostRepository.ts +++ b/src/repositories/EventPostRepository.ts @@ -78,6 +78,7 @@ export class EventPostRepository extends AbstractRepository { public async getPostsForEvent( eventTagId: string, + requestingUserId: string, source?: EventPostSource, skip: number = 0, limit: number = 10, @@ -88,7 +89,13 @@ export class EventPostRepository extends AbstractRepository { .addSelect(EventPostRepository.SOURCE_PRIORITY_EXPR, "source_priority") .addSelect(EventPostRepository.SCORE_OR_RECENCY_EXPR, "score_or_recency") .innerJoin("epr.post", "post") - .where("epr.eventTagId = :eventTagId", { eventTagId }); + .innerJoin("post.user", "author") + .where("epr.eventTagId = :eventTagId", { eventTagId }) + .andWhere("author.isActive = true") + .andWhere( + `author.firebaseUid NOT IN (SELECT "blocking" FROM "userBlockingUsers" WHERE "blockers" = :requestingUserId)`, + { requestingUserId }, + ); if (source) { qb.andWhere("epr.source = :source", { source }); @@ -124,11 +131,19 @@ export class EventPostRepository extends AbstractRepository { */ public async getPostCountForEvent( eventTagId: string, + requestingUserId: string, source?: EventPostSource, ): Promise { const qb = this.repository .createQueryBuilder("epr") - .where("epr.eventTagId = :eventTagId", { eventTagId }); + .innerJoin("epr.post", "post") + .innerJoin("post.user", "author") + .where("epr.eventTagId = :eventTagId", { eventTagId }) + .andWhere("author.isActive = true") + .andWhere( + `author.firebaseUid NOT IN (SELECT "blocking" FROM "userBlockingUsers" WHERE "blockers" = :requestingUserId)`, + { requestingUserId }, + ); if (source) { qb.andWhere("epr.source = :source", { source }); diff --git a/src/repositories/PostRepository.ts b/src/repositories/PostRepository.ts index 650d469..45270dd 100644 --- a/src/repositories/PostRepository.ts +++ b/src/repositories/PostRepository.ts @@ -522,6 +522,8 @@ export class PostRepository extends AbstractRepository { .createQueryBuilder("post") .leftJoinAndSelect("post.user", "user") .where("post.id != :excludePostId", { excludePostId }) + .andWhere("post.embedding IS NOT NULL") + .andWhere("array_length(post.embedding, 1) = 512") .andWhere("user.firebaseUid != :excludeUserId", { excludeUserId }) .orderBy(`embedding::vector <-> CAST('${lit}' AS vector(512))`) .setParameters({ embedding: queryEmbedding }) @@ -542,6 +544,7 @@ export class PostRepository extends AbstractRepository { .createQueryBuilder("post") .leftJoinAndSelect("post.user", "user") .where("post.embedding IS NOT NULL") + .andWhere("array_length(post.embedding, 1) = 512") .andWhere("user.firebaseUid != :excludeUserId", { excludeUserId }) .orderBy(`post.embedding::vector <-> CAST('${lit}' AS vector(512))`) .limit(limit) @@ -567,6 +570,7 @@ export class PostRepository extends AbstractRepository { .select("post.id", "id") .addSelect(scoreExpr, "score") .where("post.embedding IS NOT NULL") + .andWhere("array_length(post.embedding, 1) = 512") .andWhere("post.archive = false") .andWhere("post.sold = false") .andWhere(`${scoreExpr} >= :threshold`, { threshold }); @@ -712,6 +716,7 @@ export class PostRepository extends AbstractRepository { .createQueryBuilder("post") .leftJoinAndSelect("post.user", "user") .where("post.embedding IS NOT NULL") + .andWhere("array_length(post.embedding, 1) = 512") .andWhere("post.archive = false") .andWhere("post.sold = false") .andWhere("user.firebaseUid != :excludeUserId", { excludeUserId }) diff --git a/src/repositories/RequestRepository.ts b/src/repositories/RequestRepository.ts index d72dfc4..db1e8e0 100644 --- a/src/repositories/RequestRepository.ts +++ b/src/repositories/RequestRepository.ts @@ -128,6 +128,7 @@ export class RequestRepository extends AbstractRepository { "distance", ) .where("request.embedding IS NOT NULL") + .andWhere("array_length(request.embedding, 1) = 512") .andWhere("user.firebaseUid != :excludeUserId", { excludeUserId }) // 3. Safely pass the embedding string as a parameter .setParameter("embedding", embeddingString) diff --git a/src/services/EventService.ts b/src/services/EventService.ts index 74f93a3..1c99a34 100644 --- a/src/services/EventService.ts +++ b/src/services/EventService.ts @@ -32,7 +32,6 @@ export class EventService { return this.transactions.readOnly(async (transactionalEntityManager) => { const eventTagRepo = Repositories.eventTag(transactionalEntityManager); const eventPostRepo = Repositories.eventPost(transactionalEntityManager); - const userRepo = Repositories.user(transactionalEntityManager); // Validate event tag exists const matches = await eventTagRepo.findByIds([eventTagId]); @@ -40,25 +39,12 @@ export class EventService { const skip = (page - 1) * limit; - // Fetch paginated relationships and total count in parallel const [relationships, total] = await Promise.all([ - eventPostRepo.getPostsForEvent(eventTagId, source, skip, limit), - eventPostRepo.getPostCountForEvent(eventTagId, source), + eventPostRepo.getPostsForEvent(eventTagId, user.firebaseUid, source, skip, limit), + eventPostRepo.getPostCountForEvent(eventTagId, user.firebaseUid, source), ]); - // Filter inactive and blocked users - const userWithBlockedInfo = await userRepo.getUserWithBlockedInfo(user.firebaseUid); - const blockedUids = new Set( - userWithBlockedInfo?.blocking?.map(u => u.firebaseUid) ?? [], - ); - - const filtered = relationships.filter(r => - r.post?.user?.isActive && - !blockedUids.has(r.post.user.firebaseUid), - ); - - // Attach source + relevanceScore to each post - const posts: PostWithSource[] = filtered.map(r => + const posts: PostWithSource[] = relationships.map(r => Object.assign(r.post, { source: r.source, relevanceScore: r.relevanceScore, diff --git a/src/services/PostService.ts b/src/services/PostService.ts index f34790b..1d6d60f 100644 --- a/src/services/PostService.ts +++ b/src/services/PostService.ts @@ -556,6 +556,11 @@ export class PostService { const eventPostRepository = Repositories.eventPost(transactionalEntityManager); for (const tag of removedTags) { await eventPostRepository.deleteRelationship(post.id, tag.id); + + const remainingSeeds = await eventPostRepository.getUserTaggedPostsForEvent(tag.id); + if (remainingSeeds.length === 0) { + await eventPostRepository.deleteRelationshipsBySourceForEvent(tag.id, 'similarity'); + } } post.eventTags = post.eventTags?.filter(tag => !tagsToRemoveNames.has(tag.name)) || [];