dcg

BigQuery

database.bigquery

Protects the `bq` CLI and GoogleSQL against dataset drops, table overwrites, unfiltered DML, and settings that shorten the time-travel recovery window

  • 32blocking rules
  • 0safe patterns
  • 3Critical
  • 21High
  • 8Medium
~/.config/dcg/config.toml
[packs]
enabled = ["database.bigquery"]

Evaluated when a command contains bq, bigquery, DROP, TRUNCATE, DELETE, UPDATE, ALTER, OVERWRITE.

Blocking rules

Each rule ID is database.bigquery:<name>. Use it in allowlists and [policy.rules].

  1. bq-rm-recursive

    Critical

    bq rm -r deletes a dataset and every table, view, and routine inside it.

    Explanation
    Recursive removal deletes the dataset together with all of its contents in one call. Individual tables can sometimes be recovered from time travel within 2-7 days, but the dataset itself cannot be restored once dropped. Inspect the contents first: bq ls <project>:<dataset>
  2. drop-schema

    Critical

    DROP SCHEMA removes a BigQuery dataset and everything inside it.

    Explanation
    In GoogleSQL a *dataset* is a SCHEMA, so this is the dataset-level catastrophe rather than a namespace tidy-up. With CASCADE it removes every table, view, and routine in the dataset. Individual tables may be recoverable from time travel for 2-7 days; the dataset is not. List the contents first: bq ls <project>:<dataset>
  3. drop-snapshot-table

    Critical

    DROP SNAPSHOT TABLE destroys a point-in-time backup.

    Explanation
    A table snapshot is often the backup taken precisely because time travel is too short. Dropping it removes the recovery point itself, and unlike the source table it has no time-travel window of its own.
  4. alter-set-expiration

    High

    SET OPTIONS(expiration_timestamp) schedules automatic deletion.

    Explanation
    An expiration timestamp is a deferred delete: the object disappears at that time with no further prompt. Setting it in the past deletes immediately.
  5. alter-table-drop-column

    High

    ALTER TABLE DROP COLUMN removes a column and its data.

    Explanation
    Dropping a column deletes its values. Time travel recovers the whole table to a prior point rather than restoring one column, so recovery means reconstructing the table.
  6. bq-cp-force

    High

    bq cp -f overwrites the destination table without prompting.

    Explanation
    `-f` suppresses the overwrite confirmation, so an existing destination table is replaced silently. Copying onto the wrong destination is not detectable after the fact except through time travel. Check whether the destination already exists: bq show <project>:<dataset>.<table>
  7. bq-load-replace

    High

    bq load --replace overwrites all existing data in the destination table.

    Explanation
    `--replace` truncates the destination table before loading. If the source file is wrong, short, or malformed, the previous contents are already gone and only time travel can recover them. Safer alternative: - bq load --noreplace: append instead of overwriting - load into a staging table first, then swap
  8. bq-query-replace

    High

    bq query --replace overwrites the destination table with the query result.

    Explanation
    `--replace` discards the destination table's current contents before writing the result. A query that returns fewer rows than expected silently destroys the difference. Safer alternative: - bq query --append_table: add rows instead of replacing them - bq query --dry_run: check what the query would process first
  9. bq-rm

    High

    bq rm deletes a table, view, model, or dataset.

    Explanation
    Deletion is immediate. A table may be recoverable from time travel within the dataset's window (2-7 days) using the `@<epoch_ms>` decorator, but only if nothing recreates the name in the meantime; datasets and models have no such recovery. Confirm the target first: bq show <project>:<dataset>.<table>
  10. bq-rm-reservation

    High

    bq rm --reservation removes purchased capacity and can change query cost and performance.

    Explanation
    Reservations and capacity commitments are billing objects. Removing one moves the affected workloads onto on-demand pricing, which changes both cost and concurrency behaviour immediately. Inspect the reservation first: bq show --reservation --location=<location> <name>
  11. bq-rm-transfer-config

    High

    bq rm --transfer_config deletes a scheduled query or data transfer.

    Explanation
    Removing a transfer config stops the scheduled load or query silently — the next run simply never happens, and the schedule, destination, and parameters are gone with it. Record the config before removing it: bq show --transfer_config <resource-name>
  12. bq-update-expiration

    High

    bq update --expiration schedules automatic deletion of tables or partitions.

    Explanation
    An expiration is a deferred delete. Setting one on a dataset applies to tables created afterwards; setting one on a table schedules that table's removal. The deletion happens later, without a prompt, and is easy to forget was configured. Inspect the current setting: bq show --format=prettyjson <project>:<dataset>
  13. bq-update-time-travel

    High

    bq update --max_time_travel_hours shortens the only window in which deleted BigQuery data can be recovered.

    Explanation
    Time travel (48-168 hours) is BigQuery's only undo. Lowering it discards history immediately and irreversibly: data older than the new window cannot be recovered afterwards, including data you have not yet noticed is missing. This destroys the recovery path itself rather than any single table. Take a snapshot before shortening the window: bq cp <dataset>.<table>@<epoch_ms> <dataset>.<table>_backup
  14. create-or-replace-table

    High

    CREATE OR REPLACE TABLE discards the existing table and its data.

    Explanation
    This is a drop and recreate in one statement: the old rows are gone before the new ones are written. A query that produces fewer rows than expected destroys the difference silently. Safer alternative: - CREATE TABLE IF NOT EXISTS: fails instead of overwriting - write to a staging table and swap after verifying
  15. delete-all-rows

    High

    DELETE ... WHERE TRUE removes every row in the table.

    Explanation
    In GoogleSQL a WHERE clause is mandatory on DELETE, so `WHERE TRUE` is the idiomatic way to spell "delete everything" — it is a full-table delete, not a filtered one. Recovery is time travel only. Check the blast radius first: SELECT COUNT(*) FROM `<table>` WHERE <your-predicate>
  16. drop-all-row-access-policies

    High

    DROP ROW ACCESS POLICY removes row-level security from a table.

    Explanation
    This does not delete data — it exposes it. Every row previously filtered by a policy becomes visible to anyone with table access, which is a disclosure event rather than a data-loss one, and it is silent.
  17. drop-capacity-or-reservation

    High

    DROP CAPACITY/RESERVATION/ASSIGNMENT changes billing and query capacity.

    Explanation
    These are billing objects. Dropping one moves affected workloads to on-demand pricing immediately, changing both cost and concurrency.
  18. drop-model

    High

    DROP MODEL deletes a trained BigQuery ML model.

    Explanation
    A model is not covered by time travel and cannot be restored — rebuilding it means re-running training over the original data, which costs both money and hours, and reproduces the result only if that training data still exists in the same form. Copy it first: bq cp <dataset>.<model> <dataset>.<model>_backup
  19. drop-routine

    High

    DROP FUNCTION/PROCEDURE/TABLE FUNCTION removes a routine other queries may depend on.

    Explanation
    Routine definitions are not covered by time travel. Anything calling the routine — scheduled queries, views, downstream jobs — starts failing at its next run. Capture the definition first: SELECT ddl FROM `<project>.<dataset>.INFORMATION_SCHEMA.ROUTINES`
  20. drop-table

    High

    DROP TABLE removes a table and its data.

    Explanation
    The table may be recoverable from time travel within the dataset's window (2-7 days) via `<table>@<epoch_ms>`, but only if nothing recreates the name in the meantime — recreating it starts a fresh history and forecloses recovery. Snapshot before dropping: bq cp <dataset>.<table>@<epoch_ms> <dataset>.<table>_backup
  21. load-data-overwrite

    High

    LOAD DATA OVERWRITE replaces all existing data in the destination table.

    Explanation
    `OVERWRITE` truncates the destination before loading. If the source is wrong or short, the previous contents are already gone. Safer alternative: - LOAD DATA INTO: append instead of replacing
  22. merge-delete-not-matched-by-source

    High

    MERGE ... WHEN NOT MATCHED BY SOURCE THEN DELETE removes every target row absent from the source.

    Explanation
    The delete is driven by what the source query returns. If the source is empty, filtered, or partially loaded, this deletes most or all of the target table — and the statement looks routine in review. Check what the source actually returns first: SELECT COUNT(*) FROM (<source-query>)
  23. truncate-table

    High

    TRUNCATE TABLE removes every row in the table.

    Explanation
    All rows are deleted while the schema stays in place. Recovery is time travel only, within the dataset's 2-7 day window.
  24. update-all-rows

    High

    UPDATE ... WHERE TRUE rewrites every row in the table.

    Explanation
    `WHERE TRUE` is the idiomatic full-table spelling in GoogleSQL, where the WHERE clause is mandatory. Every row is rewritten, and the prior values are recoverable only through time travel. Check the blast radius first: SELECT COUNT(*) FROM `<table>` WHERE <your-predicate>
  25. alter-table-rename

    Medium

    ALTER TABLE RENAME TO breaks every reference to the old table name.

    Explanation
    Renaming is not itself data loss, but views, scheduled queries, and downstream jobs referencing the old name fail at their next run, and a later `CREATE TABLE` reusing the old name makes the break silent.
  26. bq-cancel

    Medium

    bq cancel stops a running job, which may leave a partial load or export.

    Explanation
    Cancelling a load or export mid-flight can leave the destination in a partial state: some files written, some rows loaded. Check what the job is doing before stopping it. Inspect the job first: bq show --job=true <job-id>
  27. bq-mk-force

    Medium

    bq mk -f overwrites an existing table definition.

    Explanation
    `bq mk -f` succeeds when the object already exists, replacing its definition rather than failing. Recreating a table this way drops the existing rows. Check first: bq show <project>:<dataset>.<table>
  28. create-or-replace-routine

    Medium

    CREATE OR REPLACE FUNCTION/PROCEDURE overwrites an existing routine definition.

    Explanation
    The previous definition is discarded with no version history. If the new body is wrong, the old one must be reconstructed from source control or memory.
  29. drop-materialized-view-or-external-table

    Medium

    DROP MATERIALIZED VIEW / EXTERNAL TABLE removes a derived or federated object.

    Explanation
    A materialized view holds precomputed data that must be rebuilt, which costs a full refresh; an external table definition carries the schema and source URIs needed to read the underlying files. Neither the data nor the definition is recoverable from time travel.
  30. drop-search-index

    Medium

    DROP SEARCH INDEX removes an index that must be fully rebuilt.

    Explanation
    Rebuilding a search or vector index over a large table is expensive and not instantaneous; queries relying on it degrade to full scans in the meantime.
  31. drop-view

    Medium

    DROP VIEW removes a view definition.

    Explanation
    View definitions are not covered by time travel. Downstream queries and dashboards referencing the view break at their next run. Capture the definition first: SELECT view_definition FROM `<project>.<dataset>.INFORMATION_SCHEMA.VIEWS`
  32. export-data-overwrite

    Medium

    EXPORT DATA with overwrite=true replaces files at the destination URI.

    Explanation
    Existing objects under the destination prefix in Cloud Storage are replaced. If the bucket is not versioned, the previous export is unrecoverable.