paperclip/packages/db/src/migrations
Dotta 0f08c2b526
fix(db): repair responsible user migration timestamps (#9146)
## Thinking Path

> - Paperclip is the open source app people use to manage AI agents for
work.
> - The database migration layer keeps local and deployed instances
moving forward safely as schema/data contracts evolve.
> - The responsible-user backfill migration could make historical issues
look newly updated by bumping user-visible `updated_at` columns during a
backfill.
> - That timestamp churn can invalidate inbox/archive state and make old
work appear fresh even though no user-facing activity happened.
> - This pull request moves the responsible-user invariant migration
later in the current migration sequence, keeps it from touching
user-visible timestamps, and adds a repair sweep for databases that
already saw the timestamp bump.
> - The benefit is safer migration replay and regression coverage for
future backfills that might otherwise mutate visible timestamps.

## Linked Issues or Issue Description

No public GitHub issue exists. Inline bug report:

**Pre-submission checklist**

- [x] I have searched existing open and closed issues and this is not a
duplicate.
- [x] I am on the latest released version of Paperclip (or can reproduce
on `master`).
- [x] I have confirmed the error originates in Paperclip itself — not in
my agent adapter, API provider, or local configuration.

**What happened?**

A responsible-user migration backfill could update user-visible
`updated_at` columns while filling missing responsible-user data. That
makes historical issues/runs/routines appear newer even when no
user-facing activity happened.

**Expected behavior**

Responsible-user backfills should populate ownership metadata without
mutating user-visible recency fields, and databases already affected by
a timestamp sweep should be repairable.

**Steps to reproduce**

1. Start from current `master` with the responsible-user migration
sequence.
2. Apply migrations to a database containing historical issues, runs,
routines, and companies with older activity timestamps.
3. Replay the responsible-user invariant migration and inspect
user-visible `updated_at` values.

**Paperclip version or commit**

`master` at the PR base.

**Deployment mode**

Local dev (`pnpm dev`) and deployed instances using the same migrations.

**Installation method**

Built from source (`pnpm dev` / `pnpm build`).

**Agent adapter(s) involved**

- [x] Not adapter-specific (core bug)

**Database mode**

External Postgres and embedded development Postgres migration paths.

**Access context**

Board and agent-visible issue recency can both be affected.

**Relevant logs or output**

Covered by the added embedded-Postgres regression tests.

**Relevant config (if applicable)**

Not applicable.

**Additional context**

This PR adapts an extracted local migration fix onto the current master
migration sequence, where `0133` is already occupied.

**Privacy checklist**

- [x] I have reviewed all pasted output for PII (usernames, file paths,
API keys, tokens, company names) and redacted where necessary.

## What Changed

- Renumbered the responsible-user invariant migration onto the current
master migration sequence.
- Added a repair migration that detects broad timestamp sweeps and
restores safer `updated_at` values for issues, heartbeat runs, routines,
routine runs, and companies.
- Added focused embedded-Postgres regression coverage for the relocated
migration, repair migration, and updated-at backfill allowlist.

## Verification

- `pnpm --filter @paperclipai/db run check:migrations`
- `/srv/paperclip/home/paperclipai/paperclip/node_modules/.bin/vitest
run packages/db/src/client.test.ts -t "migration 0134|migration
0135|unallowlisted migration backfills"`

## Risks

Migration behavior is the main risk. The PR intentionally changes the
active migration sequence by removing the old responsible-user invariant
slot and replaying that work later with a repair migration. Reviewers
should confirm this matches the intended release/migration policy for
installations that may already have applied the earlier migration.

> For core feature work, check [`ROADMAP.md`](ROADMAP.md) first and
discuss it in `#dev` before opening the PR. Feature PRs that overlap
with planned core work may need to be redirected — check the roadmap
first. See `CONTRIBUTING.md`.

## Model Used

OpenAI Codex, GPT-5.5 coding agent with repository tool use and local
shell execution. Context window was not surfaced by the runtime.

## Checklist

- [x] I have included a thinking path that traces from project context
to this change
- [x] I have specified the model used (with version and capability
details)
- [x] I have checked ROADMAP.md and confirmed this PR does not duplicate
planned core work
- [x] I have searched GitHub for duplicate or related PRs and linked
them above
- [x] I have either (a) linked existing issues with `Fixes: #` / `Closes
#` / `Refs #` OR (b) described the issue in-PR following the relevant
issue template
- [x] I have not referenced internal/instance-local Paperclip issues or
links (only public GitHub `#NNN` / `github.com/paperclipai/paperclip`
URLs)
- [x] My branch name describes the change (e.g. `docs/...`, `fix/...`)
and contains no internal Paperclip ticket id or instance-derived details
- [x] I have run tests locally and they pass
- [x] I have added or updated tests where applicable
- [x] I have updated relevant documentation to reflect my changes
- [x] I have considered and documented any risks above
- [ ] All Paperclip CI gates are green
- [ ] Greptile is 5/5 with no open P2s, recommendations, or follow-ups
- [ ] I will address all Greptile and reviewer comments before
requesting merge

---------

Co-authored-by: Paperclip <noreply@paperclip.ing>
2026-07-07 05:54:17 -05:00
..
meta fix(db): repair responsible user migration timestamps (#9146) 2026-07-07 05:54:17 -05:00
0000_mature_masked_marvel.sql
…
0001_fast_northstar.sql
…
0002_big_zaladane.sql
…
0003_shallow_quentin_quire.sql
…
0004_issue_identifiers.sql
…
0005_chief_luke_cage.sql
…
0006_overjoyed_mister_sinister.sql
…
0007_new_quentin_quire.sql
…
0008_amused_zzzax.sql
…
0009_fast_jackal.sql
…
0010_stale_justin_hammer.sql
…
0011_windy_corsair.sql
…
0012_perpetual_ser_duncan.sql
…
0013_dashing_wasp.sql
…
0014_many_mikhail_rasputin.sql
…
0015_project_color_archived.sql
…
0016_agent_icon.sql
…
0017_tiresome_gabe_jones.sql
…
0018_flat_sleepwalker.sql
…
0019_public_victor_mancha.sql
…
0020_white_anita_blake.sql
…
0021_chief_vindicator.sql
…
0022_company_brand_color.sql
…
0023_fair_lethal_legion.sql
…
0024_far_beast.sql
…
0025_nasty_salo.sql
…
0026_lying_pete_wisdom.sql
…
0027_tranquil_tenebrous.sql
…
0028_harsh_goliath.sql
…
0029_plugin_tables.sql
…
0030_rich_magneto.sql
…
0031_zippy_magma.sql
…
0032_pretty_doctor_octopus.sql
…
0033_shiny_black_tarantula.sql
…
0034_fat_dormammu.sql
…
0035_marvelous_satana.sql
…
0036_cheerful_nitro.sql
…
0037_friendly_eddie_brock.sql
…
0038_careless_iron_monger.sql
…
0039_fat_magneto.sql
…
0040_eager_shotgun.sql
…
0041_curly_maria_hill.sql
…
0042_spotty_the_renegades.sql
…
0043_reflective_captain_universe.sql
…
0044_illegal_toad.sql
…
0045_workable_shockwave.sql
…
0046_smooth_sentinels.sql
…
0047_overjoyed_groot.sql
…
0048_flashy_marrow.sql
…
0049_flawless_abomination.sql
…
0050_stiff_luckman.sql
…
0051_young_korg.sql
…
0052_mushy_trauma.sql
…
0053_sharp_wild_child.sql
…
0054_draft_routines.sql
…
0055_kind_weapon_omega.sql
…
0056_spooky_ultragirl.sql
…
0057_tidy_join_requests.sql
…
0058_wealthy_starbolt.sql
…
0059_plugin_database_namespaces.sql
…
0060_orange_annihilus.sql
…
0061_lively_thor_girl.sql
…
0062_routine_run_dispatch_fingerprint.sql
…
0063_issue_thread_interactions.sql
…
0064_issue_thread_interaction_idempotency.sql
…
0065_environments.sql
…
0066_issue_tree_holds.sql
…
0067_agent_default_environment.sql
…
0068_environment_local_driver_unique.sql
…
0069_liveness_recovery_dedupe.sql
…
0070_active_run_output_watchdog.sql
…
0071_default_hire_approval_off.sql
…
0072_large_sandman.sql
…
0073_shiny_salo.sql
…
0074_striped_genesis.sql
…
0075_cultured_sebastian_shaw.sql
…
0076_useful_elektra.sql
…
0077_unusual_karnak.sql
…
0078_white_darwin.sql
…
0079_company_search_document_indexes.sql
…
0080_company_search_fuzzystrmatch.sql
…
0081_optimal_dormammu.sql
…
0082_dry_vision.sql
…
0083_company_secret_provider_configs.sql
…
0084_issue_recovery_actions.sql
…
0085_tranquil_the_executioner.sql [codex] Add issue document locking (#6009) 2026-05-15 08:54:55 -05:00
0086_routine_env_runtime_contract.sql [codex] Add routine env secrets support (#6212) 2026-05-17 16:30:34 -05:00
0087_backfill_environment_manage_human_defaults.sql [codex] Add agent permissions and controls plan (#6386) 2026-05-22 08:12:52 -05:00
0088_backfill_principal_access_compatibility.sql [codex] Add agent permissions and controls plan (#6386) 2026-05-22 08:12:52 -05:00
0089_cloud_upstreams.sql [codex] Add local Cloud Upstream sync (#6548) 2026-05-22 09:56:22 -05:00
0090_resource_memberships.sql [codex] Add resource membership controls (#6677) 2026-05-25 13:12:41 -05:00
0091_old_swarm.sql [codex] Add document annotations and comments (#6733) 2026-05-26 06:41:23 -07:00
0092_mighty_puma.sql Add accepted-plan decomposition exact-once guards and UI state (#6831) 2026-05-28 23:30:18 -07:00
0093_giant_green_goblin.sql PAPA-430: workspace finalize gates + no-remote-git enforcement (#6969) 2026-05-29 08:25:29 -07:00
0094_backfill_archived_company_agent_pauses.sql fix: Stop archived companies from waking agents (#7478) 2026-06-03 21:07:14 -07:00
0095_issue_comment_tombstones.sql Redact deleted issue comments 2026-06-05 03:20:46 +00:00
0096_document_annotation_issue_comment_links.sql Redact deleted issue comments 2026-06-05 03:20:46 +00:00
0097_low_trust_source_trust.sql Add low-trust review containment (#7530) 2026-06-05 16:48:02 -05:00
0098_project_icon.sql Information Architecture + project/agent visual refresh (experimental) (#7543) 2026-06-06 09:17:27 -05:00
0099_skills_store_foundation.sql Build the Skills Store (#7990) 2026-06-11 14:02:09 -05:00
0100_skill_install_count_backfill.sql Build the Skills Store (#7990) 2026-06-11 14:02:09 -05:00
0101_plugin_company_id_tenant_isolation.sql feat(security): plugin tables get company_id FK for tenant isolation (#5865) 2026-06-12 10:17:19 -07:00
0102_managed_sandbox_dedup_index.sql fix(environments): partial unique index to dedup managed sandbox rows (#8247) 2026-06-17 16:09:45 -07:00
0103_agent_error_reason.sql fix(server): enforce agent secret binding sync across lifecycle flows (#8307) 2026-06-18 21:26:36 -07:00
0104_issue_watchdogs.sql [codex] feat(watchdog): add task watchdog control plane (#8339) 2026-06-19 15:38:52 -05:00
0105_instance_scoped_environments.sql refactor(environments): make execution environments instance-scoped (#8375) 2026-06-20 09:42:53 -07:00
0106_external_object_references.sql External object references across issue surfaces (#8512) 2026-06-23 08:27:19 -05:00
0107_external_object_display_metadata.sql External object references across issue surfaces (#8512) 2026-06-23 08:27:19 -05:00
0108_workspace_operations_issue_id.sql fix: upstream deployed document-comment, routine-annotation, workspace & board-polling fixes (#8536) 2026-06-23 09:00:14 -05:00
0109_routine_description_annotations.sql fix: upstream deployed document-comment, routine-annotation, workspace & board-polling fixes (#8536) 2026-06-23 09:00:14 -05:00
0110_document_company_cascade.sql fix: upstream deployed document-comment, routine-annotation, workspace & board-polling fixes (#8536) 2026-06-23 09:00:14 -05:00
0111_backfill_skill_create_human_defaults.sql [codex] Gate skill mutations with skills:create permission (#8616) 2026-06-25 09:49:10 -05:00
0112_rename_skill_create_permission_key.sql [codex] Gate skill mutations with skills:create permission (#8616) 2026-06-25 09:49:10 -05:00
0113_pipeline_foundation.sql Add pipeline workflow primitives and operator UI (#7903) 2026-06-26 12:02:44 -05:00
0114_pipeline_case_issue_unlinked_event.sql Add pipeline workflow primitives and operator UI (#7903) 2026-06-26 12:02:44 -05:00
0115_pipeline_routine_origin.sql Add pipeline workflow primitives and operator UI (#7903) 2026-06-26 12:02:44 -05:00
0116_pipeline_upstream_drift_event.sql Add pipeline workflow primitives and operator UI (#7903) 2026-06-26 12:02:44 -05:00
0117_pipeline_transition_forced_event.sql Add pipeline workflow primitives and operator UI (#7903) 2026-06-26 12:02:44 -05:00
0118_pipeline_case_agent_fanout.sql Add pipeline workflow primitives and operator UI (#7903) 2026-06-26 12:02:44 -05:00
0119_pipeline_drift_acknowledged_event.sql Add pipeline workflow primitives and operator UI (#7903) 2026-06-26 12:02:44 -05:00
0120_pipeline_stage_working_primitives.sql Add pipeline workflow primitives and operator UI (#7903) 2026-06-26 12:02:44 -05:00
0121_pipeline_automation_retry_effects.sql Add pipeline workflow primitives and operator UI (#7903) 2026-06-26 12:02:44 -05:00
0122_pipeline_case_documents.sql Add pipeline workflow primitives and operator UI (#7903) 2026-06-26 12:02:44 -05:00
0123_document_annotation_source_trust.sql Add pipeline workflow primitives and operator UI (#7903) 2026-06-26 12:02:44 -05:00
0124_agent_api_key_scope_config.sql [codex] Add built-in Hermes adapters (#8543) 2026-06-26 16:04:58 -05:00
0125_environment_custom_image_templates.sql Add reusable sandbox custom images (#8794) 2026-06-30 09:57:49 -07:00
0127_environment_custom_images_instance_scoped.sql Scope environment custom images to instance environments (#8850) 2026-07-01 23:57:31 -07:00
0128_user_specific_secrets.sql feat(secrets): add user-specific runtime secrets (#8825) 2026-07-05 05:58:20 -05:00
0129_agent_api_key_responsible_user.sql feat(secrets): add user-specific runtime secrets (#8825) 2026-07-05 05:58:20 -05:00
0131_repair_run_responsible_user_context_refs.sql Fix heartbeat run responsible user migration for identifier refs (#9107) 2026-07-06 13:14:18 -05:00
0132_issue_comment_derived_attribution_fast.sql fix(db): relocate slow 0126 issue-comment attribution backfill to fast idempotent 0132 (#9108) 2026-07-06 11:41:24 -07:00
0133_resource_membership_stars.sql [codex] Add starred resource sidebar controls (#9085) 2026-07-06 14:09:11 -05:00
0134_run_responsible_user_invariant.sql fix(db): repair responsible user migration timestamps (#9146) 2026-07-07 05:54:17 -05:00
0135_repair_run_responsible_user_updated_at_sweep.sql fix(db): repair responsible user migration timestamps (#9146) 2026-07-07 05:54:17 -05:00