Skip to content

storage_t::sync_schema

Yevgeniy Zakharov edited this page Nov 7, 2017 · 4 revisions
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.

Return value

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,
    };
Clone this wiki locally