def create_model_storage(model)
properties = model.properties_with_subclasses(name)
table_name = model.storage_name(name)
truncate_or_delete = self.class.auto_migrate_with
table_is_truncated = truncate_or_delete && @truncated_tables && @truncated_tables[table_name]
return false if storage_exists?(table_name) && !table_is_truncated
return false if properties.empty?
with_connection do |connection|
if table_is_truncated && storage_has_all_fields?(table_name, properties)
@truncated_tables[table_name] = nil
else
if truncate_or_delete
destroy_model_storage(model, true)
end
statement = create_table_statement(connection, model, properties)
command = connection.create_command(statement)
command.execute_non_query
(create_index_statements(model) + create_unique_index_statements(model)).each do |statement|
command = connection.create_command(statement)
command.execute_non_query
end
create_sequence_statements(model).each do |statement|
command = connection.create_command(statement)
command.execute_non_query
end
end
end
true
end