@redocly/replay 0.21.0-next.1 → 0.21.0-next.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1 +1,68 @@
1
1
  # Replay
2
+
3
+ ## Database Migrations
4
+
5
+ The Replay app uses different database backends depending on the platform:
6
+ - **Tauri (desktop)**: SQLite with Drizzle ORM
7
+ - **Web**: IndexedDB with the `idb` library
8
+
9
+ ### SQLite Migrations (Tauri)
10
+
11
+ SQLite schema is defined in `src/db/schema/` using Drizzle ORM. Migrations are auto-generated.
12
+
13
+ **To add a migration:**
14
+
15
+ 1. Update the schema in `src/db/schema/` (e.g., `history.schema.ts`)
16
+ 2. Generate the migration from the `apps/replay-app` directory:
17
+ ```bash
18
+ pnpm db:generate
19
+ ```
20
+ 3. This creates a new `.sql` file in `apps/replay-app/src-tauri/migrations/` with a unique name
21
+ 4. Migrations run automatically on app startup via the Rust backend
22
+ 5. Alternatively, manually create a new migration file in `apps/replay-app/src-tauri/migrations/`:
23
+ ```bash
24
+ # Format: YYYYMMDDHHMMSS_description.sql
25
+ src-tauri/migrations/20241224120000_add_user_settings.sql
26
+ ```
27
+
28
+ ```sql
29
+ -- Add new table
30
+ CREATE TABLE IF NOT EXISTS user_settings (
31
+ id TEXT PRIMARY KEY NOT NULL,
32
+ key TEXT NOT NULL UNIQUE,
33
+ value TEXT NOT NULL
34
+ );
35
+ ```
36
+
37
+ ### IndexedDB Migrations (Web)
38
+
39
+ IndexedDB uses version-based migrations.
40
+
41
+ **To add a migration:**
42
+
43
+ 1. Increment the version constant in the storage class (e.g., `HISTORY_DB_VERSION` in `HistoryIndexedDBStorage.ts`)
44
+ 2. Update the `setupDatabase()` method to handle both initial creation and upgrades:
45
+
46
+ ```typescript
47
+ const HISTORY_DB_VERSION = 2; // Increment for new migration
48
+
49
+ private static setupDatabase(db: IDBPDatabase<unknown>): void {
50
+ // Initial setup (runs for new databases)
51
+ if (!db.objectStoreNames.contains('history')) {
52
+ const store = db.createObjectStore('history', { keyPath: 'id' });
53
+ store.createIndex('by-date', 'date');
54
+ }
55
+
56
+ // Version 2: Add new index (runs on upgrade from v1)
57
+ const tx = db.transaction('history', 'readwrite');
58
+ const store = tx.objectStore('history');
59
+ if (!store.indexNames.contains('by-new-field')) {
60
+ store.createIndex('by-new-field', 'newField');
61
+ }
62
+ }
63
+ ```
64
+
65
+ **Best practices:**
66
+ - Always check if stores/indexes exist before creating
67
+ - Keep schema definitions in sync between SQLite and IndexedDB
68
+ - Test migrations with existing data before release