-- Downloaded from: https://github.com/TaraPadilla/MarketSpring/blob/84bf503f29fa1db3c3f4ee5acfdb7bbb59fd0f39/docs/bdmarket.sql
--
-- PostgreSQL database dump
--

-- Dumped from database version 16.4
-- Dumped by pg_dump version 16.4

-- Started on 2024-08-26 18:11:04

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;

--
-- TOC entry 6 (class 2615 OID 16595)
-- Name: base; Type: SCHEMA; Schema: -; Owner: postgres
--

CREATE SCHEMA base;


ALTER SCHEMA base OWNER TO postgres;

--
-- TOC entry 9 (class 2615 OID 17248)
-- Name: comercial; Type: SCHEMA; Schema: -; Owner: ebroot
--

CREATE SCHEMA comercial;


ALTER SCHEMA comercial OWNER TO ebroot;

--
-- TOC entry 7 (class 2615 OID 16596)
-- Name: products; Type: SCHEMA; Schema: -; Owner: postgres
--

CREATE SCHEMA products;


ALTER SCHEMA products OWNER TO postgres;

--
-- TOC entry 8 (class 2615 OID 16597)
-- Name: services; Type: SCHEMA; Schema: -; Owner: postgres
--

CREATE SCHEMA services;


ALTER SCHEMA services OWNER TO postgres;

SET default_tablespace = '';

SET default_table_access_method = heap;

--
-- TOC entry 223 (class 1259 OID 16505)
-- Name: clientes; Type: TABLE; Schema: base; Owner: ebroot
--

CREATE TABLE base.clientes (
    id character varying(255) NOT NULL,
    nombre character varying(255),
    apellidos character varying(255),
    celular double precision,
    direccion character varying(255),
    correo_electronico character varying(255)
);


ALTER TABLE base.clientes OWNER TO ebroot;

--
-- TOC entry 226 (class 1259 OID 16514)
-- Name: compras; Type: TABLE; Schema: base; Owner: ebroot
--

CREATE TABLE base.compras (
    id_compra integer NOT NULL,
    id_cliente character varying(255) NOT NULL,
    fecha timestamp without time zone,
    medio_pago character varying(1),
    comentario character varying(255),
    estado character varying(1)
);


ALTER TABLE base.compras OWNER TO ebroot;

--
-- TOC entry 227 (class 1259 OID 16519)
-- Name: compras_id_compra_seq; Type: SEQUENCE; Schema: base; Owner: ebroot
--

CREATE SEQUENCE base.compras_id_compra_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE base.compras_id_compra_seq OWNER TO ebroot;

--
-- TOC entry 4943 (class 0 OID 0)
-- Dependencies: 227
-- Name: compras_id_compra_seq; Type: SEQUENCE OWNED BY; Schema: base; Owner: ebroot
--

ALTER SEQUENCE base.compras_id_compra_seq OWNED BY base.compras.id_compra;


--
-- TOC entry 236 (class 1259 OID 16841)
-- Name: empresa; Type: TABLE; Schema: base; Owner: postgres
--

CREATE TABLE base.empresa (
    id_empresa integer NOT NULL,
    nombre character varying(255) NOT NULL,
    descripcion character varying NOT NULL,
    estado boolean DEFAULT true
);


ALTER TABLE base.empresa OWNER TO postgres;

--
-- TOC entry 235 (class 1259 OID 16840)
-- Name: empresa_id_empresa_seq; Type: SEQUENCE; Schema: base; Owner: postgres
--

ALTER TABLE base.empresa ALTER COLUMN id_empresa ADD GENERATED ALWAYS AS IDENTITY (
    SEQUENCE NAME base.empresa_id_empresa_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1
);


--
-- TOC entry 240 (class 1259 OID 17407)
-- Name: usuario; Type: TABLE; Schema: base; Owner: postgres
--

CREATE TABLE base.usuario (
    id_usuario integer NOT NULL,
    id_empresa integer NOT NULL
);


ALTER TABLE base.usuario OWNER TO postgres;

--
-- TOC entry 229 (class 1259 OID 16523)
-- Name: cotizacion; Type: TABLE; Schema: comercial; Owner: ebroot
--

CREATE TABLE comercial.cotizacion (
    id_cotizacion integer NOT NULL,
    estado character varying(255) NOT NULL,
    fecha_creacion timestamp without time zone DEFAULT CURRENT_TIMESTAMP NOT NULL,
    notas character varying(255),
    precio_total numeric(6,2) NOT NULL,
    id_catalogo integer,
    id_servicio integer,
    id_usuario integer
);


ALTER TABLE comercial.cotizacion OWNER TO ebroot;

--
-- TOC entry 230 (class 1259 OID 16529)
-- Name: cotizacion_id_cotizacion_seq; Type: SEQUENCE; Schema: comercial; Owner: ebroot
--

ALTER TABLE comercial.cotizacion ALTER COLUMN id_cotizacion ADD GENERATED BY DEFAULT AS IDENTITY (
    SEQUENCE NAME comercial.cotizacion_id_cotizacion_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1
);


--
-- TOC entry 238 (class 1259 OID 17156)
-- Name: catalogo; Type: TABLE; Schema: products; Owner: postgres
--

CREATE TABLE products.catalogo (
    id_catalogo integer NOT NULL,
    id_empresa integer,
    nombre character varying(255) NOT NULL
);


ALTER TABLE products.catalogo OWNER TO postgres;

--
-- TOC entry 237 (class 1259 OID 17155)
-- Name: catalogo_id_catalogo_seq; Type: SEQUENCE; Schema: products; Owner: postgres
--

ALTER TABLE products.catalogo ALTER COLUMN id_catalogo ADD GENERATED ALWAYS AS IDENTITY (
    SEQUENCE NAME products.catalogo_id_catalogo_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1
);


--
-- TOC entry 239 (class 1259 OID 17392)
-- Name: catalogo_productos; Type: TABLE; Schema: products; Owner: postgres
--

CREATE TABLE products.catalogo_productos (
    id_catalogo integer NOT NULL,
    id_producto integer NOT NULL
);


ALTER TABLE products.catalogo_productos OWNER TO postgres;

--
-- TOC entry 221 (class 1259 OID 16501)
-- Name: categorias; Type: TABLE; Schema: products; Owner: ebroot
--

CREATE TABLE products.categorias (
    id_categoria integer NOT NULL,
    descripcion character varying(255) NOT NULL,
    estado boolean NOT NULL
);


ALTER TABLE products.categorias OWNER TO ebroot;

--
-- TOC entry 222 (class 1259 OID 16504)
-- Name: categorias_id_categoria_seq; Type: SEQUENCE; Schema: products; Owner: ebroot
--

CREATE SEQUENCE products.categorias_id_categoria_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE products.categorias_id_categoria_seq OWNER TO ebroot;

--
-- TOC entry 4944 (class 0 OID 0)
-- Dependencies: 222
-- Name: categorias_id_categoria_seq; Type: SEQUENCE OWNED BY; Schema: products; Owner: ebroot
--

ALTER SEQUENCE products.categorias_id_categoria_seq OWNED BY products.categorias.id_categoria;


--
-- TOC entry 228 (class 1259 OID 16520)
-- Name: compras_productos; Type: TABLE; Schema: products; Owner: ebroot
--

CREATE TABLE products.compras_productos (
    id_compra integer NOT NULL,
    id_producto integer NOT NULL,
    cantidad integer,
    total numeric(38,2),
    estado boolean
);


ALTER TABLE products.compras_productos OWNER TO ebroot;

--
-- TOC entry 231 (class 1259 OID 16530)
-- Name: productos; Type: TABLE; Schema: products; Owner: ebroot
--

CREATE TABLE products.productos (
    id_producto integer NOT NULL,
    nombre character varying(255),
    id_categoria integer NOT NULL,
    codigo_barras character varying(255),
    precio_venta numeric(38,2),
    cantidad_stock integer NOT NULL,
    estado boolean
);


ALTER TABLE products.productos OWNER TO ebroot;

--
-- TOC entry 232 (class 1259 OID 16535)
-- Name: productos_id_producto_seq; Type: SEQUENCE; Schema: products; Owner: ebroot
--

CREATE SEQUENCE products.productos_id_producto_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER SEQUENCE products.productos_id_producto_seq OWNER TO ebroot;

--
-- TOC entry 4945 (class 0 OID 0)
-- Dependencies: 232
-- Name: productos_id_producto_seq; Type: SEQUENCE OWNED BY; Schema: products; Owner: ebroot
--

ALTER SEQUENCE products.productos_id_producto_seq OWNED BY products.productos.id_producto;


--
-- TOC entry 219 (class 1259 OID 16497)
-- Name: caracteristica; Type: TABLE; Schema: services; Owner: ebroot
--

CREATE TABLE services.caracteristica (
    id_caracteristica integer NOT NULL,
    descripcion character varying(255) NOT NULL,
    nombre character varying(50) NOT NULL,
    id_servicio integer
);


ALTER TABLE services.caracteristica OWNER TO ebroot;

--
-- TOC entry 220 (class 1259 OID 16500)
-- Name: caracteristica_id_caracteristica_seq; Type: SEQUENCE; Schema: services; Owner: ebroot
--

ALTER TABLE services.caracteristica ALTER COLUMN id_caracteristica ADD GENERATED BY DEFAULT AS IDENTITY (
    SEQUENCE NAME services.caracteristica_id_caracteristica_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1
);


--
-- TOC entry 224 (class 1259 OID 16510)
-- Name: componente; Type: TABLE; Schema: services; Owner: ebroot
--

CREATE TABLE services.componente (
    id_componente integer NOT NULL,
    descripcion character varying(255) NOT NULL,
    nombre character varying(50) NOT NULL,
    precio numeric(6,2) NOT NULL,
    id_servicio integer
);


ALTER TABLE services.componente OWNER TO ebroot;

--
-- TOC entry 225 (class 1259 OID 16513)
-- Name: componente_id_componente_seq; Type: SEQUENCE; Schema: services; Owner: ebroot
--

ALTER TABLE services.componente ALTER COLUMN id_componente ADD GENERATED BY DEFAULT AS IDENTITY (
    SEQUENCE NAME services.componente_id_componente_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1
);


--
-- TOC entry 233 (class 1259 OID 16536)
-- Name: servicio; Type: TABLE; Schema: services; Owner: ebroot
--

CREATE TABLE services.servicio (
    id_servicio integer NOT NULL,
    descripcion character varying(150) NOT NULL,
    nombre_servicio character varying(30) NOT NULL,
    visible boolean NOT NULL,
    id_empresa integer
);


ALTER TABLE services.servicio OWNER TO ebroot;

--
-- TOC entry 4946 (class 0 OID 0)
-- Dependencies: 233
-- Name: COLUMN servicio.id_empresa; Type: COMMENT; Schema: services; Owner: ebroot
--

COMMENT ON COLUMN services.servicio.id_empresa IS 'Empresa que presta este servicio';


--
-- TOC entry 234 (class 1259 OID 16539)
-- Name: servicio_id_cotizacion_seq; Type: SEQUENCE; Schema: services; Owner: ebroot
--

ALTER TABLE services.servicio ALTER COLUMN id_servicio ADD GENERATED BY DEFAULT AS IDENTITY (
    SEQUENCE NAME services.servicio_id_cotizacion_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1
);


--
-- TOC entry 4749 (class 2604 OID 16541)
-- Name: compras id_compra; Type: DEFAULT; Schema: base; Owner: ebroot
--

ALTER TABLE ONLY base.compras ALTER COLUMN id_compra SET DEFAULT nextval('base.compras_id_compra_seq'::regclass);


--
-- TOC entry 4748 (class 2604 OID 16540)
-- Name: categorias id_categoria; Type: DEFAULT; Schema: products; Owner: ebroot
--

ALTER TABLE ONLY products.categorias ALTER COLUMN id_categoria SET DEFAULT nextval('products.categorias_id_categoria_seq'::regclass);


--
-- TOC entry 4751 (class 2604 OID 16542)
-- Name: productos id_producto; Type: DEFAULT; Schema: products; Owner: ebroot
--

ALTER TABLE ONLY products.productos ALTER COLUMN id_producto SET DEFAULT nextval('products.productos_id_producto_seq'::regclass);


--
-- TOC entry 4758 (class 2606 OID 16548)
-- Name: clientes clientes_pkey; Type: CONSTRAINT; Schema: base; Owner: ebroot
--

ALTER TABLE ONLY base.clientes
    ADD CONSTRAINT clientes_pkey PRIMARY KEY (id);


--
-- TOC entry 4762 (class 2606 OID 16552)
-- Name: compras compras_pkey; Type: CONSTRAINT; Schema: base; Owner: ebroot
--

ALTER TABLE ONLY base.compras
    ADD CONSTRAINT compras_pkey PRIMARY KEY (id_compra);


--
-- TOC entry 4774 (class 2606 OID 16848)
-- Name: empresa pk_empresa; Type: CONSTRAINT; Schema: base; Owner: postgres
--

ALTER TABLE ONLY base.empresa
    ADD CONSTRAINT pk_empresa PRIMARY KEY (id_empresa);


--
-- TOC entry 4780 (class 2606 OID 17416)
-- Name: usuario unq_usuario_id_usuario; Type: CONSTRAINT; Schema: base; Owner: postgres
--

ALTER TABLE ONLY base.usuario
    ADD CONSTRAINT unq_usuario_id_usuario UNIQUE (id_usuario);


--
-- TOC entry 4766 (class 2606 OID 16556)
-- Name: cotizacion cotizacion_pkey; Type: CONSTRAINT; Schema: comercial; Owner: ebroot
--

ALTER TABLE ONLY comercial.cotizacion
    ADD CONSTRAINT cotizacion_pkey PRIMARY KEY (id_cotizacion);


--
-- TOC entry 4756 (class 2606 OID 16546)
-- Name: categorias categorias_pkey; Type: CONSTRAINT; Schema: products; Owner: ebroot
--

ALTER TABLE ONLY products.categorias
    ADD CONSTRAINT categorias_pkey PRIMARY KEY (id_categoria);


--
-- TOC entry 4764 (class 2606 OID 16554)
-- Name: compras_productos compras_productos_pkey; Type: CONSTRAINT; Schema: products; Owner: ebroot
--

ALTER TABLE ONLY products.compras_productos
    ADD CONSTRAINT compras_productos_pkey PRIMARY KEY (id_compra, id_producto);


--
-- TOC entry 4776 (class 2606 OID 17160)
-- Name: catalogo pk_catalogo; Type: CONSTRAINT; Schema: products; Owner: postgres
--

ALTER TABLE ONLY products.catalogo
    ADD CONSTRAINT pk_catalogo PRIMARY KEY (id_catalogo);


--
-- TOC entry 4768 (class 2606 OID 16558)
-- Name: productos productos_pkey; Type: CONSTRAINT; Schema: products; Owner: ebroot
--

ALTER TABLE ONLY products.productos
    ADD CONSTRAINT productos_pkey PRIMARY KEY (id_producto);


--
-- TOC entry 4778 (class 2606 OID 17396)
-- Name: catalogo_productos unq_catalogo_productos_id_catalogo; Type: CONSTRAINT; Schema: products; Owner: postgres
--

ALTER TABLE ONLY products.catalogo_productos
    ADD CONSTRAINT unq_catalogo_productos_id_catalogo UNIQUE (id_catalogo);


--
-- TOC entry 4754 (class 2606 OID 16544)
-- Name: caracteristica caracteristica_pkey; Type: CONSTRAINT; Schema: services; Owner: ebroot
--

ALTER TABLE ONLY services.caracteristica
    ADD CONSTRAINT caracteristica_pkey PRIMARY KEY (id_caracteristica);


--
-- TOC entry 4760 (class 2606 OID 16550)
-- Name: componente componente_pkey; Type: CONSTRAINT; Schema: services; Owner: ebroot
--

ALTER TABLE ONLY services.componente
    ADD CONSTRAINT componente_pkey PRIMARY KEY (id_componente);


--
-- TOC entry 4770 (class 2606 OID 16560)
-- Name: servicio servicio_pkey; Type: CONSTRAINT; Schema: services; Owner: ebroot
--

ALTER TABLE ONLY services.servicio
    ADD CONSTRAINT servicio_pkey PRIMARY KEY (id_servicio);


--
-- TOC entry 4772 (class 2606 OID 16562)
-- Name: servicio ukngllnswut8q6wwg87y95egn41; Type: CONSTRAINT; Schema: services; Owner: ebroot
--

ALTER TABLE ONLY services.servicio
    ADD CONSTRAINT ukngllnswut8q6wwg87y95egn41 UNIQUE (nombre_servicio);


--
-- TOC entry 4783 (class 2606 OID 16563)
-- Name: compras fk_COMPRAS_CLIENTES1; Type: FK CONSTRAINT; Schema: base; Owner: ebroot
--

ALTER TABLE ONLY base.compras
    ADD CONSTRAINT "fk_COMPRAS_CLIENTES1" FOREIGN KEY (id_cliente) REFERENCES base.clientes(id);


--
-- TOC entry 4794 (class 2606 OID 17410)
-- Name: usuario fk_usuario_empresa; Type: FK CONSTRAINT; Schema: base; Owner: postgres
--

ALTER TABLE ONLY base.usuario
    ADD CONSTRAINT fk_usuario_empresa FOREIGN KEY (id_empresa) REFERENCES base.empresa(id_empresa);


--
-- TOC entry 4786 (class 2606 OID 17194)
-- Name: cotizacion fk_cotizacion_catalogo; Type: FK CONSTRAINT; Schema: comercial; Owner: ebroot
--

ALTER TABLE ONLY comercial.cotizacion
    ADD CONSTRAINT fk_cotizacion_catalogo FOREIGN KEY (id_catalogo) REFERENCES products.catalogo(id_catalogo);


--
-- TOC entry 4787 (class 2606 OID 17199)
-- Name: cotizacion fk_cotizacion_servicio; Type: FK CONSTRAINT; Schema: comercial; Owner: ebroot
--

ALTER TABLE ONLY comercial.cotizacion
    ADD CONSTRAINT fk_cotizacion_servicio FOREIGN KEY (id_servicio) REFERENCES services.servicio(id_servicio);


--
-- TOC entry 4788 (class 2606 OID 17417)
-- Name: cotizacion fk_cotizacion_usuario; Type: FK CONSTRAINT; Schema: comercial; Owner: ebroot
--

ALTER TABLE ONLY comercial.cotizacion
    ADD CONSTRAINT fk_cotizacion_usuario FOREIGN KEY (id_usuario) REFERENCES base.usuario(id_usuario);


--
-- TOC entry 4784 (class 2606 OID 16568)
-- Name: compras_productos fk_COMPRAS_PRODUCTOS_COMPRAS1; Type: FK CONSTRAINT; Schema: products; Owner: ebroot
--

ALTER TABLE ONLY products.compras_productos
    ADD CONSTRAINT "fk_COMPRAS_PRODUCTOS_COMPRAS1" FOREIGN KEY (id_compra) REFERENCES base.compras(id_compra);


--
-- TOC entry 4785 (class 2606 OID 16573)
-- Name: compras_productos fk_COMPRAS_PRODUCTOS_PRODUCTOS1; Type: FK CONSTRAINT; Schema: products; Owner: ebroot
--

ALTER TABLE ONLY products.compras_productos
    ADD CONSTRAINT "fk_COMPRAS_PRODUCTOS_PRODUCTOS1" FOREIGN KEY (id_producto) REFERENCES products.productos(id_producto);


--
-- TOC entry 4789 (class 2606 OID 16578)
-- Name: productos fk_PRODUCTOS_CATEGORIAS; Type: FK CONSTRAINT; Schema: products; Owner: ebroot
--

ALTER TABLE ONLY products.productos
    ADD CONSTRAINT "fk_PRODUCTOS_CATEGORIAS" FOREIGN KEY (id_categoria) REFERENCES products.categorias(id_categoria);


--
-- TOC entry 4791 (class 2606 OID 17397)
-- Name: catalogo fk_catalogo_catalogo_productos; Type: FK CONSTRAINT; Schema: products; Owner: postgres
--

ALTER TABLE ONLY products.catalogo
    ADD CONSTRAINT fk_catalogo_catalogo_productos FOREIGN KEY (id_catalogo) REFERENCES products.catalogo_productos(id_catalogo);


--
-- TOC entry 4792 (class 2606 OID 17161)
-- Name: catalogo fk_catalogo_empresa; Type: FK CONSTRAINT; Schema: products; Owner: postgres
--

ALTER TABLE ONLY products.catalogo
    ADD CONSTRAINT fk_catalogo_empresa FOREIGN KEY (id_empresa) REFERENCES base.empresa(id_empresa) ON UPDATE RESTRICT ON DELETE RESTRICT;


--
-- TOC entry 4793 (class 2606 OID 17402)
-- Name: catalogo_productos fk_catalogo_productos_productos; Type: FK CONSTRAINT; Schema: products; Owner: postgres
--

ALTER TABLE ONLY products.catalogo_productos
    ADD CONSTRAINT fk_catalogo_productos_productos FOREIGN KEY (id_producto) REFERENCES products.productos(id_producto);


--
-- TOC entry 4781 (class 2606 OID 16859)
-- Name: caracteristica fk_caracteristica_servicio; Type: FK CONSTRAINT; Schema: services; Owner: ebroot
--

ALTER TABLE ONLY services.caracteristica
    ADD CONSTRAINT fk_caracteristica_servicio FOREIGN KEY (id_servicio) REFERENCES services.servicio(id_servicio) ON UPDATE RESTRICT ON DELETE RESTRICT;


--
-- TOC entry 4782 (class 2606 OID 16864)
-- Name: componente fk_componente_servicio; Type: FK CONSTRAINT; Schema: services; Owner: ebroot
--

ALTER TABLE ONLY services.componente
    ADD CONSTRAINT fk_componente_servicio FOREIGN KEY (id_servicio) REFERENCES services.servicio(id_servicio) ON UPDATE RESTRICT ON DELETE RESTRICT;


--
-- TOC entry 4790 (class 2606 OID 16854)
-- Name: servicio fk_servicio_empresa; Type: FK CONSTRAINT; Schema: services; Owner: ebroot
--

ALTER TABLE ONLY services.servicio
    ADD CONSTRAINT fk_servicio_empresa FOREIGN KEY (id_empresa) REFERENCES base.empresa(id_empresa) ON UPDATE RESTRICT ON DELETE RESTRICT;


-- Completed on 2024-08-26 18:11:04

--
-- PostgreSQL database dump complete
--

