<!-- Source: @site/projects/sqlens-for-laravel/docs/rules/pg-l4-drop-without-deploy-window.md -->
<!-- Canonical: https://docs.pushery.com/sqlens-for-laravel/rules/pg-l4-drop-without-deploy-window/ -->

# PG.L4.DROP_WITHOUT_DEPLOY_WINDOW — The previous release is still running

> A drop takes effect on commit. Every instance still serving the old release starts failing at that moment.

- **Category:** safety
- **Level:** 4
- **Confidence:** heuristic
- **Downtime class:** `online`
- **Stability:** stable
- **Suites:** lint
- **Applies to:** PostgreSQL 18

`PG.L1.DROP_TABLE` and `PG.L1.DROP_COLUMN` are about permanence. This rule is about **timing**, which
is why the same statement can produce both findings and they are not duplicates.

A drop takes effect the moment the migration commits. During a rolling deploy that moment lands in
the middle of a period where the previous release is still serving traffic — and still selecting the
object that just stopped existing. The errors start immediately, they come from instances that were
healthy a second ago, and they stop only when the last old instance is replaced.

## Why `heuristic`

The rule cannot see your deploy process. A project that stops all traffic, migrates, then starts the
new release has no overlap window and no problem. A project doing blue/green or a rolling restart
does. The finding names the risk; whether it applies is something only your pipeline knows, and it is
a perfectly reasonable one to accept with a reason.

## Flagged

```php
DB::statement('DROP TABLE legacy_events');
```

## Preferred

```php
// Release N stops reading legacy_events. Release N+1 drops it, in a migration annotated
// #[SqlensAllowDestructive] with the reason:
DB::statement('DROP TABLE legacy_events');
```

The statement does not change. What changes is when it runs: after a release that no longer reads
the table, in a later deploy, with the annotation saying so. A rename in between is no shortcut. The
release that still reads the table fails under the new name just as it would after the drop, which
is what `PG.L4.RENAME_WITHOUT_DEPLOY_WINDOW` reports.

## The expand–contract sequence

1. **Expand.** Add the new shape. Both releases work.
2. **Migrate.** Move readers and writers to it. Ship. Wait for the old release to be gone.
3. **Contract.** Drop the old shape, in its own migration, with the destructive annotation.

Steps 1 and 3 in one deploy is the whole failure this rule describes.

## The maintenance-window field

Findings that need one carry a `maintenance_window` note in the report — machine-readable, so a
deploy script can branch on it rather than a human having to remember. That field is why the rule
exists at level 4 rather than being folded into the level-1 destructive gate.

## Sources

- [PostgreSQL 18 — `ALTER TABLE`](https://www.postgresql.org/docs/18/sql-altertable.html) — dropping
  a table or column takes effect immediately on commit; an application instance still running the
  previous release fails from that moment

<!-- BEGIN generated: remediation -->
## The fix material this rule carries

A finding from this rule carries machine-readable fix material, using this sequence:

- **`deploy_window_drop`** — Drop across two deploy windows so a rollback in between still finds what it needs.

The payload is material for you or an agent to apply. SQLens writes no migration and runs no
DDL. See [the remediation payload](https://docs.pushery.com/sqlens-for-laravel/remediation-schema.md) for every field, the placeholder
semantics, and the version rules a consumer has to follow.
<!-- END generated: remediation -->
