68 lines
2.6 KiB
SQL
68 lines
2.6 KiB
SQL
-- Table: public.articulos
|
|
|
|
CREATE TABLE IF NOT EXISTS public.articulos
|
|
(
|
|
id integer NOT NULL GENERATED BY DEFAULT AS IDENTITY ( INCREMENT 1 START 1 MINVALUE 1 MAXVALUE 2147483647 CACHE 1 ),
|
|
codigo character varying(50) COLLATE pg_catalog."default" NOT NULL,
|
|
nombre character varying(100) COLLATE pg_catalog."default" NOT NULL,
|
|
descripcion character varying(500) COLLATE pg_catalog."default",
|
|
marca character varying(100) COLLATE pg_catalog."default",
|
|
modelo character varying(100) COLLATE pg_catalog."default",
|
|
numero_serie character varying(100) COLLATE pg_catalog."default",
|
|
precio numeric(10,2) NOT NULL DEFAULT 0,
|
|
fecha_adquisicion date,
|
|
imagen_url text COLLATE pg_catalog."default",
|
|
categoria_id integer NOT NULL,
|
|
estado_id integer NOT NULL,
|
|
ubicacion_id integer NOT NULL,
|
|
activo boolean NOT NULL DEFAULT true,
|
|
eliminado boolean NOT NULL DEFAULT false,
|
|
creado_en timestamp without time zone NOT NULL DEFAULT (now() AT TIME ZONE 'utc'::text),
|
|
actualizado_en timestamp without time zone NOT NULL DEFAULT (now() AT TIME ZONE 'utc'::text),
|
|
creado_por character varying(100) COLLATE pg_catalog."default",
|
|
CONSTRAINT articulos_pkey PRIMARY KEY (id),
|
|
CONSTRAINT fk_articulos_categorias FOREIGN KEY (categoria_id)
|
|
REFERENCES public.categorias (id) MATCH SIMPLE
|
|
ON UPDATE NO ACTION
|
|
ON DELETE RESTRICT,
|
|
CONSTRAINT fk_articulos_estados FOREIGN KEY (estado_id)
|
|
REFERENCES public.estados_articulos (id) MATCH SIMPLE
|
|
ON UPDATE NO ACTION
|
|
ON DELETE RESTRICT,
|
|
CONSTRAINT fk_articulos_ubicaciones FOREIGN KEY (ubicacion_id)
|
|
REFERENCES public.ubicaciones (id) MATCH SIMPLE
|
|
ON UPDATE NO ACTION
|
|
ON DELETE RESTRICT
|
|
)
|
|
TABLESPACE pg_default;
|
|
|
|
ALTER TABLE IF EXISTS public.articulos
|
|
OWNER to postgres;
|
|
|
|
-- Indexes
|
|
|
|
CREATE UNIQUE INDEX IF NOT EXISTS ix_articulos_codigo
|
|
ON public.articulos USING btree
|
|
(codigo COLLATE pg_catalog."default" ASC NULLS LAST)
|
|
TABLESPACE pg_default;
|
|
|
|
CREATE INDEX IF NOT EXISTS ix_articulos_nombre
|
|
ON public.articulos USING btree
|
|
(nombre COLLATE pg_catalog."default" ASC NULLS LAST)
|
|
TABLESPACE pg_default;
|
|
|
|
CREATE INDEX IF NOT EXISTS ix_articulos_categoria_id
|
|
ON public.articulos USING btree
|
|
(categoria_id ASC NULLS LAST)
|
|
TABLESPACE pg_default;
|
|
|
|
CREATE INDEX IF NOT EXISTS ix_articulos_estado_id
|
|
ON public.articulos USING btree
|
|
(estado_id ASC NULLS LAST)
|
|
TABLESPACE pg_default;
|
|
|
|
CREATE INDEX IF NOT EXISTS ix_articulos_ubicacion_id
|
|
ON public.articulos USING btree
|
|
(ubicacion_id ASC NULLS LAST)
|
|
TABLESPACE pg_default;
|