-
-
Notifications
You must be signed in to change notification settings - Fork 328
storage_t::sync_schema
std::map<std::string, sync_schema_result> sync_schema(bool preserve = false);
Compares database schema provided in storage with actual schema in database and performs automigration if something isn't equal.
Results of syncing a schema. Keys of map are equal table names and values are equal sync_schema_result
enum value defined in ::sqlite_orm
namespace.
enum class sync_schema_result {
/**
* created new table, table with the same tablename did not exist
*/
new_table_created,
/**
* table schema is the same as storage, nothing to be done
*/
already_in_sync,
/**
* removed excess columns in table (than storage) without dropping a table
*/
old_columns_removed,
/**
* lacking columns in table (than storage) added without dropping a table
*/
new_columns_added,
/**
* both old_columns_removed and new_columns_added
*/
new_columns_added_and_old_columns_removed,
/**
* old table is dropped and new is recreated. Reasons :
* 1. delete excess columns in the table than storage if preseve = false
* 2. Lacking columns in the table cannot be added due to NULL and DEFAULT constraint
* 3. Reasons 1 and 2 both together
* 4. data_type mismatch between table and storage.
*/
dropped_and_recreated,
};
sync_schema
call can eliminate all your data stored in database that's why you must know how it works if you care about your data. If you want to know what will happen to your tables after sync_schema
call you can call sync_schema_simulate
function and check returned value. sync_schema_simulate
returns same result that sync_schema
does but doesn't alter any table in fact.
sync_schema
iterates all tables specified in storage (not in actual database) and compares storage object's schema provided by make_table
function with actual schema in database.