Preparando proceso de despliegue local para que se parezca al de

desarrollo, problema de las migraciones
This commit is contained in:
2026-02-20 10:47:28 +01:00
parent 1583ae539e
commit b208c9c301
11 changed files with 322 additions and 386 deletions

View File

@@ -1,4 +1,5 @@
#/bin/bash
rm deployment/database/init.sql
cat deployment/database/*.sql >deployment/database/init.sql
# cat deployment/database/*.sql >deployment/database/init.sql
cp deployment/database/esquema_final* deployment/database/init.sql
docker compose -f deployment/local/docker/docker-compose.yaml --project-directory ./ build

View File

@@ -1,312 +0,0 @@
--
-- PostgreSQL database dump
--
\restrict n4DeGueXrI8Aidzy0srXafkz44IcO9Aq9s6hheFCSSTlVeaqyQcAQSMAfGX3yUg
-- Dumped from database version 16.11 (Ubuntu 16.11-0ubuntu0.24.04.1)
-- Dumped by pg_dump version 16.11 (Ubuntu 16.11-0ubuntu0.24.04.1)
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;
--
-- Name: order_status; Type: TYPE; Schema: public; Owner: -
--
CREATE TYPE public.order_status AS ENUM (
'pending',
'running',
'finished',
'failed',
'dlx'
);
--
-- Name: order_types; Type: TYPE; Schema: public; Owner: -
--
CREATE TYPE public.order_types AS ENUM (
'activate',
'preactivate',
'cancel',
'pause',
'reactivate',
'unknown'
);
--
-- Name: status_enum; Type: TYPE; Schema: public; Owner: -
--
CREATE TYPE public.status_enum AS ENUM (
'noRequestID',
'noMassID',
'running',
'finished',
'error',
'other'
);
SET default_tablespace = '';
SET default_table_access_method = heap;
--
-- Name: db_versions; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.db_versions (
version text NOT NULL,
notes text,
creation_date timestamp without time zone DEFAULT (now() AT TIME ZONE 'utc'::text) NOT NULL,
stable boolean DEFAULT false
);
--
-- Name: objenious_operation; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.objenious_operation (
id bigint NOT NULL,
retry_count integer DEFAULT 0,
max_retry integer DEFAULT 5,
max_date_retry timestamp without time zone,
iccids text,
request_id text,
mass_action_id text,
operation text NOT NULL,
start_date timestamp without time zone DEFAULT (now() AT TIME ZONE 'utc'::text) NOT NULL,
last_change_date timestamp without time zone DEFAULT (now() AT TIME ZONE 'utc'::text) NOT NULL,
end_date timestamp without time zone,
error text,
status public.status_enum,
objenious_status text
);
--
-- Name: objenious_operation_change; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.objenious_operation_change (
id bigint NOT NULL,
operation_id bigint,
creation_date timestamp without time zone DEFAULT (now() AT TIME ZONE 'utc'::text) NOT NULL,
error text,
new_status public.status_enum,
previous_status public.status_enum,
new_objenious_status text,
previous_objenious_status text,
new_request_id text,
new_mass_action_id text
);
--
-- Name: objenious_operation_change_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
ALTER TABLE public.objenious_operation_change ALTER COLUMN id ADD GENERATED ALWAYS AS IDENTITY (
SEQUENCE NAME public.objenious_operation_change_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1
);
--
-- Name: objenious_operation_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
ALTER TABLE public.objenious_operation ALTER COLUMN id ADD GENERATED ALWAYS AS IDENTITY (
SEQUENCE NAME public.objenious_operation_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1
);
--
-- Name: order_history; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.order_history (
id bigint NOT NULL,
order_id bigint NOT NULL,
previous_status public.order_status NOT NULL,
new_status public.order_status NOT NULL,
change_reason text,
change_date timestamp without time zone DEFAULT (now() AT TIME ZONE 'utc'::text) NOT NULL
);
--
-- Name: order_history_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
ALTER TABLE public.order_history ALTER COLUMN id ADD GENERATED ALWAYS AS IDENTITY (
SEQUENCE NAME public.order_history_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1
);
--
-- Name: order_tracking; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.order_tracking (
id bigint NOT NULL,
correlation_id character varying(255) NOT NULL,
exchange character varying(100),
routing_key character varying(100),
order_type public.order_types DEFAULT 'unknown'::public.order_types NOT NULL,
payload jsonb,
status public.order_status DEFAULT 'pending'::public.order_status NOT NULL,
retry_count integer DEFAULT 0,
error_message text,
error_stacktrace text,
start_date timestamp without time zone DEFAULT (now() AT TIME ZONE 'utc'::text) NOT NULL,
update_date timestamp without time zone DEFAULT (now() AT TIME ZONE 'utc'::text) NOT NULL,
finish_date timestamp without time zone
);
--
-- Name: order_tracking_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
ALTER TABLE public.order_tracking ALTER COLUMN id ADD GENERATED ALWAYS AS IDENTITY (
SEQUENCE NAME public.order_tracking_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1
);
--
-- Name: db_versions db_versions_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.db_versions
ADD CONSTRAINT db_versions_pkey PRIMARY KEY (version);
--
-- Name: objenious_operation_change objenious_operation_change_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.objenious_operation_change
ADD CONSTRAINT objenious_operation_change_pkey PRIMARY KEY (id);
--
-- Name: objenious_operation objenious_operation_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.objenious_operation
ADD CONSTRAINT objenious_operation_pkey PRIMARY KEY (id);
--
-- Name: order_history order_history_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.order_history
ADD CONSTRAINT order_history_pkey PRIMARY KEY (id);
--
-- Name: order_tracking order_tracking_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.order_tracking
ADD CONSTRAINT order_tracking_pkey PRIMARY KEY (id);
--
-- Name: idx_order_change_date; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_order_change_date ON public.order_history USING btree (change_date);
--
-- Name: idx_order_correlation; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_order_correlation ON public.order_tracking USING btree (correlation_id);
--
-- Name: idx_order_id; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_order_id ON public.order_history USING btree (order_id);
--
-- Name: operation_change; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX operation_change ON public.objenious_operation_change USING btree (operation_id);
--
-- Name: pending_operations; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX pending_operations ON public.objenious_operation USING btree (start_date) WHERE (end_date IS NULL);
--
-- Name: pending_orders; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX pending_orders ON public.order_tracking USING btree (start_date) WHERE (finish_date IS NULL);
--
-- Name: objenious_operation_change fk_operation_id; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.objenious_operation_change
ADD CONSTRAINT fk_operation_id FOREIGN KEY (operation_id) REFERENCES public.objenious_operation(id);
--
-- Name: order_history fk_order_id; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.order_history
ADD CONSTRAINT fk_order_id FOREIGN KEY (order_id) REFERENCES public.order_tracking(id) ON DELETE CASCADE;
--
-- PostgreSQL database dump complete
--
\unrestrict n4DeGueXrI8Aidzy0srXafkz44IcO9Aq9s6hheFCSSTlVeaqyQcAQSMAfGX3yUg

View File

@@ -1,64 +1,292 @@
--
-- PostgreSQL database dump
--
CREATE TYPE status_enum AS ENUM ('noRequestID','noMassID','running','finished','error','other');
\restrict 8rNdhulAsfz5yOkZrPZ5f3riDYVBHnFPTcb2MraxKbPVyPsdTm81R2jsJppwk7u
-- Tabla para gestionar las peticiones de cambio de objenious.
-- Para una o mas lineas se pueden lanzar operacione que no sabemos
-- con certeza cuando van a terminar.
-- Estas tablas está fuertemente ligadas al sistema que usa la plataforma
-- de objenioius y no debe unsarse para otra compañia.
CREATE TABLE if not exists objenious_operation (
id BIGINT PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
retry_count INT DEFAULT 0, -- No implementado en codigo
max_retry INT DEFAULT 5, -- No implementado en codigo
max_date_retry TIMESTAMP DEFAULT NULL, -- No implementado en codigo
iccids TEXT,
request_id TEXT,
mass_action_id TEXT,
operation TEXT NOT NULL,
start_date TIMESTAMP NOT NULL DEFAULT now(),
last_change_date TIMESTAMP NOT NULL DEFAULT now(),
end_date TIMESTAMP,
error TEXT,
status status_enum,
objenious_status TEXT
-- Dumped from database version 16.11 (Ubuntu 16.11-0ubuntu0.24.04.1)
-- Dumped by pg_dump version 16.11 (Ubuntu 16.11-0ubuntu0.24.04.1)
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;
--
-- Name: order_status; Type: TYPE; Schema: public; Owner: -
--
CREATE TYPE public.order_status AS ENUM (
'pending',
'running',
'finished',
'failed',
'dlx'
);
-- operaciones pendientes para revisar
CREATE INDEX IF NOT EXISTS pending_operations
ON objenious_operation(start_date)
WHERE end_date IS NULL;
CREATE TABLE if not exists objenious_operation_change (
id BIGINT PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
operation_id BIGINT,
creation_date TIMESTAMP NOT NULL DEFAULT now(),
error TEXT,
new_status status_enum,
previous_status status_enum,
new_objenious_status TEXT,
previous_objenious_status TEXT,
new_request_id TEXT,
new_mass_action_id TEXT,
--
-- Name: order_types; Type: TYPE; Schema: public; Owner: -
--
CONSTRAINT fk_operation_id
FOREIGN KEY(operation_id) REFERENCES objenious_operation(id)
CREATE TYPE public.order_types AS ENUM (
'activate',
'preactivate',
'cancel',
'pause',
'reactivate',
'unknown'
);
CREATE INDEX operation_change
ON objenious_operation_change(operation_id);
CREATE TABLE IF NOT EXISTS db_versions (
id BIGINT BIGINT PRIMARY KEY GENERATED ALWAYS AS IDENTITY,
version TEXT, -- version semantica x.x.x
notes TEXT,
creation_date TIMESTAMP NOT NULL DEFAULT (now() at time zone 'utc'),
stable BOOLEAN DEFAULT FALSE -- Si la version ha sido testada y se puede desplegar
--
-- Name: status_enum; Type: TYPE; Schema: public; Owner: -
--
CREATE TYPE public.status_enum AS ENUM (
'noRequestID',
'noMassID',
'running',
'finished',
'error',
'other'
);
INSERT INTO db_versions (
version,
notes
)
VALUES (
'0.1.0',
'Versión base'
SET default_tablespace = '';
SET default_table_access_method = heap;
--
-- Name: objenious_operation; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.objenious_operation (
id bigint NOT NULL,
retry_count integer DEFAULT 0,
max_retry integer DEFAULT 5,
max_date_retry timestamp without time zone,
iccids text,
request_id text,
mass_action_id text,
operation text NOT NULL,
start_date timestamp with time zone DEFAULT now() NOT NULL,
last_change_date timestamp with time zone DEFAULT now() NOT NULL,
end_date timestamp with time zone,
error text,
status public.status_enum,
objenious_status text
);
--
-- Name: objenious_operation_change; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.objenious_operation_change (
id bigint NOT NULL,
operation_id bigint,
creation_date timestamp with time zone DEFAULT now() NOT NULL,
error text,
new_status public.status_enum,
previous_status public.status_enum,
new_objenious_status text,
previous_objenious_status text,
new_request_id text,
new_mass_action_id text
);
--
-- Name: objenious_operation_change_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
ALTER TABLE public.objenious_operation_change ALTER COLUMN id ADD GENERATED ALWAYS AS IDENTITY (
SEQUENCE NAME public.objenious_operation_change_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1
);
--
-- Name: objenious_operation_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
ALTER TABLE public.objenious_operation ALTER COLUMN id ADD GENERATED ALWAYS AS IDENTITY (
SEQUENCE NAME public.objenious_operation_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1
);
--
-- Name: order_history; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.order_history (
id bigint NOT NULL,
order_id bigint NOT NULL,
previous_status public.order_status NOT NULL,
new_status public.order_status NOT NULL,
change_reason text,
change_date timestamp with time zone DEFAULT now() NOT NULL
);
--
-- Name: order_history_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
ALTER TABLE public.order_history ALTER COLUMN id ADD GENERATED ALWAYS AS IDENTITY (
SEQUENCE NAME public.order_history_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1
);
--
-- Name: order_tracking; Type: TABLE; Schema: public; Owner: -
--
CREATE TABLE public.order_tracking (
id bigint NOT NULL,
correlation_id character varying(255) NOT NULL,
exchange character varying(100),
routing_key character varying(100),
order_type public.order_types DEFAULT 'unknown'::public.order_types NOT NULL,
payload jsonb,
status public.order_status DEFAULT 'pending'::public.order_status NOT NULL,
retry_count integer DEFAULT 0,
error_message text,
error_stacktrace text,
start_date timestamp with time zone DEFAULT now() NOT NULL,
update_date timestamp with time zone DEFAULT now() NOT NULL,
finish_date timestamp with time zone
);
--
-- Name: order_tracking_id_seq; Type: SEQUENCE; Schema: public; Owner: -
--
ALTER TABLE public.order_tracking ALTER COLUMN id ADD GENERATED ALWAYS AS IDENTITY (
SEQUENCE NAME public.order_tracking_id_seq
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1
);
--
-- Name: objenious_operation_change objenious_operation_change_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.objenious_operation_change
ADD CONSTRAINT objenious_operation_change_pkey PRIMARY KEY (id);
--
-- Name: objenious_operation objenious_operation_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.objenious_operation
ADD CONSTRAINT objenious_operation_pkey PRIMARY KEY (id);
--
-- Name: order_history order_history_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.order_history
ADD CONSTRAINT order_history_pkey PRIMARY KEY (id);
--
-- Name: order_tracking order_tracking_pkey; Type: CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.order_tracking
ADD CONSTRAINT order_tracking_pkey PRIMARY KEY (id);
--
-- Name: idx_order_change_date; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_order_change_date ON public.order_history USING btree (change_date);
--
-- Name: idx_order_correlation; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_order_correlation ON public.order_tracking USING btree (correlation_id);
--
-- Name: idx_order_id; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX idx_order_id ON public.order_history USING btree (order_id);
--
-- Name: operation_change; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX operation_change ON public.objenious_operation_change USING btree (operation_id);
--
-- Name: pending_operations; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX pending_operations ON public.objenious_operation USING btree (start_date) WHERE (end_date IS NULL);
--
-- Name: pending_orders; Type: INDEX; Schema: public; Owner: -
--
CREATE INDEX pending_orders ON public.order_tracking USING btree (start_date) WHERE (finish_date IS NULL);
--
-- Name: objenious_operation_change fk_operation_id; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.objenious_operation_change
ADD CONSTRAINT fk_operation_id FOREIGN KEY (operation_id) REFERENCES public.objenious_operation(id);
--
-- Name: order_history fk_order_id; Type: FK CONSTRAINT; Schema: public; Owner: -
--
ALTER TABLE ONLY public.order_history
ADD CONSTRAINT fk_order_id FOREIGN KEY (order_id) REFERENCES public.order_tracking(id) ON DELETE CASCADE;
--
-- PostgreSQL database dump complete
--
\unrestrict 8rNdhulAsfz5yOkZrPZ5f3riDYVBHnFPTcb2MraxKbPVyPsdTm81R2jsJppwk7u

View File

@@ -19,4 +19,5 @@ COPY ./entrypoint.sh ./
RUN chmod +x entrypoint.sh
EXPOSE ${PORT:-3000}
ENTRYPOINT ["./entrypoint.sh"]

View File

@@ -1,16 +1,23 @@
# stage base para coordinar las fases de build y ejecucion
# Stage base para coordinar las fases de build y ejecucion
FROM node:22-alpine AS base
WORKDIR /usr/local/app
COPY ./package.json ./yarn.lock ./
RUN corepack enable && \
corepack prepare yarn@4.12.0 --activate
COPY ./package.json ./yarn.lock ./
COPY ./packages ./packages
# copia el codigo en general
COPY tsconfig*.json ./
COPY ./packages ./packages
COPY .env* ./
COPY ./.yarnrc.yml ./
RUN yarn install && yarn cache clean
COPY ./deployment/local/docker/start.sh ./
RUN yarn install && \
yarn cache clean && \
yarn build && \
chmod +x start.sh
EXPOSE ${PORT}
CMD ["yarn", "run", "dev"]
ENTRYPOINT [ "start.sh" ]

View File

@@ -24,14 +24,15 @@ services:
RABBITMQ_DEFAULT_PASS: ${RABBITMQ_PASSWORD}
volumes:
- ./rabbitmq_plugins/enabled_plugins:/etc/rabbitmq/enabled_plugins:ro
- ./deployment/rabbit/rabbitmq.conf:/etc/rabbitmq/rabbitmq.conf:ro
- ./deployment/rabbit/definitions.json:/etc/rabbitmq/definitions.json:ro
- ./deployment/local/rabbit/rabbitmq.conf:/etc/rabbitmq/rabbitmq.conf:ro
- ./deployment/local/rabbit/definitions.json:/etc/rabbitmq/definitions.json:ro
sim-gateway:
container_name: sim-gateway
sf-sims-api:
container_name: sf-sims-api
image: sf-sims-api
build:
context: ./
dockerfile: deployment/Dockerfile.dev
dockerfile: deployment/local/docker/Dockerfile.dev
args:
PORT: "${PORT:-3000}"
develop:
@@ -46,6 +47,16 @@ services:
env_file:
- .env
restart: unless-stopped
healthcheck:
test:
[
"CMD-SHELL",
'node -e "fetch(''http://localhost:'' + (process.env.PORT || 3000) + ''/health'').then(r => { if (!r.ok) process.exit(1) }).catch(() => process.exit(1))"',
]
interval: 10s
timeout: 5s
retries: 5
start_period: 15s
depends_on:
rabbitmq-sim-broker:
condition: service_healthy

View File

@@ -1,9 +1,10 @@
#!/bin/bash
cd /mnt/docker-storage/containers/savefamily/sf-shopify-orders
# cd /mnt/docker-storage/containers/savefamily/sf-shopify-orders
cd /mnt/docker-storage/containers/savefamily/sf-sims-api
docker stop sf-shopify-orders-api || true
docker rm sf-shopify-orders-api || true
docker rmi sf-shopify-orders-api || true
docker stop sf-sims-api || true
docker rm sf-sims-api || true
docker rmi sf-sims-api || true
docker compose -f docker-compose.yaml up --build -d

View File

@@ -0,0 +1,2 @@
#!/bin/sh
yarn migrate && yarn start

View File

@@ -1,6 +1,3 @@
default_user = guest
default_pass = guest
listeners.tcp.default = 5672
management.tcp.port = 15672

View File

@@ -96,14 +96,14 @@ export class SimUseCases {
} else {
return <Result<string, boolean>>{
error: String(resp.status),
data: true
data: undefined
}
}
} catch (error) {
console.error("Error preactivacion", preActivateData)
return <Result<string, boolean>>{
error: "Error preactivando la sim" + preActivateData.identifier,
data: true
data: undefined
}
}
}
@@ -127,7 +127,7 @@ export class SimUseCases {
console.error("Error reactivacion", error)
return <Result<string, boolean>>{
error: "Error reactivando la sim" + pauseData.identifier,
data: true
data: undefined
}
}
}