content icon indicating copy to clipboard operation
content copied to clipboard

Support running multiple instances on v3

Open GerryWilko opened this issue 9 months ago • 4 comments

Is your feature request related to a problem? Please describe

Currently we are unable to reliably use Nuxt Content v3 with Nuxt Test Utils with multiple parallel workers as Nuxt Content adds content to a static set of SQL tables.

The following reproduction demonstrates the issue: https://github.com/GerryWilko/content-sql-repro

Describe the solution you'd like

I would like to be able to safely run Nuxt Content v3 with multiple Nuxt instances connecting to the same DB.

During module initialization all existing content tables are dropped: https://github.com/nuxt/content/blob/96a9c4a45b3d9966f84cf15564701d9bda5cc3d5/src/module.ts#L253-L254

If we are already dropping all the content tables on module initialization we could just use a set of scoped tables within the same DB with a unique ID generated on module init. This would allow for each Nuxt instance to only interact with its own tables.

This solution may be problematic for users that are not using the built in SQLite server as they will end up with many duplicate copies of their content files. However at present if they are running multiple instances then each one is perhaps unnecessarily clearing the content dbs and they may be hitting this race condition of instances clashing with each other on start.

Describe alternatives you've considered

Alternatively we instead stop calling dropContentTables on module initialization and instead perform a clean-up operation of orphaned content files in each content table after content has been injected into and overwritten what is already present.

Additional context

GerryWilko avatar Mar 21 '25 17:03 GerryWilko

I was thinking more about this over the weekend. Is the main purpose of the dropContentTables call during module initialization to ensure that content files are always up to date?

If so would it not be better to hash the collection before creating the tables and then add the hash to the end of the table name so it would end up looking something like _content_something_xxxx. Then you can drop all collections not matching the current expected table name with hash and create any missing tables from the source files.

This could provide a much more efficient startup and would resolve the issue with multiple running Nuxt instances.

GerryWilko avatar Mar 24 '25 09:03 GerryWilko

@GerryWilko I think I'm running into this as well ("Nuxt Test Utils with multiple parallel workers"), wondering if you've found any workarounds?

case-fastly avatar Mar 31 '25 23:03 case-fastly

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 30 days.

github-actions[bot] avatar May 30 '25 23:05 github-actions[bot]

Bumping this issue, because it's had no activity. :/

case-fastly avatar May 31 '25 00:05 case-fastly

This issue is stale because it has been open 60 days with no activity. Remove stale label or comment or this will be closed in 30 days.

github-actions[bot] avatar Jul 30 '25 00:07 github-actions[bot]

This issue was closed because it has been stalled for 30 days with no activity.

github-actions[bot] avatar Aug 29 '25 02:08 github-actions[bot]