--
-- PostgreSQL database dump
--

\restrict c7tibngenZ3JJspWyr31r6mzMatTJpD95OAdikTmKQcJiOj35naiZ8VfDYXrpQI

-- Dumped from database version 18.0
-- Dumped by pg_dump version 18.4

-- Started on 2026-06-25 13:56:39 MSK

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

--
-- TOC entry 43 (class 2615 OID 442848)
-- Name: ryzhov_ka; Type: SCHEMA; Schema: -; Owner: ryzhov_ka
--

CREATE SCHEMA ryzhov_ka;


ALTER SCHEMA ryzhov_ka OWNER TO ryzhov_ka;

--
-- TOC entry 3306 (class 1247 OID 451376)
-- Name: app_role; Type: TYPE; Schema: ryzhov_ka; Owner: ryzhov_ka
--

CREATE TYPE ryzhov_ka.app_role AS ENUM (
    'admin',
    'user'
);


ALTER TYPE ryzhov_ka.app_role OWNER TO ryzhov_ka;

--
-- TOC entry 2885 (class 1247 OID 443137)
-- Name: chn; Type: DOMAIN; Schema: ryzhov_ka; Owner: ryzhov_ka
--

CREATE DOMAIN ryzhov_ka.chn AS character varying NOT NULL;


ALTER DOMAIN ryzhov_ka.chn OWNER TO ryzhov_ka;

--
-- TOC entry 1947 (class 1255 OID 454490)
-- Name: fn_audit_log_changes(); Type: FUNCTION; Schema: ryzhov_ka; Owner: ryzhov_ka
--

CREATE FUNCTION ryzhov_ka.fn_audit_log_changes() RETURNS trigger
    LANGUAGE plpgsql
    AS $$
declare
    v_record_id text;
begin
    if tg_op = 'INSERT' then
        v_record_id := coalesce(
            to_jsonb(new)->>'warehouse_id',
            to_jsonb(new)->>'employee_id',
            to_jsonb(new)->>'employee_warehouse_id',
            to_jsonb(new)->>'customer_id',
            to_jsonb(new)->>'user_id',
            to_jsonb(new)->>'product_id',
            to_jsonb(new)->>'inventory_id',
            to_jsonb(new)->>'order_id',
            to_jsonb(new)->>'order_item_id'
        );

        insert into ryzhov_ka.audit_log(table_name, operation, record_id, new_data)
        values (tg_table_name, tg_op, v_record_id, to_jsonb(new));

        return new;
    elsif tg_op = 'UPDATE' then
        v_record_id := coalesce(
            to_jsonb(new)->>'warehouse_id',
            to_jsonb(new)->>'employee_id',
            to_jsonb(new)->>'employee_warehouse_id',
            to_jsonb(new)->>'customer_id',
            to_jsonb(new)->>'user_id',
            to_jsonb(new)->>'product_id',
            to_jsonb(new)->>'inventory_id',
            to_jsonb(new)->>'order_id',
            to_jsonb(new)->>'order_item_id'
        );

        insert into ryzhov_ka.audit_log(table_name, operation, record_id, old_data, new_data)
        values (tg_table_name, tg_op, v_record_id, to_jsonb(old), to_jsonb(new));

        return new;
    elsif tg_op = 'DELETE' then
        v_record_id := coalesce(
            to_jsonb(old)->>'warehouse_id',
            to_jsonb(old)->>'employee_id',
            to_jsonb(old)->>'employee_warehouse_id',
            to_jsonb(old)->>'customer_id',
            to_jsonb(old)->>'user_id',
            to_jsonb(old)->>'product_id',
            to_jsonb(old)->>'inventory_id',
            to_jsonb(old)->>'order_id',
            to_jsonb(old)->>'order_item_id'
        );

        insert into ryzhov_ka.audit_log(table_name, operation, record_id, old_data)
        values (tg_table_name, tg_op, v_record_id, to_jsonb(old));

        return old;
    end if;

    return null;
end;
$$;


ALTER FUNCTION ryzhov_ka.fn_audit_log_changes() OWNER TO ryzhov_ka;

--
-- TOC entry 1946 (class 1255 OID 454465)
-- Name: fn_authenticate_user(character varying, text); Type: FUNCTION; Schema: ryzhov_ka; Owner: ryzhov_ka
--

CREATE FUNCTION ryzhov_ka.fn_authenticate_user(p_login character varying, p_password text) RETURNS TABLE(user_id integer, login character varying, role ryzhov_ka.app_role, employee_id integer, customer_id integer)
    LANGUAGE sql STABLE
    AS $$
    select
        au.user_id,
        au.login,
        au.role,
        au.employee_id,
        au.customer_id
    from ryzhov_ka.app_users au
    where au.login = p_login
      and au.is_active = true
      and au.password_hash = public.crypt(p_password, au.password_hash);
$$;


ALTER FUNCTION ryzhov_ka.fn_authenticate_user(p_login character varying, p_password text) OWNER TO ryzhov_ka;

--
-- TOC entry 2005 (class 1255 OID 471485)
-- Name: fn_order_items_inventory(); Type: FUNCTION; Schema: ryzhov_ka; Owner: ryzhov_ka
--

CREATE FUNCTION ryzhov_ka.fn_order_items_inventory() RETURNS trigger
    LANGUAGE plpgsql
    AS $$
DECLARE
    v_warehouse_id integer;
    v_available integer;
BEGIN
    IF TG_OP = 'INSERT' THEN
        SELECT warehouse_id
        INTO v_warehouse_id
        FROM ryzhov_ka.orders
        WHERE order_id = NEW.order_id;

        SELECT quantity
        INTO v_available
        FROM ryzhov_ka.inventory
        WHERE warehouse_id = v_warehouse_id
          AND product_id = NEW.product_id
        FOR UPDATE;

        IF v_available IS NULL OR v_available < NEW.quantity THEN
            RETURN NULL;
        END IF;

        UPDATE ryzhov_ka.inventory
        SET quantity = quantity - NEW.quantity
        WHERE warehouse_id = v_warehouse_id
          AND product_id = NEW.product_id;

        RETURN NEW;
    END IF;

    IF TG_OP = 'DELETE' THEN
        SELECT warehouse_id
        INTO v_warehouse_id
        FROM ryzhov_ka.orders
        WHERE order_id = OLD.order_id;

        UPDATE ryzhov_ka.inventory
        SET quantity = quantity + OLD.quantity
        WHERE warehouse_id = v_warehouse_id
          AND product_id = OLD.product_id;

        RETURN OLD;
    END IF;

    IF TG_OP = 'UPDATE' THEN
        SELECT warehouse_id
        INTO v_warehouse_id
        FROM ryzhov_ka.orders
        WHERE order_id = OLD.order_id;

        UPDATE ryzhov_ka.inventory
        SET quantity = quantity + OLD.quantity
        WHERE warehouse_id = v_warehouse_id
          AND product_id = OLD.product_id;

        SELECT warehouse_id
        INTO v_warehouse_id
        FROM ryzhov_ka.orders
        WHERE order_id = NEW.order_id;

        SELECT quantity
        INTO v_available
        FROM ryzhov_ka.inventory
        WHERE warehouse_id = v_warehouse_id
          AND product_id = NEW.product_id
        FOR UPDATE;

        IF v_available IS NULL OR v_available < NEW.quantity THEN
            UPDATE ryzhov_ka.inventory
            SET quantity = quantity - OLD.quantity
            WHERE warehouse_id = (
                SELECT warehouse_id
                FROM ryzhov_ka.orders
                WHERE order_id = OLD.order_id
            )
              AND product_id = OLD.product_id;

            RETURN NULL;
        END IF;

        UPDATE ryzhov_ka.inventory
        SET quantity = quantity - NEW.quantity
        WHERE warehouse_id = v_warehouse_id
          AND product_id = NEW.product_id;

        RETURN NEW;
    END IF;

    RETURN NULL;
END;
$$;


ALTER FUNCTION ryzhov_ka.fn_order_items_inventory() OWNER TO ryzhov_ka;

SET default_tablespace = '';

SET default_table_access_method = heap;

--
-- TOC entry 769 (class 1259 OID 451382)
-- Name: app_users; Type: TABLE; Schema: ryzhov_ka; Owner: ryzhov_ka
--

CREATE TABLE ryzhov_ka.app_users (
    user_id integer NOT NULL,
    login character varying(80) NOT NULL,
    password_hash text NOT NULL,
    role ryzhov_ka.app_role NOT NULL,
    is_active boolean DEFAULT true NOT NULL,
    employee_id integer,
    customer_id integer,
    CONSTRAINT chk_app_users_role_link CHECK ((((role = 'admin'::ryzhov_ka.app_role) AND (employee_id IS NOT NULL) AND (customer_id IS NULL)) OR ((role = 'user'::ryzhov_ka.app_role) AND (employee_id IS NULL) AND (customer_id IS NOT NULL))))
);


ALTER TABLE ryzhov_ka.app_users OWNER TO ryzhov_ka;

--
-- TOC entry 768 (class 1259 OID 451381)
-- Name: app_users_user_id_seq; Type: SEQUENCE; Schema: ryzhov_ka; Owner: ryzhov_ka
--

ALTER TABLE ryzhov_ka.app_users ALTER COLUMN user_id ADD GENERATED BY DEFAULT AS IDENTITY (
    SEQUENCE NAME ryzhov_ka.app_users_user_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1
);


--
-- TOC entry 936 (class 1259 OID 454472)
-- Name: audit_log; Type: TABLE; Schema: ryzhov_ka; Owner: ryzhov_ka
--

CREATE TABLE ryzhov_ka.audit_log (
    audit_id integer NOT NULL,
    table_name character varying(80) NOT NULL,
    operation character varying(10) NOT NULL,
    record_id text,
    changed_at timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
    db_user text DEFAULT CURRENT_USER NOT NULL,
    old_data jsonb,
    new_data jsonb
);


ALTER TABLE ryzhov_ka.audit_log OWNER TO ryzhov_ka;

--
-- TOC entry 935 (class 1259 OID 454471)
-- Name: audit_log_audit_id_seq; Type: SEQUENCE; Schema: ryzhov_ka; Owner: ryzhov_ka
--

ALTER TABLE ryzhov_ka.audit_log ALTER COLUMN audit_id ADD GENERATED BY DEFAULT AS IDENTITY (
    SEQUENCE NAME ryzhov_ka.audit_log_audit_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1
);


--
-- TOC entry 773 (class 1259 OID 451437)
-- Name: customers; Type: TABLE; Schema: ryzhov_ka; Owner: ryzhov_ka
--

CREATE TABLE ryzhov_ka.customers (
    customer_id integer NOT NULL,
    last_name character varying(80) NOT NULL,
    first_name character varying(80) NOT NULL,
    middle_name character varying(80),
    address text,
    phone character varying(20)
);


ALTER TABLE ryzhov_ka.customers OWNER TO ryzhov_ka;

--
-- TOC entry 772 (class 1259 OID 451436)
-- Name: customers_customer_id_seq; Type: SEQUENCE; Schema: ryzhov_ka; Owner: ryzhov_ka
--

ALTER TABLE ryzhov_ka.customers ALTER COLUMN customer_id ADD GENERATED BY DEFAULT AS IDENTITY (
    SEQUENCE NAME ryzhov_ka.customers_customer_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1
);


--
-- TOC entry 771 (class 1259 OID 451413)
-- Name: employee_warehouses; Type: TABLE; Schema: ryzhov_ka; Owner: ryzhov_ka
--

CREATE TABLE ryzhov_ka.employee_warehouses (
    employee_warehouse_id integer NOT NULL,
    employee_id integer NOT NULL,
    warehouse_id integer NOT NULL,
    start_date date NOT NULL
);


ALTER TABLE ryzhov_ka.employee_warehouses OWNER TO ryzhov_ka;

--
-- TOC entry 770 (class 1259 OID 451412)
-- Name: employee_warehouses_employee_warehouse_id_seq; Type: SEQUENCE; Schema: ryzhov_ka; Owner: ryzhov_ka
--

ALTER TABLE ryzhov_ka.employee_warehouses ALTER COLUMN employee_warehouse_id ADD GENERATED BY DEFAULT AS IDENTITY (
    SEQUENCE NAME ryzhov_ka.employee_warehouses_employee_warehouse_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1
);


--
-- TOC entry 767 (class 1259 OID 451364)
-- Name: employees; Type: TABLE; Schema: ryzhov_ka; Owner: ryzhov_ka
--

CREATE TABLE ryzhov_ka.employees (
    employee_id integer NOT NULL,
    last_name character varying(80) NOT NULL,
    first_name character varying(80) NOT NULL,
    middle_name character varying(80),
    position_name character varying(100) NOT NULL,
    birth_date date NOT NULL,
    CONSTRAINT chk_employees_birth_date_not_future CHECK ((birth_date <= CURRENT_DATE))
);


ALTER TABLE ryzhov_ka.employees OWNER TO ryzhov_ka;

--
-- TOC entry 766 (class 1259 OID 451363)
-- Name: employees_employee_id_seq; Type: SEQUENCE; Schema: ryzhov_ka; Owner: ryzhov_ka
--

ALTER TABLE ryzhov_ka.employees ALTER COLUMN employee_id ADD GENERATED BY DEFAULT AS IDENTITY (
    SEQUENCE NAME ryzhov_ka.employees_employee_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1
);


--
-- TOC entry 777 (class 1259 OID 451461)
-- Name: inventory; Type: TABLE; Schema: ryzhov_ka; Owner: ryzhov_ka
--

CREATE TABLE ryzhov_ka.inventory (
    inventory_id integer NOT NULL,
    warehouse_id integer NOT NULL,
    product_id integer NOT NULL,
    quantity integer NOT NULL,
    CONSTRAINT chk_inventory_quantity_non_negative CHECK ((quantity >= 0))
);


ALTER TABLE ryzhov_ka.inventory OWNER TO ryzhov_ka;

--
-- TOC entry 776 (class 1259 OID 451460)
-- Name: inventory_inventory_id_seq; Type: SEQUENCE; Schema: ryzhov_ka; Owner: ryzhov_ka
--

ALTER TABLE ryzhov_ka.inventory ALTER COLUMN inventory_id ADD GENERATED BY DEFAULT AS IDENTITY (
    SEQUENCE NAME ryzhov_ka.inventory_inventory_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1
);


--
-- TOC entry 781 (class 1259 OID 451517)
-- Name: order_items; Type: TABLE; Schema: ryzhov_ka; Owner: ryzhov_ka
--

CREATE TABLE ryzhov_ka.order_items (
    order_item_id integer NOT NULL,
    order_id integer NOT NULL,
    product_id integer NOT NULL,
    quantity integer NOT NULL,
    unit_price numeric(12,2) NOT NULL,
    CONSTRAINT chk_order_items_quantity_positive CHECK ((quantity > 0)),
    CONSTRAINT chk_order_items_unit_price_non_negative CHECK ((unit_price >= (0)::numeric))
);


ALTER TABLE ryzhov_ka.order_items OWNER TO ryzhov_ka;

--
-- TOC entry 780 (class 1259 OID 451516)
-- Name: order_items_order_item_id_seq; Type: SEQUENCE; Schema: ryzhov_ka; Owner: ryzhov_ka
--

ALTER TABLE ryzhov_ka.order_items ALTER COLUMN order_item_id ADD GENERATED BY DEFAULT AS IDENTITY (
    SEQUENCE NAME ryzhov_ka.order_items_order_item_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1
);


--
-- TOC entry 779 (class 1259 OID 451486)
-- Name: orders; Type: TABLE; Schema: ryzhov_ka; Owner: ryzhov_ka
--

CREATE TABLE ryzhov_ka.orders (
    order_id integer NOT NULL,
    customer_id integer NOT NULL,
    employee_id integer NOT NULL,
    order_date date NOT NULL,
    status character varying(30) NOT NULL,
    warehouse_id integer NOT NULL,
    CONSTRAINT chk_orders_status CHECK (((status)::text = ANY ((ARRAY['создан'::character varying, 'в работе'::character varying, 'выполнен'::character varying, 'отменён'::character varying])::text[])))
);


ALTER TABLE ryzhov_ka.orders OWNER TO ryzhov_ka;

--
-- TOC entry 778 (class 1259 OID 451485)
-- Name: orders_order_id_seq; Type: SEQUENCE; Schema: ryzhov_ka; Owner: ryzhov_ka
--

ALTER TABLE ryzhov_ka.orders ALTER COLUMN order_id ADD GENERATED BY DEFAULT AS IDENTITY (
    SEQUENCE NAME ryzhov_ka.orders_order_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1
);


--
-- TOC entry 775 (class 1259 OID 451448)
-- Name: products; Type: TABLE; Schema: ryzhov_ka; Owner: ryzhov_ka
--

CREATE TABLE ryzhov_ka.products (
    product_id integer NOT NULL,
    product_name character varying(150) NOT NULL,
    manufacturer character varying(120) NOT NULL,
    characteristics text,
    price numeric(12,2) NOT NULL,
    CONSTRAINT chk_products_price_non_negative CHECK ((price >= (0)::numeric))
);


ALTER TABLE ryzhov_ka.products OWNER TO ryzhov_ka;

--
-- TOC entry 774 (class 1259 OID 451447)
-- Name: products_product_id_seq; Type: SEQUENCE; Schema: ryzhov_ka; Owner: ryzhov_ka
--

ALTER TABLE ryzhov_ka.products ALTER COLUMN product_id ADD GENERATED BY DEFAULT AS IDENTITY (
    SEQUENCE NAME ryzhov_ka.products_product_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1
);


--
-- TOC entry 939 (class 1259 OID 454526)
-- Name: v_customer_order_items; Type: VIEW; Schema: ryzhov_ka; Owner: ryzhov_ka
--

CREATE VIEW ryzhov_ka.v_customer_order_items AS
 SELECT o.order_id,
    o.order_date,
    c.customer_id,
    concat_ws(' '::text, c.last_name, c.first_name, c.middle_name) AS customer_full_name,
    e.employee_id,
    concat_ws(' '::text, e.last_name, e.first_name, e.middle_name) AS employee_full_name,
    p.product_id,
    p.product_name,
    p.manufacturer,
    oi.quantity,
    oi.unit_price,
    (((oi.quantity)::numeric * oi.unit_price))::numeric(12,2) AS item_total,
    o.status
   FROM ((((ryzhov_ka.orders o
     JOIN ryzhov_ka.customers c ON ((c.customer_id = o.customer_id)))
     JOIN ryzhov_ka.employees e ON ((e.employee_id = o.employee_id)))
     JOIN ryzhov_ka.order_items oi ON ((oi.order_id = o.order_id)))
     JOIN ryzhov_ka.products p ON ((p.product_id = oi.product_id)));


ALTER VIEW ryzhov_ka.v_customer_order_items OWNER TO ryzhov_ka;

--
-- TOC entry 940 (class 1259 OID 454531)
-- Name: v_orders_with_total; Type: VIEW; Schema: ryzhov_ka; Owner: ryzhov_ka
--

CREATE VIEW ryzhov_ka.v_orders_with_total AS
 SELECT o.order_id,
    o.customer_id,
    concat_ws(' '::text, c.last_name, c.first_name, c.middle_name) AS customer_name,
    o.employee_id,
    concat_ws(' '::text, e.last_name, e.first_name, e.middle_name) AS employee_name,
    o.order_date,
    o.status,
    (COALESCE(sum(((oi.quantity)::numeric * oi.unit_price)), (0)::numeric))::numeric(12,2) AS order_total
   FROM (((ryzhov_ka.orders o
     JOIN ryzhov_ka.customers c ON ((c.customer_id = o.customer_id)))
     JOIN ryzhov_ka.employees e ON ((e.employee_id = o.employee_id)))
     LEFT JOIN ryzhov_ka.order_items oi ON ((oi.order_id = o.order_id)))
  GROUP BY o.order_id, o.customer_id, c.last_name, c.first_name, c.middle_name, o.employee_id, e.last_name, e.first_name, e.middle_name, o.order_date, o.status;


ALTER VIEW ryzhov_ka.v_orders_with_total OWNER TO ryzhov_ka;

--
-- TOC entry 765 (class 1259 OID 451345)
-- Name: warehouses; Type: TABLE; Schema: ryzhov_ka; Owner: ryzhov_ka
--

CREATE TABLE ryzhov_ka.warehouses (
    warehouse_id integer NOT NULL,
    warehouse_number character varying(30) NOT NULL,
    address text NOT NULL,
    capacity integer NOT NULL,
    CONSTRAINT chk_warehouses_capacity_non_negative CHECK ((capacity >= 0))
);


ALTER TABLE ryzhov_ka.warehouses OWNER TO ryzhov_ka;

--
-- TOC entry 764 (class 1259 OID 451344)
-- Name: warehouses_warehouse_id_seq; Type: SEQUENCE; Schema: ryzhov_ka; Owner: ryzhov_ka
--

ALTER TABLE ryzhov_ka.warehouses ALTER COLUMN warehouse_id ADD GENERATED BY DEFAULT AS IDENTITY (
    SEQUENCE NAME ryzhov_ka.warehouses_warehouse_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1
);


--
-- TOC entry 6636 (class 0 OID 451382)
-- Dependencies: 769
-- Data for Name: app_users; Type: TABLE DATA; Schema: ryzhov_ka; Owner: ryzhov_ka
--

COPY ryzhov_ka.app_users (user_id, login, password_hash, role, is_active, employee_id, customer_id) FROM stdin;
1	admin	$2a$06$GJWf9W61pP4nRNQDEUgjKu3cEvJvTR0dVsgcsxmbWVqy312Pt1pja	admin	t	1	\N
2	user	$2a$06$mj/zywYxgQrlFM5u5DBalOFkGmexjRUuc8P/SLXAFTR9M81C.RfUC	user	t	\N	2
\.


--
-- TOC entry 6650 (class 0 OID 454472)
-- Dependencies: 936
-- Data for Name: audit_log; Type: TABLE DATA; Schema: ryzhov_ka; Owner: ryzhov_ka
--

COPY ryzhov_ka.audit_log (audit_id, table_name, operation, record_id, changed_at, db_user, old_data, new_data) FROM stdin;
1	inventory	UPDATE	2	2026-06-02 16:24:23.499611	ryzhov_ka	{"quantity": 20, "product_id": 2, "inventory_id": 2, "warehouse_id": 2}	{"quantity": 20, "product_id": 2, "inventory_id": 2, "warehouse_id": 2}
2	order_items	INSERT	3	2026-06-02 16:24:55.049328	ryzhov_ka	\N	{"order_id": 4, "quantity": 1000, "product_id": 3, "unit_price": 1500.00, "order_item_id": 6}
3	order_items	DELETE	3	2026-06-02 16:25:32.911017	ryzhov_ka	{"order_id": 4, "quantity": 1000, "product_id": 3, "unit_price": 1500.00, "order_item_id": 6}	\N
4	warehouses	UPDATE	2	2026-06-02 16:37:15.758221	ryzhov_ka	{"address": "ул. Примерная, 2", "capacity": 20, "warehouse_id": 2, "warehouse_number": "N-002"}	{"address": "ул. Примерная, 2", "capacity": 50, "warehouse_id": 2, "warehouse_number": "N-002"}
5	orders	UPDATE	1	2026-06-21 16:29:05.998556	ryzhov_ka	{"status": "создан", "order_id": 3, "order_date": "2026-04-09", "customer_id": 2, "employee_id": 3, "warehouse_id": null}	{"status": "создан", "order_id": 3, "order_date": "2026-04-09", "customer_id": 2, "employee_id": 3, "warehouse_id": 1}
6	orders	UPDATE	1	2026-06-21 16:29:05.998556	ryzhov_ka	{"status": "в работе", "order_id": 4, "order_date": "2026-06-01", "customer_id": 3, "employee_id": 1, "warehouse_id": null}	{"status": "в работе", "order_id": 4, "order_date": "2026-06-01", "customer_id": 3, "employee_id": 1, "warehouse_id": 1}
7	orders	UPDATE	1	2026-06-21 16:29:05.998556	ryzhov_ka	{"status": "выполнен", "order_id": 1, "order_date": "2026-06-01", "customer_id": 1, "employee_id": 2, "warehouse_id": null}	{"status": "выполнен", "order_id": 1, "order_date": "2026-06-01", "customer_id": 1, "employee_id": 2, "warehouse_id": 1}
8	orders	UPDATE	1	2026-06-21 16:29:05.998556	ryzhov_ka	{"status": "отменён", "order_id": 2, "order_date": "2026-06-01", "customer_id": 2, "employee_id": 3, "warehouse_id": null}	{"status": "отменён", "order_id": 2, "order_date": "2026-06-01", "customer_id": 2, "employee_id": 3, "warehouse_id": 1}
9	inventory	UPDATE	1	2026-06-21 16:38:46.802904	ryzhov_ka	{"quantity": 10, "product_id": 1, "inventory_id": 1, "warehouse_id": 1}	{"quantity": 8, "product_id": 1, "inventory_id": 1, "warehouse_id": 1}
10	order_items	INSERT	1	2026-06-21 16:38:46.802904	ryzhov_ka	\N	{"order_id": 1, "quantity": 2, "product_id": 1, "unit_price": 1000.00, "order_item_id": 7}
11	orders	INSERT	2	2026-06-25 11:11:45.058147	ryzhov_ka	\N	{"status": "создан", "order_id": 5, "order_date": "2026-06-25", "customer_id": 1, "employee_id": 2, "warehouse_id": 2}
12	inventory	UPDATE	2	2026-06-25 11:25:10.592528	ryzhov_ka	{"quantity": 20, "product_id": 2, "inventory_id": 2, "warehouse_id": 2}	{"quantity": 13, "product_id": 2, "inventory_id": 2, "warehouse_id": 2}
13	order_items	INSERT	2	2026-06-25 11:25:10.592528	ryzhov_ka	\N	{"order_id": 5, "quantity": 7, "product_id": 2, "unit_price": 2500.00, "order_item_id": 8}
14	inventory	UPDATE	2	2026-06-25 11:25:20.314436	ryzhov_ka	{"quantity": 13, "product_id": 2, "inventory_id": 2, "warehouse_id": 2}	{"quantity": 20, "product_id": 2, "inventory_id": 2, "warehouse_id": 2}
15	inventory	UPDATE	2	2026-06-25 11:25:20.314436	ryzhov_ka	{"quantity": 20, "product_id": 2, "inventory_id": 2, "warehouse_id": 2}	{"quantity": 13, "product_id": 2, "inventory_id": 2, "warehouse_id": 2}
16	order_items	UPDATE	2	2026-06-25 11:25:20.314436	ryzhov_ka	{"order_id": 5, "quantity": 7, "product_id": 2, "unit_price": 2500.00, "order_item_id": 8}	{"order_id": 5, "quantity": 7, "product_id": 2, "unit_price": 2501.00, "order_item_id": 8}
17	inventory	UPDATE	2	2026-06-25 11:31:08.033551	ryzhov_ka	{"quantity": 13, "product_id": 2, "inventory_id": 2, "warehouse_id": 2}	{"quantity": 20, "product_id": 2, "inventory_id": 2, "warehouse_id": 2}
18	inventory	UPDATE	2	2026-06-25 11:31:08.033551	ryzhov_ka	{"quantity": 20, "product_id": 2, "inventory_id": 2, "warehouse_id": 2}	{"quantity": 10, "product_id": 2, "inventory_id": 2, "warehouse_id": 2}
19	order_items	UPDATE	2	2026-06-25 11:31:08.033551	ryzhov_ka	{"order_id": 5, "quantity": 7, "product_id": 2, "unit_price": 2501.00, "order_item_id": 8}	{"order_id": 5, "quantity": 10, "product_id": 2, "unit_price": 2500.00, "order_item_id": 8}
20	inventory	UPDATE	2	2026-06-25 12:12:40.361203	ryzhov_ka	{"quantity": 10, "product_id": 2, "inventory_id": 2, "warehouse_id": 2}	{"quantity": 50, "product_id": 2, "inventory_id": 2, "warehouse_id": 2}
\.


--
-- TOC entry 6640 (class 0 OID 451437)
-- Dependencies: 773
-- Data for Name: customers; Type: TABLE DATA; Schema: ryzhov_ka; Owner: ryzhov_ka
--

COPY ryzhov_ka.customers (customer_id, last_name, first_name, middle_name, address, phone) FROM stdin;
1	Кузнецов	Алексей	Дмитриевич	ул. Северная, 10	+7 900 100-10-10
2	Орлова	Мария	Сергеевна	ул. Центральная, 25	+7 900 200-20-20
3	Морозов	Денис	Павлович	ул. Южная, 7	+7 900 300-30-30
\.


--
-- TOC entry 6638 (class 0 OID 451413)
-- Dependencies: 771
-- Data for Name: employee_warehouses; Type: TABLE DATA; Schema: ryzhov_ka; Owner: ryzhov_ka
--

COPY ryzhov_ka.employee_warehouses (employee_warehouse_id, employee_id, warehouse_id, start_date) FROM stdin;
1	1	1	2026-05-20
2	2	2	2026-05-21
3	3	3	2026-05-22
\.


--
-- TOC entry 6634 (class 0 OID 451364)
-- Dependencies: 767
-- Data for Name: employees; Type: TABLE DATA; Schema: ryzhov_ka; Owner: ryzhov_ka
--

COPY ryzhov_ka.employees (employee_id, last_name, first_name, middle_name, position_name, birth_date) FROM stdin;
1	Петров	Илья	Андреевич	менеджер	1995-05-20
2	Иванов	Сергей	Петрович	продавец	1998-05-21
3	Смирнова	Анна	Олеговна	кладовщик	1992-05-22
\.


--
-- TOC entry 6644 (class 0 OID 451461)
-- Dependencies: 777
-- Data for Name: inventory; Type: TABLE DATA; Schema: ryzhov_ka; Owner: ryzhov_ka
--

COPY ryzhov_ka.inventory (inventory_id, warehouse_id, product_id, quantity) FROM stdin;
3	3	3	30
1	1	1	8
2	2	2	50
\.


--
-- TOC entry 6648 (class 0 OID 451517)
-- Dependencies: 781
-- Data for Name: order_items; Type: TABLE DATA; Schema: ryzhov_ka; Owner: ryzhov_ka
--

COPY ryzhov_ka.order_items (order_item_id, order_id, product_id, quantity, unit_price) FROM stdin;
3	1	2	19	300.00
2	3	1	1	200.00
1	4	3	3	500.00
5	2	2	3	500.00
4	3	1	4	300.00
7	1	1	2	1000.00
8	5	2	10	2500.00
\.


--
-- TOC entry 6646 (class 0 OID 451486)
-- Dependencies: 779
-- Data for Name: orders; Type: TABLE DATA; Schema: ryzhov_ka; Owner: ryzhov_ka
--

COPY ryzhov_ka.orders (order_id, customer_id, employee_id, order_date, status, warehouse_id) FROM stdin;
3	2	3	2026-04-09	создан	1
4	3	1	2026-06-01	в работе	1
1	1	2	2026-06-01	выполнен	1
2	2	3	2026-06-01	отменён	1
5	1	2	2026-06-25	создан	2
\.


--
-- TOC entry 6642 (class 0 OID 451448)
-- Dependencies: 775
-- Data for Name: products; Type: TABLE DATA; Schema: ryzhov_ka; Owner: ryzhov_ka
--

COPY ryzhov_ka.products (product_id, product_name, manufacturer, characteristics, price) FROM stdin;
1	Ноутбук Lenovo	manufacturer_1	Описание 1	1000.00
2	Монитор Samsung	manufacturer_2	Описание 2	2500.00
3	Клавиатура Logitech	manufacturer_3	Описание 3	5000.00
\.


--
-- TOC entry 6632 (class 0 OID 451345)
-- Dependencies: 765
-- Data for Name: warehouses; Type: TABLE DATA; Schema: ryzhov_ka; Owner: ryzhov_ka
--

COPY ryzhov_ka.warehouses (warehouse_id, warehouse_number, address, capacity) FROM stdin;
1	N-001	ул. Примерная, 1	10
3	N-003	ул. Примерная, 3	30
2	N-002	ул. Примерная, 2	50
\.


--
-- TOC entry 6656 (class 0 OID 0)
-- Dependencies: 768
-- Name: app_users_user_id_seq; Type: SEQUENCE SET; Schema: ryzhov_ka; Owner: ryzhov_ka
--

SELECT pg_catalog.setval('ryzhov_ka.app_users_user_id_seq', 1, false);


--
-- TOC entry 6657 (class 0 OID 0)
-- Dependencies: 935
-- Name: audit_log_audit_id_seq; Type: SEQUENCE SET; Schema: ryzhov_ka; Owner: ryzhov_ka
--

SELECT pg_catalog.setval('ryzhov_ka.audit_log_audit_id_seq', 20, true);


--
-- TOC entry 6658 (class 0 OID 0)
-- Dependencies: 772
-- Name: customers_customer_id_seq; Type: SEQUENCE SET; Schema: ryzhov_ka; Owner: ryzhov_ka
--

SELECT pg_catalog.setval('ryzhov_ka.customers_customer_id_seq', 1, false);


--
-- TOC entry 6659 (class 0 OID 0)
-- Dependencies: 770
-- Name: employee_warehouses_employee_warehouse_id_seq; Type: SEQUENCE SET; Schema: ryzhov_ka; Owner: ryzhov_ka
--

SELECT pg_catalog.setval('ryzhov_ka.employee_warehouses_employee_warehouse_id_seq', 1, false);


--
-- TOC entry 6660 (class 0 OID 0)
-- Dependencies: 766
-- Name: employees_employee_id_seq; Type: SEQUENCE SET; Schema: ryzhov_ka; Owner: ryzhov_ka
--

SELECT pg_catalog.setval('ryzhov_ka.employees_employee_id_seq', 1, false);


--
-- TOC entry 6661 (class 0 OID 0)
-- Dependencies: 776
-- Name: inventory_inventory_id_seq; Type: SEQUENCE SET; Schema: ryzhov_ka; Owner: ryzhov_ka
--

SELECT pg_catalog.setval('ryzhov_ka.inventory_inventory_id_seq', 1, false);


--
-- TOC entry 6662 (class 0 OID 0)
-- Dependencies: 780
-- Name: order_items_order_item_id_seq; Type: SEQUENCE SET; Schema: ryzhov_ka; Owner: ryzhov_ka
--

SELECT pg_catalog.setval('ryzhov_ka.order_items_order_item_id_seq', 8, true);


--
-- TOC entry 6663 (class 0 OID 0)
-- Dependencies: 778
-- Name: orders_order_id_seq; Type: SEQUENCE SET; Schema: ryzhov_ka; Owner: ryzhov_ka
--

SELECT pg_catalog.setval('ryzhov_ka.orders_order_id_seq', 5, true);


--
-- TOC entry 6664 (class 0 OID 0)
-- Dependencies: 774
-- Name: products_product_id_seq; Type: SEQUENCE SET; Schema: ryzhov_ka; Owner: ryzhov_ka
--

SELECT pg_catalog.setval('ryzhov_ka.products_product_id_seq', 1, false);


--
-- TOC entry 6665 (class 0 OID 0)
-- Dependencies: 764
-- Name: warehouses_warehouse_id_seq; Type: SEQUENCE SET; Schema: ryzhov_ka; Owner: ryzhov_ka
--

SELECT pg_catalog.setval('ryzhov_ka.warehouses_warehouse_id_seq', 1, false);


--
-- TOC entry 6341 (class 2606 OID 451398)
-- Name: app_users app_users_employee_id_key; Type: CONSTRAINT; Schema: ryzhov_ka; Owner: ryzhov_ka
--

ALTER TABLE ONLY ryzhov_ka.app_users
    ADD CONSTRAINT app_users_employee_id_key UNIQUE (employee_id);


--
-- TOC entry 6343 (class 2606 OID 451396)
-- Name: app_users app_users_login_key; Type: CONSTRAINT; Schema: ryzhov_ka; Owner: ryzhov_ka
--

ALTER TABLE ONLY ryzhov_ka.app_users
    ADD CONSTRAINT app_users_login_key UNIQUE (login);


--
-- TOC entry 6345 (class 2606 OID 451394)
-- Name: app_users app_users_pkey; Type: CONSTRAINT; Schema: ryzhov_ka; Owner: ryzhov_ka
--

ALTER TABLE ONLY ryzhov_ka.app_users
    ADD CONSTRAINT app_users_pkey PRIMARY KEY (user_id);


--
-- TOC entry 6365 (class 2606 OID 454485)
-- Name: audit_log audit_log_pkey; Type: CONSTRAINT; Schema: ryzhov_ka; Owner: ryzhov_ka
--

ALTER TABLE ONLY ryzhov_ka.audit_log
    ADD CONSTRAINT audit_log_pkey PRIMARY KEY (audit_id);


--
-- TOC entry 6353 (class 2606 OID 451446)
-- Name: customers customers_pkey; Type: CONSTRAINT; Schema: ryzhov_ka; Owner: ryzhov_ka
--

ALTER TABLE ONLY ryzhov_ka.customers
    ADD CONSTRAINT customers_pkey PRIMARY KEY (customer_id);


--
-- TOC entry 6349 (class 2606 OID 451421)
-- Name: employee_warehouses employee_warehouses_pkey; Type: CONSTRAINT; Schema: ryzhov_ka; Owner: ryzhov_ka
--

ALTER TABLE ONLY ryzhov_ka.employee_warehouses
    ADD CONSTRAINT employee_warehouses_pkey PRIMARY KEY (employee_warehouse_id);


--
-- TOC entry 6339 (class 2606 OID 451374)
-- Name: employees employees_pkey; Type: CONSTRAINT; Schema: ryzhov_ka; Owner: ryzhov_ka
--

ALTER TABLE ONLY ryzhov_ka.employees
    ADD CONSTRAINT employees_pkey PRIMARY KEY (employee_id);


--
-- TOC entry 6357 (class 2606 OID 451470)
-- Name: inventory inventory_pkey; Type: CONSTRAINT; Schema: ryzhov_ka; Owner: ryzhov_ka
--

ALTER TABLE ONLY ryzhov_ka.inventory
    ADD CONSTRAINT inventory_pkey PRIMARY KEY (inventory_id);


--
-- TOC entry 6363 (class 2606 OID 451528)
-- Name: order_items order_items_pkey; Type: CONSTRAINT; Schema: ryzhov_ka; Owner: ryzhov_ka
--

ALTER TABLE ONLY ryzhov_ka.order_items
    ADD CONSTRAINT order_items_pkey PRIMARY KEY (order_item_id);


--
-- TOC entry 6361 (class 2606 OID 451496)
-- Name: orders orders_pkey; Type: CONSTRAINT; Schema: ryzhov_ka; Owner: ryzhov_ka
--

ALTER TABLE ONLY ryzhov_ka.orders
    ADD CONSTRAINT orders_pkey PRIMARY KEY (order_id);


--
-- TOC entry 6355 (class 2606 OID 451459)
-- Name: products products_pkey; Type: CONSTRAINT; Schema: ryzhov_ka; Owner: ryzhov_ka
--

ALTER TABLE ONLY ryzhov_ka.products
    ADD CONSTRAINT products_pkey PRIMARY KEY (product_id);


--
-- TOC entry 6351 (class 2606 OID 451425)
-- Name: employee_warehouses uq_employee_warehouses_employee_warehouse; Type: CONSTRAINT; Schema: ryzhov_ka; Owner: ryzhov_ka
--

ALTER TABLE ONLY ryzhov_ka.employee_warehouses
    ADD CONSTRAINT uq_employee_warehouses_employee_warehouse UNIQUE (employee_id, warehouse_id);


--
-- TOC entry 6359 (class 2606 OID 451474)
-- Name: inventory uq_inventory_warehouse_product; Type: CONSTRAINT; Schema: ryzhov_ka; Owner: ryzhov_ka
--

ALTER TABLE ONLY ryzhov_ka.inventory
    ADD CONSTRAINT uq_inventory_warehouse_product UNIQUE (warehouse_id, product_id);


--
-- TOC entry 6335 (class 2606 OID 451358)
-- Name: warehouses uq_warehouses_number; Type: CONSTRAINT; Schema: ryzhov_ka; Owner: ryzhov_ka
--

ALTER TABLE ONLY ryzhov_ka.warehouses
    ADD CONSTRAINT uq_warehouses_number UNIQUE (warehouse_number);


--
-- TOC entry 6337 (class 2606 OID 451356)
-- Name: warehouses warehouses_pkey; Type: CONSTRAINT; Schema: ryzhov_ka; Owner: ryzhov_ka
--

ALTER TABLE ONLY ryzhov_ka.warehouses
    ADD CONSTRAINT warehouses_pkey PRIMARY KEY (warehouse_id);


--
-- TOC entry 6346 (class 1259 OID 454463)
-- Name: ux_app_users_customer_id_not_null; Type: INDEX; Schema: ryzhov_ka; Owner: ryzhov_ka
--

CREATE UNIQUE INDEX ux_app_users_customer_id_not_null ON ryzhov_ka.app_users USING btree (customer_id) WHERE (customer_id IS NOT NULL);


--
-- TOC entry 6347 (class 1259 OID 454462)
-- Name: ux_app_users_employee_id_not_null; Type: INDEX; Schema: ryzhov_ka; Owner: ryzhov_ka
--

CREATE UNIQUE INDEX ux_app_users_employee_id_not_null ON ryzhov_ka.app_users USING btree (employee_id) WHERE (employee_id IS NOT NULL);


--
-- TOC entry 6379 (class 2620 OID 454495)
-- Name: app_users trg_audit_app_users; Type: TRIGGER; Schema: ryzhov_ka; Owner: ryzhov_ka
--

CREATE TRIGGER trg_audit_app_users AFTER INSERT OR DELETE OR UPDATE ON ryzhov_ka.app_users FOR EACH ROW EXECUTE FUNCTION ryzhov_ka.fn_audit_log_changes();


--
-- TOC entry 6381 (class 2620 OID 454494)
-- Name: customers trg_audit_customers; Type: TRIGGER; Schema: ryzhov_ka; Owner: ryzhov_ka
--

CREATE TRIGGER trg_audit_customers AFTER INSERT OR DELETE OR UPDATE ON ryzhov_ka.customers FOR EACH ROW EXECUTE FUNCTION ryzhov_ka.fn_audit_log_changes();


--
-- TOC entry 6380 (class 2620 OID 454493)
-- Name: employee_warehouses trg_audit_employee_warehouses; Type: TRIGGER; Schema: ryzhov_ka; Owner: ryzhov_ka
--

CREATE TRIGGER trg_audit_employee_warehouses AFTER INSERT OR DELETE OR UPDATE ON ryzhov_ka.employee_warehouses FOR EACH ROW EXECUTE FUNCTION ryzhov_ka.fn_audit_log_changes();


--
-- TOC entry 6378 (class 2620 OID 454492)
-- Name: employees trg_audit_employees; Type: TRIGGER; Schema: ryzhov_ka; Owner: ryzhov_ka
--

CREATE TRIGGER trg_audit_employees AFTER INSERT OR DELETE OR UPDATE ON ryzhov_ka.employees FOR EACH ROW EXECUTE FUNCTION ryzhov_ka.fn_audit_log_changes();


--
-- TOC entry 6383 (class 2620 OID 454497)
-- Name: inventory trg_audit_inventory; Type: TRIGGER; Schema: ryzhov_ka; Owner: ryzhov_ka
--

CREATE TRIGGER trg_audit_inventory AFTER INSERT OR DELETE OR UPDATE ON ryzhov_ka.inventory FOR EACH ROW EXECUTE FUNCTION ryzhov_ka.fn_audit_log_changes();


--
-- TOC entry 6385 (class 2620 OID 454499)
-- Name: order_items trg_audit_order_items; Type: TRIGGER; Schema: ryzhov_ka; Owner: ryzhov_ka
--

CREATE TRIGGER trg_audit_order_items AFTER INSERT OR DELETE OR UPDATE ON ryzhov_ka.order_items FOR EACH ROW EXECUTE FUNCTION ryzhov_ka.fn_audit_log_changes();


--
-- TOC entry 6384 (class 2620 OID 454498)
-- Name: orders trg_audit_orders; Type: TRIGGER; Schema: ryzhov_ka; Owner: ryzhov_ka
--

CREATE TRIGGER trg_audit_orders AFTER INSERT OR DELETE OR UPDATE ON ryzhov_ka.orders FOR EACH ROW EXECUTE FUNCTION ryzhov_ka.fn_audit_log_changes();


--
-- TOC entry 6382 (class 2620 OID 454496)
-- Name: products trg_audit_products; Type: TRIGGER; Schema: ryzhov_ka; Owner: ryzhov_ka
--

CREATE TRIGGER trg_audit_products AFTER INSERT OR DELETE OR UPDATE ON ryzhov_ka.products FOR EACH ROW EXECUTE FUNCTION ryzhov_ka.fn_audit_log_changes();


--
-- TOC entry 6377 (class 2620 OID 454491)
-- Name: warehouses trg_audit_warehouses; Type: TRIGGER; Schema: ryzhov_ka; Owner: ryzhov_ka
--

CREATE TRIGGER trg_audit_warehouses AFTER INSERT OR DELETE OR UPDATE ON ryzhov_ka.warehouses FOR EACH ROW EXECUTE FUNCTION ryzhov_ka.fn_audit_log_changes();


--
-- TOC entry 6386 (class 2620 OID 471486)
-- Name: order_items trg_order_items_inventory; Type: TRIGGER; Schema: ryzhov_ka; Owner: ryzhov_ka
--

CREATE TRIGGER trg_order_items_inventory BEFORE INSERT OR DELETE OR UPDATE ON ryzhov_ka.order_items FOR EACH ROW EXECUTE FUNCTION ryzhov_ka.fn_order_items_inventory();


--
-- TOC entry 6366 (class 2606 OID 451399)
-- Name: app_users app_users_employee_id_fkey; Type: FK CONSTRAINT; Schema: ryzhov_ka; Owner: ryzhov_ka
--

ALTER TABLE ONLY ryzhov_ka.app_users
    ADD CONSTRAINT app_users_employee_id_fkey FOREIGN KEY (employee_id) REFERENCES ryzhov_ka.employees(employee_id);


--
-- TOC entry 6368 (class 2606 OID 451426)
-- Name: employee_warehouses employee_warehouses_employee_id_fkey; Type: FK CONSTRAINT; Schema: ryzhov_ka; Owner: ryzhov_ka
--

ALTER TABLE ONLY ryzhov_ka.employee_warehouses
    ADD CONSTRAINT employee_warehouses_employee_id_fkey FOREIGN KEY (employee_id) REFERENCES ryzhov_ka.employees(employee_id);


--
-- TOC entry 6369 (class 2606 OID 451431)
-- Name: employee_warehouses employee_warehouses_warehouse_id_fkey; Type: FK CONSTRAINT; Schema: ryzhov_ka; Owner: ryzhov_ka
--

ALTER TABLE ONLY ryzhov_ka.employee_warehouses
    ADD CONSTRAINT employee_warehouses_warehouse_id_fkey FOREIGN KEY (warehouse_id) REFERENCES ryzhov_ka.warehouses(warehouse_id);


--
-- TOC entry 6367 (class 2606 OID 451594)
-- Name: app_users fk_app_users_customer; Type: FK CONSTRAINT; Schema: ryzhov_ka; Owner: ryzhov_ka
--

ALTER TABLE ONLY ryzhov_ka.app_users
    ADD CONSTRAINT fk_app_users_customer FOREIGN KEY (customer_id) REFERENCES ryzhov_ka.customers(customer_id);


--
-- TOC entry 6370 (class 2606 OID 451480)
-- Name: inventory inventory_product_id_fkey; Type: FK CONSTRAINT; Schema: ryzhov_ka; Owner: ryzhov_ka
--

ALTER TABLE ONLY ryzhov_ka.inventory
    ADD CONSTRAINT inventory_product_id_fkey FOREIGN KEY (product_id) REFERENCES ryzhov_ka.products(product_id);


--
-- TOC entry 6371 (class 2606 OID 451475)
-- Name: inventory inventory_warehouse_id_fkey; Type: FK CONSTRAINT; Schema: ryzhov_ka; Owner: ryzhov_ka
--

ALTER TABLE ONLY ryzhov_ka.inventory
    ADD CONSTRAINT inventory_warehouse_id_fkey FOREIGN KEY (warehouse_id) REFERENCES ryzhov_ka.warehouses(warehouse_id);


--
-- TOC entry 6375 (class 2606 OID 451529)
-- Name: order_items order_items_order_id_fkey; Type: FK CONSTRAINT; Schema: ryzhov_ka; Owner: ryzhov_ka
--

ALTER TABLE ONLY ryzhov_ka.order_items
    ADD CONSTRAINT order_items_order_id_fkey FOREIGN KEY (order_id) REFERENCES ryzhov_ka.orders(order_id);


--
-- TOC entry 6376 (class 2606 OID 451534)
-- Name: order_items order_items_product_id_fkey; Type: FK CONSTRAINT; Schema: ryzhov_ka; Owner: ryzhov_ka
--

ALTER TABLE ONLY ryzhov_ka.order_items
    ADD CONSTRAINT order_items_product_id_fkey FOREIGN KEY (product_id) REFERENCES ryzhov_ka.products(product_id);


--
-- TOC entry 6372 (class 2606 OID 451497)
-- Name: orders orders_customer_id_fkey; Type: FK CONSTRAINT; Schema: ryzhov_ka; Owner: ryzhov_ka
--

ALTER TABLE ONLY ryzhov_ka.orders
    ADD CONSTRAINT orders_customer_id_fkey FOREIGN KEY (customer_id) REFERENCES ryzhov_ka.customers(customer_id);


--
-- TOC entry 6373 (class 2606 OID 451502)
-- Name: orders orders_employee_id_fkey; Type: FK CONSTRAINT; Schema: ryzhov_ka; Owner: ryzhov_ka
--

ALTER TABLE ONLY ryzhov_ka.orders
    ADD CONSTRAINT orders_employee_id_fkey FOREIGN KEY (employee_id) REFERENCES ryzhov_ka.employees(employee_id);


--
-- TOC entry 6374 (class 2606 OID 471480)
-- Name: orders orders_warehouse_id_fkey; Type: FK CONSTRAINT; Schema: ryzhov_ka; Owner: ryzhov_ka
--

ALTER TABLE ONLY ryzhov_ka.orders
    ADD CONSTRAINT orders_warehouse_id_fkey FOREIGN KEY (warehouse_id) REFERENCES ryzhov_ka.warehouses(warehouse_id);


-- Completed on 2026-06-25 13:56:44 MSK

--
-- PostgreSQL database dump complete
--

\unrestrict c7tibngenZ3JJspWyr31r6mzMatTJpD95OAdikTmKQcJiOj35naiZ8VfDYXrpQI

