From 9de857d15579c55967fb64c8b08032140d6f2f44 Mon Sep 17 00:00:00 2001 From: Rami Abdou Date: Wed, 3 Apr 2024 09:04:11 -0700 Subject: [PATCH 01/14] initialize --- package.json | 8 +- packages/core/package.json | 6 +- packages/db/.env.example | 5 + packages/db/.env.test.example | 2 + packages/db/package.json | 29 + packages/db/src/index.ts | 3 + .../migrations/2024-01-29T17:23:16Z-init.ts | 1821 +++++++++++++++++ .../2024-01-29T19:05:29Z-birthdate.ts | 12 + .../2024-02-12T21:28:42Z-fix-removal.ts | 93 + .../2024-03-11T10:33:01Z-job_offers.ts | 36 + ...4-03-18T17:06:13Z-birthday-notification.ts | 15 + .../2024-03-18T19:45:26Z-birthday-default.ts | 39 + .../2024-03-31T21:37:51Z-share-email.ts | 17 + packages/db/src/scripts/migrate.ts | 16 + packages/db/src/scripts/seed.ts | 175 ++ packages/db/src/scripts/setup.sql | 11 + packages/db/src/scripts/setup.ts | 37 + .../src/shared/create-database-connection.ts | 26 + packages/db/src/shared/env.ts | 10 + packages/db/src/shared/migrate.ts | 80 + packages/db/src/shared/truncate.ts | 31 + packages/db/src/test/constants.ts | 32 + packages/db/src/test/setup.global.ts | 10 + packages/db/src/test/setup.ts | 22 + packages/db/tsconfig.json | 10 + 25 files changed, 2537 insertions(+), 9 deletions(-) create mode 100644 packages/db/.env.example create mode 100644 packages/db/.env.test.example create mode 100644 packages/db/package.json create mode 100644 packages/db/src/index.ts create mode 100644 packages/db/src/migrations/2024-01-29T17:23:16Z-init.ts create mode 100644 packages/db/src/migrations/2024-01-29T19:05:29Z-birthdate.ts create mode 100644 packages/db/src/migrations/2024-02-12T21:28:42Z-fix-removal.ts create mode 100644 packages/db/src/migrations/2024-03-11T10:33:01Z-job_offers.ts create mode 100644 packages/db/src/migrations/2024-03-18T17:06:13Z-birthday-notification.ts create mode 100644 packages/db/src/migrations/2024-03-18T19:45:26Z-birthday-default.ts create mode 100644 packages/db/src/migrations/2024-03-31T21:37:51Z-share-email.ts create mode 100644 packages/db/src/scripts/migrate.ts create mode 100644 packages/db/src/scripts/seed.ts create mode 100644 packages/db/src/scripts/setup.sql create mode 100644 packages/db/src/scripts/setup.ts create mode 100644 packages/db/src/shared/create-database-connection.ts create mode 100644 packages/db/src/shared/env.ts create mode 100644 packages/db/src/shared/migrate.ts create mode 100644 packages/db/src/shared/truncate.ts create mode 100644 packages/db/src/test/constants.ts create mode 100644 packages/db/src/test/setup.global.ts create mode 100644 packages/db/src/test/setup.ts create mode 100644 packages/db/tsconfig.json diff --git a/package.json b/package.json index 94536209..613b6301 100644 --- a/package.json +++ b/package.json @@ -9,10 +9,10 @@ }, "scripts": { "build": "turbo run build --cache-dir=.turbo", - "db:migrate": "yarn workspace @oyster/core db:migrate", - "db:seed": "yarn workspace @oyster/core db:seed", - "db:setup": "yarn workspace @oyster/core db:setup", - "db:types": "yarn workspace @oyster/core db:types", + "db:migrate": "yarn workspace @oyster/db migrate", + "db:seed": "yarn workspace @oyster/db seed", + "db:setup": "yarn workspace @oyster/db setup", + "db:types": "yarn workspace @oyster/db types", "dev": "turbo run dev --cache-dir=.turbo", "dev:apps": "yarn dev --filter='./apps/*'", "lint": "turbo run lint --cache-dir=.turbo", diff --git a/packages/core/package.json b/packages/core/package.json index 3dbfb7e1..ab4dcd67 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -16,16 +16,12 @@ }, "scripts": { "build": "tsup", - "db:migrate": "tsx ./src/infrastructure/database/scripts/migrate.ts && yarn db:types", - "db:migrate:down": "tsx ./src/infrastructure/database/scripts/migrate.ts --down && yarn db:types", - "db:seed": "tsx ./src/infrastructure/database/scripts/seed.ts && yarn db:types", - "db:setup": "tsx ./src/infrastructure/database/scripts/setup.ts", - "db:types": "kysely-codegen --dialect=postgres --camel-case", "test": "vitest run", "type-check": "tsc --noEmit" }, "dependencies": { "@mailchimp/mailchimp_marketing": "^3.0.78", + "@oyster/db": "*", "@oyster/email-templates": "*", "@oyster/types": "*", "@oyster/utils": "*", diff --git a/packages/db/.env.example b/packages/db/.env.example new file mode 100644 index 00000000..34410540 --- /dev/null +++ b/packages/db/.env.example @@ -0,0 +1,5 @@ +# This is only needed for automatically generating types from the database +# using `kysely-codegen`. See the following: +# https://github.com/RobinBlomberg/kysely-codegen?tab=readme-ov-file#generating-type-definitions +DATABASE_URL=postgresql://colorstack:colorstack@localhost:5432/colorstack +ENVIRONMENT=development \ No newline at end of file diff --git a/packages/db/.env.test.example b/packages/db/.env.test.example new file mode 100644 index 00000000..39351de9 --- /dev/null +++ b/packages/db/.env.test.example @@ -0,0 +1,2 @@ +DATABASE_URL=postgresql://colorstack:colorstack@localhost:5432/colorstack_test +ENVIRONMENT=test \ No newline at end of file diff --git a/packages/db/package.json b/packages/db/package.json new file mode 100644 index 00000000..74a06c0a --- /dev/null +++ b/packages/db/package.json @@ -0,0 +1,29 @@ +{ + "name": "@oyster/db", + "version": "0.0.0", + "private": true, + "type": "module", + "exports": { + ".": "./index.ts" + }, + "scripts": { + "migrate": "tsx ./src/scripts/migrate.ts && yarn db:types", + "migrate:down": "tsx ./src/scripts/migrate.ts --down && yarn db:types", + "seed": "tsx ./src/scripts/seed.ts && yarn db:types", + "setup": "tsx ./src/scripts/setup.ts", + "type-check": "tsc --noEmit", + "types": "kysely-codegen --dialect=postgres --camel-case" + }, + "dependencies": { + "kysely": "^0.26.3", + "pg": "^8.8.0" + }, + "devDependencies": { + "@oyster/tsconfig": "*", + "@types/pg": "^8.11.2", + "commander": "^12.0.0", + "kysely-codegen": "^0.10.1", + "vite": "^5.0.0", + "vite-tsconfig-paths": "^4.3.1" + } +} diff --git a/packages/db/src/index.ts b/packages/db/src/index.ts new file mode 100644 index 00000000..3f9c92ce --- /dev/null +++ b/packages/db/src/index.ts @@ -0,0 +1,3 @@ +import { createDatabaseConnection } from './shared/create-database-connection'; + +export const db = createDatabaseConnection(); diff --git a/packages/db/src/migrations/2024-01-29T17:23:16Z-init.ts b/packages/db/src/migrations/2024-01-29T17:23:16Z-init.ts new file mode 100644 index 00000000..67ff67b9 --- /dev/null +++ b/packages/db/src/migrations/2024-01-29T17:23:16Z-init.ts @@ -0,0 +1,1821 @@ +import { Kysely, sql } from 'kysely'; + +export async function up(db: Kysely) { + const result = await sql` + -- + -- PostgreSQL database dump + -- + + -- Dumped from database version 15.4 (Ubuntu 15.4-2.pgdg22.04+1) + -- Dumped by pg_dump version 15.5 (Homebrew) + + -- + -- Name: cube; Type: EXTENSION; Schema: -; Owner: - + -- + + CREATE EXTENSION IF NOT EXISTS cube WITH SCHEMA public; + + + -- + -- Name: EXTENSION cube; Type: COMMENT; Schema: -; Owner: + -- + + COMMENT ON EXTENSION cube IS 'data type for multidimensional cubes'; + + + -- + -- Name: earthdistance; Type: EXTENSION; Schema: -; Owner: - + -- + + CREATE EXTENSION IF NOT EXISTS earthdistance WITH SCHEMA public; + + + -- + -- Name: EXTENSION earthdistance; Type: COMMENT; Schema: -; Owner: + -- + + COMMENT ON EXTENSION earthdistance IS 'calculate great-circle distances on the surface of the Earth'; + + + -- + -- Name: pg_trgm; Type: EXTENSION; Schema: -; Owner: - + -- + + CREATE EXTENSION IF NOT EXISTS pg_trgm WITH SCHEMA public; + + + -- + -- Name: EXTENSION pg_trgm; Type: COMMENT; Schema: -; Owner: + -- + + COMMENT ON EXTENSION pg_trgm IS 'text similarity measurement and index searching based on trigrams'; + + + -- + -- Name: applications_other_demographics_enum; Type: TYPE; Schema: public; Owner: postgres + -- + + CREATE TYPE public.applications_other_demographics_enum AS ENUM ( + 'DISABILITY', + 'FIRST_GENERATION', + 'LOW_INCOME' + ); + + -- + -- Name: applications_race_enum; Type: TYPE; Schema: public; Owner: postgres + -- + + CREATE TYPE public.applications_race_enum AS ENUM ( + 'ASIAN', + 'BLACK', + 'HISPANIC', + 'MIDDLE_EASTERN', + 'NATIVE_AMERICAN', + 'OTHER', + 'WHITE' + ); + + -- + -- Name: students_other_demographics_enum; Type: TYPE; Schema: public; Owner: postgres + -- + + CREATE TYPE public.students_other_demographics_enum AS ENUM ( + 'DISABILITY', + 'FIRST_GENERATION', + 'LOW_INCOME' + ); + + + -- + -- Name: students_race_enum; Type: TYPE; Schema: public; Owner: postgres + -- + + CREATE TYPE public.students_race_enum AS ENUM ( + 'ASIAN', + 'BLACK', + 'HISPANIC', + 'MIDDLE_EASTERN', + 'NATIVE_AMERICAN', + 'OTHER', + 'WHITE' + ); + + + SET default_tablespace = ''; + + SET default_table_access_method = heap; + + -- + -- Name: activities; Type: TABLE; Schema: public; Owner: postgres + -- + + CREATE TABLE public.activities ( + created_at timestamp with time zone DEFAULT now() NOT NULL, + deleted_at timestamp with time zone, + id text NOT NULL, + updated_at timestamp with time zone DEFAULT now() NOT NULL, + type text NOT NULL, + description text, + name text NOT NULL, + points smallint NOT NULL, + period text + ); + + -- + -- Name: admins; Type: TABLE; Schema: public; Owner: postgres + -- + + CREATE TABLE public.admins ( + created_at timestamp with time zone DEFAULT now() NOT NULL, + deleted_at timestamp with time zone, + id text NOT NULL, + updated_at timestamp with time zone DEFAULT now() NOT NULL, + email text NOT NULL, + first_name text NOT NULL, + last_name text NOT NULL, + is_ambassador boolean DEFAULT false NOT NULL + ); + + -- + -- Name: applications; Type: TABLE; Schema: public; Owner: postgres + -- + + CREATE TABLE public.applications ( + created_at timestamp with time zone DEFAULT now() NOT NULL, + deleted_at timestamp with time zone, + id text NOT NULL, + updated_at timestamp with time zone DEFAULT now() NOT NULL, + accepted_at timestamp with time zone, + contribution text NOT NULL, + education_level text NOT NULL, + email text NOT NULL, + first_name text NOT NULL, + gender text NOT NULL, + goals text NOT NULL, + graduation_year integer NOT NULL, + last_name text NOT NULL, + linked_in_url text NOT NULL, + major text NOT NULL, + other_demographics text[] NOT NULL, + other_major text, + other_school text, + race text[] NOT NULL, + rejected_at timestamp with time zone, + school_id text, + status text NOT NULL, + reviewed_by_id text + ); + + -- + -- Name: companies; Type: TABLE; Schema: public; Owner: postgres + -- + + CREATE TABLE public.companies ( + created_at timestamp with time zone DEFAULT now() NOT NULL, + deleted_at timestamp with time zone, + id text NOT NULL, + updated_at timestamp with time zone DEFAULT now() NOT NULL, + name text NOT NULL, + crunchbase_id text NOT NULL, + description text, + domain text, + image_url text, + stock_symbol text + ); + + -- + -- Name: completed_activities; Type: TABLE; Schema: public; Owner: postgres + -- + + CREATE TABLE public.completed_activities ( + created_at timestamp with time zone DEFAULT now() NOT NULL, + id text NOT NULL, + activity_id text, + occurred_at timestamp with time zone NOT NULL, + points smallint NOT NULL, + student_id text NOT NULL, + channel_id text, + message_reacted_to text, + thread_replied_to text, + event_attended text, + type text NOT NULL, + survey_responded_to text, + description text + ); + + -- + -- Name: countries; Type: TABLE; Schema: public; Owner: postgres + -- + + CREATE TABLE public.countries ( + code text NOT NULL, + demonym text NOT NULL, + flag_emoji text NOT NULL, + latitude text NOT NULL, + longitude text NOT NULL, + name text NOT NULL, + region text NOT NULL, + subregion text + ); + + -- + -- Name: educations; Type: TABLE; Schema: public; Owner: postgres + -- + + CREATE TABLE public.educations ( + created_at timestamp with time zone DEFAULT now() NOT NULL, + deleted_at timestamp with time zone, + id text NOT NULL, + updated_at timestamp with time zone DEFAULT now() NOT NULL, + degree_type text NOT NULL, + end_date date NOT NULL, + major text NOT NULL, + other_major text, + other_school text, + school_id text, + start_date date NOT NULL, + student_id text NOT NULL + ); + + -- + -- Name: email_campaign_clicks; Type: TABLE; Schema: public; Owner: postgres + -- + + CREATE TABLE public.email_campaign_clicks ( + created_at timestamp with time zone DEFAULT now() NOT NULL, + deleted_at timestamp with time zone, + id text NOT NULL, + updated_at timestamp with time zone DEFAULT now() NOT NULL, + campaign_id text NOT NULL, + clicked_at timestamp with time zone NOT NULL, + email text NOT NULL, + link_id text NOT NULL, + platform text NOT NULL, + student_id text + ); + + -- + -- Name: email_campaign_links; Type: TABLE; Schema: public; Owner: postgres + -- + + CREATE TABLE public.email_campaign_links ( + created_at timestamp with time zone DEFAULT now() NOT NULL, + deleted_at timestamp with time zone, + id text NOT NULL, + updated_at timestamp with time zone DEFAULT now() NOT NULL, + campaign_id text NOT NULL, + url text NOT NULL, + platform text NOT NULL + ); + + -- + -- Name: email_campaign_opens; Type: TABLE; Schema: public; Owner: postgres + -- + + CREATE TABLE public.email_campaign_opens ( + created_at timestamp with time zone DEFAULT now() NOT NULL, + deleted_at timestamp with time zone, + id text NOT NULL, + updated_at timestamp with time zone DEFAULT now() NOT NULL, + campaign_id text NOT NULL, + email text NOT NULL, + opened_at timestamp with time zone NOT NULL, + platform text NOT NULL, + student_id text + ); + + -- + -- Name: email_campaigns; Type: TABLE; Schema: public; Owner: postgres + -- + + CREATE TABLE public.email_campaigns ( + created_at timestamp with time zone DEFAULT now() NOT NULL, + deleted_at timestamp with time zone, + id text NOT NULL, + updated_at timestamp with time zone DEFAULT now() NOT NULL, + content text NOT NULL, + list_id text NOT NULL, + platform text NOT NULL, + sent_at timestamp with time zone, + subject text NOT NULL, + title text, + archive_url text, + sent_count integer, + last_synced_at timestamp with time zone + ); + + -- + -- Name: email_lists; Type: TABLE; Schema: public; Owner: postgres + -- + + CREATE TABLE public.email_lists ( + created_at timestamp with time zone DEFAULT now() NOT NULL, + deleted_at timestamp with time zone, + id text NOT NULL, + updated_at timestamp with time zone DEFAULT now() NOT NULL, + name text NOT NULL, + platform text NOT NULL + ); + + -- + -- Name: event_attendees; Type: TABLE; Schema: public; Owner: postgres + -- + + CREATE TABLE public.event_attendees ( + created_at timestamp with time zone DEFAULT now() NOT NULL, + email text NOT NULL, + name text, + student_id text, + event_id text NOT NULL + ); + + -- + -- Name: event_registrations; Type: TABLE; Schema: public; Owner: postgres + -- + + CREATE TABLE public.event_registrations ( + email text NOT NULL, + event_id text NOT NULL, + registered_at timestamp with time zone NOT NULL, + student_id text NOT NULL + ); + + -- + -- Name: events; Type: TABLE; Schema: public; Owner: postgres + -- + + CREATE TABLE public.events ( + created_at timestamp with time zone DEFAULT now() NOT NULL, + deleted_at timestamp with time zone, + id text NOT NULL, + end_time timestamp with time zone NOT NULL, + name text NOT NULL, + start_time timestamp with time zone NOT NULL, + type text NOT NULL, + description text, + external_link text + ); + + -- + -- Name: icebreaker_prompts; Type: TABLE; Schema: public; Owner: postgres + -- + + CREATE TABLE public.icebreaker_prompts ( + deleted_at timestamp with time zone, + id text NOT NULL, + text text NOT NULL + ); + + -- + -- Name: icebreaker_responses; Type: TABLE; Schema: public; Owner: postgres + -- + + CREATE TABLE public.icebreaker_responses ( + id text NOT NULL, + prompt_id text NOT NULL, + responded_at timestamp with time zone DEFAULT now() NOT NULL, + student_id text NOT NULL, + text text NOT NULL + ); + + -- + -- Custom... + -- + + -- + -- Name: member_ethnicities; Type: TABLE; Schema: public; Owner: postgres + -- + + CREATE TABLE public.member_ethnicities ( + country_code text NOT NULL, + student_id text NOT NULL + ); + + -- + -- Name: migrations; Type: TABLE; Schema: public; Owner: postgres + -- + + 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: postgres + -- + + 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: postgres + -- + + ALTER SEQUENCE public.migrations_id_seq OWNED BY public.migrations.id; + + + -- + -- Name: onboarding_session_attendees; Type: TABLE; Schema: public; Owner: postgres + -- + + CREATE TABLE public.onboarding_session_attendees ( + created_at timestamp with time zone DEFAULT now() NOT NULL, + deleted_at timestamp with time zone, + id text NOT NULL, + updated_at timestamp with time zone DEFAULT now() NOT NULL, + session_id text NOT NULL, + student_id text NOT NULL + ); + + -- + -- Name: onboarding_sessions; Type: TABLE; Schema: public; Owner: postgres + -- + + CREATE TABLE public.onboarding_sessions ( + created_at timestamp with time zone DEFAULT now() NOT NULL, + deleted_at timestamp with time zone, + id text NOT NULL, + updated_at timestamp with time zone DEFAULT now() NOT NULL, + date date NOT NULL, + "group" integer NOT NULL + ); + + -- + -- Name: onboarding_sessions_group_seq; Type: SEQUENCE; Schema: public; Owner: postgres + -- + + CREATE SEQUENCE public.onboarding_sessions_group_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + -- + -- Name: onboarding_sessions_group_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres + -- + + ALTER SEQUENCE public.onboarding_sessions_group_seq OWNED BY public.onboarding_sessions."group"; + + + -- + -- Name: one_time_codes; Type: TABLE; Schema: public; Owner: postgres + -- + + CREATE TABLE public.one_time_codes ( + created_at timestamp with time zone DEFAULT now() NOT NULL, + deleted_at timestamp with time zone, + id text NOT NULL, + updated_at timestamp with time zone DEFAULT now() NOT NULL, + admin_id text, + email text NOT NULL, + purpose text NOT NULL, + student_id text, + value text NOT NULL + ); + + -- + -- Name: profile_views; Type: TABLE; Schema: public; Owner: postgres + -- + + CREATE TABLE public.profile_views ( + id text NOT NULL, + profile_viewed_id text NOT NULL, + viewed_at timestamp with time zone DEFAULT now() NOT NULL, + viewer_id text NOT NULL + ); + + -- + -- Name: program_participants; Type: TABLE; Schema: public; Owner: postgres + -- + + CREATE TABLE public.program_participants ( + created_at timestamp with time zone DEFAULT now() NOT NULL, + deleted_at timestamp with time zone, + id text NOT NULL, + updated_at timestamp with time zone DEFAULT now() NOT NULL, + program_id text NOT NULL, + student_id text, + email text + ); + + -- + -- Name: programs; Type: TABLE; Schema: public; Owner: postgres + -- + + CREATE TABLE public.programs ( + created_at timestamp with time zone DEFAULT now() NOT NULL, + deleted_at timestamp with time zone, + id text NOT NULL, + updated_at timestamp with time zone DEFAULT now() NOT NULL, + end_date date NOT NULL, + name text NOT NULL, + start_date date NOT NULL + ); + + -- + -- Name: resource_users; Type: TABLE; Schema: public; Owner: postgres + -- + + CREATE TABLE public.resource_users ( + created_at timestamp with time zone DEFAULT now() NOT NULL, + deleted_at timestamp with time zone, + id text NOT NULL, + updated_at timestamp with time zone DEFAULT now() NOT NULL, + resource_id text NOT NULL, + student_id text, + used_at timestamp with time zone, + email text + ); + + -- + -- Name: resources; Type: TABLE; Schema: public; Owner: postgres + -- + + CREATE TABLE public.resources ( + created_at timestamp with time zone DEFAULT now() NOT NULL, + deleted_at timestamp with time zone, + id text NOT NULL, + updated_at timestamp with time zone DEFAULT now() NOT NULL, + name text NOT NULL, + status text NOT NULL + ); + + -- + -- Name: scholarship_recipients; Type: TABLE; Schema: public; Owner: postgres + -- + + CREATE TABLE public.scholarship_recipients ( + created_at timestamp with time zone DEFAULT now() NOT NULL, + deleted_at timestamp with time zone, + id text NOT NULL, + updated_at timestamp with time zone DEFAULT now() NOT NULL, + amount integer NOT NULL, + reason text NOT NULL, + type text NOT NULL, + student_id text NOT NULL, + awarded_at timestamp with time zone NOT NULL + ); + + -- + -- Name: schools; Type: TABLE; Schema: public; Owner: postgres + -- + + CREATE TABLE public.schools ( + created_at timestamp with time zone DEFAULT now() NOT NULL, + deleted_at timestamp with time zone, + id text NOT NULL, + updated_at timestamp with time zone DEFAULT now() NOT NULL, + address_city text NOT NULL, + address_state text NOT NULL, + address_zip text NOT NULL, + name text NOT NULL, + coordinates point + ); + + -- + -- Name: slack_channels; Type: TABLE; Schema: public; Owner: postgres + -- + + CREATE TABLE public.slack_channels ( + created_at timestamp with time zone DEFAULT now() NOT NULL, + deleted_at timestamp with time zone, + id text NOT NULL, + name text NOT NULL, + type text NOT NULL + ); + + -- + -- Name: slack_messages; Type: TABLE; Schema: public; Owner: postgres + -- + + CREATE TABLE public.slack_messages ( + created_at timestamp with time zone DEFAULT now() NOT NULL, + deleted_at timestamp with time zone, + id text NOT NULL, + channel_id text NOT NULL, + user_id text NOT NULL, + text text, + thread_id text, + student_id text + ); + + -- + -- Name: slack_reactions; Type: TABLE; Schema: public; Owner: postgres + -- + + CREATE TABLE public.slack_reactions ( + created_at timestamp with time zone DEFAULT now() NOT NULL, + user_id text NOT NULL, + message_id text NOT NULL, + reaction text NOT NULL, + student_id text, + channel_id text NOT NULL + ); + + -- + -- Name: student_active_statuses; Type: TABLE; Schema: public; Owner: postgres + -- + + CREATE TABLE public.student_active_statuses ( + date date NOT NULL, + status text NOT NULL, + student_id text NOT NULL + ); + + -- + -- Name: student_emails; Type: TABLE; Schema: public; Owner: postgres + -- + + CREATE TABLE public.student_emails ( + created_at timestamp with time zone DEFAULT now() NOT NULL, + deleted_at timestamp with time zone, + updated_at timestamp with time zone DEFAULT now() NOT NULL, + email text NOT NULL, + student_id text + ); + + -- + -- Name: students; Type: TABLE; Schema: public; Owner: postgres + -- + + CREATE TABLE public.students ( + created_at timestamp with time zone DEFAULT now() NOT NULL, + id text NOT NULL, + updated_at timestamp with time zone DEFAULT now() NOT NULL, + accepted_at timestamp with time zone NOT NULL, + address_city text, + address_line1 text, + address_line2 text, + address_state text, + address_zip text, + application_id text, + applied_at timestamp with time zone, + claimed_swag_pack_at timestamp with time zone, + education_level text NOT NULL, + email text NOT NULL, + first_name text NOT NULL, + gender text NOT NULL, + gender_pronouns text, + graduation_year text NOT NULL, + joined_slack_at timestamp with time zone, + last_name text NOT NULL, + linked_in_url text, + major text NOT NULL, + onboarded_at timestamp with time zone, + other_demographics text[] NOT NULL, + other_major text, + other_school text, + race text[] NOT NULL, + school_id text, + slack_id text, + swag_up_order_id text, + activated_at timestamp with time zone, + activation_requirements_completed text[] DEFAULT '{}'::text[] NOT NULL, + number integer NOT NULL, + preferred_name text, + profile_picture text, + calendly_url text, + github_url text, + instagram_handle text, + personal_website_url text, + twitter_handle text, + headline text, + current_location text, + current_location_coordinates point, + hometown text, + hometown_coordinates point, + joined_member_directory_at timestamp with time zone + ); + + -- + -- Name: students_number_seq; Type: SEQUENCE; Schema: public; Owner: postgres + -- + + CREATE SEQUENCE public.students_number_seq + AS integer + START WITH 1 + INCREMENT BY 1 + NO MINVALUE + NO MAXVALUE + CACHE 1; + + -- + -- Name: students_number_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres + -- + + ALTER SEQUENCE public.students_number_seq OWNED BY public.students.number; + + + -- + -- Name: survey_responses; Type: TABLE; Schema: public; Owner: postgres + -- + + CREATE TABLE public.survey_responses ( + created_at timestamp with time zone DEFAULT now() NOT NULL, + email text NOT NULL, + first_name text NOT NULL, + id text NOT NULL, + last_name text NOT NULL, + responded_on date NOT NULL, + student_id text, + survey_id text NOT NULL + ); + + -- + -- Name: surveys; Type: TABLE; Schema: public; Owner: postgres + -- + + CREATE TABLE public.surveys ( + created_at timestamp with time zone DEFAULT now() NOT NULL, + description text, + event_id text, + id text NOT NULL, + title text NOT NULL + ); + + -- + -- Name: work_experiences; Type: TABLE; Schema: public; Owner: postgres + -- + + CREATE TABLE public.work_experiences ( + created_at timestamp with time zone DEFAULT now() NOT NULL, + deleted_at timestamp with time zone, + id text NOT NULL, + updated_at timestamp with time zone DEFAULT now() NOT NULL, + company_id text, + company_name text, + end_date date, + location_city text, + location_state text, + location_type text NOT NULL, + start_date date NOT NULL, + student_id text NOT NULL, + title text NOT NULL, + employment_type text NOT NULL + ); + + -- + -- Name: migrations id; Type: DEFAULT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.migrations ALTER COLUMN id SET DEFAULT nextval('public.migrations_id_seq'::regclass); + + + -- + -- Name: onboarding_sessions group; Type: DEFAULT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.onboarding_sessions ALTER COLUMN "group" SET DEFAULT nextval('public.onboarding_sessions_group_seq'::regclass); + + + -- + -- Name: students number; Type: DEFAULT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.students ALTER COLUMN number SET DEFAULT nextval('public.students_number_seq'::regclass); + + + -- + -- Name: email_campaign_links PK_0069785eead914d9e38ed3e0486; Type: CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.email_campaign_links + ADD CONSTRAINT "PK_0069785eead914d9e38ed3e0486" PRIMARY KEY (id); + + + -- + -- Name: student_emails PK_02547c64dee0325548ee56025ff; Type: CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.student_emails + ADD CONSTRAINT "PK_02547c64dee0325548ee56025ff" PRIMARY KEY (email); + + + -- + -- Name: work_experiences PK_3189db15aaccc2861851ea3da17; Type: CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.work_experiences + ADD CONSTRAINT "PK_3189db15aaccc2861851ea3da17" PRIMARY KEY (id); + + + -- + -- Name: educations PK_36350278ed06e4381c2b4912956; Type: CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.educations + ADD CONSTRAINT "PK_36350278ed06e4381c2b4912956" PRIMARY KEY (id); + + + -- + -- Name: scholarship_recipients PK_401156c93c7624333d75a4d1aa6; Type: CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.scholarship_recipients + ADD CONSTRAINT "PK_401156c93c7624333d75a4d1aa6" PRIMARY KEY (id); + + + -- + -- Name: events PK_40731c7151fe4be3116e45ddf73; Type: CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.events + ADD CONSTRAINT "PK_40731c7151fe4be3116e45ddf73" PRIMARY KEY (id); + + + -- + -- Name: email_lists PK_5434f9b31ac88ee87a432b259b1; Type: CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.email_lists + ADD CONSTRAINT "PK_5434f9b31ac88ee87a432b259b1" PRIMARY KEY (id); + + + -- + -- Name: slack_reactions PK_5ng8jzb0vrri; Type: CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.slack_reactions + ADD CONSTRAINT "PK_5ng8jzb0vrri" PRIMARY KEY (channel_id, message_id, reaction, user_id); + + + -- + -- Name: student_active_statuses PK_626375e603a688a40df9e6a1ded; Type: CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.student_active_statuses + ADD CONSTRAINT "PK_626375e603a688a40df9e6a1ded" PRIMARY KEY (date, student_id); + + + -- + -- Name: resources PK_632484ab9dff41bba94f9b7c85e; Type: CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.resources + ADD CONSTRAINT "PK_632484ab9dff41bba94f9b7c85e" PRIMARY KEY (id); + + + -- + -- Name: email_campaigns PK_72bad329795785308e66d562350; Type: CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.email_campaigns + ADD CONSTRAINT "PK_72bad329795785308e66d562350" PRIMARY KEY (id); + + + -- + -- Name: students PK_7d7f07271ad4ce999880713f05e; Type: CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.students + ADD CONSTRAINT "PK_7d7f07271ad4ce999880713f05e" PRIMARY KEY (id); + + + -- + -- Name: activities PK_7f4004429f731ffb9c88eb486a8; Type: CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.activities + ADD CONSTRAINT "PK_7f4004429f731ffb9c88eb486a8" PRIMARY KEY (id); + + + -- + -- Name: program_participants PK_812f2ac865358ccaaf97a9f08db; Type: CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.program_participants + ADD CONSTRAINT "PK_812f2ac865358ccaaf97a9f08db" PRIMARY KEY (id); + + + -- + -- Name: migrations PK_8c82d7f526340ab734260ea46be; Type: CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.migrations + ADD CONSTRAINT "PK_8c82d7f526340ab734260ea46be" PRIMARY KEY (id); + + + -- + -- Name: completed_activities PK_8ccdc2a5be10feefbe7c2dd43f8; Type: CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.completed_activities + ADD CONSTRAINT "PK_8ccdc2a5be10feefbe7c2dd43f8" PRIMARY KEY (id); + + + -- + -- Name: onboarding_session_attendees PK_8d6422c2f867a2335d7a459ce10; Type: CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.onboarding_session_attendees + ADD CONSTRAINT "PK_8d6422c2f867a2335d7a459ce10" PRIMARY KEY (id); + + + -- + -- Name: applications PK_938c0a27255637bde919591888f; Type: CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.applications + ADD CONSTRAINT "PK_938c0a27255637bde919591888f" PRIMARY KEY (id); + + + -- + -- Name: onboarding_sessions PK_9553e455cbfe1aeebc6f43ae379; Type: CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.onboarding_sessions + ADD CONSTRAINT "PK_9553e455cbfe1aeebc6f43ae379" PRIMARY KEY (id); + + + -- + -- Name: schools PK_95b932e47ac129dd8e23a0db548; Type: CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.schools + ADD CONSTRAINT "PK_95b932e47ac129dd8e23a0db548" PRIMARY KEY (id); + + + -- + -- Name: slack_channels PK_9966694c91c805a3461d5b6f979; Type: CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.slack_channels + ADD CONSTRAINT "PK_9966694c91c805a3461d5b6f979" PRIMARY KEY (id); + + + -- + -- Name: one_time_codes PK_ae6fc30aa12eeae02fec8d6b63e; Type: CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.one_time_codes + ADD CONSTRAINT "PK_ae6fc30aa12eeae02fec8d6b63e" PRIMARY KEY (id); + + + -- + -- Name: resource_users PK_c7f28147fbfc9d54240aeb95815; Type: CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.resource_users + ADD CONSTRAINT "PK_c7f28147fbfc9d54240aeb95815" PRIMARY KEY (id); + + + -- + -- Name: slack_messages PK_cgnvg61wr16b; Type: CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.slack_messages + ADD CONSTRAINT "PK_cgnvg61wr16b" PRIMARY KEY (channel_id, id); + + + -- + -- Name: email_campaign_opens PK_d1afc92f28b86e8ab2563eb4f61; Type: CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.email_campaign_opens + ADD CONSTRAINT "PK_d1afc92f28b86e8ab2563eb4f61" PRIMARY KEY (id); + + + -- + -- Name: email_campaign_clicks PK_d3beb0d07a8e4e490cbfc4bf328; Type: CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.email_campaign_clicks + ADD CONSTRAINT "PK_d3beb0d07a8e4e490cbfc4bf328" PRIMARY KEY (id); + + + -- + -- Name: programs PK_d43c664bcaafc0e8a06dfd34e05; Type: CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.programs + ADD CONSTRAINT "PK_d43c664bcaafc0e8a06dfd34e05" PRIMARY KEY (id); + + + -- + -- Name: companies PK_d4bc3e82a314fa9e29f652c2c22; Type: CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.companies + ADD CONSTRAINT "PK_d4bc3e82a314fa9e29f652c2c22" PRIMARY KEY (id); + + + -- + -- Name: admins PK_e3b38270c97a854c48d2e80874e; Type: CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.admins + ADD CONSTRAINT "PK_e3b38270c97a854c48d2e80874e" PRIMARY KEY (id); + + + -- + -- Name: event_attendees PK_w2fq46mtaves; Type: CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.event_attendees + ADD CONSTRAINT "PK_w2fq46mtaves" PRIMARY KEY (email, event_id); + + + -- + -- Name: event_registrations PK_w4kq002onr1g; Type: CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.event_registrations + ADD CONSTRAINT "PK_w4kq002onr1g" PRIMARY KEY (email, event_id); + + + -- + -- Name: admins UQ_051db7d37d478a69a7432df1479; Type: CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.admins + ADD CONSTRAINT "UQ_051db7d37d478a69a7432df1479" UNIQUE (email); + + + -- + -- Name: completed_activities UQ_1keak785y8o9; Type: CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.completed_activities + ADD CONSTRAINT "UQ_1keak785y8o9" UNIQUE (event_attended, student_id); + + + -- + -- Name: students UQ_25985d58c714a4a427ced57507b; Type: CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.students + ADD CONSTRAINT "UQ_25985d58c714a4a427ced57507b" UNIQUE (email); + + + -- + -- Name: companies UQ_3212cc5ff994a44d966e00f1102; Type: CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.companies + ADD CONSTRAINT "UQ_3212cc5ff994a44d966e00f1102" UNIQUE (crunchbase_id); + + + -- + -- Name: schools UQ_32fbaf4feccea51ef7aeefa62bb; Type: CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.schools + ADD CONSTRAINT "UQ_32fbaf4feccea51ef7aeefa62bb" UNIQUE (name); + + + -- + -- Name: event_attendees UQ_9d32xlhph8j7; Type: CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.event_attendees + ADD CONSTRAINT "UQ_9d32xlhph8j7" UNIQUE (student_id, event_id); + + + -- + -- Name: students UQ_a23ab2db471b068703d857917ad; Type: CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.students + ADD CONSTRAINT "UQ_a23ab2db471b068703d857917ad" UNIQUE (slack_id); + + + -- + -- Name: completed_activities UQ_dkl1vdbp1v87; Type: CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.completed_activities + ADD CONSTRAINT "UQ_dkl1vdbp1v87" UNIQUE (channel_id, thread_replied_to, student_id); + + + -- + -- Name: completed_activities UQ_hu3bfyzq31aq; Type: CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.completed_activities + ADD CONSTRAINT "UQ_hu3bfyzq31aq" UNIQUE (channel_id, message_reacted_to, student_id); + + + -- + -- Name: event_registrations UQ_j5tvjlqsyvqd; Type: CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.event_registrations + ADD CONSTRAINT "UQ_j5tvjlqsyvqd" UNIQUE (event_id, student_id); + + + -- + -- Name: countries countries_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.countries + ADD CONSTRAINT countries_pkey PRIMARY KEY (code); + + + -- + -- Name: icebreaker_prompts icebreaker_prompts_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.icebreaker_prompts + ADD CONSTRAINT icebreaker_prompts_pkey PRIMARY KEY (id); + + + -- + -- Name: icebreaker_responses icebreaker_responses_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.icebreaker_responses + ADD CONSTRAINT icebreaker_responses_pkey PRIMARY KEY (id); + + + -- + -- Name: icebreaker_responses icebreaker_responses_prompt_id_student_id_key; Type: CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.icebreaker_responses + ADD CONSTRAINT icebreaker_responses_prompt_id_student_id_key UNIQUE (prompt_id, student_id); + + -- + -- Name: member_ethnicities member_ethnicities_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.member_ethnicities + ADD CONSTRAINT member_ethnicities_pkey PRIMARY KEY (country_code, student_id); + + + -- + -- Name: profile_views profile_views_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.profile_views + ADD CONSTRAINT profile_views_pkey PRIMARY KEY (id); + + + -- + -- Name: program_participants program_participants_email_program_id_key; Type: CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.program_participants + ADD CONSTRAINT program_participants_email_program_id_key UNIQUE (email, program_id); + + + -- + -- Name: resource_users resource_users_email_resource_id_key; Type: CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.resource_users + ADD CONSTRAINT resource_users_email_resource_id_key UNIQUE (email, resource_id); + + + -- + -- Name: survey_responses survey_responses_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.survey_responses + ADD CONSTRAINT survey_responses_pkey PRIMARY KEY (id); + + + -- + -- Name: surveys surveys_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.surveys + ADD CONSTRAINT surveys_pkey PRIMARY KEY (id); + + + -- + -- Name: survey_responses uq_aoq88oc8eaex; Type: CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.survey_responses + ADD CONSTRAINT uq_aoq88oc8eaex UNIQUE (student_id, survey_id); + + + -- + -- Name: survey_responses uq_oy0aq901k8hd; Type: CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.survey_responses + ADD CONSTRAINT uq_oy0aq901k8hd UNIQUE (email, survey_id); + + + -- + -- Name: completed_activities uq_uxq5qa94nscl; Type: CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.completed_activities + ADD CONSTRAINT uq_uxq5qa94nscl UNIQUE (student_id, survey_responded_to); + + + -- + -- Name: IDX_0d268fc05202a7001a97acbec6; Type: INDEX; Schema: public; Owner: postgres + -- + + CREATE INDEX "IDX_0d268fc05202a7001a97acbec6" ON public.email_campaign_links USING btree (campaign_id); + + + -- + -- Name: IDX_0m1j8gf4jcob; Type: INDEX; Schema: public; Owner: postgres + -- + + CREATE UNIQUE INDEX "IDX_0m1j8gf4jcob" ON public.completed_activities USING btree (student_id, type) WHERE (type = 'upload_profile_picture'::text); + + + -- + -- Name: IDX_18ade916f4d282e0569af931f8; Type: INDEX; Schema: public; Owner: postgres + -- + + CREATE INDEX "IDX_18ade916f4d282e0569af931f8" ON public.event_attendees USING btree (student_id); + + + -- + -- Name: IDX_26eac4de832305aa86593c04f4; Type: INDEX; Schema: public; Owner: postgres + -- + + CREATE UNIQUE INDEX "IDX_26eac4de832305aa86593c04f4" ON public.email_campaign_opens USING btree (campaign_id, opened_at, student_id); + + + -- + -- Name: IDX_36c51b6c73fe30f5e5c6f17311; Type: INDEX; Schema: public; Owner: postgres + -- + + CREATE UNIQUE INDEX "IDX_36c51b6c73fe30f5e5c6f17311" ON public.email_campaign_clicks USING btree (campaign_id, link_id, clicked_at, student_id); + + + -- + -- Name: IDX_3eff6f5ff06a40289cb3043aad; Type: INDEX; Schema: public; Owner: postgres + -- + + CREATE INDEX "IDX_3eff6f5ff06a40289cb3043aad" ON public.email_campaign_opens USING btree (student_id); + + + -- + -- Name: IDX_51114950b0357f1553aa50a286; Type: INDEX; Schema: public; Owner: postgres + -- + + CREATE UNIQUE INDEX "IDX_51114950b0357f1553aa50a286" ON public.slack_reactions USING btree (message_id, student_id, reaction); + + + -- + -- Name: IDX_7f842b2e8b974cd534c73f9201; Type: INDEX; Schema: public; Owner: postgres + -- + + CREATE UNIQUE INDEX "IDX_7f842b2e8b974cd534c73f9201" ON public.email_campaign_links USING btree (campaign_id, url); + + + -- + -- Name: IDX_862ba95e551ed267529bb8ad6a; Type: INDEX; Schema: public; Owner: postgres + -- + + CREATE INDEX "IDX_862ba95e551ed267529bb8ad6a" ON public.email_campaign_clicks USING btree (campaign_id); + + + -- + -- Name: IDX_a481b5eff9cb1ec9fbd809c49c; Type: INDEX; Schema: public; Owner: postgres + -- + + CREATE INDEX "IDX_a481b5eff9cb1ec9fbd809c49c" ON public.student_active_statuses USING btree (student_id); + + + -- + -- Name: IDX_a98wx9mszfw0; Type: INDEX; Schema: public; Owner: postgres + -- + + CREATE INDEX "IDX_a98wx9mszfw0" ON public.completed_activities USING btree (student_id); + + + -- + -- Name: IDX_ba45cb3020365126402d989431; Type: INDEX; Schema: public; Owner: postgres + -- + + CREATE UNIQUE INDEX "IDX_ba45cb3020365126402d989431" ON public.onboarding_session_attendees USING btree (session_id, student_id); + + + -- + -- Name: IDX_ba50d0f7b68ee5b73f7e7b8fdf; Type: INDEX; Schema: public; Owner: postgres + -- + + CREATE UNIQUE INDEX "IDX_ba50d0f7b68ee5b73f7e7b8fdf" ON public.programs USING btree (name); + + + -- + -- Name: IDX_c4cb735fac413057e9048b51ec; Type: INDEX; Schema: public; Owner: postgres + -- + + CREATE UNIQUE INDEX "IDX_c4cb735fac413057e9048b51ec" ON public.resource_users USING btree (resource_id, student_id); + + + -- + -- Name: IDX_cb8365260639d4ff2adec365f7; Type: INDEX; Schema: public; Owner: postgres + -- + + CREATE UNIQUE INDEX "IDX_cb8365260639d4ff2adec365f7" ON public.email_campaign_clicks USING btree (campaign_id, link_id, clicked_at, email); + + + -- + -- Name: IDX_e9dd2cd0ea65030b580faded74; Type: INDEX; Schema: public; Owner: postgres + -- + + CREATE INDEX "IDX_e9dd2cd0ea65030b580faded74" ON public.email_campaign_opens USING btree (campaign_id); + + + -- + -- Name: IDX_f276c867b5752b7cc2c6c797b2; Type: INDEX; Schema: public; Owner: postgres + -- + + CREATE UNIQUE INDEX "IDX_f276c867b5752b7cc2c6c797b2" ON public.resources USING btree (name); + + + -- + -- Name: IDX_f31b366f6f638b8bcef707e8b2; Type: INDEX; Schema: public; Owner: postgres + -- + + CREATE UNIQUE INDEX "IDX_f31b366f6f638b8bcef707e8b2" ON public.email_campaign_opens USING btree (campaign_id, opened_at, email); + + + -- + -- Name: IDX_f445685cf399095c8faf4a6fdb; Type: INDEX; Schema: public; Owner: postgres + -- + + CREATE UNIQUE INDEX "IDX_f445685cf399095c8faf4a6fdb" ON public.program_participants USING btree (program_id, student_id); + + + -- + -- Name: IDX_ff31bb932552a9a6fe61299350; Type: INDEX; Schema: public; Owner: postgres + -- + + CREATE INDEX "IDX_ff31bb932552a9a6fe61299350" ON public.email_campaign_clicks USING btree (student_id); + + + -- + -- Name: IDX_n0rlsilgnwue; Type: INDEX; Schema: public; Owner: postgres + -- + + CREATE INDEX "IDX_n0rlsilgnwue" ON public.students USING btree (school_id); + + + -- + -- Name: IDX_xw6v9c9h9doq; Type: INDEX; Schema: public; Owner: postgres + -- + + CREATE UNIQUE INDEX "IDX_xw6v9c9h9doq" ON public.completed_activities USING btree (student_id, type) WHERE (type = 'get_activated'::text); + + + -- + -- Name: idx_7q4xebf9marc; Type: INDEX; Schema: public; Owner: postgres + -- + + CREATE UNIQUE INDEX idx_7q4xebf9marc ON public.completed_activities USING btree (student_id, type) WHERE (type = 'join_member_directory'::text); + + + -- + -- Name: slack_messages_student_id_idx; Type: INDEX; Schema: public; Owner: postgres + -- + + CREATE INDEX slack_messages_student_id_idx ON public.slack_messages USING btree (student_id); + + + -- + -- Name: slack_reactions_student_id_idx; Type: INDEX; Schema: public; Owner: postgres + -- + + CREATE INDEX slack_reactions_student_id_idx ON public.slack_reactions USING btree (student_id); + + + -- + -- Name: student_active_statuses_student_id_status_date_idx; Type: INDEX; Schema: public; Owner: postgres + -- + + CREATE INDEX student_active_statuses_student_id_status_date_idx ON public.student_active_statuses USING btree (student_id, status, date DESC); + + + -- + -- Name: completed_activities FK_0140c854ae5304f6546171332b6; Type: FK CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.completed_activities + ADD CONSTRAINT "FK_0140c854ae5304f6546171332b6" FOREIGN KEY (activity_id) REFERENCES public.activities(id); + + + -- + -- Name: email_campaign_clicks FK_01e6991497a0b070a89f6bcb4bf; Type: FK CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.email_campaign_clicks + ADD CONSTRAINT "FK_01e6991497a0b070a89f6bcb4bf" FOREIGN KEY (link_id) REFERENCES public.email_campaign_links(id); + + + -- + -- Name: email_campaign_links FK_0d268fc05202a7001a97acbec6b; Type: FK CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.email_campaign_links + ADD CONSTRAINT "FK_0d268fc05202a7001a97acbec6b" FOREIGN KEY (campaign_id) REFERENCES public.email_campaigns(id); + + + -- + -- Name: event_attendees FK_18ade916f4d282e0569af931f83; Type: FK CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.event_attendees + ADD CONSTRAINT "FK_18ade916f4d282e0569af931f83" FOREIGN KEY (student_id) REFERENCES public.students(id) ON DELETE SET NULL; + + + -- + -- Name: students FK_25985d58c714a4a427ced57507b; Type: FK CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.students + ADD CONSTRAINT "FK_25985d58c714a4a427ced57507b" FOREIGN KEY (email) REFERENCES public.student_emails(email); + + + -- + -- Name: applications FK_268c174013ce6952213dd2e3c2e; Type: FK CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.applications + ADD CONSTRAINT "FK_268c174013ce6952213dd2e3c2e" FOREIGN KEY (school_id) REFERENCES public.schools(id); + + + -- + -- Name: work_experiences FK_3808b5a5551cc1296d1ae61ce9c; Type: FK CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.work_experiences + ADD CONSTRAINT "FK_3808b5a5551cc1296d1ae61ce9c" FOREIGN KEY (company_id) REFERENCES public.companies(id); + + + -- + -- Name: one_time_codes FK_384dfee27fef0a012f440a45b5b; Type: FK CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.one_time_codes + ADD CONSTRAINT "FK_384dfee27fef0a012f440a45b5b" FOREIGN KEY (student_id) REFERENCES public.students(id) ON DELETE CASCADE; + + + -- + -- Name: slack_messages FK_3e1cccaa310435f7572a4e3bd6e; Type: FK CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.slack_messages + ADD CONSTRAINT "FK_3e1cccaa310435f7572a4e3bd6e" FOREIGN KEY (student_id) REFERENCES public.students(id) ON DELETE SET NULL; + + + -- + -- Name: email_campaign_opens FK_3eff6f5ff06a40289cb3043aadd; Type: FK CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.email_campaign_opens + ADD CONSTRAINT "FK_3eff6f5ff06a40289cb3043aadd" FOREIGN KEY (student_id) REFERENCES public.students(id) ON DELETE SET NULL; + + + -- + -- Name: work_experiences FK_52b1e7a2b8965b1e9479ebffd62; Type: FK CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.work_experiences + ADD CONSTRAINT "FK_52b1e7a2b8965b1e9479ebffd62" FOREIGN KEY (student_id) REFERENCES public.students(id) ON DELETE CASCADE; + + + -- + -- Name: completed_activities FK_584a13934be81dd51e5d2c14d60; Type: FK CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.completed_activities + ADD CONSTRAINT "FK_584a13934be81dd51e5d2c14d60" FOREIGN KEY (student_id) REFERENCES public.students(id) ON DELETE CASCADE; + + + -- + -- Name: resource_users FK_5cca18dab247ece1379c21a4253; Type: FK CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.resource_users + ADD CONSTRAINT "FK_5cca18dab247ece1379c21a4253" FOREIGN KEY (resource_id) REFERENCES public.resources(id); + + + -- + -- Name: educations FK_6645bc400ae3486b7182fb36e3f; Type: FK CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.educations + ADD CONSTRAINT "FK_6645bc400ae3486b7182fb36e3f" FOREIGN KEY (school_id) REFERENCES public.schools(id); + + + -- + -- Name: resource_users FK_69f79a37afc88e975ac3d0cde42; Type: FK CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.resource_users + ADD CONSTRAINT "FK_69f79a37afc88e975ac3d0cde42" FOREIGN KEY (student_id) REFERENCES public.students(id) ON DELETE SET NULL; + + + -- + -- Name: applications FK_7b8cdcaabacb80df1ed8f7dbbea; Type: FK CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.applications + ADD CONSTRAINT "FK_7b8cdcaabacb80df1ed8f7dbbea" FOREIGN KEY (reviewed_by_id) REFERENCES public.admins(id); + + + -- + -- Name: email_campaign_clicks FK_862ba95e551ed267529bb8ad6a5; Type: FK CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.email_campaign_clicks + ADD CONSTRAINT "FK_862ba95e551ed267529bb8ad6a5" FOREIGN KEY (campaign_id) REFERENCES public.email_campaigns(id); + + + -- + -- Name: event_attendees FK_8f6qydm8w4d9; Type: FK CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.event_attendees + ADD CONSTRAINT "FK_8f6qydm8w4d9" FOREIGN KEY (event_id) REFERENCES public.events(id); + + + -- + -- Name: program_participants FK_965fe2c3b348678f5494b6ad958; Type: FK CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.program_participants + ADD CONSTRAINT "FK_965fe2c3b348678f5494b6ad958" FOREIGN KEY (program_id) REFERENCES public.programs(id); + + + -- + -- Name: educations FK_9e4fe4a0c54edfb14240310f7f7; Type: FK CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.educations + ADD CONSTRAINT "FK_9e4fe4a0c54edfb14240310f7f7" FOREIGN KEY (student_id) REFERENCES public.students(id) ON DELETE CASCADE; + + + -- + -- Name: student_active_statuses FK_a481b5eff9cb1ec9fbd809c49c9; Type: FK CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.student_active_statuses + ADD CONSTRAINT "FK_a481b5eff9cb1ec9fbd809c49c9" FOREIGN KEY (student_id) REFERENCES public.students(id) ON DELETE CASCADE; + + + -- + -- Name: students FK_aa8edc7905ad764f85924569647; Type: FK CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.students + ADD CONSTRAINT "FK_aa8edc7905ad764f85924569647" FOREIGN KEY (school_id) REFERENCES public.schools(id); + + + -- + -- Name: students FK_b3bc610967da06de7b140494c7b; Type: FK CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.students + ADD CONSTRAINT "FK_b3bc610967da06de7b140494c7b" FOREIGN KEY (application_id) REFERENCES public.applications(id); + + + -- + -- Name: one_time_codes FK_b7934bebe662bc7d70138e71cef; Type: FK CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.one_time_codes + ADD CONSTRAINT "FK_b7934bebe662bc7d70138e71cef" FOREIGN KEY (admin_id) REFERENCES public.admins(id); + + + -- + -- Name: email_campaigns FK_ba34bdeebfa85d35a5e3953dc78; Type: FK CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.email_campaigns + ADD CONSTRAINT "FK_ba34bdeebfa85d35a5e3953dc78" FOREIGN KEY (list_id) REFERENCES public.email_lists(id); + + + -- + -- Name: onboarding_session_attendees FK_bf1323140d7698f91ff21bb9a01; Type: FK CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.onboarding_session_attendees + ADD CONSTRAINT "FK_bf1323140d7698f91ff21bb9a01" FOREIGN KEY (session_id) REFERENCES public.onboarding_sessions(id); + + + -- + -- Name: student_emails FK_c868fb36612a0e7110aae3e265a; Type: FK CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.student_emails + ADD CONSTRAINT "FK_c868fb36612a0e7110aae3e265a" FOREIGN KEY (student_id) REFERENCES public.students(id) ON DELETE CASCADE; + + + -- + -- Name: program_participants FK_cb8c4f8b4567856155df7a54c88; Type: FK CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.program_participants + ADD CONSTRAINT "FK_cb8c4f8b4567856155df7a54c88" FOREIGN KEY (student_id) REFERENCES public.students(id) ON DELETE SET NULL; + + + -- + -- Name: slack_messages FK_doj63hsxt11w; Type: FK CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.slack_messages + ADD CONSTRAINT "FK_doj63hsxt11w" FOREIGN KEY (channel_id) REFERENCES public.slack_channels(id); + + + -- + -- Name: scholarship_recipients FK_e7d02c87af4a039ee9ae54b803c; Type: FK CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.scholarship_recipients + ADD CONSTRAINT "FK_e7d02c87af4a039ee9ae54b803c" FOREIGN KEY (student_id) REFERENCES public.students(id); + + + -- + -- Name: onboarding_session_attendees FK_e973d14344e5b73a9d3e20b717f; Type: FK CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.onboarding_session_attendees + ADD CONSTRAINT "FK_e973d14344e5b73a9d3e20b717f" FOREIGN KEY (student_id) REFERENCES public.students(id) ON DELETE CASCADE; + + + -- + -- Name: email_campaign_opens FK_e9dd2cd0ea65030b580faded745; Type: FK CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.email_campaign_opens + ADD CONSTRAINT "FK_e9dd2cd0ea65030b580faded745" FOREIGN KEY (campaign_id) REFERENCES public.email_campaigns(id); + + + -- + -- Name: slack_reactions FK_fa25662801e3a7cf0062d0b7009; Type: FK CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.slack_reactions + ADD CONSTRAINT "FK_fa25662801e3a7cf0062d0b7009" FOREIGN KEY (student_id) REFERENCES public.students(id) ON DELETE SET NULL; + + + -- + -- Name: email_campaign_clicks FK_ff31bb932552a9a6fe61299350e; Type: FK CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.email_campaign_clicks + ADD CONSTRAINT "FK_ff31bb932552a9a6fe61299350e" FOREIGN KEY (student_id) REFERENCES public.students(id) ON DELETE SET NULL; + + + -- + -- Name: completed_activities FK_mrbv401qw438; Type: FK CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.completed_activities + ADD CONSTRAINT "FK_mrbv401qw438" FOREIGN KEY (channel_id, message_reacted_to) REFERENCES public.slack_messages(channel_id, id) ON DELETE CASCADE; + + + -- + -- Name: slack_reactions FK_pgm1oozls356; Type: FK CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.slack_reactions + ADD CONSTRAINT "FK_pgm1oozls356" FOREIGN KEY (channel_id, message_id) REFERENCES public.slack_messages(channel_id, id) ON DELETE CASCADE; + + + -- + -- Name: slack_messages FK_w6029u2uo4kh; Type: FK CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.slack_messages + ADD CONSTRAINT "FK_w6029u2uo4kh" FOREIGN KEY (channel_id, thread_id) REFERENCES public.slack_messages(channel_id, id); + + + -- + -- Name: slack_reactions FK_wkqtysz0eb3b; Type: FK CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.slack_reactions + ADD CONSTRAINT "FK_wkqtysz0eb3b" FOREIGN KEY (channel_id) REFERENCES public.slack_channels(id); + + + -- + -- Name: completed_activities FK_y7q0nggl9ag6; Type: FK CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.completed_activities + ADD CONSTRAINT "FK_y7q0nggl9ag6" FOREIGN KEY (event_attended) REFERENCES public.events(id) ON DELETE CASCADE; + + + -- + -- Name: completed_activities FK_z76csrquvzq1; Type: FK CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.completed_activities + ADD CONSTRAINT "FK_z76csrquvzq1" FOREIGN KEY (channel_id, thread_replied_to) REFERENCES public.slack_messages(channel_id, id) ON DELETE CASCADE; + + + -- + -- Name: completed_activities completed_activities_survey_responded_to_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.completed_activities + ADD CONSTRAINT completed_activities_survey_responded_to_fkey FOREIGN KEY (survey_responded_to) REFERENCES public.surveys(id) ON DELETE CASCADE; + + + -- + -- Name: event_registrations event_registrations_event_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.event_registrations + ADD CONSTRAINT event_registrations_event_id_fkey FOREIGN KEY (event_id) REFERENCES public.events(id); + + + -- + -- Name: event_registrations event_registrations_student_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.event_registrations + ADD CONSTRAINT event_registrations_student_id_fkey FOREIGN KEY (student_id) REFERENCES public.students(id); + + + -- + -- Name: icebreaker_responses icebreaker_responses_prompt_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.icebreaker_responses + ADD CONSTRAINT icebreaker_responses_prompt_id_fkey FOREIGN KEY (prompt_id) REFERENCES public.icebreaker_prompts(id); + + + -- + -- Name: icebreaker_responses icebreaker_responses_student_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.icebreaker_responses + ADD CONSTRAINT icebreaker_responses_student_id_fkey FOREIGN KEY (student_id) REFERENCES public.students(id); + + + -- + -- Name: member_ethnicities member_ethnicities_country_code_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.member_ethnicities + ADD CONSTRAINT member_ethnicities_country_code_fkey FOREIGN KEY (country_code) REFERENCES public.countries(code); + + + -- + -- Name: member_ethnicities member_ethnicities_student_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.member_ethnicities + ADD CONSTRAINT member_ethnicities_student_id_fkey FOREIGN KEY (student_id) REFERENCES public.students(id); + + + -- + -- Name: profile_views profile_views_profile_viewed_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.profile_views + ADD CONSTRAINT profile_views_profile_viewed_id_fkey FOREIGN KEY (profile_viewed_id) REFERENCES public.students(id); + + + -- + -- Name: profile_views profile_views_viewer_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.profile_views + ADD CONSTRAINT profile_views_viewer_id_fkey FOREIGN KEY (viewer_id) REFERENCES public.students(id); + + + -- + -- Name: survey_responses survey_responses_student_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.survey_responses + ADD CONSTRAINT survey_responses_student_id_fkey FOREIGN KEY (student_id) REFERENCES public.students(id) ON DELETE SET NULL; + + + -- + -- Name: survey_responses survey_responses_survey_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.survey_responses + ADD CONSTRAINT survey_responses_survey_id_fkey FOREIGN KEY (survey_id) REFERENCES public.surveys(id); + + + -- + -- Name: surveys surveys_event_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres + -- + + ALTER TABLE ONLY public.surveys + ADD CONSTRAINT surveys_event_id_fkey FOREIGN KEY (event_id) REFERENCES public.events(id) ON DELETE SET NULL; + + + -- + -- PostgreSQL database dump complete + -- + `.execute(db); +} + +export async function down(db: Kysely) {} diff --git a/packages/db/src/migrations/2024-01-29T19:05:29Z-birthdate.ts b/packages/db/src/migrations/2024-01-29T19:05:29Z-birthdate.ts new file mode 100644 index 00000000..5494e110 --- /dev/null +++ b/packages/db/src/migrations/2024-01-29T19:05:29Z-birthdate.ts @@ -0,0 +1,12 @@ +import { Kysely } from 'kysely'; + +export async function up(db: Kysely) { + await db.schema + .alterTable('students') + .addColumn('birthdate', 'date') + .execute(); +} + +export async function down(db: Kysely) { + await db.schema.alterTable('students').dropColumn('birthdate').execute(); +} diff --git a/packages/db/src/migrations/2024-02-12T21:28:42Z-fix-removal.ts b/packages/db/src/migrations/2024-02-12T21:28:42Z-fix-removal.ts new file mode 100644 index 00000000..e8ce1fee --- /dev/null +++ b/packages/db/src/migrations/2024-02-12T21:28:42Z-fix-removal.ts @@ -0,0 +1,93 @@ +import { Kysely } from 'kysely'; + +export async function up(db: Kysely) { + // event_registrations + + await db.schema + .alterTable('event_registrations') + .dropConstraint('event_registrations_student_id_fkey') + .execute(); + + await db.schema + .alterTable('event_registrations') + .addForeignKeyConstraint( + 'event_registrations_student_id_fkey', + ['student_id'], + 'students', + ['id'] + ) + .onDelete('cascade') + .execute(); + + // icebreaker_responses + + await db.schema + .alterTable('icebreaker_responses') + .dropConstraint('icebreaker_responses_student_id_fkey') + .execute(); + + await db.schema + .alterTable('icebreaker_responses') + .addForeignKeyConstraint( + 'icebreaker_responses_student_id_fkey', + ['student_id'], + 'students', + ['id'] + ) + .onDelete('cascade') + .execute(); + + // member_ethnicities + + await db.schema + .alterTable('member_ethnicities') + .dropConstraint('member_ethnicities_student_id_fkey') + .execute(); + + await db.schema + .alterTable('member_ethnicities') + .addForeignKeyConstraint( + 'member_ethnicities_student_id_fkey', + ['student_id'], + 'students', + ['id'] + ) + .onDelete('cascade') + .execute(); + + // profile_views + + await db.schema + .alterTable('profile_views') + .dropConstraint('profile_views_profile_viewed_id_fkey') + .execute(); + + await db.schema + .alterTable('profile_views') + .dropConstraint('profile_views_viewer_id_fkey') + .execute(); + + await db.schema + .alterTable('profile_views') + .addForeignKeyConstraint( + 'profile_views_profile_viewed_id_fkey', + ['profile_viewed_id'], + 'students', + ['id'] + ) + .onDelete('cascade') + .execute(); + + await db.schema + .alterTable('profile_views') + .addForeignKeyConstraint( + 'profile_views_viewer_id_fkey', + ['viewer_id'], + 'students', + ['id'] + ) + .onDelete('cascade') + .execute(); +} + +export async function down(db: Kysely) {} diff --git a/packages/db/src/migrations/2024-03-11T10:33:01Z-job_offers.ts b/packages/db/src/migrations/2024-03-11T10:33:01Z-job_offers.ts new file mode 100644 index 00000000..748cf7f1 --- /dev/null +++ b/packages/db/src/migrations/2024-03-11T10:33:01Z-job_offers.ts @@ -0,0 +1,36 @@ +import { Kysely, sql } from 'kysely'; + +export async function up(db: Kysely) { + await db.schema + .createTable('job_offers') + .addColumn('id', 'text', (cb) => cb.primaryKey()) + .addColumn('created_at', 'timestamptz', (cb) => + cb.notNull().defaultTo(sql`now()`) + ) + .addColumn('base_salary', 'integer') + .addColumn('bonus', 'integer') + .addColumn('company_id', 'text', (cb) => { + return cb.references('companies.id'); + }) + .addColumn('compensation_type', 'text', (cb) => cb.notNull()) + .addColumn('employment_type', 'text', (cb) => cb.notNull()) + .addColumn('hourly_pay', 'integer') + .addColumn('other_company', 'text') + .addColumn('start_date', 'date', (cb) => cb.notNull()) + .addColumn('status', 'text', (cb) => cb.notNull()) + .addColumn('stock_per_year', 'integer') + .addColumn('student_id', 'text', (cb) => { + return cb.references('students.id').notNull(); + }) + .addColumn('updated_at', 'timestamptz', (cb) => + cb.notNull().defaultTo(sql`now()`) + ) + .addColumn('location', 'text') + .addColumn('location_coordinates', sql`point`) + .addColumn('location_type', 'text', (cb) => cb.notNull()) + .execute(); +} + +export async function down(db: Kysely) { + await db.schema.dropTable('job_offers').execute(); +} diff --git a/packages/db/src/migrations/2024-03-18T17:06:13Z-birthday-notification.ts b/packages/db/src/migrations/2024-03-18T17:06:13Z-birthday-notification.ts new file mode 100644 index 00000000..80783baa --- /dev/null +++ b/packages/db/src/migrations/2024-03-18T17:06:13Z-birthday-notification.ts @@ -0,0 +1,15 @@ +import { Kysely } from 'kysely'; + +export async function up(db: Kysely) { + await db.schema + .alterTable('students') + .addColumn('birthdate_notification', 'boolean') + .execute(); +} + +export async function down(db: Kysely) { + await db.schema + .alterTable('students') + .dropColumn('birthdate_notification') + .execute(); +} \ No newline at end of file diff --git a/packages/db/src/migrations/2024-03-18T19:45:26Z-birthday-default.ts b/packages/db/src/migrations/2024-03-18T19:45:26Z-birthday-default.ts new file mode 100644 index 00000000..03b62e43 --- /dev/null +++ b/packages/db/src/migrations/2024-03-18T19:45:26Z-birthday-default.ts @@ -0,0 +1,39 @@ +import { Kysely } from 'kysely'; + +export async function up(db: Kysely) { + await db + .updateTable('students') + .set({ birthdate_notification: true }) + .execute(); + + await db.schema + .alterTable('students') + .alterColumn('birthdate_notification', (column) => { + return column.setDefault(true); + }) + .execute(); + + await db.schema + .alterTable('students') + .alterColumn('birthdate_notification', (column) => { + return column.setNotNull(); + }) + .execute(); +} + +export async function down(db: Kysely) { + await db.schema + .alterTable('students') + .alterColumn('birthdate_notification', (column) => { + return column.dropNotNull(); + }) + + .execute(); + + await db.schema + .alterTable('students') + .alterColumn('birthdate_notification', (column) => { + return column.dropDefault(); + }) + .execute(); +} diff --git a/packages/db/src/migrations/2024-03-31T21:37:51Z-share-email.ts b/packages/db/src/migrations/2024-03-31T21:37:51Z-share-email.ts new file mode 100644 index 00000000..0f8b4ab2 --- /dev/null +++ b/packages/db/src/migrations/2024-03-31T21:37:51Z-share-email.ts @@ -0,0 +1,17 @@ +import { Kysely } from 'kysely'; + +export async function up(db: Kysely) { + await db.schema + .alterTable('students') + .addColumn('allow_email_share', 'boolean', (column) => { + return column.notNull().defaultTo(true); + }) + .execute(); +} + +export async function down(db: Kysely) { + await db.schema + .alterTable('students') + .dropColumn('allow_email_share') + .execute(); +} diff --git a/packages/db/src/scripts/migrate.ts b/packages/db/src/scripts/migrate.ts new file mode 100644 index 00000000..ceb0cd84 --- /dev/null +++ b/packages/db/src/scripts/migrate.ts @@ -0,0 +1,16 @@ +import { program } from 'commander'; + +import { migrate } from '../shared/migrate'; + +const DOWN_FLAG = '--down'; + +// Allow the program to use the "--down" flag. +program.option(DOWN_FLAG, 'Rollback the last migration.'); + +// Parse the command line arguments. +program.parse(); + +// Read the value of the "--down" flag. +const { down } = program.opts(); + +migrate({ down: !!down }); diff --git a/packages/db/src/scripts/seed.ts b/packages/db/src/scripts/seed.ts new file mode 100644 index 00000000..1acac2ed --- /dev/null +++ b/packages/db/src/scripts/seed.ts @@ -0,0 +1,175 @@ +import { Transaction, sql } from 'kysely'; +import { DB } from 'kysely-codegen/dist/db'; +import readline from 'readline'; +import { z } from 'zod'; + +import { db } from '..'; +import { ENVIRONMENT } from '../shared/env'; +import { migrate } from '../shared/migrate'; +import { truncate } from '../shared/truncate'; + +if (ENVIRONMENT !== 'development') { + throw new Error('Cannot seed database in non-development environment.'); +} + +async function main() { + try { + await setEmailFromCommandLine(); + console.log('(1/4) Email looks good. ✅'); + + await migrate({ db }); + console.log('(2/4) Ran migrations and initialized tables. ✅'); + + await db.transaction().execute(async (trx) => { + await truncate(trx); + await seed(trx); + }); + + console.log('(3/4) Wiped all data. ✅'); + console.log('(4/4) Seeded the database. ✅'); + } catch (e) { + console.error(e); + process.exit(1); + } finally { + await db.destroy(); + } +} + +let email = ''; + +async function seed(trx: Transaction) { + const schoolId1 = id(); + const schoolId2 = id(); + + await trx + .insertInto('schools') + .values([ + { + addressCity: 'Pittsburgh', + addressState: 'PA', + addressZip: '15213', + id: schoolId1, + name: 'Carnegie Mellon University', + }, + { + addressCity: 'Ithaca', + addressState: 'NY', + addressZip: '14850', + id: schoolId2, + name: 'Cornell University', + }, + { + addressCity: 'Washington', + addressState: 'D.C.', + addressZip: '20059', + id: id(), + name: 'Howard University', + }, + { + addressCity: 'Kennesaw', + addressState: 'GA', + addressZip: '30144', + id: id(), + name: 'Kennesaw State University', + }, + { + addressCity: 'Berkeley', + addressState: 'CA', + addressZip: '94720', + id: id(), + name: 'University of California, Berkeley', + }, + ]) + .execute(); + + await trx + .insertInto('admins') + .values([ + { + email, + id: id(), + isAmbassador: false, + firstName: 'First', + lastName: 'Last', + }, + ]) + .execute(); + + await trx.insertInto('studentEmails').values([{ email }]).execute(); + + const memberId = id(); + + await trx + .insertInto('students') + .values([ + { + acceptedAt: new Date(), + currentLocation: 'New York, NY', + currentLocationCoordinates: sql`point(-73.935242, 40.73061)`, + educationLevel: 'undergraduate', + email, + firstName: 'First', + gender: '', + graduationYear: new Date().getFullYear().toString(), + id: memberId, + lastName: 'Last', + major: 'computer_science', + otherDemographics: [], + race: [], + schoolId: schoolId1, + }, + ]) + .execute(); + + await trx + .updateTable('studentEmails') + .set({ studentId: memberId }) + .where('email', '=', email) + .execute(); +} + +async function setEmailFromCommandLine() { + const answer = await question( + 'In order to log into the Member Profile and Admin Dashboard, you will need both a member record and an admin record. Please provide an email so we can create those for you.\n' + + 'Email: ' + ); + + const result = z + .string() + .trim() + .min(1) + .email() + .transform((value) => { + return value.toLowerCase(); + }) + .safeParse(answer); + + if (!result.success) { + throw new Error('The email you provided was invalid.'); + } + + email = result.data; +} + +async function question(prompt: string) { + const cli = readline.createInterface({ + input: process.stdin, + output: process.stdout, + }); + + return new Promise((resolve) => { + cli.question(prompt, (input) => { + resolve(input); + cli.close(); + }); + }); +} + +let counter = 0; + +function id() { + counter++; + return counter.toString(); +} + +main(); diff --git a/packages/db/src/scripts/setup.sql b/packages/db/src/scripts/setup.sql new file mode 100644 index 00000000..0a714272 --- /dev/null +++ b/packages/db/src/scripts/setup.sql @@ -0,0 +1,11 @@ +-- Cleans up any existing databases/users. + +DROP DATABASE IF EXISTS colorstack; +DROP DATABASE IF EXISTS colorstack_test; +DROP ROLE IF EXISTS colorstack; + +-- Creates new databases and users. + +CREATE ROLE colorstack WITH SUPERUSER LOGIN PASSWORD 'colorstack'; +CREATE DATABASE colorstack OWNER colorstack; +CREATE DATABASE colorstack_test OWNER colorstack \ No newline at end of file diff --git a/packages/db/src/scripts/setup.ts b/packages/db/src/scripts/setup.ts new file mode 100644 index 00000000..2d79da55 --- /dev/null +++ b/packages/db/src/scripts/setup.ts @@ -0,0 +1,37 @@ +import { exec } from 'child_process'; +import path from 'path'; +import { fileURLToPath } from 'url'; + +import { ENVIRONMENT } from '../shared/env'; + +if (ENVIRONMENT !== 'development') { + throw new Error('Cannot setup database in non-development environment.'); +} + +const __filename = fileURLToPath(import.meta.url); +const __dirname = path.dirname(__filename); + +// This is the full path to the `setup.sql` file. +const pathToInitFile = path.join(__dirname, 'setup.sql'); + +exec( + // By default, everyone will have the role "postgres" and the database + // "postgres", so we use that to do our initial connection to the Postgres + // shell. We also have to specify the host, which satisfies the "peer" + // authentication requirement (if that is set in pg_hba.conf). + `psql -U postgres -h localhost -d postgres -f ${pathToInitFile}`, + (error, stdout, stderr) => { + if (stdout) { + console.log(stdout); + } + + if (stderr) { + // Log but don't throw for notices/warnings. + console.warn(stderr); + } + + if (error) { + throw new Error(`psql exited with error: ${error}`); + } + } +); diff --git a/packages/db/src/shared/create-database-connection.ts b/packages/db/src/shared/create-database-connection.ts new file mode 100644 index 00000000..097bdc4d --- /dev/null +++ b/packages/db/src/shared/create-database-connection.ts @@ -0,0 +1,26 @@ +import { CamelCasePlugin, Kysely, PostgresDialect } from 'kysely'; +import { DB } from 'kysely-codegen/dist/db'; +import pg from 'pg'; + +import { DATABASE_URL } from './env'; + +export function createDatabaseConnection() { + if (!DATABASE_URL) { + throw new Error( + '"DATABASE_URL" must be set to establish a connection to the database.' + ); + } + + const dialect = new PostgresDialect({ + pool: new pg.Pool({ + connectionString: DATABASE_URL, + }), + }); + + const db = new Kysely({ + dialect, + plugins: [new CamelCasePlugin()], + }); + + return db; +} diff --git a/packages/db/src/shared/env.ts b/packages/db/src/shared/env.ts new file mode 100644 index 00000000..fd163f4e --- /dev/null +++ b/packages/db/src/shared/env.ts @@ -0,0 +1,10 @@ +import { config } from 'dotenv'; + +// Loads the .env file into `process.env`. Note that if the config was already +// loaded (for example, in tests), this will not overwrite any existing values. +config(); + +export const DATABASE_URL = process.env.DATABASE_URL as string; +export const ENVIRONMENT = process.env.ENVIRONMENT; +export const IS_PRODUCTION = ENVIRONMENT === 'production'; +export const IS_TEST = ENVIRONMENT === 'test'; diff --git a/packages/db/src/shared/migrate.ts b/packages/db/src/shared/migrate.ts new file mode 100644 index 00000000..6bb5f2de --- /dev/null +++ b/packages/db/src/shared/migrate.ts @@ -0,0 +1,80 @@ +import { promises as fs } from 'fs'; +import { FileMigrationProvider, Kysely, Migrator } from 'kysely'; +import { DB } from 'kysely-codegen/dist/db'; +import path from 'path'; +import { fileURLToPath } from 'url'; + +import { createDatabaseConnection } from './create-database-connection'; + +type MigrateOptions = { + db?: Kysely; + down?: boolean; +}; + +const defaultOptions: MigrateOptions = { + db: undefined, + down: false, +}; + +/** + * Migrates the database to the latest version by executing all migrations. + * + * This is in the `/shared` folder because it is needed not only for the + * `db:migrate` script (self-explanatory), but also for the `db:seed` script. We + * need it for seeding because we first completely clean the database, and then + * we want to ensure that the database is migrated to the latest version before + * we seed it. + */ +export async function migrate(options: MigrateOptions = defaultOptions) { + options = { + ...defaultOptions, + ...options, + }; + + const db = options.db || createDatabaseConnection(); + + const __filename = fileURLToPath(import.meta.url); + const __dirname = path.dirname(__filename); + + const migrator = new Migrator({ + db, + provider: new FileMigrationProvider({ + fs, + path, + migrationFolder: path.join(__dirname, '../migrations'), + }), + migrationTableName: 'kysely_migrations', + migrationLockTableName: 'kysely_migrations_lock', + }); + + const { error, results } = !!options.down + ? await migrator.migrateDown() + : await migrator.migrateToLatest(); + + if (results) { + results.forEach((result) => { + const prefix = `[${result.direction}] "${result.migrationName}"`; + + if (result.status === 'Success') { + console.log(`${prefix}: Migration was executed successfully.`); + return; + } + + if (result.status === 'Error') { + console.error(`${prefix}: Failed to execute migration.`); + return; + } + }); + } + + if (error) { + console.error('An error occurred with the Kysely migrator.', error); + process.exit(1); + } + + // If a database instance was passed in, we'll yield the responsibility of + // destroying it to the caller. Otherwise, we'll destroy it here. + if (!options.db) { + await db.destroy(); + } +} diff --git a/packages/db/src/shared/truncate.ts b/packages/db/src/shared/truncate.ts new file mode 100644 index 00000000..d9bb2a6e --- /dev/null +++ b/packages/db/src/shared/truncate.ts @@ -0,0 +1,31 @@ +import { Transaction, sql } from 'kysely'; +import { DB } from 'kysely-codegen/dist/db'; + +import { IS_PRODUCTION } from './env'; + +/** + * Truncates all tables in the database - wiping all rows, but does not affect + * the schema itself. This can only be used in development/test environments. + * + * @see https://www.postgresql.org/docs/current/sql-truncate.html + */ +export async function truncate(trx: Transaction) { + if (IS_PRODUCTION) { + return; + } + + const tables = await trx.introspection.getTables(); + + const names = tables + .filter((table) => { + // We don't want to wipe the kysely tables, which track migrations b/c + // migrations should only be run once. + return !table.name.includes('kysely_'); + }) + .map((table) => { + return table.name; + }) + .join(', '); + + await sql`truncate table ${sql.raw(names)} cascade;`.execute(trx); +} diff --git a/packages/db/src/test/constants.ts b/packages/db/src/test/constants.ts new file mode 100644 index 00000000..2a2f575e --- /dev/null +++ b/packages/db/src/test/constants.ts @@ -0,0 +1,32 @@ +import { Insertable } from 'kysely'; +import { DB } from 'kysely-codegen/dist/db'; + +// Constants + +export const TEST_COMPANY_1: Insertable = { + crunchbaseId: '11', + id: '1', + name: 'Adobe', +}; + +export const TEST_COMPANY_2: Insertable = { + crunchbaseId: '22', + id: '2', + name: 'Google', +}; + +export const TEST_COMPANY_3: Insertable = { + crunchbaseId: '33', + id: '3', + name: 'Microsoft', +}; + +export const TEST_COMPANY_4: Insertable = { + crunchbaseId: '44', + description: '...', + domain: 'stripe.com', + id: '44', + imageUrl: '...', + name: 'Stripe', + stockSymbol: '...', +}; diff --git a/packages/db/src/test/setup.global.ts b/packages/db/src/test/setup.global.ts new file mode 100644 index 00000000..305586e6 --- /dev/null +++ b/packages/db/src/test/setup.global.ts @@ -0,0 +1,10 @@ +import { db } from '..'; +import { migrate } from '../shared/migrate'; + +export async function setup() { + await migrate({ db }); +} + +export async function teardown() { + await db.destroy(); +} diff --git a/packages/db/src/test/setup.ts b/packages/db/src/test/setup.ts new file mode 100644 index 00000000..51c971d4 --- /dev/null +++ b/packages/db/src/test/setup.ts @@ -0,0 +1,22 @@ +import { Transaction } from 'kysely'; +import { DB } from 'kysely-codegen/dist/db'; + +import { db } from '..'; +import { truncate } from '../shared/truncate'; +import { TEST_COMPANY_1, TEST_COMPANY_2, TEST_COMPANY_3 } from './constants'; + +beforeEach(async () => { + await db.transaction().execute(async (trx) => { + await truncate(trx); + await seed(trx); + }); +}); + +// Helpers + +async function seed(trx: Transaction) { + await trx + .insertInto('companies') + .values([TEST_COMPANY_1, TEST_COMPANY_2, TEST_COMPANY_3]) + .execute(); +} diff --git a/packages/db/tsconfig.json b/packages/db/tsconfig.json new file mode 100644 index 00000000..5fba6dba --- /dev/null +++ b/packages/db/tsconfig.json @@ -0,0 +1,10 @@ +{ + "extends": "@oyster/tsconfig/base.json", + "include": ["src"], + "compilerOptions": { + "jsx": "react-jsx", + "module": "ESNext", + "moduleResolution": "Bundler", + "types": ["vitest/globals"] + } +} From fe395e226e5e08a7faee73d49863144ccd9b17b5 Mon Sep 17 00:00:00 2001 From: Rami Abdou Date: Wed, 3 Apr 2024 09:07:20 -0700 Subject: [PATCH 02/14] move files --- .../core/src/infrastructure/database/index.ts | 3 - .../migrations/2024-01-29T17:23:16Z-init.ts | 1821 ----------------- .../2024-01-29T19:05:29Z-birthdate.ts | 12 - .../2024-02-12T21:28:42Z-fix-removal.ts | 93 - .../2024-03-11T10:33:01Z-job_offers.ts | 36 - ...4-03-18T17:06:13Z-birthday-notification.ts | 15 - .../2024-03-18T19:45:26Z-birthday-default.ts | 39 - .../2024-03-31T21:37:51Z-share-email.ts | 17 - .../database/scripts/migrate.ts | 16 - .../infrastructure/database/scripts/seed.ts | 175 -- .../infrastructure/database/scripts/setup.sql | 11 - .../infrastructure/database/scripts/setup.ts | 37 - .../shared/create-database-connection.ts | 26 - .../infrastructure/database/shared/migrate.ts | 80 - .../database/shared/truncate.ts | 31 - .../infrastructure/database/test/constants.ts | 32 - .../database/test/setup.global.ts | 10 - .../src/infrastructure/database/test/setup.ts | 22 - 18 files changed, 2476 deletions(-) delete mode 100644 packages/core/src/infrastructure/database/index.ts delete mode 100644 packages/core/src/infrastructure/database/migrations/2024-01-29T17:23:16Z-init.ts delete mode 100644 packages/core/src/infrastructure/database/migrations/2024-01-29T19:05:29Z-birthdate.ts delete mode 100644 packages/core/src/infrastructure/database/migrations/2024-02-12T21:28:42Z-fix-removal.ts delete mode 100644 packages/core/src/infrastructure/database/migrations/2024-03-11T10:33:01Z-job_offers.ts delete mode 100644 packages/core/src/infrastructure/database/migrations/2024-03-18T17:06:13Z-birthday-notification.ts delete mode 100644 packages/core/src/infrastructure/database/migrations/2024-03-18T19:45:26Z-birthday-default.ts delete mode 100644 packages/core/src/infrastructure/database/migrations/2024-03-31T21:37:51Z-share-email.ts delete mode 100644 packages/core/src/infrastructure/database/scripts/migrate.ts delete mode 100644 packages/core/src/infrastructure/database/scripts/seed.ts delete mode 100644 packages/core/src/infrastructure/database/scripts/setup.sql delete mode 100644 packages/core/src/infrastructure/database/scripts/setup.ts delete mode 100644 packages/core/src/infrastructure/database/shared/create-database-connection.ts delete mode 100644 packages/core/src/infrastructure/database/shared/migrate.ts delete mode 100644 packages/core/src/infrastructure/database/shared/truncate.ts delete mode 100644 packages/core/src/infrastructure/database/test/constants.ts delete mode 100644 packages/core/src/infrastructure/database/test/setup.global.ts delete mode 100644 packages/core/src/infrastructure/database/test/setup.ts diff --git a/packages/core/src/infrastructure/database/index.ts b/packages/core/src/infrastructure/database/index.ts deleted file mode 100644 index 3f9c92ce..00000000 --- a/packages/core/src/infrastructure/database/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -import { createDatabaseConnection } from './shared/create-database-connection'; - -export const db = createDatabaseConnection(); diff --git a/packages/core/src/infrastructure/database/migrations/2024-01-29T17:23:16Z-init.ts b/packages/core/src/infrastructure/database/migrations/2024-01-29T17:23:16Z-init.ts deleted file mode 100644 index 67ff67b9..00000000 --- a/packages/core/src/infrastructure/database/migrations/2024-01-29T17:23:16Z-init.ts +++ /dev/null @@ -1,1821 +0,0 @@ -import { Kysely, sql } from 'kysely'; - -export async function up(db: Kysely) { - const result = await sql` - -- - -- PostgreSQL database dump - -- - - -- Dumped from database version 15.4 (Ubuntu 15.4-2.pgdg22.04+1) - -- Dumped by pg_dump version 15.5 (Homebrew) - - -- - -- Name: cube; Type: EXTENSION; Schema: -; Owner: - - -- - - CREATE EXTENSION IF NOT EXISTS cube WITH SCHEMA public; - - - -- - -- Name: EXTENSION cube; Type: COMMENT; Schema: -; Owner: - -- - - COMMENT ON EXTENSION cube IS 'data type for multidimensional cubes'; - - - -- - -- Name: earthdistance; Type: EXTENSION; Schema: -; Owner: - - -- - - CREATE EXTENSION IF NOT EXISTS earthdistance WITH SCHEMA public; - - - -- - -- Name: EXTENSION earthdistance; Type: COMMENT; Schema: -; Owner: - -- - - COMMENT ON EXTENSION earthdistance IS 'calculate great-circle distances on the surface of the Earth'; - - - -- - -- Name: pg_trgm; Type: EXTENSION; Schema: -; Owner: - - -- - - CREATE EXTENSION IF NOT EXISTS pg_trgm WITH SCHEMA public; - - - -- - -- Name: EXTENSION pg_trgm; Type: COMMENT; Schema: -; Owner: - -- - - COMMENT ON EXTENSION pg_trgm IS 'text similarity measurement and index searching based on trigrams'; - - - -- - -- Name: applications_other_demographics_enum; Type: TYPE; Schema: public; Owner: postgres - -- - - CREATE TYPE public.applications_other_demographics_enum AS ENUM ( - 'DISABILITY', - 'FIRST_GENERATION', - 'LOW_INCOME' - ); - - -- - -- Name: applications_race_enum; Type: TYPE; Schema: public; Owner: postgres - -- - - CREATE TYPE public.applications_race_enum AS ENUM ( - 'ASIAN', - 'BLACK', - 'HISPANIC', - 'MIDDLE_EASTERN', - 'NATIVE_AMERICAN', - 'OTHER', - 'WHITE' - ); - - -- - -- Name: students_other_demographics_enum; Type: TYPE; Schema: public; Owner: postgres - -- - - CREATE TYPE public.students_other_demographics_enum AS ENUM ( - 'DISABILITY', - 'FIRST_GENERATION', - 'LOW_INCOME' - ); - - - -- - -- Name: students_race_enum; Type: TYPE; Schema: public; Owner: postgres - -- - - CREATE TYPE public.students_race_enum AS ENUM ( - 'ASIAN', - 'BLACK', - 'HISPANIC', - 'MIDDLE_EASTERN', - 'NATIVE_AMERICAN', - 'OTHER', - 'WHITE' - ); - - - SET default_tablespace = ''; - - SET default_table_access_method = heap; - - -- - -- Name: activities; Type: TABLE; Schema: public; Owner: postgres - -- - - CREATE TABLE public.activities ( - created_at timestamp with time zone DEFAULT now() NOT NULL, - deleted_at timestamp with time zone, - id text NOT NULL, - updated_at timestamp with time zone DEFAULT now() NOT NULL, - type text NOT NULL, - description text, - name text NOT NULL, - points smallint NOT NULL, - period text - ); - - -- - -- Name: admins; Type: TABLE; Schema: public; Owner: postgres - -- - - CREATE TABLE public.admins ( - created_at timestamp with time zone DEFAULT now() NOT NULL, - deleted_at timestamp with time zone, - id text NOT NULL, - updated_at timestamp with time zone DEFAULT now() NOT NULL, - email text NOT NULL, - first_name text NOT NULL, - last_name text NOT NULL, - is_ambassador boolean DEFAULT false NOT NULL - ); - - -- - -- Name: applications; Type: TABLE; Schema: public; Owner: postgres - -- - - CREATE TABLE public.applications ( - created_at timestamp with time zone DEFAULT now() NOT NULL, - deleted_at timestamp with time zone, - id text NOT NULL, - updated_at timestamp with time zone DEFAULT now() NOT NULL, - accepted_at timestamp with time zone, - contribution text NOT NULL, - education_level text NOT NULL, - email text NOT NULL, - first_name text NOT NULL, - gender text NOT NULL, - goals text NOT NULL, - graduation_year integer NOT NULL, - last_name text NOT NULL, - linked_in_url text NOT NULL, - major text NOT NULL, - other_demographics text[] NOT NULL, - other_major text, - other_school text, - race text[] NOT NULL, - rejected_at timestamp with time zone, - school_id text, - status text NOT NULL, - reviewed_by_id text - ); - - -- - -- Name: companies; Type: TABLE; Schema: public; Owner: postgres - -- - - CREATE TABLE public.companies ( - created_at timestamp with time zone DEFAULT now() NOT NULL, - deleted_at timestamp with time zone, - id text NOT NULL, - updated_at timestamp with time zone DEFAULT now() NOT NULL, - name text NOT NULL, - crunchbase_id text NOT NULL, - description text, - domain text, - image_url text, - stock_symbol text - ); - - -- - -- Name: completed_activities; Type: TABLE; Schema: public; Owner: postgres - -- - - CREATE TABLE public.completed_activities ( - created_at timestamp with time zone DEFAULT now() NOT NULL, - id text NOT NULL, - activity_id text, - occurred_at timestamp with time zone NOT NULL, - points smallint NOT NULL, - student_id text NOT NULL, - channel_id text, - message_reacted_to text, - thread_replied_to text, - event_attended text, - type text NOT NULL, - survey_responded_to text, - description text - ); - - -- - -- Name: countries; Type: TABLE; Schema: public; Owner: postgres - -- - - CREATE TABLE public.countries ( - code text NOT NULL, - demonym text NOT NULL, - flag_emoji text NOT NULL, - latitude text NOT NULL, - longitude text NOT NULL, - name text NOT NULL, - region text NOT NULL, - subregion text - ); - - -- - -- Name: educations; Type: TABLE; Schema: public; Owner: postgres - -- - - CREATE TABLE public.educations ( - created_at timestamp with time zone DEFAULT now() NOT NULL, - deleted_at timestamp with time zone, - id text NOT NULL, - updated_at timestamp with time zone DEFAULT now() NOT NULL, - degree_type text NOT NULL, - end_date date NOT NULL, - major text NOT NULL, - other_major text, - other_school text, - school_id text, - start_date date NOT NULL, - student_id text NOT NULL - ); - - -- - -- Name: email_campaign_clicks; Type: TABLE; Schema: public; Owner: postgres - -- - - CREATE TABLE public.email_campaign_clicks ( - created_at timestamp with time zone DEFAULT now() NOT NULL, - deleted_at timestamp with time zone, - id text NOT NULL, - updated_at timestamp with time zone DEFAULT now() NOT NULL, - campaign_id text NOT NULL, - clicked_at timestamp with time zone NOT NULL, - email text NOT NULL, - link_id text NOT NULL, - platform text NOT NULL, - student_id text - ); - - -- - -- Name: email_campaign_links; Type: TABLE; Schema: public; Owner: postgres - -- - - CREATE TABLE public.email_campaign_links ( - created_at timestamp with time zone DEFAULT now() NOT NULL, - deleted_at timestamp with time zone, - id text NOT NULL, - updated_at timestamp with time zone DEFAULT now() NOT NULL, - campaign_id text NOT NULL, - url text NOT NULL, - platform text NOT NULL - ); - - -- - -- Name: email_campaign_opens; Type: TABLE; Schema: public; Owner: postgres - -- - - CREATE TABLE public.email_campaign_opens ( - created_at timestamp with time zone DEFAULT now() NOT NULL, - deleted_at timestamp with time zone, - id text NOT NULL, - updated_at timestamp with time zone DEFAULT now() NOT NULL, - campaign_id text NOT NULL, - email text NOT NULL, - opened_at timestamp with time zone NOT NULL, - platform text NOT NULL, - student_id text - ); - - -- - -- Name: email_campaigns; Type: TABLE; Schema: public; Owner: postgres - -- - - CREATE TABLE public.email_campaigns ( - created_at timestamp with time zone DEFAULT now() NOT NULL, - deleted_at timestamp with time zone, - id text NOT NULL, - updated_at timestamp with time zone DEFAULT now() NOT NULL, - content text NOT NULL, - list_id text NOT NULL, - platform text NOT NULL, - sent_at timestamp with time zone, - subject text NOT NULL, - title text, - archive_url text, - sent_count integer, - last_synced_at timestamp with time zone - ); - - -- - -- Name: email_lists; Type: TABLE; Schema: public; Owner: postgres - -- - - CREATE TABLE public.email_lists ( - created_at timestamp with time zone DEFAULT now() NOT NULL, - deleted_at timestamp with time zone, - id text NOT NULL, - updated_at timestamp with time zone DEFAULT now() NOT NULL, - name text NOT NULL, - platform text NOT NULL - ); - - -- - -- Name: event_attendees; Type: TABLE; Schema: public; Owner: postgres - -- - - CREATE TABLE public.event_attendees ( - created_at timestamp with time zone DEFAULT now() NOT NULL, - email text NOT NULL, - name text, - student_id text, - event_id text NOT NULL - ); - - -- - -- Name: event_registrations; Type: TABLE; Schema: public; Owner: postgres - -- - - CREATE TABLE public.event_registrations ( - email text NOT NULL, - event_id text NOT NULL, - registered_at timestamp with time zone NOT NULL, - student_id text NOT NULL - ); - - -- - -- Name: events; Type: TABLE; Schema: public; Owner: postgres - -- - - CREATE TABLE public.events ( - created_at timestamp with time zone DEFAULT now() NOT NULL, - deleted_at timestamp with time zone, - id text NOT NULL, - end_time timestamp with time zone NOT NULL, - name text NOT NULL, - start_time timestamp with time zone NOT NULL, - type text NOT NULL, - description text, - external_link text - ); - - -- - -- Name: icebreaker_prompts; Type: TABLE; Schema: public; Owner: postgres - -- - - CREATE TABLE public.icebreaker_prompts ( - deleted_at timestamp with time zone, - id text NOT NULL, - text text NOT NULL - ); - - -- - -- Name: icebreaker_responses; Type: TABLE; Schema: public; Owner: postgres - -- - - CREATE TABLE public.icebreaker_responses ( - id text NOT NULL, - prompt_id text NOT NULL, - responded_at timestamp with time zone DEFAULT now() NOT NULL, - student_id text NOT NULL, - text text NOT NULL - ); - - -- - -- Custom... - -- - - -- - -- Name: member_ethnicities; Type: TABLE; Schema: public; Owner: postgres - -- - - CREATE TABLE public.member_ethnicities ( - country_code text NOT NULL, - student_id text NOT NULL - ); - - -- - -- Name: migrations; Type: TABLE; Schema: public; Owner: postgres - -- - - 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: postgres - -- - - 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: postgres - -- - - ALTER SEQUENCE public.migrations_id_seq OWNED BY public.migrations.id; - - - -- - -- Name: onboarding_session_attendees; Type: TABLE; Schema: public; Owner: postgres - -- - - CREATE TABLE public.onboarding_session_attendees ( - created_at timestamp with time zone DEFAULT now() NOT NULL, - deleted_at timestamp with time zone, - id text NOT NULL, - updated_at timestamp with time zone DEFAULT now() NOT NULL, - session_id text NOT NULL, - student_id text NOT NULL - ); - - -- - -- Name: onboarding_sessions; Type: TABLE; Schema: public; Owner: postgres - -- - - CREATE TABLE public.onboarding_sessions ( - created_at timestamp with time zone DEFAULT now() NOT NULL, - deleted_at timestamp with time zone, - id text NOT NULL, - updated_at timestamp with time zone DEFAULT now() NOT NULL, - date date NOT NULL, - "group" integer NOT NULL - ); - - -- - -- Name: onboarding_sessions_group_seq; Type: SEQUENCE; Schema: public; Owner: postgres - -- - - CREATE SEQUENCE public.onboarding_sessions_group_seq - AS integer - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - -- - -- Name: onboarding_sessions_group_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres - -- - - ALTER SEQUENCE public.onboarding_sessions_group_seq OWNED BY public.onboarding_sessions."group"; - - - -- - -- Name: one_time_codes; Type: TABLE; Schema: public; Owner: postgres - -- - - CREATE TABLE public.one_time_codes ( - created_at timestamp with time zone DEFAULT now() NOT NULL, - deleted_at timestamp with time zone, - id text NOT NULL, - updated_at timestamp with time zone DEFAULT now() NOT NULL, - admin_id text, - email text NOT NULL, - purpose text NOT NULL, - student_id text, - value text NOT NULL - ); - - -- - -- Name: profile_views; Type: TABLE; Schema: public; Owner: postgres - -- - - CREATE TABLE public.profile_views ( - id text NOT NULL, - profile_viewed_id text NOT NULL, - viewed_at timestamp with time zone DEFAULT now() NOT NULL, - viewer_id text NOT NULL - ); - - -- - -- Name: program_participants; Type: TABLE; Schema: public; Owner: postgres - -- - - CREATE TABLE public.program_participants ( - created_at timestamp with time zone DEFAULT now() NOT NULL, - deleted_at timestamp with time zone, - id text NOT NULL, - updated_at timestamp with time zone DEFAULT now() NOT NULL, - program_id text NOT NULL, - student_id text, - email text - ); - - -- - -- Name: programs; Type: TABLE; Schema: public; Owner: postgres - -- - - CREATE TABLE public.programs ( - created_at timestamp with time zone DEFAULT now() NOT NULL, - deleted_at timestamp with time zone, - id text NOT NULL, - updated_at timestamp with time zone DEFAULT now() NOT NULL, - end_date date NOT NULL, - name text NOT NULL, - start_date date NOT NULL - ); - - -- - -- Name: resource_users; Type: TABLE; Schema: public; Owner: postgres - -- - - CREATE TABLE public.resource_users ( - created_at timestamp with time zone DEFAULT now() NOT NULL, - deleted_at timestamp with time zone, - id text NOT NULL, - updated_at timestamp with time zone DEFAULT now() NOT NULL, - resource_id text NOT NULL, - student_id text, - used_at timestamp with time zone, - email text - ); - - -- - -- Name: resources; Type: TABLE; Schema: public; Owner: postgres - -- - - CREATE TABLE public.resources ( - created_at timestamp with time zone DEFAULT now() NOT NULL, - deleted_at timestamp with time zone, - id text NOT NULL, - updated_at timestamp with time zone DEFAULT now() NOT NULL, - name text NOT NULL, - status text NOT NULL - ); - - -- - -- Name: scholarship_recipients; Type: TABLE; Schema: public; Owner: postgres - -- - - CREATE TABLE public.scholarship_recipients ( - created_at timestamp with time zone DEFAULT now() NOT NULL, - deleted_at timestamp with time zone, - id text NOT NULL, - updated_at timestamp with time zone DEFAULT now() NOT NULL, - amount integer NOT NULL, - reason text NOT NULL, - type text NOT NULL, - student_id text NOT NULL, - awarded_at timestamp with time zone NOT NULL - ); - - -- - -- Name: schools; Type: TABLE; Schema: public; Owner: postgres - -- - - CREATE TABLE public.schools ( - created_at timestamp with time zone DEFAULT now() NOT NULL, - deleted_at timestamp with time zone, - id text NOT NULL, - updated_at timestamp with time zone DEFAULT now() NOT NULL, - address_city text NOT NULL, - address_state text NOT NULL, - address_zip text NOT NULL, - name text NOT NULL, - coordinates point - ); - - -- - -- Name: slack_channels; Type: TABLE; Schema: public; Owner: postgres - -- - - CREATE TABLE public.slack_channels ( - created_at timestamp with time zone DEFAULT now() NOT NULL, - deleted_at timestamp with time zone, - id text NOT NULL, - name text NOT NULL, - type text NOT NULL - ); - - -- - -- Name: slack_messages; Type: TABLE; Schema: public; Owner: postgres - -- - - CREATE TABLE public.slack_messages ( - created_at timestamp with time zone DEFAULT now() NOT NULL, - deleted_at timestamp with time zone, - id text NOT NULL, - channel_id text NOT NULL, - user_id text NOT NULL, - text text, - thread_id text, - student_id text - ); - - -- - -- Name: slack_reactions; Type: TABLE; Schema: public; Owner: postgres - -- - - CREATE TABLE public.slack_reactions ( - created_at timestamp with time zone DEFAULT now() NOT NULL, - user_id text NOT NULL, - message_id text NOT NULL, - reaction text NOT NULL, - student_id text, - channel_id text NOT NULL - ); - - -- - -- Name: student_active_statuses; Type: TABLE; Schema: public; Owner: postgres - -- - - CREATE TABLE public.student_active_statuses ( - date date NOT NULL, - status text NOT NULL, - student_id text NOT NULL - ); - - -- - -- Name: student_emails; Type: TABLE; Schema: public; Owner: postgres - -- - - CREATE TABLE public.student_emails ( - created_at timestamp with time zone DEFAULT now() NOT NULL, - deleted_at timestamp with time zone, - updated_at timestamp with time zone DEFAULT now() NOT NULL, - email text NOT NULL, - student_id text - ); - - -- - -- Name: students; Type: TABLE; Schema: public; Owner: postgres - -- - - CREATE TABLE public.students ( - created_at timestamp with time zone DEFAULT now() NOT NULL, - id text NOT NULL, - updated_at timestamp with time zone DEFAULT now() NOT NULL, - accepted_at timestamp with time zone NOT NULL, - address_city text, - address_line1 text, - address_line2 text, - address_state text, - address_zip text, - application_id text, - applied_at timestamp with time zone, - claimed_swag_pack_at timestamp with time zone, - education_level text NOT NULL, - email text NOT NULL, - first_name text NOT NULL, - gender text NOT NULL, - gender_pronouns text, - graduation_year text NOT NULL, - joined_slack_at timestamp with time zone, - last_name text NOT NULL, - linked_in_url text, - major text NOT NULL, - onboarded_at timestamp with time zone, - other_demographics text[] NOT NULL, - other_major text, - other_school text, - race text[] NOT NULL, - school_id text, - slack_id text, - swag_up_order_id text, - activated_at timestamp with time zone, - activation_requirements_completed text[] DEFAULT '{}'::text[] NOT NULL, - number integer NOT NULL, - preferred_name text, - profile_picture text, - calendly_url text, - github_url text, - instagram_handle text, - personal_website_url text, - twitter_handle text, - headline text, - current_location text, - current_location_coordinates point, - hometown text, - hometown_coordinates point, - joined_member_directory_at timestamp with time zone - ); - - -- - -- Name: students_number_seq; Type: SEQUENCE; Schema: public; Owner: postgres - -- - - CREATE SEQUENCE public.students_number_seq - AS integer - START WITH 1 - INCREMENT BY 1 - NO MINVALUE - NO MAXVALUE - CACHE 1; - - -- - -- Name: students_number_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres - -- - - ALTER SEQUENCE public.students_number_seq OWNED BY public.students.number; - - - -- - -- Name: survey_responses; Type: TABLE; Schema: public; Owner: postgres - -- - - CREATE TABLE public.survey_responses ( - created_at timestamp with time zone DEFAULT now() NOT NULL, - email text NOT NULL, - first_name text NOT NULL, - id text NOT NULL, - last_name text NOT NULL, - responded_on date NOT NULL, - student_id text, - survey_id text NOT NULL - ); - - -- - -- Name: surveys; Type: TABLE; Schema: public; Owner: postgres - -- - - CREATE TABLE public.surveys ( - created_at timestamp with time zone DEFAULT now() NOT NULL, - description text, - event_id text, - id text NOT NULL, - title text NOT NULL - ); - - -- - -- Name: work_experiences; Type: TABLE; Schema: public; Owner: postgres - -- - - CREATE TABLE public.work_experiences ( - created_at timestamp with time zone DEFAULT now() NOT NULL, - deleted_at timestamp with time zone, - id text NOT NULL, - updated_at timestamp with time zone DEFAULT now() NOT NULL, - company_id text, - company_name text, - end_date date, - location_city text, - location_state text, - location_type text NOT NULL, - start_date date NOT NULL, - student_id text NOT NULL, - title text NOT NULL, - employment_type text NOT NULL - ); - - -- - -- Name: migrations id; Type: DEFAULT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.migrations ALTER COLUMN id SET DEFAULT nextval('public.migrations_id_seq'::regclass); - - - -- - -- Name: onboarding_sessions group; Type: DEFAULT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.onboarding_sessions ALTER COLUMN "group" SET DEFAULT nextval('public.onboarding_sessions_group_seq'::regclass); - - - -- - -- Name: students number; Type: DEFAULT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.students ALTER COLUMN number SET DEFAULT nextval('public.students_number_seq'::regclass); - - - -- - -- Name: email_campaign_links PK_0069785eead914d9e38ed3e0486; Type: CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.email_campaign_links - ADD CONSTRAINT "PK_0069785eead914d9e38ed3e0486" PRIMARY KEY (id); - - - -- - -- Name: student_emails PK_02547c64dee0325548ee56025ff; Type: CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.student_emails - ADD CONSTRAINT "PK_02547c64dee0325548ee56025ff" PRIMARY KEY (email); - - - -- - -- Name: work_experiences PK_3189db15aaccc2861851ea3da17; Type: CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.work_experiences - ADD CONSTRAINT "PK_3189db15aaccc2861851ea3da17" PRIMARY KEY (id); - - - -- - -- Name: educations PK_36350278ed06e4381c2b4912956; Type: CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.educations - ADD CONSTRAINT "PK_36350278ed06e4381c2b4912956" PRIMARY KEY (id); - - - -- - -- Name: scholarship_recipients PK_401156c93c7624333d75a4d1aa6; Type: CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.scholarship_recipients - ADD CONSTRAINT "PK_401156c93c7624333d75a4d1aa6" PRIMARY KEY (id); - - - -- - -- Name: events PK_40731c7151fe4be3116e45ddf73; Type: CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.events - ADD CONSTRAINT "PK_40731c7151fe4be3116e45ddf73" PRIMARY KEY (id); - - - -- - -- Name: email_lists PK_5434f9b31ac88ee87a432b259b1; Type: CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.email_lists - ADD CONSTRAINT "PK_5434f9b31ac88ee87a432b259b1" PRIMARY KEY (id); - - - -- - -- Name: slack_reactions PK_5ng8jzb0vrri; Type: CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.slack_reactions - ADD CONSTRAINT "PK_5ng8jzb0vrri" PRIMARY KEY (channel_id, message_id, reaction, user_id); - - - -- - -- Name: student_active_statuses PK_626375e603a688a40df9e6a1ded; Type: CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.student_active_statuses - ADD CONSTRAINT "PK_626375e603a688a40df9e6a1ded" PRIMARY KEY (date, student_id); - - - -- - -- Name: resources PK_632484ab9dff41bba94f9b7c85e; Type: CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.resources - ADD CONSTRAINT "PK_632484ab9dff41bba94f9b7c85e" PRIMARY KEY (id); - - - -- - -- Name: email_campaigns PK_72bad329795785308e66d562350; Type: CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.email_campaigns - ADD CONSTRAINT "PK_72bad329795785308e66d562350" PRIMARY KEY (id); - - - -- - -- Name: students PK_7d7f07271ad4ce999880713f05e; Type: CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.students - ADD CONSTRAINT "PK_7d7f07271ad4ce999880713f05e" PRIMARY KEY (id); - - - -- - -- Name: activities PK_7f4004429f731ffb9c88eb486a8; Type: CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.activities - ADD CONSTRAINT "PK_7f4004429f731ffb9c88eb486a8" PRIMARY KEY (id); - - - -- - -- Name: program_participants PK_812f2ac865358ccaaf97a9f08db; Type: CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.program_participants - ADD CONSTRAINT "PK_812f2ac865358ccaaf97a9f08db" PRIMARY KEY (id); - - - -- - -- Name: migrations PK_8c82d7f526340ab734260ea46be; Type: CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.migrations - ADD CONSTRAINT "PK_8c82d7f526340ab734260ea46be" PRIMARY KEY (id); - - - -- - -- Name: completed_activities PK_8ccdc2a5be10feefbe7c2dd43f8; Type: CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.completed_activities - ADD CONSTRAINT "PK_8ccdc2a5be10feefbe7c2dd43f8" PRIMARY KEY (id); - - - -- - -- Name: onboarding_session_attendees PK_8d6422c2f867a2335d7a459ce10; Type: CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.onboarding_session_attendees - ADD CONSTRAINT "PK_8d6422c2f867a2335d7a459ce10" PRIMARY KEY (id); - - - -- - -- Name: applications PK_938c0a27255637bde919591888f; Type: CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.applications - ADD CONSTRAINT "PK_938c0a27255637bde919591888f" PRIMARY KEY (id); - - - -- - -- Name: onboarding_sessions PK_9553e455cbfe1aeebc6f43ae379; Type: CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.onboarding_sessions - ADD CONSTRAINT "PK_9553e455cbfe1aeebc6f43ae379" PRIMARY KEY (id); - - - -- - -- Name: schools PK_95b932e47ac129dd8e23a0db548; Type: CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.schools - ADD CONSTRAINT "PK_95b932e47ac129dd8e23a0db548" PRIMARY KEY (id); - - - -- - -- Name: slack_channels PK_9966694c91c805a3461d5b6f979; Type: CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.slack_channels - ADD CONSTRAINT "PK_9966694c91c805a3461d5b6f979" PRIMARY KEY (id); - - - -- - -- Name: one_time_codes PK_ae6fc30aa12eeae02fec8d6b63e; Type: CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.one_time_codes - ADD CONSTRAINT "PK_ae6fc30aa12eeae02fec8d6b63e" PRIMARY KEY (id); - - - -- - -- Name: resource_users PK_c7f28147fbfc9d54240aeb95815; Type: CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.resource_users - ADD CONSTRAINT "PK_c7f28147fbfc9d54240aeb95815" PRIMARY KEY (id); - - - -- - -- Name: slack_messages PK_cgnvg61wr16b; Type: CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.slack_messages - ADD CONSTRAINT "PK_cgnvg61wr16b" PRIMARY KEY (channel_id, id); - - - -- - -- Name: email_campaign_opens PK_d1afc92f28b86e8ab2563eb4f61; Type: CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.email_campaign_opens - ADD CONSTRAINT "PK_d1afc92f28b86e8ab2563eb4f61" PRIMARY KEY (id); - - - -- - -- Name: email_campaign_clicks PK_d3beb0d07a8e4e490cbfc4bf328; Type: CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.email_campaign_clicks - ADD CONSTRAINT "PK_d3beb0d07a8e4e490cbfc4bf328" PRIMARY KEY (id); - - - -- - -- Name: programs PK_d43c664bcaafc0e8a06dfd34e05; Type: CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.programs - ADD CONSTRAINT "PK_d43c664bcaafc0e8a06dfd34e05" PRIMARY KEY (id); - - - -- - -- Name: companies PK_d4bc3e82a314fa9e29f652c2c22; Type: CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.companies - ADD CONSTRAINT "PK_d4bc3e82a314fa9e29f652c2c22" PRIMARY KEY (id); - - - -- - -- Name: admins PK_e3b38270c97a854c48d2e80874e; Type: CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.admins - ADD CONSTRAINT "PK_e3b38270c97a854c48d2e80874e" PRIMARY KEY (id); - - - -- - -- Name: event_attendees PK_w2fq46mtaves; Type: CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.event_attendees - ADD CONSTRAINT "PK_w2fq46mtaves" PRIMARY KEY (email, event_id); - - - -- - -- Name: event_registrations PK_w4kq002onr1g; Type: CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.event_registrations - ADD CONSTRAINT "PK_w4kq002onr1g" PRIMARY KEY (email, event_id); - - - -- - -- Name: admins UQ_051db7d37d478a69a7432df1479; Type: CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.admins - ADD CONSTRAINT "UQ_051db7d37d478a69a7432df1479" UNIQUE (email); - - - -- - -- Name: completed_activities UQ_1keak785y8o9; Type: CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.completed_activities - ADD CONSTRAINT "UQ_1keak785y8o9" UNIQUE (event_attended, student_id); - - - -- - -- Name: students UQ_25985d58c714a4a427ced57507b; Type: CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.students - ADD CONSTRAINT "UQ_25985d58c714a4a427ced57507b" UNIQUE (email); - - - -- - -- Name: companies UQ_3212cc5ff994a44d966e00f1102; Type: CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.companies - ADD CONSTRAINT "UQ_3212cc5ff994a44d966e00f1102" UNIQUE (crunchbase_id); - - - -- - -- Name: schools UQ_32fbaf4feccea51ef7aeefa62bb; Type: CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.schools - ADD CONSTRAINT "UQ_32fbaf4feccea51ef7aeefa62bb" UNIQUE (name); - - - -- - -- Name: event_attendees UQ_9d32xlhph8j7; Type: CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.event_attendees - ADD CONSTRAINT "UQ_9d32xlhph8j7" UNIQUE (student_id, event_id); - - - -- - -- Name: students UQ_a23ab2db471b068703d857917ad; Type: CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.students - ADD CONSTRAINT "UQ_a23ab2db471b068703d857917ad" UNIQUE (slack_id); - - - -- - -- Name: completed_activities UQ_dkl1vdbp1v87; Type: CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.completed_activities - ADD CONSTRAINT "UQ_dkl1vdbp1v87" UNIQUE (channel_id, thread_replied_to, student_id); - - - -- - -- Name: completed_activities UQ_hu3bfyzq31aq; Type: CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.completed_activities - ADD CONSTRAINT "UQ_hu3bfyzq31aq" UNIQUE (channel_id, message_reacted_to, student_id); - - - -- - -- Name: event_registrations UQ_j5tvjlqsyvqd; Type: CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.event_registrations - ADD CONSTRAINT "UQ_j5tvjlqsyvqd" UNIQUE (event_id, student_id); - - - -- - -- Name: countries countries_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.countries - ADD CONSTRAINT countries_pkey PRIMARY KEY (code); - - - -- - -- Name: icebreaker_prompts icebreaker_prompts_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.icebreaker_prompts - ADD CONSTRAINT icebreaker_prompts_pkey PRIMARY KEY (id); - - - -- - -- Name: icebreaker_responses icebreaker_responses_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.icebreaker_responses - ADD CONSTRAINT icebreaker_responses_pkey PRIMARY KEY (id); - - - -- - -- Name: icebreaker_responses icebreaker_responses_prompt_id_student_id_key; Type: CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.icebreaker_responses - ADD CONSTRAINT icebreaker_responses_prompt_id_student_id_key UNIQUE (prompt_id, student_id); - - -- - -- Name: member_ethnicities member_ethnicities_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.member_ethnicities - ADD CONSTRAINT member_ethnicities_pkey PRIMARY KEY (country_code, student_id); - - - -- - -- Name: profile_views profile_views_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.profile_views - ADD CONSTRAINT profile_views_pkey PRIMARY KEY (id); - - - -- - -- Name: program_participants program_participants_email_program_id_key; Type: CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.program_participants - ADD CONSTRAINT program_participants_email_program_id_key UNIQUE (email, program_id); - - - -- - -- Name: resource_users resource_users_email_resource_id_key; Type: CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.resource_users - ADD CONSTRAINT resource_users_email_resource_id_key UNIQUE (email, resource_id); - - - -- - -- Name: survey_responses survey_responses_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.survey_responses - ADD CONSTRAINT survey_responses_pkey PRIMARY KEY (id); - - - -- - -- Name: surveys surveys_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.surveys - ADD CONSTRAINT surveys_pkey PRIMARY KEY (id); - - - -- - -- Name: survey_responses uq_aoq88oc8eaex; Type: CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.survey_responses - ADD CONSTRAINT uq_aoq88oc8eaex UNIQUE (student_id, survey_id); - - - -- - -- Name: survey_responses uq_oy0aq901k8hd; Type: CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.survey_responses - ADD CONSTRAINT uq_oy0aq901k8hd UNIQUE (email, survey_id); - - - -- - -- Name: completed_activities uq_uxq5qa94nscl; Type: CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.completed_activities - ADD CONSTRAINT uq_uxq5qa94nscl UNIQUE (student_id, survey_responded_to); - - - -- - -- Name: IDX_0d268fc05202a7001a97acbec6; Type: INDEX; Schema: public; Owner: postgres - -- - - CREATE INDEX "IDX_0d268fc05202a7001a97acbec6" ON public.email_campaign_links USING btree (campaign_id); - - - -- - -- Name: IDX_0m1j8gf4jcob; Type: INDEX; Schema: public; Owner: postgres - -- - - CREATE UNIQUE INDEX "IDX_0m1j8gf4jcob" ON public.completed_activities USING btree (student_id, type) WHERE (type = 'upload_profile_picture'::text); - - - -- - -- Name: IDX_18ade916f4d282e0569af931f8; Type: INDEX; Schema: public; Owner: postgres - -- - - CREATE INDEX "IDX_18ade916f4d282e0569af931f8" ON public.event_attendees USING btree (student_id); - - - -- - -- Name: IDX_26eac4de832305aa86593c04f4; Type: INDEX; Schema: public; Owner: postgres - -- - - CREATE UNIQUE INDEX "IDX_26eac4de832305aa86593c04f4" ON public.email_campaign_opens USING btree (campaign_id, opened_at, student_id); - - - -- - -- Name: IDX_36c51b6c73fe30f5e5c6f17311; Type: INDEX; Schema: public; Owner: postgres - -- - - CREATE UNIQUE INDEX "IDX_36c51b6c73fe30f5e5c6f17311" ON public.email_campaign_clicks USING btree (campaign_id, link_id, clicked_at, student_id); - - - -- - -- Name: IDX_3eff6f5ff06a40289cb3043aad; Type: INDEX; Schema: public; Owner: postgres - -- - - CREATE INDEX "IDX_3eff6f5ff06a40289cb3043aad" ON public.email_campaign_opens USING btree (student_id); - - - -- - -- Name: IDX_51114950b0357f1553aa50a286; Type: INDEX; Schema: public; Owner: postgres - -- - - CREATE UNIQUE INDEX "IDX_51114950b0357f1553aa50a286" ON public.slack_reactions USING btree (message_id, student_id, reaction); - - - -- - -- Name: IDX_7f842b2e8b974cd534c73f9201; Type: INDEX; Schema: public; Owner: postgres - -- - - CREATE UNIQUE INDEX "IDX_7f842b2e8b974cd534c73f9201" ON public.email_campaign_links USING btree (campaign_id, url); - - - -- - -- Name: IDX_862ba95e551ed267529bb8ad6a; Type: INDEX; Schema: public; Owner: postgres - -- - - CREATE INDEX "IDX_862ba95e551ed267529bb8ad6a" ON public.email_campaign_clicks USING btree (campaign_id); - - - -- - -- Name: IDX_a481b5eff9cb1ec9fbd809c49c; Type: INDEX; Schema: public; Owner: postgres - -- - - CREATE INDEX "IDX_a481b5eff9cb1ec9fbd809c49c" ON public.student_active_statuses USING btree (student_id); - - - -- - -- Name: IDX_a98wx9mszfw0; Type: INDEX; Schema: public; Owner: postgres - -- - - CREATE INDEX "IDX_a98wx9mszfw0" ON public.completed_activities USING btree (student_id); - - - -- - -- Name: IDX_ba45cb3020365126402d989431; Type: INDEX; Schema: public; Owner: postgres - -- - - CREATE UNIQUE INDEX "IDX_ba45cb3020365126402d989431" ON public.onboarding_session_attendees USING btree (session_id, student_id); - - - -- - -- Name: IDX_ba50d0f7b68ee5b73f7e7b8fdf; Type: INDEX; Schema: public; Owner: postgres - -- - - CREATE UNIQUE INDEX "IDX_ba50d0f7b68ee5b73f7e7b8fdf" ON public.programs USING btree (name); - - - -- - -- Name: IDX_c4cb735fac413057e9048b51ec; Type: INDEX; Schema: public; Owner: postgres - -- - - CREATE UNIQUE INDEX "IDX_c4cb735fac413057e9048b51ec" ON public.resource_users USING btree (resource_id, student_id); - - - -- - -- Name: IDX_cb8365260639d4ff2adec365f7; Type: INDEX; Schema: public; Owner: postgres - -- - - CREATE UNIQUE INDEX "IDX_cb8365260639d4ff2adec365f7" ON public.email_campaign_clicks USING btree (campaign_id, link_id, clicked_at, email); - - - -- - -- Name: IDX_e9dd2cd0ea65030b580faded74; Type: INDEX; Schema: public; Owner: postgres - -- - - CREATE INDEX "IDX_e9dd2cd0ea65030b580faded74" ON public.email_campaign_opens USING btree (campaign_id); - - - -- - -- Name: IDX_f276c867b5752b7cc2c6c797b2; Type: INDEX; Schema: public; Owner: postgres - -- - - CREATE UNIQUE INDEX "IDX_f276c867b5752b7cc2c6c797b2" ON public.resources USING btree (name); - - - -- - -- Name: IDX_f31b366f6f638b8bcef707e8b2; Type: INDEX; Schema: public; Owner: postgres - -- - - CREATE UNIQUE INDEX "IDX_f31b366f6f638b8bcef707e8b2" ON public.email_campaign_opens USING btree (campaign_id, opened_at, email); - - - -- - -- Name: IDX_f445685cf399095c8faf4a6fdb; Type: INDEX; Schema: public; Owner: postgres - -- - - CREATE UNIQUE INDEX "IDX_f445685cf399095c8faf4a6fdb" ON public.program_participants USING btree (program_id, student_id); - - - -- - -- Name: IDX_ff31bb932552a9a6fe61299350; Type: INDEX; Schema: public; Owner: postgres - -- - - CREATE INDEX "IDX_ff31bb932552a9a6fe61299350" ON public.email_campaign_clicks USING btree (student_id); - - - -- - -- Name: IDX_n0rlsilgnwue; Type: INDEX; Schema: public; Owner: postgres - -- - - CREATE INDEX "IDX_n0rlsilgnwue" ON public.students USING btree (school_id); - - - -- - -- Name: IDX_xw6v9c9h9doq; Type: INDEX; Schema: public; Owner: postgres - -- - - CREATE UNIQUE INDEX "IDX_xw6v9c9h9doq" ON public.completed_activities USING btree (student_id, type) WHERE (type = 'get_activated'::text); - - - -- - -- Name: idx_7q4xebf9marc; Type: INDEX; Schema: public; Owner: postgres - -- - - CREATE UNIQUE INDEX idx_7q4xebf9marc ON public.completed_activities USING btree (student_id, type) WHERE (type = 'join_member_directory'::text); - - - -- - -- Name: slack_messages_student_id_idx; Type: INDEX; Schema: public; Owner: postgres - -- - - CREATE INDEX slack_messages_student_id_idx ON public.slack_messages USING btree (student_id); - - - -- - -- Name: slack_reactions_student_id_idx; Type: INDEX; Schema: public; Owner: postgres - -- - - CREATE INDEX slack_reactions_student_id_idx ON public.slack_reactions USING btree (student_id); - - - -- - -- Name: student_active_statuses_student_id_status_date_idx; Type: INDEX; Schema: public; Owner: postgres - -- - - CREATE INDEX student_active_statuses_student_id_status_date_idx ON public.student_active_statuses USING btree (student_id, status, date DESC); - - - -- - -- Name: completed_activities FK_0140c854ae5304f6546171332b6; Type: FK CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.completed_activities - ADD CONSTRAINT "FK_0140c854ae5304f6546171332b6" FOREIGN KEY (activity_id) REFERENCES public.activities(id); - - - -- - -- Name: email_campaign_clicks FK_01e6991497a0b070a89f6bcb4bf; Type: FK CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.email_campaign_clicks - ADD CONSTRAINT "FK_01e6991497a0b070a89f6bcb4bf" FOREIGN KEY (link_id) REFERENCES public.email_campaign_links(id); - - - -- - -- Name: email_campaign_links FK_0d268fc05202a7001a97acbec6b; Type: FK CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.email_campaign_links - ADD CONSTRAINT "FK_0d268fc05202a7001a97acbec6b" FOREIGN KEY (campaign_id) REFERENCES public.email_campaigns(id); - - - -- - -- Name: event_attendees FK_18ade916f4d282e0569af931f83; Type: FK CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.event_attendees - ADD CONSTRAINT "FK_18ade916f4d282e0569af931f83" FOREIGN KEY (student_id) REFERENCES public.students(id) ON DELETE SET NULL; - - - -- - -- Name: students FK_25985d58c714a4a427ced57507b; Type: FK CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.students - ADD CONSTRAINT "FK_25985d58c714a4a427ced57507b" FOREIGN KEY (email) REFERENCES public.student_emails(email); - - - -- - -- Name: applications FK_268c174013ce6952213dd2e3c2e; Type: FK CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.applications - ADD CONSTRAINT "FK_268c174013ce6952213dd2e3c2e" FOREIGN KEY (school_id) REFERENCES public.schools(id); - - - -- - -- Name: work_experiences FK_3808b5a5551cc1296d1ae61ce9c; Type: FK CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.work_experiences - ADD CONSTRAINT "FK_3808b5a5551cc1296d1ae61ce9c" FOREIGN KEY (company_id) REFERENCES public.companies(id); - - - -- - -- Name: one_time_codes FK_384dfee27fef0a012f440a45b5b; Type: FK CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.one_time_codes - ADD CONSTRAINT "FK_384dfee27fef0a012f440a45b5b" FOREIGN KEY (student_id) REFERENCES public.students(id) ON DELETE CASCADE; - - - -- - -- Name: slack_messages FK_3e1cccaa310435f7572a4e3bd6e; Type: FK CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.slack_messages - ADD CONSTRAINT "FK_3e1cccaa310435f7572a4e3bd6e" FOREIGN KEY (student_id) REFERENCES public.students(id) ON DELETE SET NULL; - - - -- - -- Name: email_campaign_opens FK_3eff6f5ff06a40289cb3043aadd; Type: FK CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.email_campaign_opens - ADD CONSTRAINT "FK_3eff6f5ff06a40289cb3043aadd" FOREIGN KEY (student_id) REFERENCES public.students(id) ON DELETE SET NULL; - - - -- - -- Name: work_experiences FK_52b1e7a2b8965b1e9479ebffd62; Type: FK CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.work_experiences - ADD CONSTRAINT "FK_52b1e7a2b8965b1e9479ebffd62" FOREIGN KEY (student_id) REFERENCES public.students(id) ON DELETE CASCADE; - - - -- - -- Name: completed_activities FK_584a13934be81dd51e5d2c14d60; Type: FK CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.completed_activities - ADD CONSTRAINT "FK_584a13934be81dd51e5d2c14d60" FOREIGN KEY (student_id) REFERENCES public.students(id) ON DELETE CASCADE; - - - -- - -- Name: resource_users FK_5cca18dab247ece1379c21a4253; Type: FK CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.resource_users - ADD CONSTRAINT "FK_5cca18dab247ece1379c21a4253" FOREIGN KEY (resource_id) REFERENCES public.resources(id); - - - -- - -- Name: educations FK_6645bc400ae3486b7182fb36e3f; Type: FK CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.educations - ADD CONSTRAINT "FK_6645bc400ae3486b7182fb36e3f" FOREIGN KEY (school_id) REFERENCES public.schools(id); - - - -- - -- Name: resource_users FK_69f79a37afc88e975ac3d0cde42; Type: FK CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.resource_users - ADD CONSTRAINT "FK_69f79a37afc88e975ac3d0cde42" FOREIGN KEY (student_id) REFERENCES public.students(id) ON DELETE SET NULL; - - - -- - -- Name: applications FK_7b8cdcaabacb80df1ed8f7dbbea; Type: FK CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.applications - ADD CONSTRAINT "FK_7b8cdcaabacb80df1ed8f7dbbea" FOREIGN KEY (reviewed_by_id) REFERENCES public.admins(id); - - - -- - -- Name: email_campaign_clicks FK_862ba95e551ed267529bb8ad6a5; Type: FK CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.email_campaign_clicks - ADD CONSTRAINT "FK_862ba95e551ed267529bb8ad6a5" FOREIGN KEY (campaign_id) REFERENCES public.email_campaigns(id); - - - -- - -- Name: event_attendees FK_8f6qydm8w4d9; Type: FK CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.event_attendees - ADD CONSTRAINT "FK_8f6qydm8w4d9" FOREIGN KEY (event_id) REFERENCES public.events(id); - - - -- - -- Name: program_participants FK_965fe2c3b348678f5494b6ad958; Type: FK CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.program_participants - ADD CONSTRAINT "FK_965fe2c3b348678f5494b6ad958" FOREIGN KEY (program_id) REFERENCES public.programs(id); - - - -- - -- Name: educations FK_9e4fe4a0c54edfb14240310f7f7; Type: FK CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.educations - ADD CONSTRAINT "FK_9e4fe4a0c54edfb14240310f7f7" FOREIGN KEY (student_id) REFERENCES public.students(id) ON DELETE CASCADE; - - - -- - -- Name: student_active_statuses FK_a481b5eff9cb1ec9fbd809c49c9; Type: FK CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.student_active_statuses - ADD CONSTRAINT "FK_a481b5eff9cb1ec9fbd809c49c9" FOREIGN KEY (student_id) REFERENCES public.students(id) ON DELETE CASCADE; - - - -- - -- Name: students FK_aa8edc7905ad764f85924569647; Type: FK CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.students - ADD CONSTRAINT "FK_aa8edc7905ad764f85924569647" FOREIGN KEY (school_id) REFERENCES public.schools(id); - - - -- - -- Name: students FK_b3bc610967da06de7b140494c7b; Type: FK CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.students - ADD CONSTRAINT "FK_b3bc610967da06de7b140494c7b" FOREIGN KEY (application_id) REFERENCES public.applications(id); - - - -- - -- Name: one_time_codes FK_b7934bebe662bc7d70138e71cef; Type: FK CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.one_time_codes - ADD CONSTRAINT "FK_b7934bebe662bc7d70138e71cef" FOREIGN KEY (admin_id) REFERENCES public.admins(id); - - - -- - -- Name: email_campaigns FK_ba34bdeebfa85d35a5e3953dc78; Type: FK CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.email_campaigns - ADD CONSTRAINT "FK_ba34bdeebfa85d35a5e3953dc78" FOREIGN KEY (list_id) REFERENCES public.email_lists(id); - - - -- - -- Name: onboarding_session_attendees FK_bf1323140d7698f91ff21bb9a01; Type: FK CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.onboarding_session_attendees - ADD CONSTRAINT "FK_bf1323140d7698f91ff21bb9a01" FOREIGN KEY (session_id) REFERENCES public.onboarding_sessions(id); - - - -- - -- Name: student_emails FK_c868fb36612a0e7110aae3e265a; Type: FK CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.student_emails - ADD CONSTRAINT "FK_c868fb36612a0e7110aae3e265a" FOREIGN KEY (student_id) REFERENCES public.students(id) ON DELETE CASCADE; - - - -- - -- Name: program_participants FK_cb8c4f8b4567856155df7a54c88; Type: FK CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.program_participants - ADD CONSTRAINT "FK_cb8c4f8b4567856155df7a54c88" FOREIGN KEY (student_id) REFERENCES public.students(id) ON DELETE SET NULL; - - - -- - -- Name: slack_messages FK_doj63hsxt11w; Type: FK CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.slack_messages - ADD CONSTRAINT "FK_doj63hsxt11w" FOREIGN KEY (channel_id) REFERENCES public.slack_channels(id); - - - -- - -- Name: scholarship_recipients FK_e7d02c87af4a039ee9ae54b803c; Type: FK CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.scholarship_recipients - ADD CONSTRAINT "FK_e7d02c87af4a039ee9ae54b803c" FOREIGN KEY (student_id) REFERENCES public.students(id); - - - -- - -- Name: onboarding_session_attendees FK_e973d14344e5b73a9d3e20b717f; Type: FK CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.onboarding_session_attendees - ADD CONSTRAINT "FK_e973d14344e5b73a9d3e20b717f" FOREIGN KEY (student_id) REFERENCES public.students(id) ON DELETE CASCADE; - - - -- - -- Name: email_campaign_opens FK_e9dd2cd0ea65030b580faded745; Type: FK CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.email_campaign_opens - ADD CONSTRAINT "FK_e9dd2cd0ea65030b580faded745" FOREIGN KEY (campaign_id) REFERENCES public.email_campaigns(id); - - - -- - -- Name: slack_reactions FK_fa25662801e3a7cf0062d0b7009; Type: FK CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.slack_reactions - ADD CONSTRAINT "FK_fa25662801e3a7cf0062d0b7009" FOREIGN KEY (student_id) REFERENCES public.students(id) ON DELETE SET NULL; - - - -- - -- Name: email_campaign_clicks FK_ff31bb932552a9a6fe61299350e; Type: FK CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.email_campaign_clicks - ADD CONSTRAINT "FK_ff31bb932552a9a6fe61299350e" FOREIGN KEY (student_id) REFERENCES public.students(id) ON DELETE SET NULL; - - - -- - -- Name: completed_activities FK_mrbv401qw438; Type: FK CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.completed_activities - ADD CONSTRAINT "FK_mrbv401qw438" FOREIGN KEY (channel_id, message_reacted_to) REFERENCES public.slack_messages(channel_id, id) ON DELETE CASCADE; - - - -- - -- Name: slack_reactions FK_pgm1oozls356; Type: FK CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.slack_reactions - ADD CONSTRAINT "FK_pgm1oozls356" FOREIGN KEY (channel_id, message_id) REFERENCES public.slack_messages(channel_id, id) ON DELETE CASCADE; - - - -- - -- Name: slack_messages FK_w6029u2uo4kh; Type: FK CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.slack_messages - ADD CONSTRAINT "FK_w6029u2uo4kh" FOREIGN KEY (channel_id, thread_id) REFERENCES public.slack_messages(channel_id, id); - - - -- - -- Name: slack_reactions FK_wkqtysz0eb3b; Type: FK CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.slack_reactions - ADD CONSTRAINT "FK_wkqtysz0eb3b" FOREIGN KEY (channel_id) REFERENCES public.slack_channels(id); - - - -- - -- Name: completed_activities FK_y7q0nggl9ag6; Type: FK CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.completed_activities - ADD CONSTRAINT "FK_y7q0nggl9ag6" FOREIGN KEY (event_attended) REFERENCES public.events(id) ON DELETE CASCADE; - - - -- - -- Name: completed_activities FK_z76csrquvzq1; Type: FK CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.completed_activities - ADD CONSTRAINT "FK_z76csrquvzq1" FOREIGN KEY (channel_id, thread_replied_to) REFERENCES public.slack_messages(channel_id, id) ON DELETE CASCADE; - - - -- - -- Name: completed_activities completed_activities_survey_responded_to_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.completed_activities - ADD CONSTRAINT completed_activities_survey_responded_to_fkey FOREIGN KEY (survey_responded_to) REFERENCES public.surveys(id) ON DELETE CASCADE; - - - -- - -- Name: event_registrations event_registrations_event_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.event_registrations - ADD CONSTRAINT event_registrations_event_id_fkey FOREIGN KEY (event_id) REFERENCES public.events(id); - - - -- - -- Name: event_registrations event_registrations_student_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.event_registrations - ADD CONSTRAINT event_registrations_student_id_fkey FOREIGN KEY (student_id) REFERENCES public.students(id); - - - -- - -- Name: icebreaker_responses icebreaker_responses_prompt_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.icebreaker_responses - ADD CONSTRAINT icebreaker_responses_prompt_id_fkey FOREIGN KEY (prompt_id) REFERENCES public.icebreaker_prompts(id); - - - -- - -- Name: icebreaker_responses icebreaker_responses_student_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.icebreaker_responses - ADD CONSTRAINT icebreaker_responses_student_id_fkey FOREIGN KEY (student_id) REFERENCES public.students(id); - - - -- - -- Name: member_ethnicities member_ethnicities_country_code_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.member_ethnicities - ADD CONSTRAINT member_ethnicities_country_code_fkey FOREIGN KEY (country_code) REFERENCES public.countries(code); - - - -- - -- Name: member_ethnicities member_ethnicities_student_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.member_ethnicities - ADD CONSTRAINT member_ethnicities_student_id_fkey FOREIGN KEY (student_id) REFERENCES public.students(id); - - - -- - -- Name: profile_views profile_views_profile_viewed_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.profile_views - ADD CONSTRAINT profile_views_profile_viewed_id_fkey FOREIGN KEY (profile_viewed_id) REFERENCES public.students(id); - - - -- - -- Name: profile_views profile_views_viewer_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.profile_views - ADD CONSTRAINT profile_views_viewer_id_fkey FOREIGN KEY (viewer_id) REFERENCES public.students(id); - - - -- - -- Name: survey_responses survey_responses_student_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.survey_responses - ADD CONSTRAINT survey_responses_student_id_fkey FOREIGN KEY (student_id) REFERENCES public.students(id) ON DELETE SET NULL; - - - -- - -- Name: survey_responses survey_responses_survey_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.survey_responses - ADD CONSTRAINT survey_responses_survey_id_fkey FOREIGN KEY (survey_id) REFERENCES public.surveys(id); - - - -- - -- Name: surveys surveys_event_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: postgres - -- - - ALTER TABLE ONLY public.surveys - ADD CONSTRAINT surveys_event_id_fkey FOREIGN KEY (event_id) REFERENCES public.events(id) ON DELETE SET NULL; - - - -- - -- PostgreSQL database dump complete - -- - `.execute(db); -} - -export async function down(db: Kysely) {} diff --git a/packages/core/src/infrastructure/database/migrations/2024-01-29T19:05:29Z-birthdate.ts b/packages/core/src/infrastructure/database/migrations/2024-01-29T19:05:29Z-birthdate.ts deleted file mode 100644 index 5494e110..00000000 --- a/packages/core/src/infrastructure/database/migrations/2024-01-29T19:05:29Z-birthdate.ts +++ /dev/null @@ -1,12 +0,0 @@ -import { Kysely } from 'kysely'; - -export async function up(db: Kysely) { - await db.schema - .alterTable('students') - .addColumn('birthdate', 'date') - .execute(); -} - -export async function down(db: Kysely) { - await db.schema.alterTable('students').dropColumn('birthdate').execute(); -} diff --git a/packages/core/src/infrastructure/database/migrations/2024-02-12T21:28:42Z-fix-removal.ts b/packages/core/src/infrastructure/database/migrations/2024-02-12T21:28:42Z-fix-removal.ts deleted file mode 100644 index e8ce1fee..00000000 --- a/packages/core/src/infrastructure/database/migrations/2024-02-12T21:28:42Z-fix-removal.ts +++ /dev/null @@ -1,93 +0,0 @@ -import { Kysely } from 'kysely'; - -export async function up(db: Kysely) { - // event_registrations - - await db.schema - .alterTable('event_registrations') - .dropConstraint('event_registrations_student_id_fkey') - .execute(); - - await db.schema - .alterTable('event_registrations') - .addForeignKeyConstraint( - 'event_registrations_student_id_fkey', - ['student_id'], - 'students', - ['id'] - ) - .onDelete('cascade') - .execute(); - - // icebreaker_responses - - await db.schema - .alterTable('icebreaker_responses') - .dropConstraint('icebreaker_responses_student_id_fkey') - .execute(); - - await db.schema - .alterTable('icebreaker_responses') - .addForeignKeyConstraint( - 'icebreaker_responses_student_id_fkey', - ['student_id'], - 'students', - ['id'] - ) - .onDelete('cascade') - .execute(); - - // member_ethnicities - - await db.schema - .alterTable('member_ethnicities') - .dropConstraint('member_ethnicities_student_id_fkey') - .execute(); - - await db.schema - .alterTable('member_ethnicities') - .addForeignKeyConstraint( - 'member_ethnicities_student_id_fkey', - ['student_id'], - 'students', - ['id'] - ) - .onDelete('cascade') - .execute(); - - // profile_views - - await db.schema - .alterTable('profile_views') - .dropConstraint('profile_views_profile_viewed_id_fkey') - .execute(); - - await db.schema - .alterTable('profile_views') - .dropConstraint('profile_views_viewer_id_fkey') - .execute(); - - await db.schema - .alterTable('profile_views') - .addForeignKeyConstraint( - 'profile_views_profile_viewed_id_fkey', - ['profile_viewed_id'], - 'students', - ['id'] - ) - .onDelete('cascade') - .execute(); - - await db.schema - .alterTable('profile_views') - .addForeignKeyConstraint( - 'profile_views_viewer_id_fkey', - ['viewer_id'], - 'students', - ['id'] - ) - .onDelete('cascade') - .execute(); -} - -export async function down(db: Kysely) {} diff --git a/packages/core/src/infrastructure/database/migrations/2024-03-11T10:33:01Z-job_offers.ts b/packages/core/src/infrastructure/database/migrations/2024-03-11T10:33:01Z-job_offers.ts deleted file mode 100644 index 748cf7f1..00000000 --- a/packages/core/src/infrastructure/database/migrations/2024-03-11T10:33:01Z-job_offers.ts +++ /dev/null @@ -1,36 +0,0 @@ -import { Kysely, sql } from 'kysely'; - -export async function up(db: Kysely) { - await db.schema - .createTable('job_offers') - .addColumn('id', 'text', (cb) => cb.primaryKey()) - .addColumn('created_at', 'timestamptz', (cb) => - cb.notNull().defaultTo(sql`now()`) - ) - .addColumn('base_salary', 'integer') - .addColumn('bonus', 'integer') - .addColumn('company_id', 'text', (cb) => { - return cb.references('companies.id'); - }) - .addColumn('compensation_type', 'text', (cb) => cb.notNull()) - .addColumn('employment_type', 'text', (cb) => cb.notNull()) - .addColumn('hourly_pay', 'integer') - .addColumn('other_company', 'text') - .addColumn('start_date', 'date', (cb) => cb.notNull()) - .addColumn('status', 'text', (cb) => cb.notNull()) - .addColumn('stock_per_year', 'integer') - .addColumn('student_id', 'text', (cb) => { - return cb.references('students.id').notNull(); - }) - .addColumn('updated_at', 'timestamptz', (cb) => - cb.notNull().defaultTo(sql`now()`) - ) - .addColumn('location', 'text') - .addColumn('location_coordinates', sql`point`) - .addColumn('location_type', 'text', (cb) => cb.notNull()) - .execute(); -} - -export async function down(db: Kysely) { - await db.schema.dropTable('job_offers').execute(); -} diff --git a/packages/core/src/infrastructure/database/migrations/2024-03-18T17:06:13Z-birthday-notification.ts b/packages/core/src/infrastructure/database/migrations/2024-03-18T17:06:13Z-birthday-notification.ts deleted file mode 100644 index 80783baa..00000000 --- a/packages/core/src/infrastructure/database/migrations/2024-03-18T17:06:13Z-birthday-notification.ts +++ /dev/null @@ -1,15 +0,0 @@ -import { Kysely } from 'kysely'; - -export async function up(db: Kysely) { - await db.schema - .alterTable('students') - .addColumn('birthdate_notification', 'boolean') - .execute(); -} - -export async function down(db: Kysely) { - await db.schema - .alterTable('students') - .dropColumn('birthdate_notification') - .execute(); -} \ No newline at end of file diff --git a/packages/core/src/infrastructure/database/migrations/2024-03-18T19:45:26Z-birthday-default.ts b/packages/core/src/infrastructure/database/migrations/2024-03-18T19:45:26Z-birthday-default.ts deleted file mode 100644 index 03b62e43..00000000 --- a/packages/core/src/infrastructure/database/migrations/2024-03-18T19:45:26Z-birthday-default.ts +++ /dev/null @@ -1,39 +0,0 @@ -import { Kysely } from 'kysely'; - -export async function up(db: Kysely) { - await db - .updateTable('students') - .set({ birthdate_notification: true }) - .execute(); - - await db.schema - .alterTable('students') - .alterColumn('birthdate_notification', (column) => { - return column.setDefault(true); - }) - .execute(); - - await db.schema - .alterTable('students') - .alterColumn('birthdate_notification', (column) => { - return column.setNotNull(); - }) - .execute(); -} - -export async function down(db: Kysely) { - await db.schema - .alterTable('students') - .alterColumn('birthdate_notification', (column) => { - return column.dropNotNull(); - }) - - .execute(); - - await db.schema - .alterTable('students') - .alterColumn('birthdate_notification', (column) => { - return column.dropDefault(); - }) - .execute(); -} diff --git a/packages/core/src/infrastructure/database/migrations/2024-03-31T21:37:51Z-share-email.ts b/packages/core/src/infrastructure/database/migrations/2024-03-31T21:37:51Z-share-email.ts deleted file mode 100644 index 0f8b4ab2..00000000 --- a/packages/core/src/infrastructure/database/migrations/2024-03-31T21:37:51Z-share-email.ts +++ /dev/null @@ -1,17 +0,0 @@ -import { Kysely } from 'kysely'; - -export async function up(db: Kysely) { - await db.schema - .alterTable('students') - .addColumn('allow_email_share', 'boolean', (column) => { - return column.notNull().defaultTo(true); - }) - .execute(); -} - -export async function down(db: Kysely) { - await db.schema - .alterTable('students') - .dropColumn('allow_email_share') - .execute(); -} diff --git a/packages/core/src/infrastructure/database/scripts/migrate.ts b/packages/core/src/infrastructure/database/scripts/migrate.ts deleted file mode 100644 index ceb0cd84..00000000 --- a/packages/core/src/infrastructure/database/scripts/migrate.ts +++ /dev/null @@ -1,16 +0,0 @@ -import { program } from 'commander'; - -import { migrate } from '../shared/migrate'; - -const DOWN_FLAG = '--down'; - -// Allow the program to use the "--down" flag. -program.option(DOWN_FLAG, 'Rollback the last migration.'); - -// Parse the command line arguments. -program.parse(); - -// Read the value of the "--down" flag. -const { down } = program.opts(); - -migrate({ down: !!down }); diff --git a/packages/core/src/infrastructure/database/scripts/seed.ts b/packages/core/src/infrastructure/database/scripts/seed.ts deleted file mode 100644 index 5e1a586a..00000000 --- a/packages/core/src/infrastructure/database/scripts/seed.ts +++ /dev/null @@ -1,175 +0,0 @@ -import { Transaction, sql } from 'kysely'; -import { DB } from 'kysely-codegen/dist/db'; -import readline from 'readline'; -import { z } from 'zod'; - -import { db } from '@/infrastructure/database'; -import { ENVIRONMENT } from '@/shared/env'; -import { migrate } from '../shared/migrate'; -import { truncate } from '../shared/truncate'; - -if (ENVIRONMENT !== 'development') { - throw new Error('Cannot seed database in non-development environment.'); -} - -async function main() { - try { - await setEmailFromCommandLine(); - console.log('(1/4) Email looks good. ✅'); - - await migrate({ db }); - console.log('(2/4) Ran migrations and initialized tables. ✅'); - - await db.transaction().execute(async (trx) => { - await truncate(trx); - await seed(trx); - }); - - console.log('(3/4) Wiped all data. ✅'); - console.log('(4/4) Seeded the database. ✅'); - } catch (e) { - console.error(e); - process.exit(1); - } finally { - await db.destroy(); - } -} - -let email = ''; - -async function seed(trx: Transaction) { - const schoolId1 = id(); - const schoolId2 = id(); - - await trx - .insertInto('schools') - .values([ - { - addressCity: 'Pittsburgh', - addressState: 'PA', - addressZip: '15213', - id: schoolId1, - name: 'Carnegie Mellon University', - }, - { - addressCity: 'Ithaca', - addressState: 'NY', - addressZip: '14850', - id: schoolId2, - name: 'Cornell University', - }, - { - addressCity: 'Washington', - addressState: 'D.C.', - addressZip: '20059', - id: id(), - name: 'Howard University', - }, - { - addressCity: 'Kennesaw', - addressState: 'GA', - addressZip: '30144', - id: id(), - name: 'Kennesaw State University', - }, - { - addressCity: 'Berkeley', - addressState: 'CA', - addressZip: '94720', - id: id(), - name: 'University of California, Berkeley', - }, - ]) - .execute(); - - await trx - .insertInto('admins') - .values([ - { - email, - id: id(), - isAmbassador: false, - firstName: 'First', - lastName: 'Last', - }, - ]) - .execute(); - - await trx.insertInto('studentEmails').values([{ email }]).execute(); - - const memberId = id(); - - await trx - .insertInto('students') - .values([ - { - acceptedAt: new Date(), - currentLocation: 'New York, NY', - currentLocationCoordinates: sql`point(-73.935242, 40.73061)`, - educationLevel: 'undergraduate', - email, - firstName: 'First', - gender: '', - graduationYear: new Date().getFullYear().toString(), - id: memberId, - lastName: 'Last', - major: 'computer_science', - otherDemographics: [], - race: [], - schoolId: schoolId1, - }, - ]) - .execute(); - - await trx - .updateTable('studentEmails') - .set({ studentId: memberId }) - .where('email', '=', email) - .execute(); -} - -async function setEmailFromCommandLine() { - const answer = await question( - 'In order to log into the Member Profile and Admin Dashboard, you will need both a member record and an admin record. Please provide an email so we can create those for you.\n' + - 'Email: ' - ); - - const result = z - .string() - .trim() - .min(1) - .email() - .transform((value) => { - return value.toLowerCase(); - }) - .safeParse(answer); - - if (!result.success) { - throw new Error('The email you provided was invalid.'); - } - - email = result.data; -} - -async function question(prompt: string) { - const cli = readline.createInterface({ - input: process.stdin, - output: process.stdout, - }); - - return new Promise((resolve) => { - cli.question(prompt, (input) => { - resolve(input); - cli.close(); - }); - }); -} - -let counter = 0; - -function id() { - counter++; - return counter.toString(); -} - -main(); diff --git a/packages/core/src/infrastructure/database/scripts/setup.sql b/packages/core/src/infrastructure/database/scripts/setup.sql deleted file mode 100644 index 0a714272..00000000 --- a/packages/core/src/infrastructure/database/scripts/setup.sql +++ /dev/null @@ -1,11 +0,0 @@ --- Cleans up any existing databases/users. - -DROP DATABASE IF EXISTS colorstack; -DROP DATABASE IF EXISTS colorstack_test; -DROP ROLE IF EXISTS colorstack; - --- Creates new databases and users. - -CREATE ROLE colorstack WITH SUPERUSER LOGIN PASSWORD 'colorstack'; -CREATE DATABASE colorstack OWNER colorstack; -CREATE DATABASE colorstack_test OWNER colorstack \ No newline at end of file diff --git a/packages/core/src/infrastructure/database/scripts/setup.ts b/packages/core/src/infrastructure/database/scripts/setup.ts deleted file mode 100644 index 2ba2adc9..00000000 --- a/packages/core/src/infrastructure/database/scripts/setup.ts +++ /dev/null @@ -1,37 +0,0 @@ -import { exec } from 'child_process'; -import path from 'path'; -import { fileURLToPath } from 'url'; - -import { ENVIRONMENT } from '@/shared/env'; - -if (ENVIRONMENT !== 'development') { - throw new Error('Cannot setup database in non-development environment.'); -} - -const __filename = fileURLToPath(import.meta.url); -const __dirname = path.dirname(__filename); - -// This is the full path to the `setup.sql` file. -const pathToInitFile = path.join(__dirname, 'setup.sql'); - -exec( - // By default, everyone will have the role "postgres" and the database - // "postgres", so we use that to do our initial connection to the Postgres - // shell. We also have to specify the host, which satisfies the "peer" - // authentication requirement (if that is set in pg_hba.conf). - `psql -U postgres -h localhost -d postgres -f ${pathToInitFile}`, - (error, stdout, stderr) => { - if (stdout) { - console.log(stdout); - } - - if (stderr) { - // Log but don't throw for notices/warnings. - console.warn(stderr); - } - - if (error) { - throw new Error(`psql exited with error: ${error}`); - } - } -); diff --git a/packages/core/src/infrastructure/database/shared/create-database-connection.ts b/packages/core/src/infrastructure/database/shared/create-database-connection.ts deleted file mode 100644 index 7ba13427..00000000 --- a/packages/core/src/infrastructure/database/shared/create-database-connection.ts +++ /dev/null @@ -1,26 +0,0 @@ -import { CamelCasePlugin, Kysely, PostgresDialect } from 'kysely'; -import { DB } from 'kysely-codegen/dist/db'; -import pg from 'pg'; - -import { DATABASE_URL } from '@/shared/env'; - -export function createDatabaseConnection() { - if (!DATABASE_URL) { - throw new Error( - '"DATABASE_URL" must be set to establish a connection to the database.' - ); - } - - const dialect = new PostgresDialect({ - pool: new pg.Pool({ - connectionString: DATABASE_URL, - }), - }); - - const db = new Kysely({ - dialect, - plugins: [new CamelCasePlugin()], - }); - - return db; -} diff --git a/packages/core/src/infrastructure/database/shared/migrate.ts b/packages/core/src/infrastructure/database/shared/migrate.ts deleted file mode 100644 index 6bb5f2de..00000000 --- a/packages/core/src/infrastructure/database/shared/migrate.ts +++ /dev/null @@ -1,80 +0,0 @@ -import { promises as fs } from 'fs'; -import { FileMigrationProvider, Kysely, Migrator } from 'kysely'; -import { DB } from 'kysely-codegen/dist/db'; -import path from 'path'; -import { fileURLToPath } from 'url'; - -import { createDatabaseConnection } from './create-database-connection'; - -type MigrateOptions = { - db?: Kysely; - down?: boolean; -}; - -const defaultOptions: MigrateOptions = { - db: undefined, - down: false, -}; - -/** - * Migrates the database to the latest version by executing all migrations. - * - * This is in the `/shared` folder because it is needed not only for the - * `db:migrate` script (self-explanatory), but also for the `db:seed` script. We - * need it for seeding because we first completely clean the database, and then - * we want to ensure that the database is migrated to the latest version before - * we seed it. - */ -export async function migrate(options: MigrateOptions = defaultOptions) { - options = { - ...defaultOptions, - ...options, - }; - - const db = options.db || createDatabaseConnection(); - - const __filename = fileURLToPath(import.meta.url); - const __dirname = path.dirname(__filename); - - const migrator = new Migrator({ - db, - provider: new FileMigrationProvider({ - fs, - path, - migrationFolder: path.join(__dirname, '../migrations'), - }), - migrationTableName: 'kysely_migrations', - migrationLockTableName: 'kysely_migrations_lock', - }); - - const { error, results } = !!options.down - ? await migrator.migrateDown() - : await migrator.migrateToLatest(); - - if (results) { - results.forEach((result) => { - const prefix = `[${result.direction}] "${result.migrationName}"`; - - if (result.status === 'Success') { - console.log(`${prefix}: Migration was executed successfully.`); - return; - } - - if (result.status === 'Error') { - console.error(`${prefix}: Failed to execute migration.`); - return; - } - }); - } - - if (error) { - console.error('An error occurred with the Kysely migrator.', error); - process.exit(1); - } - - // If a database instance was passed in, we'll yield the responsibility of - // destroying it to the caller. Otherwise, we'll destroy it here. - if (!options.db) { - await db.destroy(); - } -} diff --git a/packages/core/src/infrastructure/database/shared/truncate.ts b/packages/core/src/infrastructure/database/shared/truncate.ts deleted file mode 100644 index 3bd6efa2..00000000 --- a/packages/core/src/infrastructure/database/shared/truncate.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { Transaction, sql } from 'kysely'; -import { DB } from 'kysely-codegen/dist/db'; - -import { IS_PRODUCTION } from '@/shared/env'; - -/** - * Truncates all tables in the database - wiping all rows, but does not affect - * the schema itself. This can only be used in development/test environments. - * - * @see https://www.postgresql.org/docs/current/sql-truncate.html - */ -export async function truncate(trx: Transaction) { - if (IS_PRODUCTION) { - return; - } - - const tables = await trx.introspection.getTables(); - - const names = tables - .filter((table) => { - // We don't want to wipe the kysely tables, which track migrations b/c - // migrations should only be run once. - return !table.name.includes('kysely_'); - }) - .map((table) => { - return table.name; - }) - .join(', '); - - await sql`truncate table ${sql.raw(names)} cascade;`.execute(trx); -} diff --git a/packages/core/src/infrastructure/database/test/constants.ts b/packages/core/src/infrastructure/database/test/constants.ts deleted file mode 100644 index 2a2f575e..00000000 --- a/packages/core/src/infrastructure/database/test/constants.ts +++ /dev/null @@ -1,32 +0,0 @@ -import { Insertable } from 'kysely'; -import { DB } from 'kysely-codegen/dist/db'; - -// Constants - -export const TEST_COMPANY_1: Insertable = { - crunchbaseId: '11', - id: '1', - name: 'Adobe', -}; - -export const TEST_COMPANY_2: Insertable = { - crunchbaseId: '22', - id: '2', - name: 'Google', -}; - -export const TEST_COMPANY_3: Insertable = { - crunchbaseId: '33', - id: '3', - name: 'Microsoft', -}; - -export const TEST_COMPANY_4: Insertable = { - crunchbaseId: '44', - description: '...', - domain: 'stripe.com', - id: '44', - imageUrl: '...', - name: 'Stripe', - stockSymbol: '...', -}; diff --git a/packages/core/src/infrastructure/database/test/setup.global.ts b/packages/core/src/infrastructure/database/test/setup.global.ts deleted file mode 100644 index 93a82d27..00000000 --- a/packages/core/src/infrastructure/database/test/setup.global.ts +++ /dev/null @@ -1,10 +0,0 @@ -import { db } from '@/infrastructure/database'; -import { migrate } from '../shared/migrate'; - -export async function setup() { - await migrate({ db }); -} - -export async function teardown() { - await db.destroy(); -} diff --git a/packages/core/src/infrastructure/database/test/setup.ts b/packages/core/src/infrastructure/database/test/setup.ts deleted file mode 100644 index ef4da9cb..00000000 --- a/packages/core/src/infrastructure/database/test/setup.ts +++ /dev/null @@ -1,22 +0,0 @@ -import { Transaction } from 'kysely'; -import { DB } from 'kysely-codegen/dist/db'; - -import { db } from '@/infrastructure/database'; -import { truncate } from '../shared/truncate'; -import { TEST_COMPANY_1, TEST_COMPANY_2, TEST_COMPANY_3 } from './constants'; - -beforeEach(async () => { - await db.transaction().execute(async (trx) => { - await truncate(trx); - await seed(trx); - }); -}); - -// Helpers - -async function seed(trx: Transaction) { - await trx - .insertInto('companies') - .values([TEST_COMPANY_1, TEST_COMPANY_2, TEST_COMPANY_3]) - .execute(); -} From 41b772b42b4bc06d5f5b956e1ee9adce83f130fb Mon Sep 17 00:00:00 2001 From: Rami Abdou Date: Wed, 3 Apr 2024 09:19:29 -0700 Subject: [PATCH 03/14] export DB --- packages/core/src/infrastructure/database/index.ts | 1 + packages/core/src/member-profile.server.ts | 2 +- .../core/src/modules/application/queries/get-application.ts | 5 +++-- .../src/modules/employment/queries/get-work-experience.ts | 5 +++-- .../employment/use-cases/save-company-if-necessary.ts | 2 +- packages/core/src/modules/event/queries/get-event.ts | 2 +- packages/core/src/modules/event/queries/list-events.ts | 5 +++-- .../src/modules/icebreaker/queries/get-icebreaker-prompts.ts | 5 +++-- .../modules/icebreaker/queries/get-icebreaker-responses.ts | 5 +++-- .../icebreaker/use-cases/upsert-icebreaker-responses.ts | 5 +++-- .../src/modules/member/use-cases/join-member-directory.ts | 3 ++- .../src/modules/member/use-cases/update-allow-email-share.ts | 3 ++- packages/db/package.json | 2 +- packages/db/src/index.ts | 5 ++--- packages/db/src/scripts/seed.ts | 2 +- packages/db/src/shared/db.ts | 3 +++ packages/db/src/test/setup.global.ts | 2 +- packages/db/src/test/setup.ts | 2 +- 18 files changed, 35 insertions(+), 24 deletions(-) create mode 100644 packages/core/src/infrastructure/database/index.ts create mode 100644 packages/db/src/shared/db.ts diff --git a/packages/core/src/infrastructure/database/index.ts b/packages/core/src/infrastructure/database/index.ts new file mode 100644 index 00000000..536a1ad8 --- /dev/null +++ b/packages/core/src/infrastructure/database/index.ts @@ -0,0 +1 @@ +export { db } from '@oyster/db'; diff --git a/packages/core/src/member-profile.server.ts b/packages/core/src/member-profile.server.ts index a67fb839..d0118ff9 100644 --- a/packages/core/src/member-profile.server.ts +++ b/packages/core/src/member-profile.server.ts @@ -1,4 +1,4 @@ -export type { DB } from 'kysely-codegen/dist/db'; +export type { DB } from '@oyster/db'; export { job } from './infrastructure/bull/use-cases/job'; export { db } from './infrastructure/database'; export { getActiveStreak } from './modules/active-status/queries/get-active-streak'; diff --git a/packages/core/src/modules/application/queries/get-application.ts b/packages/core/src/modules/application/queries/get-application.ts index b2327205..484e5689 100644 --- a/packages/core/src/modules/application/queries/get-application.ts +++ b/packages/core/src/modules/application/queries/get-application.ts @@ -1,5 +1,6 @@ import type { SelectExpression } from 'kysely'; -import type { DB } from 'kysely-codegen/dist/db'; + +import type { DB } from '@oyster/db'; import { db } from '@/infrastructure/database'; @@ -8,7 +9,7 @@ type GetApplicationOptions = { }; export async function getApplication< - Selection extends SelectExpression + Selection extends SelectExpression, >(id: string, selections: Selection[], options: GetApplicationOptions = {}) { const result = await db .selectFrom('applications') diff --git a/packages/core/src/modules/employment/queries/get-work-experience.ts b/packages/core/src/modules/employment/queries/get-work-experience.ts index 4956d295..d8f7be0d 100644 --- a/packages/core/src/modules/employment/queries/get-work-experience.ts +++ b/packages/core/src/modules/employment/queries/get-work-experience.ts @@ -1,5 +1,6 @@ import { SelectExpression } from 'kysely'; -import { DB } from 'kysely-codegen/dist/db'; + +import { DB } from '@oyster/db'; import { db } from '@/infrastructure/database'; import { WorkExperience } from '../employment.types'; @@ -11,7 +12,7 @@ type GetWorkExperienceOptions = { }; export async function getWorkExperience< - Selection extends SelectExpression + Selection extends SelectExpression, >( { id, studentId }: GetWorkExperienceQuery, selections: Selection[], diff --git a/packages/core/src/modules/employment/use-cases/save-company-if-necessary.ts b/packages/core/src/modules/employment/use-cases/save-company-if-necessary.ts index 59f076c1..0437fbaa 100644 --- a/packages/core/src/modules/employment/use-cases/save-company-if-necessary.ts +++ b/packages/core/src/modules/employment/use-cases/save-company-if-necessary.ts @@ -1,6 +1,6 @@ import { Transaction } from 'kysely'; -import { DB } from 'kysely-codegen/dist/db'; +import { DB } from '@oyster/db'; import { id } from '@oyster/utils'; import { db } from '@/infrastructure/database'; diff --git a/packages/core/src/modules/event/queries/get-event.ts b/packages/core/src/modules/event/queries/get-event.ts index aa720fc8..0204d1a3 100644 --- a/packages/core/src/modules/event/queries/get-event.ts +++ b/packages/core/src/modules/event/queries/get-event.ts @@ -1,6 +1,6 @@ import type { SelectExpression } from 'kysely'; -import type { DB } from 'kysely-codegen/dist/db'; +import { DB } from '@oyster/db'; import { EventType } from '@oyster/types'; import { db } from '@/infrastructure/database'; diff --git a/packages/core/src/modules/event/queries/list-events.ts b/packages/core/src/modules/event/queries/list-events.ts index de4f0255..e4998617 100644 --- a/packages/core/src/modules/event/queries/list-events.ts +++ b/packages/core/src/modules/event/queries/list-events.ts @@ -1,5 +1,6 @@ import type { SelectExpression } from 'kysely'; -import type { DB } from 'kysely-codegen/dist/db'; + +import { DB } from '@oyster/db'; import { db } from '@/infrastructure/database'; @@ -10,7 +11,7 @@ type ListEventsQuery = Partial<{ }>; export async function listEvents< - Selection extends SelectExpression + Selection extends SelectExpression, >({ limit = 100, page = 1, search }: ListEventsQuery, selections: Selection[]) { const query = db.selectFrom('events').$if(!!search, (qb) => { return qb.where('events.name', 'ilike', `%${search}%`); diff --git a/packages/core/src/modules/icebreaker/queries/get-icebreaker-prompts.ts b/packages/core/src/modules/icebreaker/queries/get-icebreaker-prompts.ts index b504f2eb..47196036 100644 --- a/packages/core/src/modules/icebreaker/queries/get-icebreaker-prompts.ts +++ b/packages/core/src/modules/icebreaker/queries/get-icebreaker-prompts.ts @@ -1,10 +1,11 @@ import type { SelectExpression } from 'kysely'; -import type { DB } from 'kysely-codegen/dist/db'; + +import { DB } from '@oyster/db'; import { db } from '@/infrastructure/database'; export async function getIcebreakerPrompts< - Selection extends SelectExpression + Selection extends SelectExpression, >(selections: Selection[]) { const prompts = await db .selectFrom('icebreakerPrompts') diff --git a/packages/core/src/modules/icebreaker/queries/get-icebreaker-responses.ts b/packages/core/src/modules/icebreaker/queries/get-icebreaker-responses.ts index d414c93a..e9f747ad 100644 --- a/packages/core/src/modules/icebreaker/queries/get-icebreaker-responses.ts +++ b/packages/core/src/modules/icebreaker/queries/get-icebreaker-responses.ts @@ -1,10 +1,11 @@ import type { SelectExpression } from 'kysely'; -import type { DB } from 'kysely-codegen/dist/db'; + +import { DB } from '@oyster/db'; import { db } from '@/infrastructure/database'; export async function getIcebreakerResponses< - Selection extends SelectExpression + Selection extends SelectExpression, >(memberId: string, selections: Selection[]) { const icebreakerResponses = await db .selectFrom('icebreakerResponses') diff --git a/packages/core/src/modules/icebreaker/use-cases/upsert-icebreaker-responses.ts b/packages/core/src/modules/icebreaker/use-cases/upsert-icebreaker-responses.ts index 5a47fc81..d9bea9c9 100644 --- a/packages/core/src/modules/icebreaker/use-cases/upsert-icebreaker-responses.ts +++ b/packages/core/src/modules/icebreaker/use-cases/upsert-icebreaker-responses.ts @@ -1,10 +1,11 @@ import { Insertable, Transaction } from 'kysely'; -import type { DB, IcebreakerResponses } from 'kysely-codegen/dist/db'; + +import { DB } from '@oyster/db'; export async function upsertIcebreakerResponses( trx: Transaction, memberId: string, - data: Insertable[] + data: Insertable[] ) { await trx .deleteFrom('icebreakerResponses') diff --git a/packages/core/src/modules/member/use-cases/join-member-directory.ts b/packages/core/src/modules/member/use-cases/join-member-directory.ts index b8caf3ac..1fbb3448 100644 --- a/packages/core/src/modules/member/use-cases/join-member-directory.ts +++ b/packages/core/src/modules/member/use-cases/join-member-directory.ts @@ -1,5 +1,6 @@ import { Transaction } from 'kysely'; -import { DB } from 'kysely-codegen/dist/db'; + +import { DB } from '@oyster/db'; import { job } from '@/infrastructure/bull/use-cases/job'; diff --git a/packages/core/src/modules/member/use-cases/update-allow-email-share.ts b/packages/core/src/modules/member/use-cases/update-allow-email-share.ts index 6fb6e8ec..3dcfda3b 100644 --- a/packages/core/src/modules/member/use-cases/update-allow-email-share.ts +++ b/packages/core/src/modules/member/use-cases/update-allow-email-share.ts @@ -1,5 +1,6 @@ import { Transaction } from 'kysely'; -import { DB } from 'kysely-codegen/dist/db'; + +import { DB } from '@oyster/db'; export async function updateAllowEmailShare( trx: Transaction, diff --git a/packages/db/package.json b/packages/db/package.json index 74a06c0a..85721451 100644 --- a/packages/db/package.json +++ b/packages/db/package.json @@ -4,7 +4,7 @@ "private": true, "type": "module", "exports": { - ".": "./index.ts" + ".": "./src/index.ts" }, "scripts": { "migrate": "tsx ./src/scripts/migrate.ts && yarn db:types", diff --git a/packages/db/src/index.ts b/packages/db/src/index.ts index 3f9c92ce..d3ff65df 100644 --- a/packages/db/src/index.ts +++ b/packages/db/src/index.ts @@ -1,3 +1,2 @@ -import { createDatabaseConnection } from './shared/create-database-connection'; - -export const db = createDatabaseConnection(); +export type { DB } from 'kysely-codegen/dist/db'; +export { db } from './shared/db'; diff --git a/packages/db/src/scripts/seed.ts b/packages/db/src/scripts/seed.ts index 1acac2ed..33cb01e0 100644 --- a/packages/db/src/scripts/seed.ts +++ b/packages/db/src/scripts/seed.ts @@ -3,7 +3,7 @@ import { DB } from 'kysely-codegen/dist/db'; import readline from 'readline'; import { z } from 'zod'; -import { db } from '..'; +import { db } from '../shared/db'; import { ENVIRONMENT } from '../shared/env'; import { migrate } from '../shared/migrate'; import { truncate } from '../shared/truncate'; diff --git a/packages/db/src/shared/db.ts b/packages/db/src/shared/db.ts new file mode 100644 index 00000000..d37b83f3 --- /dev/null +++ b/packages/db/src/shared/db.ts @@ -0,0 +1,3 @@ +import { createDatabaseConnection } from './create-database-connection'; + +export const db = createDatabaseConnection(); diff --git a/packages/db/src/test/setup.global.ts b/packages/db/src/test/setup.global.ts index 305586e6..b7583d80 100644 --- a/packages/db/src/test/setup.global.ts +++ b/packages/db/src/test/setup.global.ts @@ -1,4 +1,4 @@ -import { db } from '..'; +import { db } from '../shared/db'; import { migrate } from '../shared/migrate'; export async function setup() { diff --git a/packages/db/src/test/setup.ts b/packages/db/src/test/setup.ts index 51c971d4..dae21e9c 100644 --- a/packages/db/src/test/setup.ts +++ b/packages/db/src/test/setup.ts @@ -1,7 +1,7 @@ import { Transaction } from 'kysely'; import { DB } from 'kysely-codegen/dist/db'; -import { db } from '..'; +import { db } from '../shared/db'; import { truncate } from '../shared/truncate'; import { TEST_COMPANY_1, TEST_COMPANY_2, TEST_COMPANY_3 } from './constants'; From 4ca08a0cbf2100430cc3f9927d41fc807423e3b3 Mon Sep 17 00:00:00 2001 From: Rami Abdou Date: Wed, 3 Apr 2024 09:40:38 -0700 Subject: [PATCH 04/14] exports --- packages/core/package.json | 4 ---- .../employment/use-cases/save-company-if-necessary.test.ts | 6 ++---- packages/core/vitest.config.ts | 4 ++-- packages/db/.env.test.example | 2 -- packages/db/package.json | 4 +++- 5 files changed, 7 insertions(+), 13 deletions(-) delete mode 100644 packages/db/.env.test.example diff --git a/packages/core/package.json b/packages/core/package.json index ab4dcd67..0a625488 100644 --- a/packages/core/package.json +++ b/packages/core/package.json @@ -37,7 +37,6 @@ "kysely": "^0.26.3", "nanoid": "^3.0.0", "nodemailer": "^6.9.13", - "pg": "^8.8.0", "postmark": "^3.0.15", "statsig-node": "^5.3.0" }, @@ -49,9 +48,6 @@ "@types/jsonwebtoken": "^9.0.2", "@types/mailchimp__mailchimp_marketing": "^3.0.8", "@types/nodemailer": "^6.4.14", - "@types/pg": "^8.11.2", - "commander": "^12.0.0", - "kysely-codegen": "^0.10.1", "nanoid": "^3.0.0", "react": "^18.2.0", "tsup": "^6.1.3", diff --git a/packages/core/src/modules/employment/use-cases/save-company-if-necessary.test.ts b/packages/core/src/modules/employment/use-cases/save-company-if-necessary.test.ts index e468763e..13e13f97 100644 --- a/packages/core/src/modules/employment/use-cases/save-company-if-necessary.test.ts +++ b/packages/core/src/modules/employment/use-cases/save-company-if-necessary.test.ts @@ -1,8 +1,6 @@ +import { TEST_COMPANY_1, TEST_COMPANY_4 } from '@oyster/db/test/constants'; + import { db } from '@/infrastructure/database'; -import { - TEST_COMPANY_1, - TEST_COMPANY_4, -} from '@/infrastructure/database/test/constants'; import * as module from '../queries/get-crunchbase-organization'; import { saveCompanyIfNecessary } from './save-company-if-necessary'; diff --git a/packages/core/vitest.config.ts b/packages/core/vitest.config.ts index 82511e7a..ebe22603 100644 --- a/packages/core/vitest.config.ts +++ b/packages/core/vitest.config.ts @@ -32,11 +32,11 @@ export default defineConfig({ // The global setup file is only run once before ALL test suites. // See: https://vitest.dev/config/#globalsetup - globalSetup: ['./src/infrastructure/database/test/setup.global.ts'], + globalSetup: ['@oyster/db/test/setup.global.ts'], // The setup files are run before EACH test suite. // See: https://vitest.dev/config/#setupfiles - setupFiles: ['./src/infrastructure/database/test/setup.ts'], + setupFiles: ['@oyster/db/test/setup.ts'], // Mocking diff --git a/packages/db/.env.test.example b/packages/db/.env.test.example deleted file mode 100644 index 39351de9..00000000 --- a/packages/db/.env.test.example +++ /dev/null @@ -1,2 +0,0 @@ -DATABASE_URL=postgresql://colorstack:colorstack@localhost:5432/colorstack_test -ENVIRONMENT=test \ No newline at end of file diff --git a/packages/db/package.json b/packages/db/package.json index 85721451..8338fa08 100644 --- a/packages/db/package.json +++ b/packages/db/package.json @@ -4,7 +4,9 @@ "private": true, "type": "module", "exports": { - ".": "./src/index.ts" + ".": "./src/index.ts", + "./test/*": "./src/test/*", + "./test/constants": "./src/test/constants.ts" }, "scripts": { "migrate": "tsx ./src/scripts/migrate.ts && yarn db:types", From 1c30c72c48566f4db350fff64dc886e740b2dc26 Mon Sep 17 00:00:00 2001 From: Rami Abdou Date: Wed, 3 Apr 2024 09:41:02 -0700 Subject: [PATCH 05/14] remove vite --- packages/db/package.json | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/packages/db/package.json b/packages/db/package.json index 8338fa08..3e2b5ad2 100644 --- a/packages/db/package.json +++ b/packages/db/package.json @@ -24,8 +24,6 @@ "@oyster/tsconfig": "*", "@types/pg": "^8.11.2", "commander": "^12.0.0", - "kysely-codegen": "^0.10.1", - "vite": "^5.0.0", - "vite-tsconfig-paths": "^4.3.1" + "kysely-codegen": "^0.10.1" } } From dfe63bc62ff2d966ca2fd1bcaf8b5302ce49563a Mon Sep 17 00:00:00 2001 From: Rami Abdou Date: Wed, 3 Apr 2024 09:43:31 -0700 Subject: [PATCH 06/14] use-cases folder --- packages/db/src/scripts/migrate.ts | 2 +- packages/db/src/scripts/seed.ts | 4 ++-- packages/db/src/shared/db.ts | 2 +- packages/db/src/test/setup.global.ts | 2 +- packages/db/src/test/setup.ts | 2 +- .../src/{shared => use-cases}/create-database-connection.ts | 2 +- packages/db/src/{shared => use-cases}/migrate.ts | 0 packages/db/src/{shared => use-cases}/truncate.ts | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) rename packages/db/src/{shared => use-cases}/create-database-connection.ts (92%) rename packages/db/src/{shared => use-cases}/migrate.ts (100%) rename packages/db/src/{shared => use-cases}/truncate.ts (94%) diff --git a/packages/db/src/scripts/migrate.ts b/packages/db/src/scripts/migrate.ts index ceb0cd84..129ac3c4 100644 --- a/packages/db/src/scripts/migrate.ts +++ b/packages/db/src/scripts/migrate.ts @@ -1,6 +1,6 @@ import { program } from 'commander'; -import { migrate } from '../shared/migrate'; +import { migrate } from '../use-cases/migrate'; const DOWN_FLAG = '--down'; diff --git a/packages/db/src/scripts/seed.ts b/packages/db/src/scripts/seed.ts index 33cb01e0..566ae6d5 100644 --- a/packages/db/src/scripts/seed.ts +++ b/packages/db/src/scripts/seed.ts @@ -5,8 +5,8 @@ import { z } from 'zod'; import { db } from '../shared/db'; import { ENVIRONMENT } from '../shared/env'; -import { migrate } from '../shared/migrate'; -import { truncate } from '../shared/truncate'; +import { migrate } from '../use-cases/migrate'; +import { truncate } from '../use-cases/truncate'; if (ENVIRONMENT !== 'development') { throw new Error('Cannot seed database in non-development environment.'); diff --git a/packages/db/src/shared/db.ts b/packages/db/src/shared/db.ts index d37b83f3..38d04f9f 100644 --- a/packages/db/src/shared/db.ts +++ b/packages/db/src/shared/db.ts @@ -1,3 +1,3 @@ -import { createDatabaseConnection } from './create-database-connection'; +import { createDatabaseConnection } from '../use-cases/create-database-connection'; export const db = createDatabaseConnection(); diff --git a/packages/db/src/test/setup.global.ts b/packages/db/src/test/setup.global.ts index b7583d80..c2ffa83d 100644 --- a/packages/db/src/test/setup.global.ts +++ b/packages/db/src/test/setup.global.ts @@ -1,5 +1,5 @@ import { db } from '../shared/db'; -import { migrate } from '../shared/migrate'; +import { migrate } from '../use-cases/migrate'; export async function setup() { await migrate({ db }); diff --git a/packages/db/src/test/setup.ts b/packages/db/src/test/setup.ts index dae21e9c..f6ba3548 100644 --- a/packages/db/src/test/setup.ts +++ b/packages/db/src/test/setup.ts @@ -2,7 +2,7 @@ import { Transaction } from 'kysely'; import { DB } from 'kysely-codegen/dist/db'; import { db } from '../shared/db'; -import { truncate } from '../shared/truncate'; +import { truncate } from '../use-cases/truncate'; import { TEST_COMPANY_1, TEST_COMPANY_2, TEST_COMPANY_3 } from './constants'; beforeEach(async () => { diff --git a/packages/db/src/shared/create-database-connection.ts b/packages/db/src/use-cases/create-database-connection.ts similarity index 92% rename from packages/db/src/shared/create-database-connection.ts rename to packages/db/src/use-cases/create-database-connection.ts index 097bdc4d..f7b64bd7 100644 --- a/packages/db/src/shared/create-database-connection.ts +++ b/packages/db/src/use-cases/create-database-connection.ts @@ -2,7 +2,7 @@ import { CamelCasePlugin, Kysely, PostgresDialect } from 'kysely'; import { DB } from 'kysely-codegen/dist/db'; import pg from 'pg'; -import { DATABASE_URL } from './env'; +import { DATABASE_URL } from '../shared/env'; export function createDatabaseConnection() { if (!DATABASE_URL) { diff --git a/packages/db/src/shared/migrate.ts b/packages/db/src/use-cases/migrate.ts similarity index 100% rename from packages/db/src/shared/migrate.ts rename to packages/db/src/use-cases/migrate.ts diff --git a/packages/db/src/shared/truncate.ts b/packages/db/src/use-cases/truncate.ts similarity index 94% rename from packages/db/src/shared/truncate.ts rename to packages/db/src/use-cases/truncate.ts index d9bb2a6e..60614ac8 100644 --- a/packages/db/src/shared/truncate.ts +++ b/packages/db/src/use-cases/truncate.ts @@ -1,7 +1,7 @@ import { Transaction, sql } from 'kysely'; import { DB } from 'kysely-codegen/dist/db'; -import { IS_PRODUCTION } from './env'; +import { IS_PRODUCTION } from '../shared/env'; /** * Truncates all tables in the database - wiping all rows, but does not affect From e3d03f51fa2f511c265aa657d921172de12a0f14 Mon Sep 17 00:00:00 2001 From: Rami Abdou Date: Wed, 3 Apr 2024 09:45:22 -0700 Subject: [PATCH 07/14] remove DATABASE_URL --- packages/core/src/shared/env.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/packages/core/src/shared/env.ts b/packages/core/src/shared/env.ts index 6c7f0b09..d28effb5 100644 --- a/packages/core/src/shared/env.ts +++ b/packages/core/src/shared/env.ts @@ -40,7 +40,6 @@ export const ENV = { // package and thus in this file after the dotenv has loaded the config. // Everything else above should be colocated with its respective module. -export const DATABASE_URL = process.env.DATABASE_URL as string; export const ENVIRONMENT = process.env.ENVIRONMENT as Environment; export const IS_PRODUCTION = ENVIRONMENT === 'production'; export const IS_TEST = ENVIRONMENT === 'test'; From d22abd8dbad78806f95f55ad8e9b25ca1a898527 Mon Sep 17 00:00:00 2001 From: Rami Abdou Date: Wed, 3 Apr 2024 09:56:34 -0700 Subject: [PATCH 08/14] remove env --- packages/core/.env.example | 5 ----- packages/db/.env.example | 3 +-- 2 files changed, 1 insertion(+), 7 deletions(-) delete mode 100644 packages/core/.env.example diff --git a/packages/core/.env.example b/packages/core/.env.example deleted file mode 100644 index 34410540..00000000 --- a/packages/core/.env.example +++ /dev/null @@ -1,5 +0,0 @@ -# This is only needed for automatically generating types from the database -# using `kysely-codegen`. See the following: -# https://github.com/RobinBlomberg/kysely-codegen?tab=readme-ov-file#generating-type-definitions -DATABASE_URL=postgresql://colorstack:colorstack@localhost:5432/colorstack -ENVIRONMENT=development \ No newline at end of file diff --git a/packages/db/.env.example b/packages/db/.env.example index 34410540..1cbdee2c 100644 --- a/packages/db/.env.example +++ b/packages/db/.env.example @@ -1,5 +1,4 @@ # This is only needed for automatically generating types from the database # using `kysely-codegen`. See the following: # https://github.com/RobinBlomberg/kysely-codegen?tab=readme-ov-file#generating-type-definitions -DATABASE_URL=postgresql://colorstack:colorstack@localhost:5432/colorstack -ENVIRONMENT=development \ No newline at end of file +DATABASE_URL=postgresql://colorstack:colorstack@localhost:5432/colorstack \ No newline at end of file From 8c3b2e376a78f91f1e1c5adf43806c1f972eaf23 Mon Sep 17 00:00:00 2001 From: Rami Abdou Date: Wed, 3 Apr 2024 10:07:35 -0700 Subject: [PATCH 09/14] update documentation --- CONTRIBUTING.md | 2 +- README.md | 8 +++++--- docs/how-to-implement-a-database-migration.md | 11 +++++------ 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 3c0ac4cb..dc567ef3 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -116,8 +116,8 @@ Set up your environment variable files by doing the following: - In `/apps/admin-dashboard`, duplicate the `.env.example` to `.env`. - In `/apps/api`, duplicate the `.env.example` to `.env`. - In `/apps/member-profile`, duplicate the `.env.example` to `.env`. -- In `/packages/core`, duplicate the `.env.example` to `.env`. - In `/packages/core`, duplicate the `.env.test.example` to `.env.test`. +- In `/packages/db`, duplicate the `.env.example` to `.env`. You'll notice that a lot of environment variables are empty. Most of these empty variables are tied to the 3rd party integrations we have with platforms such as diff --git a/README.md b/README.md index a8e3d991..3759f2aa 100644 --- a/README.md +++ b/README.md @@ -58,6 +58,7 @@ apps |--- member-profile packages |--- core +|--- db |--- email-templates |--- types |--- ui @@ -70,9 +71,10 @@ section). The `packages` directory contains reusable pieces of code that are used across our applications. -- `core`: Nearly all of our business logic, including our database layer and - more. Will eventually colocate feature-based UI next to its related business - logic. +- `core`: Nearly all of our core business logic. Will eventually colocate + feature-based UI next to its related business logic. +- `db`: Database layer, which houses all migrations, database scripts (ie: + `seed`) and testing utilities that involve the database. - `email-templates`: React-based email templates built with [Resend](https://resend.com). - `types`: Miscellaneous types shared across applications. diff --git a/docs/how-to-implement-a-database-migration.md b/docs/how-to-implement-a-database-migration.md index 83a55b27..d7d08d1f 100644 --- a/docs/how-to-implement-a-database-migration.md +++ b/docs/how-to-implement-a-database-migration.md @@ -8,15 +8,14 @@ database. Kysely also supports classic "up"/"down" migrations. ## Where Our Migrations Live -All of our database migrations live in our `@oyster/core` package, specifically -[here](../packages/core/src/infrastructure/database/migrations). +All of our database migrations live in our `@oyster/db` package, specifically +[here](../packages/db/src/migrations). ## How to Run Migrations -We have a -[`migrate`](../packages/core/src/infrastructure/database/scripts/migrate.ts) -script, which effectively executes any migrations that haven't been executed -yet. To run this script: +We have a [`migrate`](../packages/db/src/scripts/migrate.ts) script, which +effectively executes any migrations that haven't been executed yet. To run this +script: ``` yarn db:migrate From 8abf3faf8ed2928b38e8552892d8e9d1c1c7194a Mon Sep 17 00:00:00 2001 From: Rami Abdou Date: Wed, 3 Apr 2024 10:10:11 -0700 Subject: [PATCH 10/14] cool --- packages/db/package.json | 6 +++--- packages/db/src/scripts/seed.ts | 4 ++-- packages/db/src/scripts/setup.ts | 4 ++-- packages/db/src/shared/env.ts | 1 - 4 files changed, 7 insertions(+), 8 deletions(-) diff --git a/packages/db/package.json b/packages/db/package.json index 3e2b5ad2..dcef1c7c 100644 --- a/packages/db/package.json +++ b/packages/db/package.json @@ -9,9 +9,9 @@ "./test/constants": "./src/test/constants.ts" }, "scripts": { - "migrate": "tsx ./src/scripts/migrate.ts && yarn db:types", - "migrate:down": "tsx ./src/scripts/migrate.ts --down && yarn db:types", - "seed": "tsx ./src/scripts/seed.ts && yarn db:types", + "migrate": "tsx ./src/scripts/migrate.ts && yarn types", + "migrate:down": "tsx ./src/scripts/migrate.ts --down && yarn types", + "seed": "tsx ./src/scripts/seed.ts && yarn types", "setup": "tsx ./src/scripts/setup.ts", "type-check": "tsc --noEmit", "types": "kysely-codegen --dialect=postgres --camel-case" diff --git a/packages/db/src/scripts/seed.ts b/packages/db/src/scripts/seed.ts index 566ae6d5..6eda2e39 100644 --- a/packages/db/src/scripts/seed.ts +++ b/packages/db/src/scripts/seed.ts @@ -4,11 +4,11 @@ import readline from 'readline'; import { z } from 'zod'; import { db } from '../shared/db'; -import { ENVIRONMENT } from '../shared/env'; +import { IS_PRODUCTION } from '../shared/env'; import { migrate } from '../use-cases/migrate'; import { truncate } from '../use-cases/truncate'; -if (ENVIRONMENT !== 'development') { +if (IS_PRODUCTION) { throw new Error('Cannot seed database in non-development environment.'); } diff --git a/packages/db/src/scripts/setup.ts b/packages/db/src/scripts/setup.ts index 2d79da55..62ba1c9f 100644 --- a/packages/db/src/scripts/setup.ts +++ b/packages/db/src/scripts/setup.ts @@ -2,9 +2,9 @@ import { exec } from 'child_process'; import path from 'path'; import { fileURLToPath } from 'url'; -import { ENVIRONMENT } from '../shared/env'; +import { IS_PRODUCTION } from '../shared/env'; -if (ENVIRONMENT !== 'development') { +if (IS_PRODUCTION) { throw new Error('Cannot setup database in non-development environment.'); } diff --git a/packages/db/src/shared/env.ts b/packages/db/src/shared/env.ts index fd163f4e..396609ea 100644 --- a/packages/db/src/shared/env.ts +++ b/packages/db/src/shared/env.ts @@ -7,4 +7,3 @@ config(); export const DATABASE_URL = process.env.DATABASE_URL as string; export const ENVIRONMENT = process.env.ENVIRONMENT; export const IS_PRODUCTION = ENVIRONMENT === 'production'; -export const IS_TEST = ENVIRONMENT === 'test'; From 8bd42203f401330be92d79b0988fd6ff1447b8ee Mon Sep 17 00:00:00 2001 From: Rami Abdou Date: Wed, 3 Apr 2024 10:15:34 -0700 Subject: [PATCH 11/14] @oyster/db to apps --- apps/admin-dashboard/package.json | 1 + apps/member-profile/package.json | 1 + 2 files changed, 2 insertions(+) diff --git a/apps/admin-dashboard/package.json b/apps/admin-dashboard/package.json index 4ed4b41b..24208500 100644 --- a/apps/admin-dashboard/package.json +++ b/apps/admin-dashboard/package.json @@ -13,6 +13,7 @@ }, "dependencies": { "@oyster/core": "*", + "@oyster/db": "*", "@oyster/types": "*", "@oyster/ui": "*", "@oyster/utils": "*", diff --git a/apps/member-profile/package.json b/apps/member-profile/package.json index 2669c281..76305361 100644 --- a/apps/member-profile/package.json +++ b/apps/member-profile/package.json @@ -13,6 +13,7 @@ }, "dependencies": { "@oyster/core": "*", + "@oyster/db": "*", "@oyster/types": "*", "@oyster/ui": "*", "@oyster/utils": "*", From c97c8426636cedc09ee76db1215a26d7a3e4f9fa Mon Sep 17 00:00:00 2001 From: Rami Abdou Date: Wed, 3 Apr 2024 10:15:58 -0700 Subject: [PATCH 12/14] import db directly from oyster/db --- apps/admin-dashboard/app/shared/core.server.ts | 4 ++++ apps/member-profile/app/shared/core.server.ts | 4 ++++ packages/core/src/admin-dashboard.server.ts | 1 - packages/core/src/member-profile.server.ts | 2 -- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/apps/admin-dashboard/app/shared/core.server.ts b/apps/admin-dashboard/app/shared/core.server.ts index 85db673d..90802832 100644 --- a/apps/admin-dashboard/app/shared/core.server.ts +++ b/apps/admin-dashboard/app/shared/core.server.ts @@ -1 +1,5 @@ export * from '@oyster/core/admin-dashboard.server'; + +// TODO: Once all database access is moved to the core package, we should +// remove this! +export { db } from '@oyster/db'; diff --git a/apps/member-profile/app/shared/core.server.ts b/apps/member-profile/app/shared/core.server.ts index 2e91edf3..e5a74092 100644 --- a/apps/member-profile/app/shared/core.server.ts +++ b/apps/member-profile/app/shared/core.server.ts @@ -1 +1,5 @@ export * from '@oyster/core/member-profile.server'; + +// TODO: Once all database access is moved to the core package, we should +// remove this! +export { db, type DB } from '@oyster/db'; diff --git a/packages/core/src/admin-dashboard.server.ts b/packages/core/src/admin-dashboard.server.ts index 27267483..34dd3ff4 100644 --- a/packages/core/src/admin-dashboard.server.ts +++ b/packages/core/src/admin-dashboard.server.ts @@ -1,6 +1,5 @@ export { QueueFromName } from './infrastructure/bull/bull'; export { job } from './infrastructure/bull/use-cases/job'; -export { db } from './infrastructure/database'; export { addAdmin } from './modules/admin/use-cases/add-admin'; export { countPendingApplications } from './modules/application/queries/count-pending-applications'; export { getApplication } from './modules/application/queries/get-application'; diff --git a/packages/core/src/member-profile.server.ts b/packages/core/src/member-profile.server.ts index d0118ff9..7e6d1525 100644 --- a/packages/core/src/member-profile.server.ts +++ b/packages/core/src/member-profile.server.ts @@ -1,6 +1,4 @@ -export type { DB } from '@oyster/db'; export { job } from './infrastructure/bull/use-cases/job'; -export { db } from './infrastructure/database'; export { getActiveStreak } from './modules/active-status/queries/get-active-streak'; export { getActiveStreakLeaderboard } from './modules/active-status/queries/get-active-streak-leaderboard'; export { getActiveStreakLeaderboardPosition } from './modules/active-status/queries/get-active-streak-leaderboard-position'; From 2effa59a6345d7b293353b664baea4562d0c1254 Mon Sep 17 00:00:00 2001 From: Rami Abdou Date: Wed, 3 Apr 2024 10:17:00 -0700 Subject: [PATCH 13/14] reorder --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 613b6301..cabfb822 100644 --- a/package.json +++ b/package.json @@ -16,8 +16,8 @@ "dev": "turbo run dev --cache-dir=.turbo", "dev:apps": "yarn dev --filter='./apps/*'", "lint": "turbo run lint --cache-dir=.turbo", - "test": "turbo run test --cache-dir=.turbo", "start": "turbo run start --cache-dir=.turbo", + "test": "turbo run test --cache-dir=.turbo", "type-check": "turbo run type-check --cache-dir=.turbo" }, "devDependencies": { From a980252095ccc89682abbcc92b1960bf8a4d51d7 Mon Sep 17 00:00:00 2001 From: Rami Abdou Date: Wed, 3 Apr 2024 10:26:48 -0700 Subject: [PATCH 14/14] db --- apps/admin-dashboard/railway.json | 1 + apps/api/railway.json | 1 + apps/member-profile/railway.json | 1 + 3 files changed, 3 insertions(+) diff --git a/apps/admin-dashboard/railway.json b/apps/admin-dashboard/railway.json index 84147e42..ea72e108 100644 --- a/apps/admin-dashboard/railway.json +++ b/apps/admin-dashboard/railway.json @@ -7,6 +7,7 @@ "watchPatterns": [ "/apps/admin-dashboard/**/*", "/packages/core/**/*", + "/packages/db/**/*", "/packages/ui/**/*" ] }, diff --git a/apps/api/railway.json b/apps/api/railway.json index 661272f4..fc1c4ac5 100644 --- a/apps/api/railway.json +++ b/apps/api/railway.json @@ -7,6 +7,7 @@ "watchPatterns": [ "/apps/api/**/*", "/packages/core/**/*", + "/packages/db/**/*", "/packages/email-templates/**/*" ] }, diff --git a/apps/member-profile/railway.json b/apps/member-profile/railway.json index 6f0af379..0a22a44d 100644 --- a/apps/member-profile/railway.json +++ b/apps/member-profile/railway.json @@ -7,6 +7,7 @@ "watchPatterns": [ "/apps/member-profile/**/*", "/packages/core/**/*", + "/packages/db/**/*", "/packages/ui/**/*" ] },