Skip to content

Make the Linear importer safe to run against a live database #307

Backlog

Description

@NathanTarbert

scripts/import-linear.ts copies Linear issues and their comments into Outpost tickets. It works for a first, one-off import into an empty database. Running it again, or against a database the bots are already writing to, can go wrong in five ways. These came up while reviewing #306, and none of them were introduced there.

Display IDs can collide with existing tickets. nextDisplayId reads the display ID of the most recently created ticket and runs parseInt on it to seed a counter. Tickets created by the bots and the web app get random IDs from generateTicketId(), such as TKT-K7QX2M9P. That parses to NaN, so the counter falls back to 1000 and starts reissuing numbers the previous import already used. Every create then fails on the unique displayId constraint and is counted as failed. Using generateTicketId() in the importer too would remove the counter altogether.

A failure partway through one issue leaves a ticket that a rerun duplicates. The ticket, its Linear external link and its comments are separate writes. If the link write fails after the ticket is created, the ticket stays in the database with no link. The rerun's skip check only looks for the link, so it creates a second ticket for the same Linear issue. Wrapping each issue's writes in prisma.$transaction keeps them together.

The page loop can run forever. If Linear reports hasNextPage: true with a null endCursor, the cursor becomes undefined and the next request fetches the first page again. Every issue on it is skipped as already linked, and the loop never ends. The loop should stop or throw when that happens.

Long comment threads are cut short. issue.comments() and issue.labels() are each called once, so only the first page comes back. An issue with a long thread is imported with part of its conversation missing, and the log line reports the smaller count as the total. Paging through until hasNextPage is false fixes it.

Imported tickets lose their original dates. Neither prisma.ticket.create nor prisma.message.create passes createdAt, so both get the import time. A six-month-old issue and all its comments show up as created within the same second. That breaks the order of the conversation, and any age- or SLA-based view treats the ticket as brand new. Passing issue.createdAt and comment.createdAt keeps the real history.

Activity

  1. joei4cm commented on Dec 2, 2026

    @joei4cm

    我们接手。会修复 Linear importer 的五类问题:使用随机 display ID、每个 issue 的事务化写入、分页 cursor 校验、评论与标签分页、保留原始创建时间,并补回归测试。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions