Skip to content

Database is not recreated in Xcode Previews #449

@pro100filipp

Description

@pro100filipp

Description

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.
  • This issue hasn't been addressed in an existing GitHub issue or discussion.

Expected behavior

I expect that, similar to SwiftData, if we use an in-memory database, it will be recreated each time we run the preview.

Actual behavior

The database exists and is not recreated.

Reproducing project

SqliteDataPreview.zip

SQLiteData version information

1.6.1

Sharing version information

2.8.0

GRDB version information

7.10.0

Destination operating system

iOS 26

Xcode version information

Version 26.4

Swift Compiler version information

swift-driver version: 1.148.6 Apple Swift version 6.3 (swiftlang-6.3.0.123.5 clang-2100.0.123.102)
Target: arm64-apple-macosx26.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions