--
-- PostgreSQL database dump
--

\restrict NRX91yBJCm445olT8iSjLqcIZtZiNWfMWQkgNOCa1Jc3ckwdYcbEMalzD8ITVN9

-- Dumped from database version 15.15
-- Dumped by pg_dump version 15.15

SET statement_timeout = 0;
SET lock_timeout = 0;
SET idle_in_transaction_session_timeout = 0;
SET client_encoding = 'UTF8';
SET standard_conforming_strings = on;
SELECT pg_catalog.set_config('search_path', '', false);
SET check_function_bodies = false;
SET xmloption = content;
SET client_min_messages = warning;
SET row_security = off;

SET default_tablespace = '';

SET default_table_access_method = heap;

--
-- Name: adverse_events; Type: TABLE; Schema: public; Owner: ctms_user
--

CREATE TABLE public.adverse_events (
    id uuid NOT NULL,
    study_id uuid NOT NULL,
    site_id uuid,
    subject_id uuid,
    visit_id uuid,
    term character varying(255) NOT NULL,
    onset_date date,
    resolution_date date,
    seriousness character varying(50) NOT NULL,
    severity character varying(50) NOT NULL,
    causality character varying(50),
    action_taken text,
    outcome character varying(50),
    reported_to_sponsor boolean NOT NULL,
    report_due_date date,
    status character varying(20) NOT NULL,
    description text,
    created_by uuid NOT NULL,
    created_at timestamp with time zone DEFAULT now() NOT NULL,
    updated_at timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.adverse_events OWNER TO ctms_user;

--
-- Name: attachments; Type: TABLE; Schema: public; Owner: ctms_user
--

CREATE TABLE public.attachments (
    id uuid NOT NULL,
    study_id uuid NOT NULL,
    entity_type character varying(50) NOT NULL,
    entity_id uuid NOT NULL,
    filename character varying(255) NOT NULL,
    file_path character varying(500) NOT NULL,
    file_size integer NOT NULL,
    content_type character varying(100),
    uploaded_by uuid NOT NULL,
    uploaded_at timestamp with time zone DEFAULT now() NOT NULL,
    is_deleted boolean DEFAULT false NOT NULL
);


ALTER TABLE public.attachments OWNER TO ctms_user;

--
-- Name: audit_logs; Type: TABLE; Schema: public; Owner: ctms_user
--

CREATE TABLE public.audit_logs (
    id uuid NOT NULL,
    study_id uuid,
    entity_type character varying(50) NOT NULL,
    entity_id uuid,
    action character varying(50) NOT NULL,
    detail text,
    operator_id uuid NOT NULL,
    operator_role character varying(50) NOT NULL,
    created_at timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.audit_logs OWNER TO ctms_user;

--
-- Name: comments; Type: TABLE; Schema: public; Owner: ctms_user
--

CREATE TABLE public.comments (
    id uuid NOT NULL,
    study_id uuid NOT NULL,
    entity_type character varying(50) NOT NULL,
    entity_id uuid NOT NULL,
    content text NOT NULL,
    created_by uuid NOT NULL,
    created_at timestamp with time zone DEFAULT now() NOT NULL,
    is_deleted boolean DEFAULT false NOT NULL
);


ALTER TABLE public.comments OWNER TO ctms_user;

--
-- Name: data_queries; Type: TABLE; Schema: public; Owner: ctms_user
--

CREATE TABLE public.data_queries (
    id uuid NOT NULL,
    study_id uuid NOT NULL,
    site_id uuid,
    subject_id uuid,
    visit_id uuid,
    title character varying(255) NOT NULL,
    description text,
    category character varying(50) NOT NULL,
    priority character varying(20) NOT NULL,
    assigned_to uuid,
    due_date date,
    status character varying(20) NOT NULL,
    resolution text,
    closed_at timestamp with time zone,
    created_by uuid NOT NULL,
    created_at timestamp with time zone DEFAULT now() NOT NULL,
    updated_at timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.data_queries OWNER TO ctms_user;

--
-- Name: faq_categories; Type: TABLE; Schema: public; Owner: ctms_user
--

CREATE TABLE public.faq_categories (
    id uuid NOT NULL,
    study_id uuid,
    name character varying(100) NOT NULL,
    description text,
    sort_order integer NOT NULL,
    is_active boolean NOT NULL,
    created_at timestamp with time zone DEFAULT now() NOT NULL,
    updated_at timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.faq_categories OWNER TO ctms_user;

--
-- Name: faq_items; Type: TABLE; Schema: public; Owner: ctms_user
--

CREATE TABLE public.faq_items (
    id uuid NOT NULL,
    study_id uuid,
    category_id uuid NOT NULL,
    question text NOT NULL,
    answer text NOT NULL,
    keywords character varying(255),
    version integer NOT NULL,
    is_active boolean NOT NULL,
    created_by uuid NOT NULL,
    created_at timestamp with time zone DEFAULT now() NOT NULL,
    updated_at timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.faq_items OWNER TO ctms_user;

--
-- Name: finance_items; Type: TABLE; Schema: public; Owner: ctms_user
--

CREATE TABLE public.finance_items (
    id uuid NOT NULL,
    study_id uuid NOT NULL,
    site_id uuid,
    subject_id uuid,
    visit_id uuid,
    category character varying(50) NOT NULL,
    title character varying(255) NOT NULL,
    description text,
    currency character varying(10) NOT NULL,
    amount numeric(12,2) NOT NULL,
    occur_date date NOT NULL,
    status character varying(20) NOT NULL,
    submitted_at timestamp with time zone,
    approved_at timestamp with time zone,
    rejected_at timestamp with time zone,
    paid_at timestamp with time zone,
    approver_id uuid,
    payer_id uuid,
    reject_reason text,
    created_by uuid NOT NULL,
    created_at timestamp with time zone DEFAULT now() NOT NULL,
    updated_at timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.finance_items OWNER TO ctms_user;

--
-- Name: imp_batches; Type: TABLE; Schema: public; Owner: ctms_user
--

CREATE TABLE public.imp_batches (
    id uuid NOT NULL,
    study_id uuid NOT NULL,
    product_id uuid NOT NULL,
    batch_no character varying(100) NOT NULL,
    expiry_date date,
    manufacture_date date,
    status character varying(20) NOT NULL,
    created_at timestamp with time zone DEFAULT now() NOT NULL,
    updated_at timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.imp_batches OWNER TO ctms_user;

--
-- Name: imp_inventory; Type: TABLE; Schema: public; Owner: ctms_user
--

CREATE TABLE public.imp_inventory (
    id uuid NOT NULL,
    study_id uuid NOT NULL,
    site_id uuid NOT NULL,
    batch_id uuid NOT NULL,
    quantity_on_hand integer NOT NULL,
    updated_at timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.imp_inventory OWNER TO ctms_user;

--
-- Name: imp_products; Type: TABLE; Schema: public; Owner: ctms_user
--

CREATE TABLE public.imp_products (
    id uuid NOT NULL,
    study_id uuid NOT NULL,
    name character varying(255) NOT NULL,
    form character varying(100),
    strength character varying(100),
    unit character varying(50) NOT NULL,
    description text,
    is_active boolean NOT NULL,
    created_at timestamp with time zone DEFAULT now() NOT NULL,
    updated_at timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.imp_products OWNER TO ctms_user;

--
-- Name: imp_transactions; Type: TABLE; Schema: public; Owner: ctms_user
--

CREATE TABLE public.imp_transactions (
    id uuid NOT NULL,
    study_id uuid NOT NULL,
    site_id uuid NOT NULL,
    batch_id uuid NOT NULL,
    subject_id uuid,
    tx_type character varying(20) NOT NULL,
    quantity integer NOT NULL,
    tx_date date NOT NULL,
    reference character varying(255),
    notes text,
    created_by uuid NOT NULL,
    created_at timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.imp_transactions OWNER TO ctms_user;

--
-- Name: issues; Type: TABLE; Schema: public; Owner: ctms_user
--

CREATE TABLE public.issues (
    id uuid NOT NULL,
    study_id uuid NOT NULL,
    site_id uuid,
    subject_id uuid,
    title character varying(255) NOT NULL,
    description text,
    category character varying(50) NOT NULL,
    level character varying(20) NOT NULL,
    owner_id uuid,
    due_date date,
    status character varying(20) NOT NULL,
    capa text,
    closed_at timestamp with time zone,
    created_by uuid NOT NULL,
    created_at timestamp with time zone DEFAULT now() NOT NULL,
    updated_at timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.issues OWNER TO ctms_user;

--
-- Name: milestones; Type: TABLE; Schema: public; Owner: ctms_user
--

CREATE TABLE public.milestones (
    id uuid NOT NULL,
    study_id uuid NOT NULL,
    type character varying(50) NOT NULL,
    name character varying(200) NOT NULL,
    planned_date date,
    actual_date date,
    status character varying(20) NOT NULL,
    owner_id uuid,
    notes text,
    created_at timestamp with time zone DEFAULT now() NOT NULL,
    updated_at timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.milestones OWNER TO ctms_user;

--
-- Name: sites; Type: TABLE; Schema: public; Owner: ctms_user
--

CREATE TABLE public.sites (
    id uuid NOT NULL,
    study_id uuid NOT NULL,
    name character varying(200) NOT NULL,
    city character varying(100),
    pi_name character varying(100),
    contact character varying(100),
    is_active boolean DEFAULT true NOT NULL,
    created_at timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.sites OWNER TO ctms_user;

--
-- Name: studies; Type: TABLE; Schema: public; Owner: ctms_user
--

CREATE TABLE public.studies (
    id uuid NOT NULL,
    code character varying(50) NOT NULL,
    name character varying(200) NOT NULL,
    sponsor character varying(200),
    protocol_no character varying(100),
    phase character varying(50),
    status character varying(20) NOT NULL,
    created_by uuid,
    created_at timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.studies OWNER TO ctms_user;

--
-- Name: study_members; Type: TABLE; Schema: public; Owner: ctms_user
--

CREATE TABLE public.study_members (
    id uuid NOT NULL,
    study_id uuid NOT NULL,
    user_id uuid NOT NULL,
    role_in_study character varying(20) NOT NULL,
    is_active boolean DEFAULT true NOT NULL,
    added_at timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.study_members OWNER TO ctms_user;

--
-- Name: subjects; Type: TABLE; Schema: public; Owner: ctms_user
--

CREATE TABLE public.subjects (
    id uuid NOT NULL,
    study_id uuid NOT NULL,
    site_id uuid NOT NULL,
    subject_no character varying(50) NOT NULL,
    status character varying(20) NOT NULL,
    screening_date date,
    enrollment_date date,
    completion_date date,
    drop_reason text,
    created_at timestamp with time zone DEFAULT now() NOT NULL,
    updated_at timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.subjects OWNER TO ctms_user;

--
-- Name: tasks; Type: TABLE; Schema: public; Owner: ctms_user
--

CREATE TABLE public.tasks (
    id uuid NOT NULL,
    study_id uuid NOT NULL,
    milestone_id uuid,
    title character varying(200) NOT NULL,
    description text,
    assignee_id uuid,
    priority character varying(20) NOT NULL,
    due_date date,
    status character varying(20) NOT NULL,
    completed_at timestamp with time zone,
    created_by uuid NOT NULL,
    created_at timestamp with time zone DEFAULT now() NOT NULL,
    updated_at timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.tasks OWNER TO ctms_user;

--
-- Name: users; Type: TABLE; Schema: public; Owner: ctms_user
--

CREATE TABLE public.users (
    id uuid NOT NULL,
    username character varying(50) NOT NULL,
    hashed_password character varying(255) NOT NULL,
    role character varying(20) NOT NULL,
    is_active boolean DEFAULT true NOT NULL,
    created_at timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.users OWNER TO ctms_user;

--
-- Name: verification_progress; Type: TABLE; Schema: public; Owner: ctms_user
--

CREATE TABLE public.verification_progress (
    id uuid NOT NULL,
    study_id uuid NOT NULL,
    site_id uuid NOT NULL,
    subject_id uuid NOT NULL,
    level character varying(10) NOT NULL,
    percent integer NOT NULL,
    last_verified_at date,
    verifier_id uuid,
    notes text,
    created_at timestamp with time zone DEFAULT now() NOT NULL,
    updated_at timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.verification_progress OWNER TO ctms_user;

--
-- Name: visits; Type: TABLE; Schema: public; Owner: ctms_user
--

CREATE TABLE public.visits (
    id uuid NOT NULL,
    study_id uuid NOT NULL,
    subject_id uuid NOT NULL,
    visit_code character varying(50) NOT NULL,
    visit_name character varying(200) NOT NULL,
    planned_date date,
    actual_date date,
    status character varying(20) NOT NULL,
    window_start date,
    window_end date,
    notes text,
    created_at timestamp with time zone DEFAULT now() NOT NULL,
    updated_at timestamp with time zone DEFAULT now() NOT NULL
);


ALTER TABLE public.visits OWNER TO ctms_user;

--
-- Data for Name: adverse_events; Type: TABLE DATA; Schema: public; Owner: ctms_user
--

COPY public.adverse_events (id, study_id, site_id, subject_id, visit_id, term, onset_date, resolution_date, seriousness, severity, causality, action_taken, outcome, reported_to_sponsor, report_due_date, status, description, created_by, created_at, updated_at) FROM stdin;
aaaaaaa1-aaaa-aaaa-aaaa-aaaaaaaaaaa1	44444444-4444-4444-4444-444444444444	55555555-5555-5555-5555-555555555555	88888888-8888-8888-8888-888888888888	99999999-9999-9999-9999-999999999999	轻微头痛	2025-01-18	2025-01-19	NON_SERIOUS	MILD	RELATED	休息观察	RECOVERED	f	2025-01-25	CLOSED	访视后出现轻微头痛，已恢复	33333333-3333-3333-3333-333333333333	2025-12-18 00:55:17.568504+00	2025-12-18 00:55:17.568504+00
\.


--
-- Data for Name: attachments; Type: TABLE DATA; Schema: public; Owner: ctms_user
--

COPY public.attachments (id, study_id, entity_type, entity_id, filename, file_path, file_size, content_type, uploaded_by, uploaded_at, is_deleted) FROM stdin;
aaaabbbb-cccc-dddd-eeee-ffff00001111	44444444-4444-4444-4444-444444444444	task	77777777-7777-7777-7777-777777777777	伦理文件.pdf	/uploads/demo/ethics.pdf	123456	application/pdf	33333333-3333-3333-3333-333333333333	2025-12-18 00:55:17.568504+00	f
\.


--
-- Data for Name: audit_logs; Type: TABLE DATA; Schema: public; Owner: ctms_user
--

COPY public.audit_logs (id, study_id, entity_type, entity_id, action, detail, operator_id, operator_role, created_at) FROM stdin;
99998888-7777-6666-5555-444433332222	44444444-4444-4444-4444-444444444444	study	44444444-4444-4444-4444-444444444444	CREATE	创建示例项目并导入 demo 数据	11111111-1111-1111-1111-111111111111	ADMIN	2025-12-18 00:55:17.568504+00
\.


--
-- Data for Name: comments; Type: TABLE DATA; Schema: public; Owner: ctms_user
--

COPY public.comments (id, study_id, entity_type, entity_id, content, created_by, created_at, is_deleted) FROM stdin;
22223333-4444-5555-6666-777788889999	44444444-4444-4444-4444-444444444444	task	77777777-7777-7777-7777-777777777777	资料已提交伦理，等待批件。	33333333-3333-3333-3333-333333333333	2025-12-18 00:55:17.568504+00	f
\.


--
-- Data for Name: data_queries; Type: TABLE DATA; Schema: public; Owner: ctms_user
--

COPY public.data_queries (id, study_id, site_id, subject_id, visit_id, title, description, category, priority, assigned_to, due_date, status, resolution, closed_at, created_by, created_at, updated_at) FROM stdin;
ccccccc1-cccc-cccc-cccc-ccccccccccc1	44444444-4444-4444-4444-444444444444	55555555-5555-5555-5555-555555555555	88888888-8888-8888-8888-888888888888	99999999-9999-9999-9999-999999999999	血压录入缺失	V1 访视缺少舒张压	SAFETY	HIGH	33333333-3333-3333-3333-333333333333	2025-01-22	OPEN	\N	\N	33333333-3333-3333-3333-333333333333	2025-12-18 00:55:17.568504+00	2025-12-18 00:55:17.568504+00
\.


--
-- Data for Name: faq_categories; Type: TABLE DATA; Schema: public; Owner: ctms_user
--

COPY public.faq_categories (id, study_id, name, description, sort_order, is_active, created_at, updated_at) FROM stdin;
eeeeeee1-eeee-eeee-eeee-eeeeeeeeeee1	44444444-4444-4444-4444-444444444444	访视相关	访视常见问答	1	t	2025-12-18 00:55:17.568504+00	2025-12-18 00:55:17.568504+00
\.


--
-- Data for Name: faq_items; Type: TABLE DATA; Schema: public; Owner: ctms_user
--

COPY public.faq_items (id, study_id, category_id, question, answer, keywords, version, is_active, created_by, created_at, updated_at) FROM stdin;
fffffff1-ffff-ffff-ffff-fffffffffff1	44444444-4444-4444-4444-444444444444	eeeeeee1-eeee-eeee-eeee-eeeeeeeeeee1	V1 访视需要携带什么？	携带受试者知情同意书、病历和药物记录本。	访视,携带物品	1	t	22222222-2222-2222-2222-222222222222	2025-12-18 00:55:17.568504+00	2025-12-18 00:55:17.568504+00
\.


--
-- Data for Name: finance_items; Type: TABLE DATA; Schema: public; Owner: ctms_user
--

COPY public.finance_items (id, study_id, site_id, subject_id, visit_id, category, title, description, currency, amount, occur_date, status, submitted_at, approved_at, rejected_at, paid_at, approver_id, payer_id, reject_reason, created_by, created_at, updated_at) FROM stdin;
11112222-3333-4444-5555-666677778888	44444444-4444-4444-4444-444444444444	55555555-5555-5555-5555-555555555555	88888888-8888-8888-8888-888888888888	99999999-9999-9999-9999-999999999999	VISIT_FEE	V1 随访补贴	受试者 V1 访视补贴	CNY	200.00	2025-01-18	PAID	2025-12-18 00:55:17.568504+00	2025-12-18 00:55:17.568504+00	\N	2025-12-18 00:55:17.568504+00	22222222-2222-2222-2222-222222222222	11111111-1111-1111-1111-111111111111	\N	22222222-2222-2222-2222-222222222222	2025-12-18 00:55:17.568504+00	2025-12-18 00:55:17.568504+00
\.


--
-- Data for Name: imp_batches; Type: TABLE DATA; Schema: public; Owner: ctms_user
--

COPY public.imp_batches (id, study_id, product_id, batch_no, expiry_date, manufacture_date, status, created_at, updated_at) FROM stdin;
abcd0000-1111-2222-3333-444455556667	44444444-4444-4444-4444-444444444444	abcd0000-1111-2222-3333-444455556666	BATCH-001	2026-12-31	2024-12-01	ACTIVE	2025-12-18 00:55:17.568504+00	2025-12-18 00:55:17.568504+00
\.


--
-- Data for Name: imp_inventory; Type: TABLE DATA; Schema: public; Owner: ctms_user
--

COPY public.imp_inventory (id, study_id, site_id, batch_id, quantity_on_hand, updated_at) FROM stdin;
abcd0000-1111-2222-3333-444455556668	44444444-4444-4444-4444-444444444444	55555555-5555-5555-5555-555555555555	abcd0000-1111-2222-3333-444455556667	100	2025-12-18 00:55:17.568504+00
\.


--
-- Data for Name: imp_products; Type: TABLE DATA; Schema: public; Owner: ctms_user
--

COPY public.imp_products (id, study_id, name, form, strength, unit, description, is_active, created_at, updated_at) FROM stdin;
abcd0000-1111-2222-3333-444455556666	44444444-4444-4444-4444-444444444444	DP-001 片剂	tablet	50mg	mg	IMP 示例产品	t	2025-12-18 00:55:17.568504+00	2025-12-18 00:55:17.568504+00
\.


--
-- Data for Name: imp_transactions; Type: TABLE DATA; Schema: public; Owner: ctms_user
--

COPY public.imp_transactions (id, study_id, site_id, batch_id, subject_id, tx_type, quantity, tx_date, reference, notes, created_by, created_at) FROM stdin;
abcd0000-1111-2222-3333-444455556669	44444444-4444-4444-4444-444444444444	55555555-5555-5555-5555-555555555555	abcd0000-1111-2222-3333-444455556667	88888888-8888-8888-8888-888888888888	DISPENSE	2	2025-01-18	V1给药	基线访视发药	33333333-3333-3333-3333-333333333333	2025-12-18 00:55:17.568504+00
\.


--
-- Data for Name: issues; Type: TABLE DATA; Schema: public; Owner: ctms_user
--

COPY public.issues (id, study_id, site_id, subject_id, title, description, category, level, owner_id, due_date, status, capa, closed_at, created_by, created_at, updated_at) FROM stdin;
bbbbbbb1-bbbb-bbbb-bbbb-bbbbbbbbbbb1	44444444-4444-4444-4444-444444444444	55555555-5555-5555-5555-555555555555	88888888-8888-8888-8888-888888888888	实验室报告延迟	实验室报告上传滞后	LAB	MEDIUM	22222222-2222-2222-2222-222222222222	2025-01-25	OPEN	督促供应商提速	\N	22222222-2222-2222-2222-222222222222	2025-12-18 00:55:17.568504+00	2025-12-18 00:55:17.568504+00
\.


--
-- Data for Name: milestones; Type: TABLE DATA; Schema: public; Owner: ctms_user
--

COPY public.milestones (id, study_id, type, name, planned_date, actual_date, status, owner_id, notes, created_at, updated_at) FROM stdin;
66666666-6666-6666-6666-666666666666	44444444-4444-4444-4444-444444444444	STARTUP	启动会	2025-01-10	2025-01-12	DONE	22222222-2222-2222-2222-222222222222	现场启动完成	2025-12-18 00:55:17.568504+00	2025-12-18 00:55:17.568504+00
\.


--
-- Data for Name: sites; Type: TABLE DATA; Schema: public; Owner: ctms_user
--

COPY public.sites (id, study_id, name, city, pi_name, contact, is_active, created_at) FROM stdin;
55555555-5555-5555-5555-555555555555	44444444-4444-4444-4444-444444444444	北京协和医院	北京	李主任	010-12345678	t	2025-12-18 00:55:17.568504+00
\.


--
-- Data for Name: studies; Type: TABLE DATA; Schema: public; Owner: ctms_user
--

COPY public.studies (id, code, name, sponsor, protocol_no, phase, status, created_by, created_at) FROM stdin;
44444444-4444-4444-4444-444444444444	STUDY-001	示例项目：糖尿病新药	Demo Pharma	DP-001	Phase II	ACTIVE	11111111-1111-1111-1111-111111111111	2025-12-18 00:55:17.568504+00
\.


--
-- Data for Name: study_members; Type: TABLE DATA; Schema: public; Owner: ctms_user
--

COPY public.study_members (id, study_id, user_id, role_in_study, is_active, added_at) FROM stdin;
aaaa1111-2222-3333-4444-555566667777	44444444-4444-4444-4444-444444444444	11111111-1111-1111-1111-111111111111	ADMIN	t	2025-12-18 00:55:17.568504+00
bbbb1111-2222-3333-4444-555566667777	44444444-4444-4444-4444-444444444444	22222222-2222-2222-2222-222222222222	PM	t	2025-12-18 00:55:17.568504+00
cccc1111-2222-3333-4444-555566667777	44444444-4444-4444-4444-444444444444	33333333-3333-3333-3333-333333333333	CRA	t	2025-12-18 00:55:17.568504+00
\.


--
-- Data for Name: subjects; Type: TABLE DATA; Schema: public; Owner: ctms_user
--

COPY public.subjects (id, study_id, site_id, subject_no, status, screening_date, enrollment_date, completion_date, drop_reason, created_at, updated_at) FROM stdin;
88888888-8888-8888-8888-888888888888	44444444-4444-4444-4444-444444444444	55555555-5555-5555-5555-555555555555	SUBJ-001	ONGOING	2025-01-15	2025-01-18	\N	\N	2025-12-18 00:55:17.568504+00	2025-12-18 00:55:17.568504+00
\.


--
-- Data for Name: tasks; Type: TABLE DATA; Schema: public; Owner: ctms_user
--

COPY public.tasks (id, study_id, milestone_id, title, description, assignee_id, priority, due_date, status, completed_at, created_by, created_at, updated_at) FROM stdin;
77777777-7777-7777-7777-777777777777	44444444-4444-4444-4444-444444444444	66666666-6666-6666-6666-666666666666	伦理资料提交	准备伦理文件并提交	33333333-3333-3333-3333-333333333333	HIGH	2025-01-20	IN_PROGRESS	\N	22222222-2222-2222-2222-222222222222	2025-12-18 00:55:17.568504+00	2025-12-18 00:55:17.568504+00
\.


--
-- Data for Name: users; Type: TABLE DATA; Schema: public; Owner: ctms_user
--

COPY public.users (id, username, hashed_password, role, is_active, created_at) FROM stdin;
11111111-1111-1111-1111-111111111111	admin	$2b$12$q5T2aW/GgTQ0yxOCpuRhFetYVL6CmRecEIUeXwuXiLWbY00RD3rp6	ADMIN	t	2025-12-18 00:55:17.568504+00
22222222-2222-2222-2222-222222222222	pm1	$2b$12$oMZt76T4H5GabqIPVD.uSe7NkaIJWqSreaYRvIRhF9CSWy9BVrjYS	PM	t	2025-12-18 00:55:17.568504+00
33333333-3333-3333-3333-333333333333	cra1	$2b$12$iQuY.bTrrBWYRAgS.LmJbe2yqOY1Tmv86FpC0lXBH0eYPIcyeh7uO	CRA	t	2025-12-18 00:55:17.568504+00
\.


--
-- Data for Name: verification_progress; Type: TABLE DATA; Schema: public; Owner: ctms_user
--

COPY public.verification_progress (id, study_id, site_id, subject_id, level, percent, last_verified_at, verifier_id, notes, created_at, updated_at) FROM stdin;
ddddddd1-dddd-dddd-dddd-ddddddddddd1	44444444-4444-4444-4444-444444444444	55555555-5555-5555-5555-555555555555	88888888-8888-8888-8888-888888888888	SDV	50	2025-01-19	33333333-3333-3333-3333-333333333333	已完成前50% SDV	2025-12-18 00:55:17.568504+00	2025-12-18 00:55:17.568504+00
\.


--
-- Data for Name: visits; Type: TABLE DATA; Schema: public; Owner: ctms_user
--

COPY public.visits (id, study_id, subject_id, visit_code, visit_name, planned_date, actual_date, status, window_start, window_end, notes, created_at, updated_at) FROM stdin;
99999999-9999-9999-9999-999999999999	44444444-4444-4444-4444-444444444444	88888888-8888-8888-8888-888888888888	V1	基线访视	2025-01-18	2025-01-18	COMPLETED	2025-01-16	2025-01-20	无偏差	2025-12-18 00:55:17.568504+00	2025-12-18 00:55:17.568504+00
\.


--
-- Name: adverse_events adverse_events_pkey; Type: CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.adverse_events
    ADD CONSTRAINT adverse_events_pkey PRIMARY KEY (id);


--
-- Name: attachments attachments_pkey; Type: CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.attachments
    ADD CONSTRAINT attachments_pkey PRIMARY KEY (id);


--
-- Name: audit_logs audit_logs_pkey; Type: CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.audit_logs
    ADD CONSTRAINT audit_logs_pkey PRIMARY KEY (id);


--
-- Name: comments comments_pkey; Type: CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.comments
    ADD CONSTRAINT comments_pkey PRIMARY KEY (id);


--
-- Name: data_queries data_queries_pkey; Type: CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.data_queries
    ADD CONSTRAINT data_queries_pkey PRIMARY KEY (id);


--
-- Name: faq_categories faq_categories_pkey; Type: CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.faq_categories
    ADD CONSTRAINT faq_categories_pkey PRIMARY KEY (id);


--
-- Name: faq_items faq_items_pkey; Type: CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.faq_items
    ADD CONSTRAINT faq_items_pkey PRIMARY KEY (id);


--
-- Name: finance_items finance_items_pkey; Type: CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.finance_items
    ADD CONSTRAINT finance_items_pkey PRIMARY KEY (id);


--
-- Name: imp_batches imp_batches_pkey; Type: CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.imp_batches
    ADD CONSTRAINT imp_batches_pkey PRIMARY KEY (id);


--
-- Name: imp_inventory imp_inventory_pkey; Type: CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.imp_inventory
    ADD CONSTRAINT imp_inventory_pkey PRIMARY KEY (id);


--
-- Name: imp_products imp_products_pkey; Type: CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.imp_products
    ADD CONSTRAINT imp_products_pkey PRIMARY KEY (id);


--
-- Name: imp_transactions imp_transactions_pkey; Type: CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.imp_transactions
    ADD CONSTRAINT imp_transactions_pkey PRIMARY KEY (id);


--
-- Name: issues issues_pkey; Type: CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.issues
    ADD CONSTRAINT issues_pkey PRIMARY KEY (id);


--
-- Name: milestones milestones_pkey; Type: CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.milestones
    ADD CONSTRAINT milestones_pkey PRIMARY KEY (id);


--
-- Name: sites sites_pkey; Type: CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.sites
    ADD CONSTRAINT sites_pkey PRIMARY KEY (id);


--
-- Name: studies studies_pkey; Type: CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.studies
    ADD CONSTRAINT studies_pkey PRIMARY KEY (id);


--
-- Name: study_members study_members_pkey; Type: CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.study_members
    ADD CONSTRAINT study_members_pkey PRIMARY KEY (id);


--
-- Name: subjects subjects_pkey; Type: CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.subjects
    ADD CONSTRAINT subjects_pkey PRIMARY KEY (id);


--
-- Name: tasks tasks_pkey; Type: CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.tasks
    ADD CONSTRAINT tasks_pkey PRIMARY KEY (id);


--
-- Name: faq_categories uq_faq_category_name; Type: CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.faq_categories
    ADD CONSTRAINT uq_faq_category_name UNIQUE (study_id, name);


--
-- Name: imp_batches uq_imp_batch_no; Type: CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.imp_batches
    ADD CONSTRAINT uq_imp_batch_no UNIQUE (study_id, batch_no, product_id);


--
-- Name: imp_inventory uq_imp_inventory_site_batch; Type: CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.imp_inventory
    ADD CONSTRAINT uq_imp_inventory_site_batch UNIQUE (study_id, site_id, batch_id);


--
-- Name: imp_products uq_imp_product_name; Type: CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.imp_products
    ADD CONSTRAINT uq_imp_product_name UNIQUE (study_id, name);


--
-- Name: study_members uq_study_member; Type: CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.study_members
    ADD CONSTRAINT uq_study_member UNIQUE (study_id, user_id);


--
-- Name: subjects uq_subject_study_no; Type: CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.subjects
    ADD CONSTRAINT uq_subject_study_no UNIQUE (study_id, subject_no);


--
-- Name: verification_progress uq_verification_subject_level; Type: CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.verification_progress
    ADD CONSTRAINT uq_verification_subject_level UNIQUE (study_id, subject_id, level);


--
-- Name: users users_pkey; Type: CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.users
    ADD CONSTRAINT users_pkey PRIMARY KEY (id);


--
-- Name: verification_progress verification_progress_pkey; Type: CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.verification_progress
    ADD CONSTRAINT verification_progress_pkey PRIMARY KEY (id);


--
-- Name: visits visits_pkey; Type: CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.visits
    ADD CONSTRAINT visits_pkey PRIMARY KEY (id);


--
-- Name: ix_adverse_events_site_id; Type: INDEX; Schema: public; Owner: ctms_user
--

CREATE INDEX ix_adverse_events_site_id ON public.adverse_events USING btree (site_id);


--
-- Name: ix_adverse_events_study_id; Type: INDEX; Schema: public; Owner: ctms_user
--

CREATE INDEX ix_adverse_events_study_id ON public.adverse_events USING btree (study_id);


--
-- Name: ix_adverse_events_subject_id; Type: INDEX; Schema: public; Owner: ctms_user
--

CREATE INDEX ix_adverse_events_subject_id ON public.adverse_events USING btree (subject_id);


--
-- Name: ix_comments_study_id; Type: INDEX; Schema: public; Owner: ctms_user
--

CREATE INDEX ix_comments_study_id ON public.comments USING btree (study_id);


--
-- Name: ix_data_queries_site_id; Type: INDEX; Schema: public; Owner: ctms_user
--

CREATE INDEX ix_data_queries_site_id ON public.data_queries USING btree (site_id);


--
-- Name: ix_data_queries_study_id; Type: INDEX; Schema: public; Owner: ctms_user
--

CREATE INDEX ix_data_queries_study_id ON public.data_queries USING btree (study_id);


--
-- Name: ix_data_queries_subject_id; Type: INDEX; Schema: public; Owner: ctms_user
--

CREATE INDEX ix_data_queries_subject_id ON public.data_queries USING btree (subject_id);


--
-- Name: ix_faq_categories_study_id; Type: INDEX; Schema: public; Owner: ctms_user
--

CREATE INDEX ix_faq_categories_study_id ON public.faq_categories USING btree (study_id);


--
-- Name: ix_faq_items_category_id; Type: INDEX; Schema: public; Owner: ctms_user
--

CREATE INDEX ix_faq_items_category_id ON public.faq_items USING btree (category_id);


--
-- Name: ix_faq_items_study_id; Type: INDEX; Schema: public; Owner: ctms_user
--

CREATE INDEX ix_faq_items_study_id ON public.faq_items USING btree (study_id);


--
-- Name: ix_finance_items_site_id; Type: INDEX; Schema: public; Owner: ctms_user
--

CREATE INDEX ix_finance_items_site_id ON public.finance_items USING btree (site_id);


--
-- Name: ix_finance_items_study_id; Type: INDEX; Schema: public; Owner: ctms_user
--

CREATE INDEX ix_finance_items_study_id ON public.finance_items USING btree (study_id);


--
-- Name: ix_finance_items_subject_id; Type: INDEX; Schema: public; Owner: ctms_user
--

CREATE INDEX ix_finance_items_subject_id ON public.finance_items USING btree (subject_id);


--
-- Name: ix_imp_batches_product_id; Type: INDEX; Schema: public; Owner: ctms_user
--

CREATE INDEX ix_imp_batches_product_id ON public.imp_batches USING btree (product_id);


--
-- Name: ix_imp_batches_study_id; Type: INDEX; Schema: public; Owner: ctms_user
--

CREATE INDEX ix_imp_batches_study_id ON public.imp_batches USING btree (study_id);


--
-- Name: ix_imp_inventory_batch_id; Type: INDEX; Schema: public; Owner: ctms_user
--

CREATE INDEX ix_imp_inventory_batch_id ON public.imp_inventory USING btree (batch_id);


--
-- Name: ix_imp_inventory_site_id; Type: INDEX; Schema: public; Owner: ctms_user
--

CREATE INDEX ix_imp_inventory_site_id ON public.imp_inventory USING btree (site_id);


--
-- Name: ix_imp_inventory_study_id; Type: INDEX; Schema: public; Owner: ctms_user
--

CREATE INDEX ix_imp_inventory_study_id ON public.imp_inventory USING btree (study_id);


--
-- Name: ix_imp_products_study_id; Type: INDEX; Schema: public; Owner: ctms_user
--

CREATE INDEX ix_imp_products_study_id ON public.imp_products USING btree (study_id);


--
-- Name: ix_imp_transactions_batch_id; Type: INDEX; Schema: public; Owner: ctms_user
--

CREATE INDEX ix_imp_transactions_batch_id ON public.imp_transactions USING btree (batch_id);


--
-- Name: ix_imp_transactions_site_id; Type: INDEX; Schema: public; Owner: ctms_user
--

CREATE INDEX ix_imp_transactions_site_id ON public.imp_transactions USING btree (site_id);


--
-- Name: ix_imp_transactions_study_id; Type: INDEX; Schema: public; Owner: ctms_user
--

CREATE INDEX ix_imp_transactions_study_id ON public.imp_transactions USING btree (study_id);


--
-- Name: ix_issues_site_id; Type: INDEX; Schema: public; Owner: ctms_user
--

CREATE INDEX ix_issues_site_id ON public.issues USING btree (site_id);


--
-- Name: ix_issues_study_id; Type: INDEX; Schema: public; Owner: ctms_user
--

CREATE INDEX ix_issues_study_id ON public.issues USING btree (study_id);


--
-- Name: ix_issues_subject_id; Type: INDEX; Schema: public; Owner: ctms_user
--

CREATE INDEX ix_issues_subject_id ON public.issues USING btree (subject_id);


--
-- Name: ix_milestones_study_id; Type: INDEX; Schema: public; Owner: ctms_user
--

CREATE INDEX ix_milestones_study_id ON public.milestones USING btree (study_id);


--
-- Name: ix_sites_study_id; Type: INDEX; Schema: public; Owner: ctms_user
--

CREATE INDEX ix_sites_study_id ON public.sites USING btree (study_id);


--
-- Name: ix_studies_code; Type: INDEX; Schema: public; Owner: ctms_user
--

CREATE UNIQUE INDEX ix_studies_code ON public.studies USING btree (code);


--
-- Name: ix_study_members_study_id; Type: INDEX; Schema: public; Owner: ctms_user
--

CREATE INDEX ix_study_members_study_id ON public.study_members USING btree (study_id);


--
-- Name: ix_subjects_site_id; Type: INDEX; Schema: public; Owner: ctms_user
--

CREATE INDEX ix_subjects_site_id ON public.subjects USING btree (site_id);


--
-- Name: ix_subjects_study_id; Type: INDEX; Schema: public; Owner: ctms_user
--

CREATE INDEX ix_subjects_study_id ON public.subjects USING btree (study_id);


--
-- Name: ix_tasks_study_id; Type: INDEX; Schema: public; Owner: ctms_user
--

CREATE INDEX ix_tasks_study_id ON public.tasks USING btree (study_id);


--
-- Name: ix_users_username; Type: INDEX; Schema: public; Owner: ctms_user
--

CREATE UNIQUE INDEX ix_users_username ON public.users USING btree (username);


--
-- Name: ix_verification_progress_site_id; Type: INDEX; Schema: public; Owner: ctms_user
--

CREATE INDEX ix_verification_progress_site_id ON public.verification_progress USING btree (site_id);


--
-- Name: ix_verification_progress_study_id; Type: INDEX; Schema: public; Owner: ctms_user
--

CREATE INDEX ix_verification_progress_study_id ON public.verification_progress USING btree (study_id);


--
-- Name: ix_verification_progress_subject_id; Type: INDEX; Schema: public; Owner: ctms_user
--

CREATE INDEX ix_verification_progress_subject_id ON public.verification_progress USING btree (subject_id);


--
-- Name: ix_visits_subject_id; Type: INDEX; Schema: public; Owner: ctms_user
--

CREATE INDEX ix_visits_subject_id ON public.visits USING btree (subject_id);


--
-- Name: adverse_events adverse_events_created_by_fkey; Type: FK CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.adverse_events
    ADD CONSTRAINT adverse_events_created_by_fkey FOREIGN KEY (created_by) REFERENCES public.users(id);


--
-- Name: adverse_events adverse_events_site_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.adverse_events
    ADD CONSTRAINT adverse_events_site_id_fkey FOREIGN KEY (site_id) REFERENCES public.sites(id);


--
-- Name: adverse_events adverse_events_study_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.adverse_events
    ADD CONSTRAINT adverse_events_study_id_fkey FOREIGN KEY (study_id) REFERENCES public.studies(id);


--
-- Name: adverse_events adverse_events_subject_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.adverse_events
    ADD CONSTRAINT adverse_events_subject_id_fkey FOREIGN KEY (subject_id) REFERENCES public.subjects(id);


--
-- Name: attachments attachments_study_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.attachments
    ADD CONSTRAINT attachments_study_id_fkey FOREIGN KEY (study_id) REFERENCES public.studies(id);


--
-- Name: attachments attachments_uploaded_by_fkey; Type: FK CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.attachments
    ADD CONSTRAINT attachments_uploaded_by_fkey FOREIGN KEY (uploaded_by) REFERENCES public.users(id);


--
-- Name: audit_logs audit_logs_operator_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.audit_logs
    ADD CONSTRAINT audit_logs_operator_id_fkey FOREIGN KEY (operator_id) REFERENCES public.users(id);


--
-- Name: audit_logs audit_logs_study_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.audit_logs
    ADD CONSTRAINT audit_logs_study_id_fkey FOREIGN KEY (study_id) REFERENCES public.studies(id);


--
-- Name: comments comments_created_by_fkey; Type: FK CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.comments
    ADD CONSTRAINT comments_created_by_fkey FOREIGN KEY (created_by) REFERENCES public.users(id);


--
-- Name: comments comments_study_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.comments
    ADD CONSTRAINT comments_study_id_fkey FOREIGN KEY (study_id) REFERENCES public.studies(id);


--
-- Name: data_queries data_queries_assigned_to_fkey; Type: FK CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.data_queries
    ADD CONSTRAINT data_queries_assigned_to_fkey FOREIGN KEY (assigned_to) REFERENCES public.users(id);


--
-- Name: data_queries data_queries_created_by_fkey; Type: FK CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.data_queries
    ADD CONSTRAINT data_queries_created_by_fkey FOREIGN KEY (created_by) REFERENCES public.users(id);


--
-- Name: data_queries data_queries_site_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.data_queries
    ADD CONSTRAINT data_queries_site_id_fkey FOREIGN KEY (site_id) REFERENCES public.sites(id);


--
-- Name: data_queries data_queries_study_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.data_queries
    ADD CONSTRAINT data_queries_study_id_fkey FOREIGN KEY (study_id) REFERENCES public.studies(id);


--
-- Name: data_queries data_queries_subject_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.data_queries
    ADD CONSTRAINT data_queries_subject_id_fkey FOREIGN KEY (subject_id) REFERENCES public.subjects(id);


--
-- Name: faq_categories faq_categories_study_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.faq_categories
    ADD CONSTRAINT faq_categories_study_id_fkey FOREIGN KEY (study_id) REFERENCES public.studies(id);


--
-- Name: faq_items faq_items_category_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.faq_items
    ADD CONSTRAINT faq_items_category_id_fkey FOREIGN KEY (category_id) REFERENCES public.faq_categories(id);


--
-- Name: faq_items faq_items_created_by_fkey; Type: FK CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.faq_items
    ADD CONSTRAINT faq_items_created_by_fkey FOREIGN KEY (created_by) REFERENCES public.users(id);


--
-- Name: faq_items faq_items_study_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.faq_items
    ADD CONSTRAINT faq_items_study_id_fkey FOREIGN KEY (study_id) REFERENCES public.studies(id);


--
-- Name: finance_items finance_items_approver_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.finance_items
    ADD CONSTRAINT finance_items_approver_id_fkey FOREIGN KEY (approver_id) REFERENCES public.users(id);


--
-- Name: finance_items finance_items_created_by_fkey; Type: FK CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.finance_items
    ADD CONSTRAINT finance_items_created_by_fkey FOREIGN KEY (created_by) REFERENCES public.users(id);


--
-- Name: finance_items finance_items_payer_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.finance_items
    ADD CONSTRAINT finance_items_payer_id_fkey FOREIGN KEY (payer_id) REFERENCES public.users(id);


--
-- Name: finance_items finance_items_site_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.finance_items
    ADD CONSTRAINT finance_items_site_id_fkey FOREIGN KEY (site_id) REFERENCES public.sites(id);


--
-- Name: finance_items finance_items_study_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.finance_items
    ADD CONSTRAINT finance_items_study_id_fkey FOREIGN KEY (study_id) REFERENCES public.studies(id);


--
-- Name: finance_items finance_items_subject_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.finance_items
    ADD CONSTRAINT finance_items_subject_id_fkey FOREIGN KEY (subject_id) REFERENCES public.subjects(id);


--
-- Name: imp_batches imp_batches_product_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.imp_batches
    ADD CONSTRAINT imp_batches_product_id_fkey FOREIGN KEY (product_id) REFERENCES public.imp_products(id);


--
-- Name: imp_batches imp_batches_study_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.imp_batches
    ADD CONSTRAINT imp_batches_study_id_fkey FOREIGN KEY (study_id) REFERENCES public.studies(id);


--
-- Name: imp_inventory imp_inventory_batch_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.imp_inventory
    ADD CONSTRAINT imp_inventory_batch_id_fkey FOREIGN KEY (batch_id) REFERENCES public.imp_batches(id);


--
-- Name: imp_inventory imp_inventory_site_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.imp_inventory
    ADD CONSTRAINT imp_inventory_site_id_fkey FOREIGN KEY (site_id) REFERENCES public.sites(id);


--
-- Name: imp_inventory imp_inventory_study_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.imp_inventory
    ADD CONSTRAINT imp_inventory_study_id_fkey FOREIGN KEY (study_id) REFERENCES public.studies(id);


--
-- Name: imp_products imp_products_study_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.imp_products
    ADD CONSTRAINT imp_products_study_id_fkey FOREIGN KEY (study_id) REFERENCES public.studies(id);


--
-- Name: imp_transactions imp_transactions_batch_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.imp_transactions
    ADD CONSTRAINT imp_transactions_batch_id_fkey FOREIGN KEY (batch_id) REFERENCES public.imp_batches(id);


--
-- Name: imp_transactions imp_transactions_created_by_fkey; Type: FK CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.imp_transactions
    ADD CONSTRAINT imp_transactions_created_by_fkey FOREIGN KEY (created_by) REFERENCES public.users(id);


--
-- Name: imp_transactions imp_transactions_site_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.imp_transactions
    ADD CONSTRAINT imp_transactions_site_id_fkey FOREIGN KEY (site_id) REFERENCES public.sites(id);


--
-- Name: imp_transactions imp_transactions_study_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.imp_transactions
    ADD CONSTRAINT imp_transactions_study_id_fkey FOREIGN KEY (study_id) REFERENCES public.studies(id);


--
-- Name: imp_transactions imp_transactions_subject_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.imp_transactions
    ADD CONSTRAINT imp_transactions_subject_id_fkey FOREIGN KEY (subject_id) REFERENCES public.subjects(id);


--
-- Name: issues issues_created_by_fkey; Type: FK CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.issues
    ADD CONSTRAINT issues_created_by_fkey FOREIGN KEY (created_by) REFERENCES public.users(id);


--
-- Name: issues issues_owner_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.issues
    ADD CONSTRAINT issues_owner_id_fkey FOREIGN KEY (owner_id) REFERENCES public.users(id);


--
-- Name: issues issues_site_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.issues
    ADD CONSTRAINT issues_site_id_fkey FOREIGN KEY (site_id) REFERENCES public.sites(id);


--
-- Name: issues issues_study_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.issues
    ADD CONSTRAINT issues_study_id_fkey FOREIGN KEY (study_id) REFERENCES public.studies(id);


--
-- Name: issues issues_subject_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.issues
    ADD CONSTRAINT issues_subject_id_fkey FOREIGN KEY (subject_id) REFERENCES public.subjects(id);


--
-- Name: milestones milestones_owner_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.milestones
    ADD CONSTRAINT milestones_owner_id_fkey FOREIGN KEY (owner_id) REFERENCES public.users(id);


--
-- Name: milestones milestones_study_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.milestones
    ADD CONSTRAINT milestones_study_id_fkey FOREIGN KEY (study_id) REFERENCES public.studies(id);


--
-- Name: sites sites_study_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.sites
    ADD CONSTRAINT sites_study_id_fkey FOREIGN KEY (study_id) REFERENCES public.studies(id);


--
-- Name: studies studies_created_by_fkey; Type: FK CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.studies
    ADD CONSTRAINT studies_created_by_fkey FOREIGN KEY (created_by) REFERENCES public.users(id);


--
-- Name: study_members study_members_study_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.study_members
    ADD CONSTRAINT study_members_study_id_fkey FOREIGN KEY (study_id) REFERENCES public.studies(id);


--
-- Name: study_members study_members_user_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.study_members
    ADD CONSTRAINT study_members_user_id_fkey FOREIGN KEY (user_id) REFERENCES public.users(id);


--
-- Name: subjects subjects_site_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.subjects
    ADD CONSTRAINT subjects_site_id_fkey FOREIGN KEY (site_id) REFERENCES public.sites(id);


--
-- Name: subjects subjects_study_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.subjects
    ADD CONSTRAINT subjects_study_id_fkey FOREIGN KEY (study_id) REFERENCES public.studies(id);


--
-- Name: tasks tasks_assignee_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.tasks
    ADD CONSTRAINT tasks_assignee_id_fkey FOREIGN KEY (assignee_id) REFERENCES public.users(id);


--
-- Name: tasks tasks_created_by_fkey; Type: FK CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.tasks
    ADD CONSTRAINT tasks_created_by_fkey FOREIGN KEY (created_by) REFERENCES public.users(id);


--
-- Name: tasks tasks_milestone_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.tasks
    ADD CONSTRAINT tasks_milestone_id_fkey FOREIGN KEY (milestone_id) REFERENCES public.milestones(id);


--
-- Name: tasks tasks_study_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.tasks
    ADD CONSTRAINT tasks_study_id_fkey FOREIGN KEY (study_id) REFERENCES public.studies(id);


--
-- Name: verification_progress verification_progress_site_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.verification_progress
    ADD CONSTRAINT verification_progress_site_id_fkey FOREIGN KEY (site_id) REFERENCES public.sites(id);


--
-- Name: verification_progress verification_progress_study_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.verification_progress
    ADD CONSTRAINT verification_progress_study_id_fkey FOREIGN KEY (study_id) REFERENCES public.studies(id);


--
-- Name: verification_progress verification_progress_subject_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.verification_progress
    ADD CONSTRAINT verification_progress_subject_id_fkey FOREIGN KEY (subject_id) REFERENCES public.subjects(id);


--
-- Name: verification_progress verification_progress_verifier_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.verification_progress
    ADD CONSTRAINT verification_progress_verifier_id_fkey FOREIGN KEY (verifier_id) REFERENCES public.users(id);


--
-- Name: visits visits_study_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.visits
    ADD CONSTRAINT visits_study_id_fkey FOREIGN KEY (study_id) REFERENCES public.studies(id);


--
-- Name: visits visits_subject_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: ctms_user
--

ALTER TABLE ONLY public.visits
    ADD CONSTRAINT visits_subject_id_fkey FOREIGN KEY (subject_id) REFERENCES public.subjects(id);


--
-- PostgreSQL database dump complete
--

\unrestrict NRX91yBJCm445olT8iSjLqcIZtZiNWfMWQkgNOCa1Jc3ckwdYcbEMalzD8ITVN9

