@@ -2,19 +2,19 @@ import 'package:powersync/powersync.dart';
2
2
import 'package:powersync_flutter_local_only_demo/models/sync_mode.dart' ;
3
3
4
4
/// This schema design supports a local-only to sync workflow by managing data
5
- /// across two versions of each table: one for local/offline use and one for
6
- /// online/synced use. This approach simplifies the handling of data in different
7
- /// connectivity states.
5
+ /// across two versions of each table: one for local-only use without syncing before a user registers,
6
+ /// the other for sync-enabled use after the user registers/signs in.
8
7
///
9
8
/// See the README for details.
10
9
///
11
- /// For an offline-to-online transition [switchToSyncedSchema] copies data so that it ends up in the upload queue.
10
+ /// [switchToSyncedSchema] copies data from the local-only tables to the sync-enabled tables
11
+ /// so that it ends up in the upload queue.
12
12
13
13
const todosTable = 'todos' ;
14
14
const listsTable = 'lists' ;
15
15
16
16
Schema makeSchema ({synced = bool }) {
17
- String onlineName (String table) {
17
+ String syncedName (String table) {
18
18
if (synced) {
19
19
return table;
20
20
} else {
@@ -53,7 +53,7 @@ Schema makeSchema({synced = bool}) {
53
53
return Schema ([
54
54
for (var table in tables)
55
55
Table (table.name, table.columns,
56
- indexes: table.indexes, viewName: onlineName (table.name)),
56
+ indexes: table.indexes, viewName: syncedName (table.name)),
57
57
for (var table in tables)
58
58
Table .localOnly ('local_${table .name }' , table.columns,
59
59
indexes: table.indexes, viewName: localName (table.name))
@@ -68,8 +68,8 @@ switchToSyncedSchema(PowerSyncDatabase db, String userId) async {
68
68
await setSyncEnabled (true );
69
69
70
70
await db.writeTransaction ((tx) async {
71
- // Copy local-only data to the "online" views.
72
- // This records each operation to the crud queue.
71
+ // Copy local-only data to the sync-enabled tables/ views.
72
+ // This records each operation in the upload queue.
73
73
await tx.execute (
74
74
'INSERT INTO lists(id, name, created_at, owner_id) SELECT id, name, created_at, ? FROM inactive_local_lists' ,
75
75
[userId]);
0 commit comments