You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using it in preview, it seems the database is preserved between preview runs, not recreated anew. It clearly exists in memory (not on disk), and the context shows we are inside the preview.
This is evident because when the preview is run again, the console shows a unique constraint violation error on the table. In other words, the database already exists and contains the corresponding record.
SQLite error 19: UNIQUE constraint failed: examples.id - while executing `INSERT INTO "examples" ("id", "name") VALUES (?, ?)`
Checklist
I have determined whether this bug is also reproducible in a vanilla SwiftUI project.
I have determined whether this bug is also reproducible in a vanilla GRDB project.
If possible, I've reproduced the issue using the main branch of this package.
An in-memory SQLite database survives for as long as its connection is retained, and Xcode can rerun a preview without restarting the preview process, so tying reset behavior only to XCODE_RUNNING_FOR_PREVIEWS may still be ambiguous. It would help to establish whether the package promises a fresh database per preview process, per preview render, or per dependency construction. A regression test that constructs the preview dependency twice and performs the same unique insert would make the desired lifetime explicit without changing normal in-memory database semantics.
Hi @pro100filipp, this is just how previews work. They can execute multiple times in the same process. To work around this fact you can use stable IDs for all of your seed data and perform upsets instead of inserts.
Since this isn't an issue with the library I am going to convert it to a discussion. Please feel free to continue the conversation over there!
Activity
hiSandog commentedon Jul 10, 2026
An in-memory SQLite database survives for as long as its connection is retained, and Xcode can rerun a preview without restarting the preview process, so tying reset behavior only to
XCODE_RUNNING_FOR_PREVIEWSmay still be ambiguous. It would help to establish whether the package promises a fresh database per preview process, per preview render, or per dependency construction. A regression test that constructs the preview dependency twice and performs the same unique insert would make the desired lifetime explicit without changing normal in-memory database semantics.mbrandonw commentedon Jul 20, 2026
Hi @pro100filipp, this is just how previews work. They can execute multiple times in the same process. To work around this fact you can use stable IDs for all of your seed data and perform
upsets instead ofinserts.Since this isn't an issue with the library I am going to convert it to a discussion. Please feel free to continue the conversation over there!