Additive Changes
Additive Changes
Example: Add a new table that a new version of the app depends on, or add a new column to an existing table.
- Apply source schema changes (i.e. in Postgres database) (often as a pre-deploy step as part of 2)
- Deploy backend application changes
- Deploy Sync Rule changes
- Wait for Sync Rule reprocessing to complete
- Publish the app (may be deployed with delayed publishing at any prior point)
Renaming a Table on the Server
Renaming a Table on the Server
The approach here is to have the Sync Rules handle both the old and the new table name during the migration period.Using maintenance mode on the backend here for simplicity. Other processes may be used to avoid maintenance mode, but that doesn’t affect PowerSync system.
- Deploy Sync Rules containing both the old and the new table name, with a mapping (alias) from the new name to the old one (so that both end up with the old name on the client). This will cause validation errors because of a missing table, but PowerSync will still allow the deploy.
- Wait for Sync Rule reprocessing to complete.
- Put the backend in maintenance mode.
- i.e. Backend needs to be made unavailable to avoid breaking things during migrations.
- Apply the source schema changes (i.e. in Postgres database)
- Deploy backend changes and re-activate backend.
- Remove the old table from Sync Rules, then deploy and activate the Sync Rules.
Renaming a Table on the Client
Renaming a Table on the Client
Pass in a “
schema_version” or similar parameter from the client, and use this in Sync Rules to use either the old or new table name in the data queries.See this section for details:Multiple Client VersionsRenaming a Table on Both Server and Client
Renaming a Table on Both Server and Client
Treat this as two separate steps and follow the process for both Renaming a Table on the Server and Renaming a Table on the Client.
Renaming a Column on the Server
Renaming a Column on the Server
Use the This may produce a validation error because of a missing column, but PowerSync will still allow the deploy.Once the changes have been deployed and replicated, the old reference can be removed from the Sync Rules:
ifnull function in Sync Rules to output whichever column is available. This would handle both the old and new schema versions:Renaming a Column on the Client
Renaming a Column on the Client
Use the same approach as for renaming tables.
Changing a Column Type
Changing a Column Type
If the column types have the same representation in Sync Rules, the type can be changed freely without issues (for example changing between
VARCHAR and TEXT).Other type changes, for example changing between INT and TEXT, require more care.To change the type, it is usually best to create a new column with the new type, then remove the old column once nothing uses it anymore.When changing the type of a column without renaming, use a column type mapping to still use the old type for existing client applications.