From 23ec83e6b72488f0e814a22ee9fe002d20dd7695 Mon Sep 17 00:00:00 2001 From: Edvaldo Szymonek Date: Tue, 8 Sep 2026 22:21:32 -0300 Subject: [PATCH] =?UTF-8?q?adiciona=20vari=C3=A1vel=20para=20exclus=C3=A3o?= =?UTF-8?q?=20de=20tabelas=20durante=20a=20sincroniza=C3=A7=C3=A3o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .cursor/rules/type-and-file-names.mdc | 32 +++++++++++++++++++++++++ script/database-sync/Dockerfile | 4 ---- script/database-sync/database-sync.sh | 22 +++++++++++++---- script/database-sync/docker-compose.yml | 1 + 4 files changed, 51 insertions(+), 8 deletions(-) create mode 100644 .cursor/rules/type-and-file-names.mdc diff --git a/.cursor/rules/type-and-file-names.mdc b/.cursor/rules/type-and-file-names.mdc new file mode 100644 index 00000000..415914eb --- /dev/null +++ b/.cursor/rules/type-and-file-names.mdc @@ -0,0 +1,32 @@ +--- +description: Type and file names use 3rd-person present verbs, not the infinitive, in Portuguese or English +globs: "{src,test}/**/*.{ts,js}" +alwaysApply: false +--- + +# Type and file names + +Name new controllers, use cases, and their tests after the **action as a finite verb**: 3rd-person singular present (the form that agrees with “it does X”). Do not use the infinitive (“to X”) or the bare uninflected stem. + +The same conjugation rule applies in Portuguese and in English. Keep the language of a module consistent; do not mix languages in one type or file name. + +## How to name a type + +1. Choose the action verb in the module’s language. +2. Inflect it to 3rd-person singular present. +3. Append the resource noun (plural for a collection, singular for one entity). +4. Append the role suffix (`Controller`, `UseCase`, and the same for other application/domain types). + +| Role | Pattern | +| --- | --- | +| List a collection | `{Verb}{Resources}Controller` / `{Verb}{Resources}UseCase` | +| Get one by id | `{Verb}{Resource}UseCase` (and matching controller) | +| Tests | One file per action; kebab-case of the same verb + resource stem | + +Type files are PascalCase and match the exported type. Test files use kebab-case of that stem (for example `lists-countries.test.ts`), not a different verb and not several actions in one file. + +## When renaming + +Delete the old file. Do not leave unused duplicates that use the infinitive or a different inflection. + +Do not copy drifted names already in the tree. Match the inflection rule above for every new module. diff --git a/script/database-sync/Dockerfile b/script/database-sync/Dockerfile index d38515fa..274a127c 100644 --- a/script/database-sync/Dockerfile +++ b/script/database-sync/Dockerfile @@ -8,19 +8,15 @@ RUN \ gnupg \ curl \ ca-certificates && \ - curl -fsSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor -o /usr/share/keyrings/postgresql.gpg && \ echo "deb [signed-by=/usr/share/keyrings/postgresql.gpg] https://apt.postgresql.org/pub/repos/apt bookworm-pgdg main" > /etc/apt/sources.list.d/pgdg.list && \ - apt-get update && \ apt-get install -y \ postgresql-client-18 && \ - apt-get remove -y \ curl \ ca-certificates \ gnupg && \ - rm -rf /var/lib/apt/lists/* ENV TZ=America/Sao_Paulo diff --git a/script/database-sync/database-sync.sh b/script/database-sync/database-sync.sh index 431a01bd..91562579 100755 --- a/script/database-sync/database-sync.sh +++ b/script/database-sync/database-sync.sh @@ -4,6 +4,18 @@ set -euo pipefail echo "Starting synchronization process..." +exclude_args=() +if [[ -n "${SYNC_EXCLUDE_TABLES:-}" ]]; then + IFS=$' \t\n,' read -r -a exclude_tables <<< "$SYNC_EXCLUDE_TABLES" + for table in "${exclude_tables[@]}"; do + [[ -z "$table" ]] && continue + exclude_args+=(--exclude-table="$table" --exclude-table="${table}_id_seq") + done + echo "Excluding tables: ${exclude_tables[*]}" +fi + +# Plain SQL so we can CASCADE drops. Destination excluded tables keep their +# rows; CASCADE only removes leftover FKs that would block --clean. PGPASSWORD="$SYNC_SOURCE_PASSWORD" pg_dump \ -h "$SYNC_SOURCE_HOST" \ -p "$SYNC_SOURCE_PORT" \ @@ -13,13 +25,15 @@ PGPASSWORD="$SYNC_SOURCE_PASSWORD" pg_dump \ --no-privileges \ --clean \ --if-exists \ - --format=c | \ -PGPASSWORD="$SYNC_DEST_PASSWORD" pg_restore \ + "${exclude_args[@]}" | \ +sed -E \ + -e 's/^(DROP TABLE IF EXISTS .+);$/\1 CASCADE;/' \ + -e 's/^(ALTER TABLE .+ DROP CONSTRAINT IF EXISTS .+);$/\1 CASCADE;/' | \ +PGPASSWORD="$SYNC_DEST_PASSWORD" psql \ -h "$SYNC_DEST_HOST" \ -p "$SYNC_DEST_PORT" \ -U "$SYNC_DEST_USER" \ -d "$SYNC_DEST_DATABASE" \ - --clean \ - --if-exists + -v ON_ERROR_STOP=1 echo "Synchronization completed successfully: ${SYNC_SOURCE_DATABASE} -> ${SYNC_DEST_DATABASE}" diff --git a/script/database-sync/docker-compose.yml b/script/database-sync/docker-compose.yml index b88a7a65..1f396801 100644 --- a/script/database-sync/docker-compose.yml +++ b/script/database-sync/docker-compose.yml @@ -14,5 +14,6 @@ services: SYNC_DEST_USER: "postgres" SYNC_DEST_PASSWORD: "masterkey" SYNC_DEST_DATABASE: "herbario_dev" + # SYNC_EXCLUDE_TABLES: "public.usuarios" CRON_SCHEDULE: "*/2 * * * *" TZ: "America/Sao_Paulo"