Skip to content

Commit 8ff3e57

Browse files
committed
Documentation edits made through Mintlify web editor
1 parent 37e3d9a commit 8ff3e57

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

usage/lifecycle-maintenance/implementing-schema-changes.mdx

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@ title: "Implementing Schema Changes"
66

77
The [PowerSync protocol](/architecture/powersync-protocol) is schemaless, and not directly affected by schema changes.
88

9-
Replicating data from the source database to [sync buckets](/usage/sync-rules) may be affected by server-side changes to the schema (in the case of Postgres), and may need reprocessing in some cases.
9+
Replicating data from the source database to [sync buckets](/usage/sync-rules) may be affected by server-side changes to the schema (in the case of Postgres), and may need [reprocessing](/usage/lifecycle-maintenance/compacting-buckets) in some cases.
1010

1111
The [client-side schema](/installation/client-side-setup/define-your-schema) is just a view on top of the schemaless data. Updating this client-side schema is immediate when the new version of the app runs, with no client-side migrations required.
1212

1313
The developer is responsible for keeping client-side schema changes backwards-compatible with older versions of client apps. PowerSync has some functionality to assist with this:
1414

1515
1. [Different Sync Rules](/usage/sync-rules/advanced-topics/multiple-client-versions) can be applied based on [parameters](/usage/sync-rules/advanced-topics/client-parameters) such as client version.
16+
1617
2. Sync Rules can apply simple [data transformations](/usage/sync-rules/data-queries) to keep data in a format compatible with older clients.
1718

1819
## Client-Side Impact of Schema and Sync Rule Changes
@@ -22,28 +23,39 @@ As mentioned above, the PowerSync system itself is schemaless — the client syn
2223
The schema as supplied on the client is only a view on top of the schemaless data.
2324

2425
1. If tables/collections not described by the client-side schema are synced, it is stored internally, but not accessible.
26+
2527
2. Same applies for columns/field not described by the client-side schema.
28+
2629
3. When there is a type mismatch, SQLite's `CAST` functionality is used to cast to the type described by the schema.
30+
2731
1. Data is internally stored as JSON.
32+
2833
2. SQLite's `CAST` is used to cast values to `TEXT`, `INTEGER` or `REAL`.
34+
2935
3. Casting between types should never error, but it may not fully represent the original data. For example, casting an arbitrary string to `INTEGER` will likely result in a "0" value.
36+
3037
4. Full rules for casting between types are described [in the SQLite documentation here](https://www.sqlite.org/lang%5Fexpr.html#castexpr).
38+
3139
4. Removing a table/collection is handled on the client as if the table exists with no data.
40+
3241
5. Removing a column/field is handled on the client as if the values are `undefined`.
3342

3443
Nothing in PowerSync will fail hard if there are incompatible schema changes. But depending on how the app uses the data, app logic may break. For example, removing a table/collection that the app actively uses may break workflows in the app.
3544

3645
To avoid certain types of breaking changes on older clients, Sync Rule [transformations](/usage/sync-rules/data-queries) may be used.
3746

38-
## <Icon icon="elephant" iconType="solid" size="24"/> Postgres Specifics
47+
## <Icon icon="elephant" iconType="solid" size="24" /> Postgres Specifics
3948

4049
PowerSync keeps the [sync buckets](/usage/sync-rules/organize-data-into-buckets) up to date with any incremental data changes, as recorded in the Postgres [WAL](https://www.postgresql.org/docs/8.0/wal.html) / received in the logical replication stream. This is also referred to as DML (Data Manipulation Language) queries.
4150

4251
However, this does not include DDL (Data Definition Language), which includes:
4352

4453
1. Creating, dropping or renaming tables.
54+
4555
2. Changing replica identity of a table.
56+
4657
3. Adding, dropping or renaming columns.
58+
4759
4. Changing the type of a column.
4860

4961
### Postgres schema changes affecting Sync Rules
@@ -58,7 +70,7 @@ The new table is detected as soon as data is inserted.
5870

5971
#### DROP and re-CREATE table
6072

61-
This is a special case of combining `DROP` and `CREATE`. If a dropped table is created again, _and_ data is inserted into the new table, the schema change is detected by PowerSync. PowerSync will delete the old data in this case, as if `TRUNCATE` was called before dropping.
73+
This is a special case of combining `DROP` and `CREATE`. If a dropped table is created again, *and* data is inserted into the new table, the schema change is detected by PowerSync. PowerSync will delete the old data in this case, as if `TRUNCATE` was called before dropping.
6274

6375
#### RENAME table
6476

@@ -73,13 +85,17 @@ This may be a slow operation if the table is large, and all other replication wi
7385
The replica identity of a table is considered changed if either:
7486

7587
1. The type of replica identity changes (`DEFAULT`, `INDEX`, `FULL`, `NOTHING`).
88+
7689
2. The name or type of columns part of the replica identity changes.
7790

7891
The latter can happen if:
7992

8093
1. Using `REPLICA IDENTITY FULL`, and any column is added, removed, renamed, or the type changed.
94+
8195
2. Using `REPLICA IDENTITY DEFAULT`, and the type of any column in the primary key is changed.
96+
8297
3. Using `REPLICA IDENTITY INDEX`, and the type of any column in the replica index is changed.
98+
8399
4. The primary key or replica index is removed or changed.
84100

85101
When the replica identity changes, the entire table is re-replicated again. This may be a slow operation if the table is large, and all other replication will be blocked until the table is replicated again.
@@ -107,21 +123,22 @@ If a table is added to the publication, it is treated the same as a new table, a
107123
There are additional changes that can be made to a table in a publication:
108124

109125
1. Which operations are replicated (insert, update, delete and truncate).
126+
110127
2. Which rows are replicated (row filters).
111128

112129
Those changes are not automatically picked up by PowerSync during replication, and can cause PowerSync to miss changes if the changes are filtered out. PowerSync will not automatically recover the data when for example removing a row filter. Use these with caution.
113130

114-
## <Icon icon="leaf" iconType="solid" size="24"/> MongoDB (Alpha) Specifics
131+
## <Icon icon="leaf" iconType="solid" size="24" /> MongoDB (Alpha) Specifics
115132

116133
<Info>
117-
This section is a work in progress. More details for MongoDB connections are coming soon. In the meantime, check our [MongoDB guide](/migration-guides/mongodb-atlas) to try out our MongoDB alpha support, and ask on our [Discord server](https://discord.gg/powersync) if you have any questions.
134+
This section is a work in progress. More details for MongoDB connections are coming soon. In the meantime, check our [MongoDB guide](/migration-guides/mongodb-atlas) to try out our MongoDB alpha support, and ask on our [Discord server](https://discord.gg/powersync) if you have any questions.
118135
</Info>
119136

120137
Since MongoDB is generally schemaless, there are generally no schema changes that impact PowerSync.
121138

122139
However, dropping and renaming collections in MongoDB needs to be taken into consideration. More details on this will be documented soon.
123140

124-
## <Icon icon="dolphin" iconType="solid" size="24"/> MySQL (Alpha) Specifics
141+
## <Icon icon="dolphin" iconType="solid" size="24" /> MySQL (Alpha) Specifics
125142

126143
<Info>
127144
This section is a work in progress. More details for MySQL connections are coming soon. In the meantime, ask on our [Discord server](https://discord.gg/powersync) if you have any questions.
@@ -130,4 +147,5 @@ However, dropping and renaming collections in MongoDB needs to be taken into con
130147
## See Also
131148

132149
* [Custom Types, Arrays and JSON](/usage/use-case-examples/custom-types-arrays-and-json)
133-
* [Deploying Schema Changes](/usage/lifecycle-maintenance/deploying-schema-changes)
150+
151+
* [Deploying Schema Changes](/usage/lifecycle-maintenance/deploying-schema-changes)

0 commit comments

Comments
 (0)