diff --git a/scripts/schema-snapshot.sh b/scripts/schema-snapshot.sh index 0bf6998..5911724 100755 --- a/scripts/schema-snapshot.sh +++ b/scripts/schema-snapshot.sh @@ -152,7 +152,46 @@ if [[ "${copy_exit}" -ne 0 ]]; then fi # ----------------------------------------------------------------------------- -# Step 5 — Report success +# Step 5 — Strip ghost-collection entries +# +# Directus's `schema snapshot` auto-discovers every table in the public schema +# and registers it in the snapshot YAML, regardless of whether the table is +# Directus-managed. This includes db-init-owned tables (positions hypertable, +# migrations_applied guard table) which we intentionally do NOT want Directus +# to manage. +# +# On a fresh CI Postgres, db-init creates these tables before schema-apply +# runs. If the snapshot includes them, schema-apply tries to "Create" them +# again as Directus collections — fails with "Invalid payload. Collection +# X already exists" because the underlying table already exists from db-init. +# +# Filter them out post-snapshot. Only the `collections:` section is affected +# (these tables have no fields/relations registered in directus_fields / +# directus_relations, so they only appear at the top of the YAML). +# +# Add new ghost names to this list when introducing more db-init-only tables. +# ----------------------------------------------------------------------------- + +GHOST_COLLECTIONS=( "migrations_applied" "positions" ) + +log_info "stripping ghost-collection entries from snapshot" + +for ghost in "${GHOST_COLLECTIONS[@]}"; do + # awk pattern: skip the ` - collection: ` line and all its indented + # children (meta:, schema:, etc. — 4-space indent) until the next sibling + # ` - ` or top-level section header. + awk -v ghost="${ghost}" ' + BEGIN { skip = 0 } + $0 == " - collection: " ghost { skip = 1; next } + skip && /^ - / { skip = 0 } + skip && /^[^ ]/ { skip = 0 } + !skip { print } + ' "${HOST_SNAPSHOT_PATH}" > "${HOST_SNAPSHOT_PATH}.tmp" \ + && mv "${HOST_SNAPSHOT_PATH}.tmp" "${HOST_SNAPSHOT_PATH}" +done + +# ----------------------------------------------------------------------------- +# Step 6 — Report success # ----------------------------------------------------------------------------- # Compute the size of the written file for the one-line success log. diff --git a/snapshots/schema.yaml b/snapshots/schema.yaml index 65aaaaa..a614861 100644 --- a/snapshots/schema.yaml +++ b/snapshots/schema.yaml @@ -158,30 +158,6 @@ collections: versioning: false schema: name: events - - collection: migrations_applied - meta: - accountability: all - archive_app_filter: true - archive_field: null - archive_value: null - collapse: open - collection: migrations_applied - color: null - display_template: null - group: null - hidden: false - icon: null - item_duplication_fields: null - note: null - preview_url: null - singleton: false - sort: null - sort_field: null - translations: null - unarchive_value: null - versioning: false - schema: - name: migrations_applied - collection: organization_devices meta: accountability: all @@ -282,30 +258,6 @@ collections: versioning: false schema: name: organizations - - collection: positions - meta: - accountability: all - archive_app_filter: true - archive_field: null - archive_value: null - collapse: open - collection: positions - color: null - display_template: null - group: null - hidden: false - icon: null - item_duplication_fields: null - note: null - preview_url: null - singleton: false - sort: null - sort_field: null - translations: null - unarchive_value: null - versioning: false - schema: - name: positions - collection: vehicles meta: accountability: all