@@ -39,25 +39,16 @@ fn update_tables(db: *mut sqlite::sqlite3, schema: &Schema) -> Result<(), PowerS
3939 // In a block so that all statements are finalized before dropping tables.
4040 for table in & schema. tables {
4141 if let Some ( existing) = existing_tables. remove ( & * table. name ) {
42- if existing. local_only && !table. local_only ( ) {
43- // Migrate from a local-only to a synced table. Because none of the local writes
44- // would have created CRUD entries, we'll have to re-create the table from
45- // scratch.
42+ if existing. local_only != table. local_only ( ) {
43+ // Migrating between local-only and synced tables. This works by deleting
44+ // existing and re-creating the table from scratch. We can re-create first and
45+ // delete the old table afterwards because they have a different name
46+ // (local-only tables have a ps_data_local prefix).
4647
4748 // To delete the old existing table in the end.
4849 existing_tables. insert ( & existing. name , existing) ;
49- } else if !existing. local_only && table. local_only ( ) {
50- // Migrate from a synced table to a local-only table. We can keep existing rows
51- // and will also keep existing CRUD data to be uploaded before the switch.
52- db. exec_safe ( & format ! (
53- "ALTER TABLE {} RENAME TO {}" ,
54- quote_identifier( & existing. internal_name) ,
55- quote_identifier( & table. internal_name( ) ) ,
56- ) )
57- . into_db_result ( db) ?;
58- continue ;
5950 } else {
60- // Identical table exists already, nothing to do.
51+ // Compatible table exists already, nothing to do.
6152 continue ;
6253 }
6354 }
0 commit comments