def create_model_storage(model)
name = self.name
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
statements = [ create_table_statement(connection, model, properties) ]
statements.concat(create_index_statements(model))
statements.concat(create_unique_index_statements(model))
statements.concat(create_sequence_statements(model))
statements.each do |statement|
command = connection.create_command(statement)
command.execute_non_query
end
end
end
true
end