public function getSchemaFromMetadata(array $metadata)
    {
        $entityMetadataSchemaConfig = $this->schemaManager->createSchemaConfig();
        $schema = new Schema([], [], $entityMetadataSchemaConfig);
        $pivotTables = [];

        foreach ($metadata as $entityMetadata) {
            $this->generateTableFromMetadata($schema, $entityMetadata['table']);
            // create version table
            if (! empty($entityMetadata['versionTable'])) {
                $this->generateTableFromMetadata($schema, $entityMetadata['versionTable']);
            }

            foreach ($entityMetadata['relations'] as $relationMetadata) {
                if (! empty($relationMetadata['pivotTable'])) {
                    // create pivot table for many to many relations
                    if (! in_array($relationMetadata['pivotTable']['name'], $pivotTables)) {
                        $this->generateTableFromMetadata($schema, $relationMetadata['pivotTable']);
                    }

                    $pivotTables[] = $relationMetadata['pivotTable']['name'];
                }
            }
        }

        return $schema;
    }