Should `n8n import:workflow --input=file.json` keep workflow ID from json file or force to make a new incremented ID? What behavior is by design?

With a command n8n import:workflow --input=file.json you can import a workflow into n8n instance. And ID, the imported workflow will get, depends on database that n8n used under the hood: ID either kept from input json file or n8n creates new ID by incrementing last ID from database. That is obviously a bug, because behavior should be the same regardless of used database.

So question is: what behavior is by design? I suggest that keeping id from json file should be by design, because that way I can recreate exact copy of existing n8n instance. For example from development environment to production.

Below behavior for three databases:

  • SQLite (default database): IDs are kept from json file.
  • Postgres: n8n creates new IDs by incrementing
  • MySQL: IDs are kept from json file.

The interesting thing that SQL queries for postgres and mysql that creating new workflow (as a result of import command) are different:

  • Postgres: INSERT INTO "public"."workflow_entity"("name", "active", "nodes", "connections", "createdAt", "updatedAt", "settings", "staticData", "pinData") VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9)
  • MySQL: INSERT INTO workflow_entity(id, name, active, nodes, connections, createdAt, updatedAt, settings, staticData, pinData) VALUES (54, ...

As you can see, for Postgres value for ID field doesn’t passed. That might be ORM issue.

Hey @Andrew_Shmelev,

I feel like making a new ID would be the correct approach as if the current ID is 5 and your workflow is 10 when it runs you might hit an index issue, The other side is if you already have a workflow with an ID and you import a workflow someone else has made you probably wouldn’t want to overwrite an existing workflow.

I will add this one to our internal tracker so we can make sure it is consistent between platforms.

Hi, @Jon

  1. What do you mean by hitting an index issue? Suppose this: the last id in database is 5. I imported workflow with id = 10. Then, if I create a new workflow through a UI, new ID will be 11. This is for sure. No issue here.

  2. “The other side is if you already have a workflow with an ID and you import a workflow someone else has made you probably wouldn’t want to overwrite an existing workflow”. There is already instruments: API reference - n8n Documentation (create a new workflow using API) and in UI: “Import from file”, “Import from URL”. These are make a new ID (incremented). But CLI command n8n import:workflow --input=file.json that sets ID from json file is useful when you want to create an exact copy of n8n instance. I wrote about it above. Lets emphasize it again. Suppose you have dev instance of n8n with workflows. Some workflows links other by id. And you want to make exact copy of this instance for production. You can do it by importing workflows. And you want here to preserve all IDs the same. So if you guys want to make it possible for n8n users, then import:workflow should keep IDs by design.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.